From 9af30b08cece43f8d2de4ef87b5ae96d46519afb Mon Sep 17 00:00:00 2001 From: serso Date: Mon, 22 Feb 2016 15:24:49 +0100 Subject: [PATCH] Fix button text size --- .../org/solovyev/android/calculator/App.java | 4 ++ .../calculator/about/AboutActivity.java | 5 +-- .../functions/FunctionsActivity.java | 4 +- .../calculator/history/HistoryActivity.java | 3 +- .../calculator/keyboard/BaseKeyboardUi.java | 38 +++++++++++++------ .../operators/OperatorsActivity.java | 4 +- .../preferences/PreferencesActivity.java | 3 +- .../variables/VariablesActivity.java | 5 ++- .../wizard/DragButtonWizardStep.java | 10 +++-- app/src/main/res/values/styles.xml | 5 +-- 10 files changed, 50 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/App.java b/app/src/main/java/org/solovyev/android/calculator/App.java index a95ed149..e0572d5c 100644 --- a/app/src/main/java/org/solovyev/android/calculator/App.java +++ b/app/src/main/java/org/solovyev/android/calculator/App.java @@ -358,4 +358,8 @@ public final class App { "Failed to show permission settings for " + action, e); } } + + public static boolean isTablet(@NonNull Context context) { + return context.getResources().getBoolean(R.bool.cpp_tablet); + } } \ No newline at end of file diff --git a/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java b/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java index be2f0f4d..a3f3223f 100644 --- a/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java @@ -25,9 +25,9 @@ package org.solovyev.android.calculator.about; import android.content.Context; import android.support.annotation.NonNull; +import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.FragmentTab; -import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.view.Tabs; import javax.annotation.Nonnull; @@ -39,8 +39,7 @@ public class AboutActivity extends BaseActivity { @Nonnull public static Class getClass(@NonNull Context context) { - boolean tablet = context.getResources().getBoolean(R.bool.cpp_tablet); - return tablet ? Dialog.class : AboutActivity.class; + return App.isTablet(context) ? Dialog.class : AboutActivity.class; } diff --git a/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java b/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java index acc8ed30..822694c6 100644 --- a/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsActivity.java @@ -27,6 +27,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.view.View; +import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.FragmentTab; import org.solovyev.android.calculator.R; @@ -41,8 +42,7 @@ public class FunctionsActivity extends BaseActivity { @Nonnull public static Class getClass(@NonNull Context context) { - boolean tablet = context.getResources().getBoolean(R.bool.cpp_tablet); - return tablet ? Dialog.class : FunctionsActivity.class; + return App.isTablet(context) ? Dialog.class : FunctionsActivity.class; } @Override diff --git a/app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java b/app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java index 3993d5dc..e4f712d1 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/HistoryActivity.java @@ -49,8 +49,7 @@ public class HistoryActivity extends BaseActivity { @Nonnull public static Class getClass(@NonNull Context context) { - boolean tablet = context.getResources().getBoolean(R.bool.cpp_tablet); - return tablet ? Dialog.class : HistoryActivity.class; + return App.isTablet(context) ? Dialog.class : HistoryActivity.class; } diff --git a/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseKeyboardUi.java b/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseKeyboardUi.java index ea8155b5..29a96119 100644 --- a/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseKeyboardUi.java +++ b/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseKeyboardUi.java @@ -1,7 +1,16 @@ package org.solovyev.android.calculator.keyboard; +import static android.view.HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING; +import static android.view.HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING; +import static android.view.HapticFeedbackConstants.KEYBOARD_TAP; +import static org.solovyev.android.calculator.App.cast; +import static org.solovyev.android.calculator.App.getScreenMetrics; +import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple; +import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile; + import android.app.Activity; import android.app.Application; +import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; import android.graphics.Typeface; @@ -11,8 +20,15 @@ import android.util.TypedValue; import android.view.View; import android.widget.ImageView; import android.widget.TextView; + import org.solovyev.android.Views; -import org.solovyev.android.calculator.*; +import org.solovyev.android.calculator.ActivityUi; +import org.solovyev.android.calculator.App; +import org.solovyev.android.calculator.Calculator; +import org.solovyev.android.calculator.Editor; +import org.solovyev.android.calculator.Keyboard; +import org.solovyev.android.calculator.Preferences; +import org.solovyev.android.calculator.PreferredPreferences; import org.solovyev.android.calculator.buttons.CppSpecialButton; import org.solovyev.android.calculator.view.ScreenMetrics; import org.solovyev.android.views.Adjuster; @@ -21,20 +37,18 @@ import org.solovyev.android.views.dragbutton.DragButton; import org.solovyev.android.views.dragbutton.DragDirection; import org.solovyev.android.views.dragbutton.SimpleDragListener; -import javax.annotation.Nonnull; -import javax.inject.Inject; import java.util.ArrayList; import java.util.List; -import static android.view.HapticFeedbackConstants.*; -import static org.solovyev.android.calculator.App.cast; -import static org.solovyev.android.calculator.App.getScreenMetrics; -import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple; -import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile; +import javax.annotation.Nonnull; +import javax.inject.Inject; public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPreferenceChangeListener, SimpleDragListener.DragProcessor, View.OnClickListener { - public static final float TEXT_SCALE = 0.6f; + public static float getTextScale(@NonNull Context context) { + return App.isTablet(context) ? 0.5f : 0.6f; + } + public static final float IMAGE_SCALE = 0.6f; public static final float IMAGE_SCALE_ERASE = 0.5f; @@ -57,14 +71,16 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer protected int orientation = Configuration.ORIENTATION_PORTRAIT; private int textSize; private Preferences.Gui.Layout layout; + private final float textScale; public BaseKeyboardUi(@NonNull Application application) { listener = new SimpleDragListener(this, application); + textScale = getTextScale(application); } public static void adjustButton(@NonNull View button) { if (button instanceof TextView) { - Adjuster.adjustText((TextView) button, TEXT_SCALE); + Adjuster.adjustText((TextView) button, getTextScale(button.getContext())); } else if (button instanceof ImageView) { Adjuster.adjustImage((ImageView) button, IMAGE_SCALE); } @@ -110,7 +126,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer button.setOnDragListener(listener); ActivityUi.setFont(button, typeface); button.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); - Adjuster.adjustText(button, TEXT_SCALE); + Adjuster.adjustText(button, textScale); } protected final void hideText(@Nullable DirectionDragButton button, @Nonnull DragDirection... directions) { diff --git a/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsActivity.java b/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsActivity.java index 5a0a9a5d..dc36487e 100644 --- a/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsActivity.java @@ -25,6 +25,7 @@ package org.solovyev.android.calculator.operators; import android.content.Context; import android.support.annotation.NonNull; +import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.FragmentTab; import org.solovyev.android.calculator.R; @@ -39,8 +40,7 @@ public class OperatorsActivity extends BaseActivity { @Nonnull public static Class getClass(@NonNull Context context) { - boolean tablet = context.getResources().getBoolean(R.bool.cpp_tablet); - return tablet ? Dialog.class : OperatorsActivity.class; + return App.isTablet(context) ? Dialog.class : OperatorsActivity.class; } @Override diff --git a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java index f2ca9248..7b668bdf 100644 --- a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java @@ -32,8 +32,7 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc private static final SparseArray preferences = new SparseArray<>(); public static Class getClass(@NonNull Context context) { - final boolean tablet = context.getResources().getBoolean(R.bool.cpp_tablet); - return tablet ? Dialog.class : PreferencesActivity.class; + return App.isTablet(context) ? Dialog.class : PreferencesActivity.class; } static { diff --git a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java index b55866dc..81970d98 100644 --- a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesActivity.java @@ -26,6 +26,8 @@ import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.view.View; + +import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.FragmentTab; import org.solovyev.android.calculator.R; @@ -40,8 +42,7 @@ public class VariablesActivity extends BaseActivity { @Nonnull public static Class getClass(@NonNull Context context) { - boolean tablet = context.getResources().getBoolean(R.bool.cpp_tablet); - return tablet ? Dialog.class : VariablesActivity.class; + return App.isTablet(context) ? Dialog.class : VariablesActivity.class; } @Override diff --git a/app/src/main/java/org/solovyev/android/calculator/wizard/DragButtonWizardStep.java b/app/src/main/java/org/solovyev/android/calculator/wizard/DragButtonWizardStep.java index 0f1a14b8..01cdd7b0 100644 --- a/app/src/main/java/org/solovyev/android/calculator/wizard/DragButtonWizardStep.java +++ b/app/src/main/java/org/solovyev/android/calculator/wizard/DragButtonWizardStep.java @@ -22,12 +22,15 @@ package org.solovyev.android.calculator.wizard; +import static org.solovyev.android.calculator.App.cast; + import android.graphics.PointF; import android.graphics.Typeface; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.widget.TextView; + import org.solovyev.android.calculator.ActivityUi; import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.keyboard.BaseKeyboardUi; @@ -37,12 +40,11 @@ import org.solovyev.android.views.dragbutton.DragButton; import org.solovyev.android.views.dragbutton.DragDirection; import org.solovyev.android.views.dragbutton.SimpleDragListener; +import java.util.Arrays; + import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.inject.Inject; -import java.util.Arrays; - -import static org.solovyev.android.calculator.App.cast; public class DragButtonWizardStep extends WizardFragment { @@ -76,7 +78,7 @@ public class DragButtonWizardStep extends WizardFragment { dragButton.setOnDragListener( new SimpleDragListener(new DragButtonProcessor(), getActivity())); ActivityUi.setFont(dragButton, typeface); - Adjuster.adjustText(dragButton, BaseKeyboardUi.TEXT_SCALE); + Adjuster.adjustText(dragButton, BaseKeyboardUi.getTextScale(getActivity())); actionTextView = (TextView) root.findViewById(R.id.wizard_dragbutton_action_textview); if (savedInstanceState != null) { setAction((DragButtonAction) savedInstanceState.getSerializable(ACTION)); diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index ab71723b..392952ac 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -96,9 +96,8 @@