From 8a5d163b068ba63d9dccc1d7b4bf5d6de65df5aa Mon Sep 17 00:00:00 2001 From: serso Date: Tue, 16 Feb 2016 16:00:22 +0100 Subject: [PATCH] Fix text scales in keyboard buttons --- .../android/calculator/AppComponent.java | 5 +- .../calculator/keyboard/BaseKeyboardUi.java | 29 +++++--- .../wizard/ChooseThemeWizardStep.java | 19 +++++- .../wizard/DragButtonWizardStep.java | 68 ++++++------------- .../cpp_wizard_step_choose_theme_preview.xml | 6 +- 5 files changed, 66 insertions(+), 61 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/AppComponent.java b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java index 10f0e3c0..af4aca6e 100644 --- a/app/src/main/java/org/solovyev/android/calculator/AppComponent.java +++ b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java @@ -1,6 +1,5 @@ package org.solovyev.android.calculator; -import dagger.Component; import org.solovyev.android.calculator.converter.ConverterFragment; import org.solovyev.android.calculator.errors.FixableErrorFragment; import org.solovyev.android.calculator.errors.FixableErrorsActivity; @@ -16,6 +15,9 @@ import org.solovyev.android.calculator.preferences.PreferencesActivity; import org.solovyev.android.calculator.preferences.PurchaseDialogActivity; import org.solovyev.android.calculator.variables.EditVariableFragment; import org.solovyev.android.calculator.variables.VariablesFragment; +import org.solovyev.android.calculator.wizard.DragButtonWizardStep; + +import dagger.Component; import javax.inject.Singleton; @@ -46,4 +48,5 @@ public interface AppComponent { void inject(PreferencesActivity activity); void inject(BaseKeyboardUi ui); void inject(CalculatorOnscreenView view); + void inject(DragButtonWizardStep fragment); } 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 d608698e..de8c8a38 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,5 +1,13 @@ 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.SharedPreferences; @@ -10,8 +18,14 @@ import android.support.annotation.Nullable; import android.util.TypedValue; import android.view.View; import android.widget.ImageView; + import org.solovyev.android.Views; -import org.solovyev.android.calculator.*; +import org.solovyev.android.calculator.BaseUi; +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; @@ -20,21 +34,16 @@ 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 { - protected static final float TEXT_SCALE = 0.6f; - protected static final float IMAGE_SCALE = 0.6f; + public static final float TEXT_SCALE = 0.6f; + public static final float IMAGE_SCALE = 0.6f; @NonNull private final List dragButtons = new ArrayList<>(); diff --git a/app/src/main/java/org/solovyev/android/calculator/wizard/ChooseThemeWizardStep.java b/app/src/main/java/org/solovyev/android/calculator/wizard/ChooseThemeWizardStep.java index 30c05e9e..898db0c2 100644 --- a/app/src/main/java/org/solovyev/android/calculator/wizard/ChooseThemeWizardStep.java +++ b/app/src/main/java/org/solovyev/android/calculator/wizard/ChooseThemeWizardStep.java @@ -28,16 +28,23 @@ import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.widget.AdapterView; +import android.widget.Button; import android.widget.FrameLayout; +import android.widget.ImageView; import android.widget.Spinner; + +import org.solovyev.android.Views; import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.Preferences; import org.solovyev.android.calculator.R; +import org.solovyev.android.calculator.keyboard.BaseKeyboardUi; +import org.solovyev.android.views.Adjuster; -import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.List; +import javax.annotation.Nonnull; + public class ChooseThemeWizardStep extends WizardFragment implements AdapterView.OnItemSelectedListener { @Nonnull @@ -85,6 +92,16 @@ public class ChooseThemeWizardStep extends WizardFragment implements AdapterView preview.removeAllViews(); final ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), theme.theme); LayoutInflater.from(context).inflate(R.layout.cpp_wizard_step_choose_theme_preview, preview); + Views.processViews(preview, new Views.ViewProcessor() { + @Override + public void process(@Nonnull View view) { + if (view instanceof Button) { + Adjuster.adjustText((Button) view, BaseKeyboardUi.TEXT_SCALE); + } else if (view instanceof ImageView) { + Adjuster.adjustImage((ImageView) view, BaseKeyboardUi.IMAGE_SCALE); + } + } + }); } @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 1a90d09c..e981bcee 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,13 +22,19 @@ 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.BaseUi; import org.solovyev.android.calculator.R; +import org.solovyev.android.calculator.keyboard.BaseKeyboardUi; +import org.solovyev.android.views.Adjuster; import org.solovyev.android.views.dragbutton.DirectionDragButton; import org.solovyev.android.views.dragbutton.DragButton; import org.solovyev.android.views.dragbutton.DragDirection; @@ -38,41 +44,24 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.inject.Inject; public class DragButtonWizardStep extends WizardFragment { - /* - ********************************************************************** - * - * CONSTANTS - * - ********************************************************************** - */ - private static final String ACTION = "action"; - /* - ********************************************************************** - * - * FIELDS - * - ********************************************************************** - */ - - @Nullable - private DirectionDragButton dragButton; - @Nullable private TextView actionTextView; - @Nonnull - private TextView descriptionTextView; - private DragButtonAction action = DragButtonAction.center; + @Inject + Typeface typeface; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + cast(this).getComponent().inject(this); } @Override @@ -84,12 +73,13 @@ public class DragButtonWizardStep extends WizardFragment { public void onViewCreated(View root, Bundle savedInstanceState) { super.onViewCreated(root, savedInstanceState); - dragButton = (DirectionDragButton) root.findViewById(R.id.wizard_dragbutton); - dragButton.setOnClickListener(new DragButtonOnClickListener()); - dragButton.setOnDragListener(new SimpleDragListener(new DragButtonProcessor(), getActivity())); + final DirectionDragButton dragButton =(DirectionDragButton) root.findViewById(R.id.wizard_dragbutton); + dragButton.setOnClickListener(this); + dragButton.setOnDragListener( + new SimpleDragListener(new DragButtonProcessor(), getActivity())); + BaseUi.setFont(dragButton, typeface); + Adjuster.adjustText(dragButton, BaseKeyboardUi.TEXT_SCALE); actionTextView = (TextView) root.findViewById(R.id.wizard_dragbutton_action_textview); - descriptionTextView = (TextView) root.findViewById(R.id.wizard_dragbutton_description_textview); - if (savedInstanceState != null) { setAction((DragButtonAction) savedInstanceState.getSerializable(ACTION)); } @@ -102,14 +92,6 @@ public class DragButtonWizardStep extends WizardFragment { outState.putSerializable(ACTION, action); } - /* - ********************************************************************** - * - * STATIC/INNER - * - ********************************************************************** - */ - private void setNextAction() { setAction(action.getNextAction()); } @@ -120,14 +102,6 @@ public class DragButtonWizardStep extends WizardFragment { if (actionTextView != null) { actionTextView.setText(this.action.actionTextResId); } - - boolean firstChange = false; - if (action != DragButtonAction.center) { - firstChange = true; - } - if (firstChange) { - //descriptionTextView.setVisibility(GONE); - } } } @@ -159,13 +133,15 @@ public class DragButtonWizardStep extends WizardFragment { } } - private class DragButtonOnClickListener implements View.OnClickListener { - @Override - public void onClick(View v) { + @Override + public void onClick(View v) { + if(v.getId() == R.id.wizard_dragbutton) { if (action == DragButtonAction.center || action == DragButtonAction.end) { setNextAction(); } + return; } + super.onClick(v); } private class DragButtonProcessor implements SimpleDragListener.DragProcessor { diff --git a/app/src/main/res/layout/cpp_wizard_step_choose_theme_preview.xml b/app/src/main/res/layout/cpp_wizard_step_choose_theme_preview.xml index 9f6a7672..5bb93e0f 100644 --- a/app/src/main/res/layout/cpp_wizard_step_choose_theme_preview.xml +++ b/app/src/main/res/layout/cpp_wizard_step_choose_theme_preview.xml @@ -34,7 +34,7 @@ @@ -51,7 +51,7 @@ @@ -64,7 +64,7 @@