From b9432db42a69d5326396788d2ddfe2ef60dace73 Mon Sep 17 00:00:00 2001 From: serso Date: Tue, 15 Mar 2016 22:43:27 +0100 Subject: [PATCH] Fix fonts in floating keyboards --- .../android/calculator/BaseActivity.java | 11 +++++-- .../floating/FloatingCalculatorView.java | 32 +++---------------- .../functions/BaseFunctionFragment.java | 9 ++++++ .../keyboard/BaseFloatingKeyboard.java | 2 ++ .../calculator/keyboard/BaseKeyboardUi.java | 3 +- .../calculator/keyboard/FloatingKeyboard.java | 3 ++ .../variables/EditVariableFragment.java | 9 ++++++ 7 files changed, 38 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/BaseActivity.java b/app/src/main/java/org/solovyev/android/calculator/BaseActivity.java index 3ff1902a..2eff5c7d 100644 --- a/app/src/main/java/org/solovyev/android/calculator/BaseActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/BaseActivity.java @@ -24,6 +24,7 @@ import org.solovyev.android.calculator.history.History; import org.solovyev.android.calculator.language.Language; import org.solovyev.android.calculator.language.Languages; import org.solovyev.android.calculator.view.Tabs; +import org.solovyev.android.views.dragbutton.DirectionDragImageButton; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -86,6 +87,14 @@ public class BaseActivity extends AppCompatActivity { ga.getAnalytics().reportActivityStart(activity); } + public static void setFont(@Nonnull View view, @Nonnull Typeface newTypeface) { + if (view instanceof TextView) { + setFont((TextView) view, newTypeface); + } else if (view instanceof DirectionDragImageButton) { + ((DirectionDragImageButton) view).setTypeface(newTypeface); + } + } + public static void setFont(@Nonnull TextView view, @Nonnull Typeface newTypeface) { final Typeface oldTypeface = view.getTypeface(); if (oldTypeface == newTypeface) { @@ -248,6 +257,4 @@ public class BaseActivity extends AppCompatActivity { } }); } - - } diff --git a/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorView.java b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorView.java index 8d0be61f..85109d2e 100644 --- a/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorView.java +++ b/app/src/main/java/org/solovyev/android/calculator/floating/FloatingCalculatorView.java @@ -34,23 +34,9 @@ import android.support.annotation.NonNull; import android.support.v7.view.ContextThemeWrapper; import android.util.DisplayMetrics; import android.view.Display; -import android.view.Gravity; -import android.view.MotionEvent; -import android.view.View; -import android.view.WindowManager; +import android.view.*; import android.widget.ImageView; -import android.widget.TextView; - -import org.solovyev.android.calculator.AppModule; -import org.solovyev.android.calculator.BaseActivity; -import org.solovyev.android.calculator.DisplayState; -import org.solovyev.android.calculator.DisplayView; -import org.solovyev.android.calculator.Editor; -import org.solovyev.android.calculator.EditorState; -import org.solovyev.android.calculator.EditorView; -import org.solovyev.android.calculator.Keyboard; -import org.solovyev.android.calculator.Preferences; -import org.solovyev.android.calculator.R; +import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.buttons.CppButton; import org.solovyev.android.calculator.keyboard.BaseKeyboardUi; import org.solovyev.android.views.Adjuster; @@ -59,14 +45,8 @@ import javax.annotation.Nonnull; import javax.inject.Inject; import javax.inject.Named; -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 android.view.HapticFeedbackConstants.LONG_PRESS; -import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; -import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; -import static android.view.WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; -import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; +import static android.view.HapticFeedbackConstants.*; +import static android.view.WindowManager.LayoutParams.*; import static org.solovyev.android.calculator.App.cast; public class FloatingCalculatorView { @@ -377,9 +357,7 @@ public class FloatingCalculatorView { } else { BaseKeyboardUi.adjustButton(button); } - if (button instanceof TextView) { - BaseActivity.setFont((TextView) button, typeface); - } + BaseActivity.setFont(button, typeface); } final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); diff --git a/app/src/main/java/org/solovyev/android/calculator/functions/BaseFunctionFragment.java b/app/src/main/java/org/solovyev/android/calculator/functions/BaseFunctionFragment.java index c673167f..bc07ecd4 100644 --- a/app/src/main/java/org/solovyev/android/calculator/functions/BaseFunctionFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/functions/BaseFunctionFragment.java @@ -26,6 +26,7 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.DialogInterface; import android.content.res.Resources; +import android.graphics.Typeface; import android.os.Bundle; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; @@ -83,6 +84,8 @@ public abstract class BaseFunctionFragment extends BaseDialogFragment implements @Inject Keyboard keyboard; @Inject + Typeface typeface; + @Inject FunctionsRegistry functionsRegistry; @Inject VariablesRegistry variablesRegistry; @@ -497,6 +500,12 @@ public abstract class BaseFunctionFragment extends BaseDialogFragment implements return keyboard.isVibrateOnKeypress(); } + @NonNull + @Override + public Typeface getTypeface() { + return typeface; + } + @Override public void done() { keyboardWindow.hide(); diff --git a/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseFloatingKeyboard.java b/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseFloatingKeyboard.java index 6f0feb6b..5196770c 100644 --- a/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseFloatingKeyboard.java +++ b/app/src/main/java/org/solovyev/android/calculator/keyboard/BaseFloatingKeyboard.java @@ -15,6 +15,7 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import org.solovyev.android.calculator.App; +import org.solovyev.android.calculator.BaseActivity; import org.solovyev.android.calculator.R; import org.solovyev.android.views.dragbutton.DirectionDragButton; @@ -75,6 +76,7 @@ public abstract class BaseFloatingKeyboard implements FloatingKeyboard { } protected void fillButton(@NonNull View button, @IdRes int id) { + BaseActivity.setFont(button, user.getTypeface()); button.setId(id); button.setBackgroundResource(buttonBackground); button.setPadding(sidePadding, 1, sidePadding, 1); 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 e363fd0d..bfa29323 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 @@ -115,6 +115,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer // we call android.view.View.performHapticFeedback(int, int) from #onClick button.setHapticFeedbackEnabled(false); button.setOnClickListener(this); + BaseActivity.setFont(button, typeface); } protected final void prepareButton(@Nullable DirectionDragImageButton button) { @@ -125,7 +126,6 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer button.setVibrateOnDrag(keyboard.isVibrateOnKeypress()); prepareButton((ImageView) button); button.setOnDragListener(listener); - button.setTypeface(typeface); button.setTextSize(textSize); Adjuster.adjustText(button, AdjusterHelper.instance, textScale, 0); } @@ -138,7 +138,6 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer button.setVibrateOnDrag(keyboard.isVibrateOnKeypress()); prepareButton((View) button); button.setOnDragListener(listener); - BaseActivity.setFont(button, typeface); button.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); Adjuster.adjustText(button, textScale); } diff --git a/app/src/main/java/org/solovyev/android/calculator/keyboard/FloatingKeyboard.java b/app/src/main/java/org/solovyev/android/calculator/keyboard/FloatingKeyboard.java index 1fd61543..5fc1550e 100644 --- a/app/src/main/java/org/solovyev/android/calculator/keyboard/FloatingKeyboard.java +++ b/app/src/main/java/org/solovyev/android/calculator/keyboard/FloatingKeyboard.java @@ -2,6 +2,7 @@ package org.solovyev.android.calculator.keyboard; import android.content.Context; import android.content.res.Resources; +import android.graphics.Typeface; import android.support.annotation.NonNull; import android.view.ViewGroup; import android.widget.EditText; @@ -35,5 +36,7 @@ public interface FloatingKeyboard { boolean isVibrateOnKeypress(); + @NonNull + Typeface getTypeface(); } } diff --git a/app/src/main/java/org/solovyev/android/calculator/variables/EditVariableFragment.java b/app/src/main/java/org/solovyev/android/calculator/variables/EditVariableFragment.java index 378c4b21..79c4e738 100644 --- a/app/src/main/java/org/solovyev/android/calculator/variables/EditVariableFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/variables/EditVariableFragment.java @@ -27,6 +27,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; +import android.graphics.Typeface; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.TextInputLayout; @@ -93,6 +94,8 @@ public class EditVariableFragment extends BaseDialogFragment implements View.OnF @Inject Keyboard keyboard; @Inject + Typeface typeface; + @Inject FunctionsRegistry functionsRegistry; @Inject VariablesRegistry variablesRegistry; @@ -421,5 +424,11 @@ public class EditVariableFragment extends BaseDialogFragment implements View.OnF public boolean isVibrateOnKeypress() { return keyboard.isVibrateOnKeypress(); } + + @NonNull + @Override + public Typeface getTypeface() { + return typeface; + } } }