From 1dcd43258ccd24ae379ab5e1d031645b68524c54 Mon Sep 17 00:00:00 2001 From: serso Date: Sun, 13 Mar 2016 23:45:54 +0100 Subject: [PATCH] Style fixing --- .../FloatingCalculatorKeyboard.java | 7 +-- .../android/calculator/Preferences.java | 2 - .../calculator/keyboard/BaseKeyboardUi.java | 50 ++++++++------- .../calculator/keyboard/KeyboardUi.java | 61 +++++++------------ .../keyboard/PartialKeyboardUi.java | 38 ++++-------- .../android/calculator/memory/Memory.java | 4 ++ .../org/solovyev/android/views/Adjuster.java | 38 +++++++++--- .../views/dragbutton/DirectionDragButton.java | 10 +-- .../dragbutton/DirectionDragImageButton.java | 11 +++- .../views/dragbutton/DirectionTextView.java | 11 +++- .../android/views/dragbutton/Drag.java | 10 ++- .../main/res/layout-land/activity_main.xml | 14 ++--- .../main/res/layout-land/cpp_app_keyboard.xml | 14 ++--- app/src/main/res/layout/cpp_app_button_6.xml | 1 + app/src/main/res/layout/cpp_app_button_9.xml | 2 - .../main/res/layout/cpp_app_button_clear.xml | 5 +- .../res/layout/cpp_app_button_division.xml | 2 - .../layout/cpp_app_button_equals_no_bg.xml | 3 +- .../main/res/layout/cpp_app_button_erase.xml | 1 + .../res/layout/cpp_app_button_functions.xml | 1 + .../main/res/layout/cpp_app_button_memory.xml | 4 +- .../main/res/layout/cpp_app_button_minus.xml | 1 - .../layout/cpp_app_button_multiplication.xml | 3 - .../res/layout/cpp_app_button_percent.xml | 34 +++++++++++ .../layout/cpp_app_button_round_brackets.xml | 2 +- .../main/res/layout/cpp_app_button_vars.xml | 3 +- app/src/main/res/layout/cpp_app_keyboard.xml | 51 ++++++++-------- app/src/main/res/values-land/dimens.xml | 5 ++ app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/dimens.xml | 4 +- .../main/res/values/text_non_translatable.xml | 2 +- .../main/res/xml/preferences_appearance.xml | 7 --- 32 files changed, 221 insertions(+), 181 deletions(-) create mode 100644 app/src/main/res/layout/cpp_app_button_percent.xml create mode 100644 app/src/main/res/values-land/dimens.xml diff --git a/app/src/main/java/org/solovyev/android/calculator/FloatingCalculatorKeyboard.java b/app/src/main/java/org/solovyev/android/calculator/FloatingCalculatorKeyboard.java index c47d4778..532cb8da 100644 --- a/app/src/main/java/org/solovyev/android/calculator/FloatingCalculatorKeyboard.java +++ b/app/src/main/java/org/solovyev/android/calculator/FloatingCalculatorKeyboard.java @@ -9,10 +9,7 @@ import android.widget.LinearLayout; import org.solovyev.android.calculator.keyboard.BaseFloatingKeyboard; import org.solovyev.android.calculator.keyboard.FloatingKeyboard; import org.solovyev.android.calculator.view.EditTextLongClickEraser; -import org.solovyev.android.views.dragbutton.DirectionDragButton; -import org.solovyev.android.views.dragbutton.DirectionDragListener; -import org.solovyev.android.views.dragbutton.DragDirection; -import org.solovyev.android.views.dragbutton.DragEvent; +import org.solovyev.android.views.dragbutton.*; import java.util.List; @@ -35,7 +32,7 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard { this.dragListener = new DirectionDragListener(user.getContext()) { @Override protected boolean onDrag(@NonNull View view, @NonNull DragEvent event, @NonNull DragDirection direction) { - return buttonHandler.onDrag(view, direction); + return Drag.hasDirectionText(view, direction) && buttonHandler.onDrag(view, direction); } }; } diff --git a/app/src/main/java/org/solovyev/android/calculator/Preferences.java b/app/src/main/java/org/solovyev/android/calculator/Preferences.java index bd1f35c9..e7bbd734 100644 --- a/app/src/main/java/org/solovyev/android/calculator/Preferences.java +++ b/app/src/main/java/org/solovyev/android/calculator/Preferences.java @@ -83,7 +83,6 @@ public final class Preferences { migratePreference(preferences, editor, Gui.layout, Deleted.layout); migratePreference(preferences, editor, Gui.useBackAsPrevious, Deleted.usePrevAsBack); migratePreference(preferences, editor, Gui.showReleaseNotes, Deleted.showReleaseNotes); - migratePreference(preferences, editor, Gui.showEqualsButton, Deleted.showEqualsButton); migratePreference(preferences, editor, Gui.rotateScreen, Deleted.autoOrientation); final Gui.Layout layout = Deleted.layout.getPreference(preferences); if (layout == Gui.Layout.main_cellphone) { @@ -137,7 +136,6 @@ public final class Preferences { Gui.layout.tryPutDefault(preferences, editor); Gui.showReleaseNotes.tryPutDefault(preferences, editor); Gui.useBackAsPrevious.tryPutDefault(preferences, editor); - Gui.showEqualsButton.tryPutDefault(preferences, editor); Gui.rotateScreen.tryPutDefault(preferences, editor); Gui.keepScreenOn.tryPutDefault(preferences, editor); Gui.language.tryPutDefault(preferences, editor); 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 f8f9efb9..3bbcdaf9 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 @@ -12,35 +12,20 @@ import android.util.TypedValue; import android.view.View; import android.widget.ImageView; import android.widget.TextView; - -import org.solovyev.android.calculator.ActivityLauncher; -import org.solovyev.android.calculator.App; -import org.solovyev.android.calculator.BaseActivity; -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 dagger.Lazy; +import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.buttons.CppSpecialButton; +import org.solovyev.android.calculator.memory.Memory; import org.solovyev.android.views.Adjuster; -import org.solovyev.android.views.dragbutton.DirectionDragButton; -import org.solovyev.android.views.dragbutton.DirectionDragImageButton; -import org.solovyev.android.views.dragbutton.DirectionDragListener; -import org.solovyev.android.views.dragbutton.DirectionDragView; -import org.solovyev.android.views.dragbutton.DragDirection; -import org.solovyev.android.views.dragbutton.DragEvent; -import org.solovyev.android.views.dragbutton.DragView; - -import java.util.ArrayList; -import java.util.List; +import org.solovyev.android.views.dragbutton.*; import javax.annotation.Nonnull; import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; import static android.content.res.Configuration.ORIENTATION_PORTRAIT; -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.*; import static org.solovyev.android.calculator.App.cast; import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple; import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile; @@ -71,6 +56,8 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer @Inject ActivityLauncher launcher; @Inject + Lazy memory; + @Inject PreferredPreferences preferredPreferences; protected int orientation = ORIENTATION_PORTRAIT; private int textSize; @@ -81,7 +68,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer listener = new DirectionDragListener(application) { @Override protected boolean onDrag(@NonNull View view, @NonNull DragEvent event, @NonNull DragDirection direction) { - return BaseKeyboardUi.this.onDrag(view, direction); + return Drag.hasDirectionText(view, direction) && BaseKeyboardUi.this.onDrag(view, direction); } }; textScale = getTextScale(application); @@ -136,6 +123,8 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer prepareButton((ImageView) button); button.setOnDragListener(listener); button.setTypeface(typeface); + button.setTextSize(textSize); + Adjuster.adjustText(button, AdjusterHelper.instance, textScale, 0); } protected final void prepareButton(@Nullable DirectionDragButton button) { @@ -209,4 +198,19 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer protected final void onClick(@Nonnull View v, @Nonnull CppSpecialButton b) { onClick(v, b.action); } + + private static class AdjusterHelper implements Adjuster.Helper { + + public static AdjusterHelper instance = new AdjusterHelper(); + + @Override + public void apply(@NonNull DirectionDragImageButton view, float textSize) { + view.setTextSize(textSize); + } + + @Override + public float getTextSize(@NonNull DirectionDragImageButton view) { + return view.getTextSize(); + } + } } diff --git a/app/src/main/java/org/solovyev/android/calculator/keyboard/KeyboardUi.java b/app/src/main/java/org/solovyev/android/calculator/keyboard/KeyboardUi.java index fb21d9e1..18de0617 100644 --- a/app/src/main/java/org/solovyev/android/calculator/keyboard/KeyboardUi.java +++ b/app/src/main/java/org/solovyev/android/calculator/keyboard/KeyboardUi.java @@ -10,16 +10,15 @@ import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ImageButton; - -import org.solovyev.android.calculator.ActivityLauncher; -import org.solovyev.android.calculator.App; -import org.solovyev.android.calculator.Display; -import org.solovyev.android.calculator.DisplayState; -import org.solovyev.android.calculator.Engine; -import org.solovyev.android.calculator.R; +import butterknife.Bind; +import butterknife.ButterKnife; +import jscl.AngleUnit; +import jscl.NumeralBase; +import jscl.math.Expression; +import jscl.math.Generic; +import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.buttons.CppSpecialButton; import org.solovyev.android.calculator.history.History; -import org.solovyev.android.calculator.memory.Memory; import org.solovyev.android.calculator.view.AngleUnitsButton; import org.solovyev.android.calculator.view.NumeralBasesButton; import org.solovyev.android.views.dragbutton.DirectionDragButton; @@ -30,20 +29,8 @@ import org.solovyev.android.views.dragbutton.DragDirection; import javax.annotation.Nonnull; import javax.inject.Inject; -import butterknife.Bind; -import butterknife.ButterKnife; -import dagger.Lazy; -import jscl.AngleUnit; -import jscl.NumeralBase; -import jscl.math.Expression; -import jscl.math.Generic; - -import static org.solovyev.android.calculator.Engine.Preferences.angleUnit; -import static org.solovyev.android.calculator.Engine.Preferences.multiplicationSign; -import static org.solovyev.android.calculator.Engine.Preferences.numeralBase; -import static org.solovyev.android.views.dragbutton.DragDirection.down; -import static org.solovyev.android.views.dragbutton.DragDirection.left; -import static org.solovyev.android.views.dragbutton.DragDirection.up; +import static org.solovyev.android.calculator.Engine.Preferences.*; +import static org.solovyev.android.views.dragbutton.DragDirection.*; public class KeyboardUi extends BaseKeyboardUi { @@ -76,8 +63,6 @@ public class KeyboardUi extends BaseKeyboardUi { @Inject Display display; @Inject - Lazy memory; - @Inject PartialKeyboardUi partialUi; @Bind(R.id.cpp_button_vars) DirectionDragButton variablesButton; @@ -108,6 +93,9 @@ public class KeyboardUi extends BaseKeyboardUi { @Bind(R.id.cpp_button_like) ImageButton likeButton; @Nullable + @Bind(R.id.cpp_button_percent) + DirectionDragButton percentButton; + @Nullable @Bind(R.id.cpp_button_memory) DirectionDragButton memoryButton; @@ -143,6 +131,7 @@ public class KeyboardUi extends BaseKeyboardUi { prepareButton(periodButton); prepareButton(bracketsButton); + prepareButton(percentButton); prepareButton(button0); prepareButton(button1); @@ -163,9 +152,9 @@ public class KeyboardUi extends BaseKeyboardUi { prepareButton(memoryButton); if (isSimpleLayout()) { - hideText(button1, up, down); - hideText(button2, up, down); - hideText(button3, up, down); + hideText(button1, down); + hideText(button2, down); + hideText(button3, down); hideText(button4, down); hideText(button5, down); hideText(button7, left, up, down); @@ -175,6 +164,7 @@ public class KeyboardUi extends BaseKeyboardUi { hideText(plusButton, up, down); hideText(copyButton, left, up, down); hideText(pasteButton, left, up, down); + hideText(functionsButton, up, down); } multiplicationButton.setText(engine.getMultiplicationSign()); toggleNumericDigits(); @@ -216,6 +206,7 @@ public class KeyboardUi extends BaseKeyboardUi { case R.id.cpp_button_9: case R.id.cpp_button_division: case R.id.cpp_button_period: + case R.id.cpp_button_percent: case R.id.cpp_button_subtraction: case R.id.cpp_button_multiplication: case R.id.cpp_button_plus: @@ -252,13 +243,13 @@ public class KeyboardUi extends BaseKeyboardUi { @Override protected boolean onDrag(@NonNull View view, @NonNull DragDirection direction) { switch (view.getId()) { - case R.id.cpp_button_vars: - launcher.showConstantEditor(); - return true; case R.id.cpp_button_functions: if (direction == up) { launcher.showFunctionEditor(); return true; + } else if (direction == down) { + launcher.showConstantEditor(); + return true; } return false; case R.id.cpp_button_history: @@ -272,12 +263,6 @@ public class KeyboardUi extends BaseKeyboardUi { return false; case R.id.cpp_button_memory: return processMemoryButton(direction); - case R.id.cpp_button_subtraction: - if (direction == down) { - launcher.showOperators(); - return true; - } - return false; case R.id.cpp_button_copy: return processNumeralBaseButton(direction, (DirectionDragView) view); case R.id.cpp_button_paste: @@ -307,6 +292,7 @@ public class KeyboardUi extends BaseKeyboardUi { } } if (value == null) { + memory.get().show(); return false; } switch (direction) { @@ -316,9 +302,6 @@ public class KeyboardUi extends BaseKeyboardUi { case down: memory.get().subtract(value); return true; - case left: - memory.get().clear(); - return true; } return false; } diff --git a/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java b/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java index 1e11a8c6..42887091 100644 --- a/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java +++ b/app/src/main/java/org/solovyev/android/calculator/keyboard/PartialKeyboardUi.java @@ -3,14 +3,12 @@ package org.solovyev.android.calculator.keyboard; import android.app.Activity; import android.app.Application; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.view.View; -import android.widget.Button; import android.widget.ImageButton; - -import org.solovyev.android.calculator.Preferences; +import butterknife.Bind; +import butterknife.ButterKnife; import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.buttons.CppSpecialButton; import org.solovyev.android.calculator.view.EditorLongClickEraser; @@ -21,10 +19,6 @@ import org.solovyev.android.views.dragbutton.DragDirection; import javax.annotation.Nonnull; import javax.inject.Inject; -import butterknife.Bind; -import butterknife.ButterKnife; - -import static org.solovyev.android.calculator.Preferences.Gui.showEqualsButton; import static org.solovyev.android.calculator.Preferences.Gui.vibrateOnKeypress; import static org.solovyev.android.views.dragbutton.DragDirection.down; import static org.solovyev.android.views.dragbutton.DragDirection.up; @@ -39,7 +33,7 @@ public class PartialKeyboardUi extends BaseKeyboardUi { DirectionDragImageButton leftButton; @Nullable @Bind(R.id.cpp_button_clear) - Button clearButton; + DirectionDragButton clearButton; @Nullable @Bind(R.id.cpp_button_erase) ImageButton eraseButton; @@ -67,30 +61,14 @@ public class PartialKeyboardUi extends BaseKeyboardUi { prepareButton(eraseButton, IMAGE_SCALE_ERASE); longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress(), editor, calculator); } - toggleEqualsButton(); - } - - public void toggleEqualsButton() { - if (equalsButton == null) { - return; - } - if (orientation != Configuration.ORIENTATION_PORTRAIT && Preferences.Gui.rotateScreen.getPreference(preferences)) { - return; - } - - if (Preferences.Gui.showEqualsButton.getPreference(preferences)) { - equalsButton.setVisibility(View.VISIBLE); - } else { - equalsButton.setVisibility(View.GONE); + if(isSimpleLayout()) { + hideText(equalsButton, down); } } @Override public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { super.onSharedPreferenceChanged(preferences, key); - if (equalsButton != null && showEqualsButton.isSameKey(key)) { - toggleEqualsButton(); - } if (longClickEraser != null && vibrateOnKeypress.isSameKey(key)) { longClickEraser.setVibrateOnKeypress(vibrateOnKeypress.getPreference(preferences)); } @@ -105,6 +83,12 @@ public class PartialKeyboardUi extends BaseKeyboardUi { case R.id.cpp_button_left: editor.setCursorOnStart(); return true; + case R.id.cpp_button_clear: + if(direction == up) { + memory.get().clear(); + return true; + } + return false; case R.id.cpp_button_equals: if (direction == down) { launcher.plotDisplayedExpression(); diff --git a/app/src/main/java/org/solovyev/android/calculator/memory/Memory.java b/app/src/main/java/org/solovyev/android/calculator/memory/Memory.java index 14f0be53..0f6aa8c1 100644 --- a/app/src/main/java/org/solovyev/android/calculator/memory/Memory.java +++ b/app/src/main/java/org/solovyev/android/calculator/memory/Memory.java @@ -156,6 +156,10 @@ public class Memory { value = numeric(newValue); handler.removeCallbacks(writeTask); handler.postDelayed(writeTask, 3000L); + show(); + } + + public void show() { notifier.showMessage(getValue()); } 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 e6fd0292..e3bc93ef 100644 --- a/app/src/main/java/org/solovyev/android/views/Adjuster.java +++ b/app/src/main/java/org/solovyev/android/views/Adjuster.java @@ -16,17 +16,33 @@ import static android.graphics.Matrix.MSCALE_Y; public class Adjuster { private static final float[] MATRIX = new float[9]; + @NonNull + private static Helper textViewHelper = new Helper() { + @Override + public void apply(@NonNull TextView view, float textSize) { + view.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); + } + + @Override + public float getTextSize(@NonNull TextView view) { + return view.getTextSize(); + } + }; public static void adjustText(@NonNull final TextView view, final float percentage) { - adjustText(view, percentage, 0); + adjustText(view, textViewHelper, percentage, 0); } - public static void adjustText(@NonNull final TextView view, final float percentage, final float minTextSizePxs) { + public static void adjustText(@NonNull final TextView view, final float percentage, int minTextSizePxs) { + adjustText(view, textViewHelper, percentage, minTextSizePxs); + } + + public static void adjustText(@NonNull final V view, @NonNull Helper helper, final float percentage, final float minTextSizePxs) { ViewTreeObserver treeObserver = getTreeObserver(view); if (treeObserver == null) { return; } - treeObserver.addOnPreDrawListener(new TextViewAdjuster(view, percentage, minTextSizePxs)); + treeObserver.addOnPreDrawListener(new TextViewAdjuster(view, helper, percentage, minTextSizePxs)); } @Nullable @@ -57,6 +73,12 @@ public class Adjuster { treeObserver.addOnPreDrawListener(new MaxWidthAdjuster(view, maxWidth)); } + public interface Helper { + void apply(@NonNull V view, float textSize); + + float getTextSize(@NonNull V view); + } + private static abstract class BaseViewAdjuster implements ViewTreeObserver.OnPreDrawListener { @NonNull protected final V view; @@ -82,24 +104,26 @@ public class Adjuster { protected abstract boolean adjust(int width, int height); } - private static class TextViewAdjuster extends BaseViewAdjuster { + private static class TextViewAdjuster extends BaseViewAdjuster { private final float percentage; private final float minTextSizePxs; + private final Helper helper; - public TextViewAdjuster(@NonNull TextView view, float percentage, float minTextSizePxs) { + public TextViewAdjuster(@NonNull V view, @NonNull Helper helper, float percentage, float minTextSizePxs) { super(view); + this.helper = helper; this.percentage = percentage; this.minTextSizePxs = minTextSizePxs; } @Override protected boolean adjust(int width, int height) { - final float oldTextSize = Math.round(view.getTextSize()); + final float oldTextSize = Math.round(helper.getTextSize(view)); final float newTextSize = Math.max(minTextSizePxs, Math.round(height * percentage)); if (oldTextSize == newTextSize) { return true; } - view.setTextSize(TypedValue.COMPLEX_UNIT_PX, newTextSize); + helper.apply(view, newTextSize); return false; } } diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java b/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java index 75338e8d..b3d8b1ed 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java +++ b/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java @@ -41,20 +41,16 @@ public class DirectionDragButton extends DragButton implements DirectionDragView } @Override - public boolean onPreDraw() { + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); final TextPaint paint = getPaint(); if (baseTextPaint.getTextSize() != paint.getTextSize() || + baseTextPaint.getTypeface() != paint.getTypeface() || baseTextPaint.getColor() != paint.getColor() || baseTextPaint.getAlpha() != paint.getAlpha()) { baseTextPaint.set(paint); textView.setBaseTextPaint(paint); } - return super.onPreDraw(); - } - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); textView.draw(canvas); } diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java b/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java index 58bda9eb..9cdc759b 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java +++ b/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java @@ -54,10 +54,19 @@ public class DirectionDragImageButton extends DragImageButton implements Directi public void setTypeface(@Nonnull Typeface newTypeface) { final Typeface oldTypeface = baseTextPaint.getTypeface(); - if(oldTypeface == newTypeface) { + if (oldTypeface == newTypeface) { return; } baseTextPaint.setTypeface(newTypeface); textView.setBaseTextPaint(baseTextPaint); } + + public void setTextSize(float textSizePxs) { + baseTextPaint.setTextSize(textSizePxs); + textView.setBaseTextPaint(baseTextPaint); + } + + public float getTextSize() { + return baseTextPaint.getTextSize(); + } } diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java b/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java index 0e997b71..3de23fb9 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java +++ b/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java @@ -127,7 +127,10 @@ public class DirectionTextView { paint.set(base); paint.setColor(color); paint.setAlpha(intAlpha()); - paint.setTypeface(Typeface.DEFAULT); + final Typeface typeface = base.getTypeface(); + if (typeface != null && typeface.getStyle() != Typeface.NORMAL) { + paint.setTypeface(Typeface.create(typeface, Typeface.NORMAL)); + } // pre-calculate fixed height paint.setTextSize(Math.max(base.getTextSize() * DEF_SCALE, minTextSize)); @@ -176,7 +179,7 @@ public class DirectionTextView { } public void draw(@NonNull Canvas canvas) { - if (!visible || TextUtils.isEmpty(value)) { + if (!hasValue()) { return; } if (position.x < 0 || position.y < 0) { @@ -222,6 +225,10 @@ public class DirectionTextView { return visible ? value : ""; } + public boolean hasValue() { + return visible && !TextUtils.isEmpty(value); + } + public void setValue(@NonNull String value) { if (TextUtils.equals(this.value, value)) { return; diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/Drag.java b/app/src/main/java/org/solovyev/android/views/dragbutton/Drag.java index a499a99b..425ebafe 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/Drag.java +++ b/app/src/main/java/org/solovyev/android/views/dragbutton/Drag.java @@ -3,8 +3,9 @@ package org.solovyev.android.views.dragbutton; import android.graphics.PointF; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.view.View; -final class Drag { +public final class Drag { private Drag() { } @@ -19,6 +20,13 @@ final class Drag { return new PointF(p1.x - p2.x, p1.y - p2.y); } + public static boolean hasDirectionText(@NonNull View view, @NonNull DragDirection direction) { + if (view instanceof DirectionDragView) { + return ((DirectionDragView) view).getText(direction).hasValue(); + } + return false; + } + @NonNull public static PointF sum(@NonNull PointF p1, @NonNull PointF p2) { return new PointF(p1.x + p2.x, p1.y + p2.y); diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml index 63f2ba2f..c9ab7aee 100644 --- a/app/src/main/res/layout-land/activity_main.xml +++ b/app/src/main/res/layout-land/activity_main.xml @@ -38,13 +38,7 @@ a:orientation="horizontal"> - - @@ -53,17 +47,17 @@ a:id="@+id/display" a:layout_width="0dp" a:layout_height="match_parent" - a:layout_weight="4" + a:layout_weight="5" a:orientation="horizontal" /> diff --git a/app/src/main/res/layout-land/cpp_app_keyboard.xml b/app/src/main/res/layout-land/cpp_app_keyboard.xml index 0219fc2a..e735a01d 100644 --- a/app/src/main/res/layout-land/cpp_app_keyboard.xml +++ b/app/src/main/res/layout-land/cpp_app_keyboard.xml @@ -34,10 +34,10 @@ a:baselineAligned="false" a:orientation="horizontal"> - - + + @@ -48,7 +48,7 @@ - + @@ -59,9 +59,9 @@ a:baselineAligned="false" a:orientation="horizontal"> - + - + @@ -84,9 +84,9 @@ a:baselineAligned="false" a:orientation="horizontal"> - + - + diff --git a/app/src/main/res/layout/cpp_app_button_6.xml b/app/src/main/res/layout/cpp_app_button_6.xml index de56b116..1abffd6e 100644 --- a/app/src/main/res/layout/cpp_app_button_6.xml +++ b/app/src/main/res/layout/cpp_app_button_6.xml @@ -29,5 +29,6 @@ a:id="@id/cpp_button_6" style="?attr/cpp_button_style_digit" a:text="6" + c:directionTextUp="√" c:directionTextLeft="F" tools:ignore="HardcodedText" /> \ No newline at end of file diff --git a/app/src/main/res/layout/cpp_app_button_9.xml b/app/src/main/res/layout/cpp_app_button_9.xml index dbca25a2..5dfa09b1 100644 --- a/app/src/main/res/layout/cpp_app_button_9.xml +++ b/app/src/main/res/layout/cpp_app_button_9.xml @@ -29,7 +29,5 @@ a:id="@id/cpp_button_9" style="?attr/cpp_button_style_digit" a:text="9" - c:directionTextDown="e" c:directionTextLeft="0x:" - c:directionTextUp="π" tools:ignore="HardcodedText" /> \ No newline at end of file diff --git a/app/src/main/res/layout/cpp_app_button_clear.xml b/app/src/main/res/layout/cpp_app_button_clear.xml index f274f6c8..179b4f44 100644 --- a/app/src/main/res/layout/cpp_app_button_clear.xml +++ b/app/src/main/res/layout/cpp_app_button_clear.xml @@ -22,9 +22,12 @@ ~ Site: http://se.solovyev.org --> -