From 282d17ad1c5bdf257357106ae1071e0b07f01909 Mon Sep 17 00:00:00 2001 From: serso Date: Mon, 22 Feb 2016 13:19:30 +0100 Subject: [PATCH] Editor text size --- .../android/calculator/EditorView.java | 11 +++++++++-- .../org/solovyev/android/views/Adjuster.java | 16 +++++++++++----- app/src/main/res/layout/onscreen_editor.xml | 18 ++++-------------- .../main/res/layout/onscreen_editor_light.xml | 18 ++++-------------- app/src/main/res/layout/onscreen_layout.xml | 3 +-- .../layout/onscreen_layout_material_light.xml | 3 +-- app/src/main/res/values-large-hdpi/dimens.xml | 1 - app/src/main/res/values-large-mdpi/dimens.xml | 1 - app/src/main/res/values-large-tvdpi/dimens.xml | 1 - app/src/main/res/values-large/dimens.xml | 1 + app/src/main/res/values-normal/dimens.xml | 2 +- app/src/main/res/values-small/dimens.xml | 2 +- app/src/main/res/values-xlarge-hdpi/dimens.xml | 1 - app/src/main/res/values-xlarge-mdpi/dimens.xml | 1 - app/src/main/res/values-xlarge/dimens.xml | 1 + app/src/main/res/values/dimens.xml | 2 +- app/src/main/res/values/styles.xml | 5 ++++- 17 files changed, 39 insertions(+), 48 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/EditorView.java b/app/src/main/java/org/solovyev/android/calculator/EditorView.java index 70e5f740..0a996d85 100644 --- a/app/src/main/java/org/solovyev/android/calculator/EditorView.java +++ b/app/src/main/java/org/solovyev/android/calculator/EditorView.java @@ -65,7 +65,10 @@ public class EditorView extends EditTextCompat { } private void init() { - Adjuster.adjustText(this, 0.25f); + if (!isFloatingCalculator()) { + Adjuster.adjustText(this, 0.22f, + getResources().getDimensionPixelSize(R.dimen.cpp_min_editor_text_size)); + } addTextChangedListener(new MyTextWatcher()); dontShowSoftInputOnFocusCompat(); // changes should only be reported after the view has been set up completely, i.e. now @@ -86,7 +89,7 @@ public class EditorView extends EditTextCompat { Check.isMainThread(); // we don't want to be notified about changes we make ourselves reportChanges = false; - if (App.getTheme().light && getContext() instanceof FloatingCalculatorService) { + if (App.getTheme().light && isFloatingCalculator()) { // don't need formatting setText(state.getTextString()); } else { @@ -96,6 +99,10 @@ public class EditorView extends EditTextCompat { reportChanges = true; } + private boolean isFloatingCalculator() { + return getContext() instanceof FloatingCalculatorService; + } + @Override protected void onSelectionChanged(int start, int end) { Check.isMainThread(); diff --git a/app/src/main/java/org/solovyev/android/views/Adjuster.java b/app/src/main/java/org/solovyev/android/views/Adjuster.java index d2fa193e..7f906221 100644 --- a/app/src/main/java/org/solovyev/android/views/Adjuster.java +++ b/app/src/main/java/org/solovyev/android/views/Adjuster.java @@ -1,5 +1,7 @@ package org.solovyev.android.views; +import static android.graphics.Matrix.MSCALE_Y; + import android.graphics.drawable.Drawable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -9,18 +11,20 @@ import android.view.ViewTreeObserver; import android.widget.ImageView; import android.widget.TextView; -import static android.graphics.Matrix.MSCALE_Y; - public class Adjuster { private static final float[] MATRIX = new float[9]; public static void adjustText(@NonNull final TextView view, final float percentage) { + adjustText(view, percentage, 0); + } + + public static void adjustText(@NonNull final TextView view, final float percentage, final float minTextSizePxs) { ViewTreeObserver treeObserver = getTreeObserver(view); if (treeObserver == null) { return; } - treeObserver.addOnPreDrawListener(new TextViewAdjuster(view, percentage)); + treeObserver.addOnPreDrawListener(new TextViewAdjuster(view, percentage, minTextSizePxs)); } @Nullable @@ -47,11 +51,13 @@ public class Adjuster { @NonNull private final TextView view; private final float percentage; + private final float minTextSizePxs; private int lastHeight; - public TextViewAdjuster(@NonNull TextView view, float percentage) { + public TextViewAdjuster(@NonNull TextView view, float percentage, float minTextSizePxs) { this.view = view; this.percentage = percentage; + this.minTextSizePxs = minTextSizePxs; } @Override @@ -62,7 +68,7 @@ public class Adjuster { } lastHeight = height; final float oldTextSize = Math.round(view.getTextSize()); - final float newTextSize = Math.round(height * percentage); + final float newTextSize = Math.max(minTextSizePxs, Math.round(height * percentage)); if (oldTextSize == newTextSize) { return true; } diff --git a/app/src/main/res/layout/onscreen_editor.xml b/app/src/main/res/layout/onscreen_editor.xml index 777b5c34..e88fe6b1 100644 --- a/app/src/main/res/layout/onscreen_editor.xml +++ b/app/src/main/res/layout/onscreen_editor.xml @@ -6,17 +6,7 @@ ~ or visit http://se.solovyev.org --> - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/onscreen_editor_light.xml b/app/src/main/res/layout/onscreen_editor_light.xml index bf97f6a0..38945920 100644 --- a/app/src/main/res/layout/onscreen_editor_light.xml +++ b/app/src/main/res/layout/onscreen_editor_light.xml @@ -6,17 +6,7 @@ ~ or visit http://se.solovyev.org --> - - - - - \ No newline at end of file + diff --git a/app/src/main/res/layout/onscreen_layout.xml b/app/src/main/res/layout/onscreen_layout.xml index 4f296d24..af3d2101 100644 --- a/app/src/main/res/layout/onscreen_layout.xml +++ b/app/src/main/res/layout/onscreen_layout.xml @@ -1,7 +1,6 @@ - diff --git a/app/src/main/res/layout/onscreen_layout_material_light.xml b/app/src/main/res/layout/onscreen_layout_material_light.xml index 2b682313..f3249ef1 100644 --- a/app/src/main/res/layout/onscreen_layout_material_light.xml +++ b/app/src/main/res/layout/onscreen_layout_material_light.xml @@ -1,7 +1,6 @@ - diff --git a/app/src/main/res/values-large-hdpi/dimens.xml b/app/src/main/res/values-large-hdpi/dimens.xml index c5fd54f6..fbf2800b 100644 --- a/app/src/main/res/values-large-hdpi/dimens.xml +++ b/app/src/main/res/values-large-hdpi/dimens.xml @@ -21,7 +21,6 @@ --> - 20sp 20sp 24dp \ No newline at end of file diff --git a/app/src/main/res/values-large-mdpi/dimens.xml b/app/src/main/res/values-large-mdpi/dimens.xml index 5be31bbb..0a4f8e72 100644 --- a/app/src/main/res/values-large-mdpi/dimens.xml +++ b/app/src/main/res/values-large-mdpi/dimens.xml @@ -21,7 +21,6 @@ --> - 25sp 20sp 35dp \ No newline at end of file diff --git a/app/src/main/res/values-large-tvdpi/dimens.xml b/app/src/main/res/values-large-tvdpi/dimens.xml index 492b4c8f..9f5535ca 100644 --- a/app/src/main/res/values-large-tvdpi/dimens.xml +++ b/app/src/main/res/values-large-tvdpi/dimens.xml @@ -21,7 +21,6 @@ --> - 30sp 30sp 33dp \ No newline at end of file diff --git a/app/src/main/res/values-large/dimens.xml b/app/src/main/res/values-large/dimens.xml index 22c2a4c6..251349bd 100644 --- a/app/src/main/res/values-large/dimens.xml +++ b/app/src/main/res/values-large/dimens.xml @@ -21,6 +21,7 @@ --> + 28sp 17sp 25sp \ No newline at end of file diff --git a/app/src/main/res/values-normal/dimens.xml b/app/src/main/res/values-normal/dimens.xml index 17f5d575..88f9a974 100644 --- a/app/src/main/res/values-normal/dimens.xml +++ b/app/src/main/res/values-normal/dimens.xml @@ -22,6 +22,6 @@ 15sp - 30sp + 24sp 30sp \ No newline at end of file diff --git a/app/src/main/res/values-small/dimens.xml b/app/src/main/res/values-small/dimens.xml index de7c6e5a..51140923 100644 --- a/app/src/main/res/values-small/dimens.xml +++ b/app/src/main/res/values-small/dimens.xml @@ -22,7 +22,7 @@ 15sp - 20sp + 18sp 20sp 40dp \ No newline at end of file diff --git a/app/src/main/res/values-xlarge-hdpi/dimens.xml b/app/src/main/res/values-xlarge-hdpi/dimens.xml index 99175d81..a58edea6 100644 --- a/app/src/main/res/values-xlarge-hdpi/dimens.xml +++ b/app/src/main/res/values-xlarge-hdpi/dimens.xml @@ -21,7 +21,6 @@ --> - 30sp 30sp 40dp \ No newline at end of file diff --git a/app/src/main/res/values-xlarge-mdpi/dimens.xml b/app/src/main/res/values-xlarge-mdpi/dimens.xml index 42fba28f..940910b6 100644 --- a/app/src/main/res/values-xlarge-mdpi/dimens.xml +++ b/app/src/main/res/values-xlarge-mdpi/dimens.xml @@ -21,7 +21,6 @@ --> - 40sp 30sp 35dp \ No newline at end of file diff --git a/app/src/main/res/values-xlarge/dimens.xml b/app/src/main/res/values-xlarge/dimens.xml index 07ea2386..03ca7e93 100644 --- a/app/src/main/res/values-xlarge/dimens.xml +++ b/app/src/main/res/values-xlarge/dimens.xml @@ -21,6 +21,7 @@ --> + 32sp 30sp 40sp \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index d2b8c8c7..2fdc7706 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -17,7 +17,7 @@ 12dp 25sp - 25sp + 24sp 2dp 16sp 14sp diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9b3385d4..ed2144be 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -52,7 +52,10 @@ 1 1 1 + text|textNoSuggestions + center_vertical|left horizontal + @dimen/cpp_editor_padding @color/cpp_text @@ -61,7 +64,7 @@ left|top match_parent match_parent - @dimen/cpp_editor_text_size + @dimen/cpp_min_editor_text_size ?attr/cpp_text_color textMultiLine|textNoSuggestions