From 5ee51fc3f07274917c276fd77128ed74aebe947e Mon Sep 17 00:00:00 2001 From: serso Date: Sat, 15 Oct 2011 21:11:11 +0400 Subject: [PATCH] changes: themes support, scale for direction text --- res/drawable/light_blue_button.xml | 8 +- res/drawable/violet_button.xml | 14 ++ res/layout/calc_division_button.xml | 3 +- res/layout/calc_eight_digit_button.xml | 4 +- res/layout/calc_five_digit_button.xml | 2 +- res/layout/calc_four_digit_button.xml | 2 +- res/layout/calc_multiplication_button.xml | 4 +- res/layout/calc_nine_digit_button.xml | 4 +- res/layout/calc_one_digit_button.xml | 2 +- res/layout/calc_plus_button.xml | 7 +- res/layout/calc_round_brackets_button.xml | 4 +- res/layout/calc_seven_digit_button.xml | 4 +- res/layout/calc_six_digit_button.xml | 2 +- res/layout/calc_square_brackets_button.xml | 4 +- res/layout/calc_subtraction_button.xml | 4 +- res/layout/calc_three_digit_button.xml | 2 +- res/layout/calc_two_digit_button.xml | 2 +- res/layout/calc_zero_digit_button.xml | 4 +- res/layout/drag_button_calibration.xml | 4 +- res/values/arrays.xml | 18 +++ res/values/attrs.xml | 3 + res/values/default_values.xml | 4 + res/values/strings.xml | 1 + res/values/styles.xml | 23 ++- res/xml/main_preferences.xml | 57 ++++--- .../calculator/CalculatorActivity.java | 139 ++++++++++++++---- .../view/widgets/DirectionDragButton.java | 50 +++---- .../view/widgets/SimpleOnDragListener.java | 4 +- 28 files changed, 276 insertions(+), 103 deletions(-) create mode 100644 res/drawable/violet_button.xml create mode 100644 res/values/arrays.xml diff --git a/res/drawable/light_blue_button.xml b/res/drawable/light_blue_button.xml index 4b0623ee..6c2b2aca 100644 --- a/res/drawable/light_blue_button.xml +++ b/res/drawable/light_blue_button.xml @@ -1,6 +1,8 @@ - - - + + + diff --git a/res/drawable/violet_button.xml b/res/drawable/violet_button.xml new file mode 100644 index 00000000..b5133366 --- /dev/null +++ b/res/drawable/violet_button.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/res/layout/calc_division_button.xml b/res/layout/calc_division_button.xml index af34e07e..cb6dc93b 100644 --- a/res/layout/calc_division_button.xml +++ b/res/layout/calc_division_button.xml @@ -10,5 +10,6 @@ xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator" a:id="@+id/divisionButton" a:text="/" calc:textUp="√" - style="@style/digit_button_style" + calc:directionTextScale="0.5" + style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/calc_eight_digit_button.xml b/res/layout/calc_eight_digit_button.xml index 8f3a85c1..3f67d691 100644 --- a/res/layout/calc_eight_digit_button.xml +++ b/res/layout/calc_eight_digit_button.xml @@ -11,5 +11,7 @@ a:id="@+id/eightDigitButton" a:text="8" calc:textUp="ln" calc:textDown="" - style="@style/digit_button_style" + calc:directionTextScale="0.5" + + style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/calc_five_digit_button.xml b/res/layout/calc_five_digit_button.xml index e0298ed0..c398a472 100644 --- a/res/layout/calc_five_digit_button.xml +++ b/res/layout/calc_five_digit_button.xml @@ -11,5 +11,5 @@ a:text="5" calc:textUp="cosh" calc:textDown="acosh" - style="@style/digit_button_style" + style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/calc_four_digit_button.xml b/res/layout/calc_four_digit_button.xml index 0e91a73d..2e3d1311 100644 --- a/res/layout/calc_four_digit_button.xml +++ b/res/layout/calc_four_digit_button.xml @@ -11,5 +11,5 @@ a:text="4" calc:textUp="sinh" calc:textDown="asinh" - style="@style/digit_button_style" + style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/calc_multiplication_button.xml b/res/layout/calc_multiplication_button.xml index 2f098764..1f76d1e6 100644 --- a/res/layout/calc_multiplication_button.xml +++ b/res/layout/calc_multiplication_button.xml @@ -12,5 +12,7 @@ a:text="×" calc:textUp="^" calc:textDown="^2" - style="@style/digit_button_style" + style="?digitButtonStyle" + calc:directionTextScale="0.5" + a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/calc_nine_digit_button.xml b/res/layout/calc_nine_digit_button.xml index 5551abe5..b3bfc9cb 100644 --- a/res/layout/calc_nine_digit_button.xml +++ b/res/layout/calc_nine_digit_button.xml @@ -11,5 +11,7 @@ a:id="@+id/nineDigitButton" a:text="9" calc:textDown="e" calc:textUp="π" - style="@style/digit_button_style" + calc:directionTextScale="0.5" + + style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/calc_one_digit_button.xml b/res/layout/calc_one_digit_button.xml index a8122356..4be170b3 100644 --- a/res/layout/calc_one_digit_button.xml +++ b/res/layout/calc_one_digit_button.xml @@ -12,5 +12,5 @@ a:text="1" calc:textUp="sin" calc:textDown="asin" - style="@style/digit_button_style" + style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/calc_plus_button.xml b/res/layout/calc_plus_button.xml index c0124cb7..95bc03a4 100644 --- a/res/layout/calc_plus_button.xml +++ b/res/layout/calc_plus_button.xml @@ -7,6 +7,9 @@ --> \ No newline at end of file diff --git a/res/layout/calc_round_brackets_button.xml b/res/layout/calc_round_brackets_button.xml index b1f780ed..87b91989 100644 --- a/res/layout/calc_round_brackets_button.xml +++ b/res/layout/calc_round_brackets_button.xml @@ -11,5 +11,7 @@ a:id="@+id/roundBracketsButton" a:text="()" calc:textUp="(" calc:textDown=")" - style="@style/digit_button_style" + calc:directionTextScale="0.5" + + style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/calc_seven_digit_button.xml b/res/layout/calc_seven_digit_button.xml index 04813bc1..880db6da 100644 --- a/res/layout/calc_seven_digit_button.xml +++ b/res/layout/calc_seven_digit_button.xml @@ -11,5 +11,7 @@ a:id="@+id/sevenDigitButton" a:text="7" calc:textUp="i" calc:textDown="" - style="@style/digit_button_style" + calc:directionTextScale="0.5" + + style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/calc_six_digit_button.xml b/res/layout/calc_six_digit_button.xml index 8246edb7..36645dcc 100644 --- a/res/layout/calc_six_digit_button.xml +++ b/res/layout/calc_six_digit_button.xml @@ -11,5 +11,5 @@ a:id="@+id/sixDigitButton" a:text="6" calc:textUp="tanh" calc:textDown="atanh" - style="@style/digit_button_style" + style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/calc_square_brackets_button.xml b/res/layout/calc_square_brackets_button.xml index f23abd5c..1afa8205 100644 --- a/res/layout/calc_square_brackets_button.xml +++ b/res/layout/calc_square_brackets_button.xml @@ -11,5 +11,7 @@ a:id="@+id/squareBracketsButton" a:text="[]" calc:textUp="[" calc:textDown="]" - style="@style/digit_button_style" + calc:directionTextScale="0.5" + + style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/calc_subtraction_button.xml b/res/layout/calc_subtraction_button.xml index cc48a901..a0d68986 100644 --- a/res/layout/calc_subtraction_button.xml +++ b/res/layout/calc_subtraction_button.xml @@ -10,5 +10,7 @@ a:id="@+id/subtractionButton" a:text="-" calc:textUp="{" calc:textDown="}" - style="@style/digit_button_style" + calc:directionTextScale="0.5" + + style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/calc_three_digit_button.xml b/res/layout/calc_three_digit_button.xml index c35e6e78..75883444 100644 --- a/res/layout/calc_three_digit_button.xml +++ b/res/layout/calc_three_digit_button.xml @@ -12,5 +12,5 @@ a:text="3" calc:textUp="tan" calc:textDown="atan" - style="@style/digit_button_style" + style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/calc_two_digit_button.xml b/res/layout/calc_two_digit_button.xml index 7df28622..f2897ad6 100644 --- a/res/layout/calc_two_digit_button.xml +++ b/res/layout/calc_two_digit_button.xml @@ -12,5 +12,5 @@ a:text="2" calc:textUp="cos" calc:textDown="acos" - style="@style/digit_button_style" + style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/calc_zero_digit_button.xml b/res/layout/calc_zero_digit_button.xml index 3bb1b7f7..794d1f56 100644 --- a/res/layout/calc_zero_digit_button.xml +++ b/res/layout/calc_zero_digit_button.xml @@ -11,5 +11,7 @@ a:id="@+id/zeroDigitButton" a:text="0" calc:textUp="." calc:textDown="," - style="@style/digit_button_style" + calc:directionTextScale="0.5" + + style="?digitButtonStyle" a:onClick="digitButtonClickHandler"/> \ No newline at end of file diff --git a/res/layout/drag_button_calibration.xml b/res/layout/drag_button_calibration.xml index 47179e82..ca040aab 100644 --- a/res/layout/drag_button_calibration.xml +++ b/res/layout/drag_button_calibration.xml @@ -27,7 +27,7 @@ calc:textDown="@string/c_down" a:layout_width="80dp" a:layout_height="80dp" - style="@style/digit_button_style"/> + style="?digitButtonStyle"/> + style="?digitButtonStyle"/> + + + + Default + Violet + Light blue + + + default_theme + violet_theme + light_blue_theme + + \ No newline at end of file diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 51f2e6a6..dbfabffb 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -3,6 +3,7 @@ + @@ -10,4 +11,6 @@ + + diff --git a/res/values/default_values.xml b/res/values/default_values.xml index ca207e09..5b8b8f63 100644 --- a/res/values/default_values.xml +++ b/res/values/default_values.xml @@ -20,4 +20,8 @@ true org.solovyev.android.calculator.CalculatorModel_vars + + org.solovyev.android.calculator.CalculatorActivity_calc_theme + default_theme + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index a0efd8a9..604d8e0b 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -75,4 +75,5 @@ History is empty! History Character \'%s\' is not accepted in variable name! + Theme diff --git a/res/values/styles.xml b/res/values/styles.xml index c3bcfbe8..38631ef0 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -15,13 +15,23 @@ 20dp @drawable/button 1dp + 1dp - + + + + @@ -56,5 +66,16 @@ match_parent + + + + + diff --git a/res/xml/main_preferences.xml b/res/xml/main_preferences.xml index d0730155..efc486d3 100644 --- a/res/xml/main_preferences.xml +++ b/res/xml/main_preferences.xml @@ -11,33 +11,42 @@ range:boundaries="0;10"/> + a:key="@string/p_calc_color_display_key" + a:title="@string/c_calc_color_display_title" + a:defaultValue="true"/> - + diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index dd4a1bcf..07f9fd17 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -31,6 +31,10 @@ import org.solovyev.common.utils.history.HistoryAction; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener { @@ -54,11 +58,26 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh private volatile boolean initialized; + @NotNull + private String themeName; + + // key: style name, value: id of style in R.class + private Map styles = null; + + // ids of drag buttons in R.class + private List dragButtonIds = null; + + /** * Called when the activity is first created. */ @Override public void onCreate(@Nullable Bundle savedInstanceState) { + Log.d(this.getClass().getName(), "org.solovyev.android.calculator.CalculatorActivity.onCreate()"); + + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); + + setTheme(preferences); super.onCreate(savedInstanceState); setContentView(R.layout.main); @@ -68,28 +87,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh dpclRegister.clear(); - final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(this); + final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, this); - final SimpleOnDragListener onDragListener = new SimpleOnDragListener(new DigitButtonDragProcessor(calculatorView), dragPreferences); - dpclRegister.addListener(onDragListener); - - // todo serso: check if there is more convenient method for doing this - final R.id ids = new R.id(); - for (Field field : R.id.class.getDeclaredFields()) { - int modifiers = field.getModifiers(); - if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) { - try { - final View view = findViewById(field.getInt(ids)); - if (view instanceof DragButton) { - ((DragButton) view).setOnDragListener(onDragListener); - } - } catch (IllegalArgumentException e) { - Log.e(CalculatorActivity.class.getName(), e.getMessage()); - } catch (IllegalAccessException e) { - Log.e(CalculatorActivity.class.getName(), e.getMessage()); - } - } - } + setOnDragListeners(dragPreferences); final SimpleOnDragListener historyOnDragListener = new SimpleOnDragListener(new HistoryDragProcessor(this.calculatorView), dragPreferences); ((DragButton) findViewById(R.id.historyButton)).setOnDragListener(historyOnDragListener); @@ -100,10 +100,68 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh ((DragButton) findViewById(R.id.leftButton)).setOnDragListener(toPositionOnDragListener); dpclRegister.addListener(toPositionOnDragListener); - final SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - defaultSharedPreferences.registerOnSharedPreferenceChangeListener(this); + preferences.registerOnSharedPreferenceChangeListener(this); - this.onSharedPreferenceChanged(defaultSharedPreferences, null); + this.onSharedPreferenceChanged(preferences, null); + } + + private synchronized void setOnDragListeners(@NotNull SimpleOnDragListener.Preferences dragPreferences) { + final SimpleOnDragListener onDragListener = new SimpleOnDragListener(new DigitButtonDragProcessor(calculatorView), dragPreferences); + dpclRegister.addListener(onDragListener); + + if (dragButtonIds == null) { + dragButtonIds = new ArrayList(); + + for (Field field : R.id.class.getDeclaredFields()) { + int modifiers = field.getModifiers(); + if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) { + try { + int dragButtonId = field.getInt(R.id.class); + final View view = findViewById(dragButtonId); + if (view instanceof DragButton) { + dragButtonIds.add(dragButtonId); + } + } catch (IllegalAccessException e) { + Log.e(CalculatorActivity.class.getName(), e.getMessage()); + } + } + } + } + + for (Integer dragButtonId : dragButtonIds) { + ((DragButton) findViewById(dragButtonId)).setOnDragListener(onDragListener); + } + } + + private synchronized void setTheme(@NotNull SharedPreferences preferences) { + if (styles == null) { + styles = new HashMap(); + for (Field themeField : R.style.class.getDeclaredFields()) { + int modifiers = themeField.getModifiers(); + if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) { + try { + Log.d(this.getClass().getName(), "Style found: " + themeField.getName()); + int styleId = themeField.getInt(R.style.class); + Log.d(this.getClass().getName(), "Style id: " + styleId); + styles.put(themeField.getName(), styleId); + } catch (IllegalAccessException e) { + Log.e(CalculatorActivity.class.getName(), e.getMessage()); + } + } + } + } + + themeName = preferences.getString(getString(R.string.p_calc_theme_key), getString(R.string.p_calc_theme)); + + Integer styleId = styles.get(themeName); + if (styleId == null) { + Log.d(this.getClass().getName(), "No saved theme found => applying default theme: " + R.style.default_theme); + styleId = R.style.default_theme; + } else { + Log.d(this.getClass().getName(), "Saved them found: " + styleId); + } + + setTheme(styleId); } private void init() { @@ -130,6 +188,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh @Override public void doOperation(@NotNull EditText editor) { editor.setText(s); + calculatorView.setCursorOnEnd(); } }); } @@ -146,13 +205,13 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh try { CalculatorModel.instance.init(this); } catch (EvalError evalError) { - // todo serso: create serso runtime exception throw new RuntimeException("Could not initialize interpreter!"); } initialized = true; } } + @Override protected void onDestroy() { unregisterReceiver(textReceiver); @@ -332,15 +391,39 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontPixelSize * ratio); } + public void restart() { + final Intent intent = getIntent(); + overridePendingTransition(0, 0); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + + Log.d(this.getClass().getName(), "Finishing current activity!"); + finish(); + + overridePendingTransition(0, 0); + Log.d(this.getClass().getName(), "Starting new activity!"); + startActivity(intent); + } + @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, @Nullable String s) { - dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(CalculatorActivity.this)); + protected void onResume() { + super.onResume(); + + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); + final String newThemeName = preferences.getString(getString(R.string.p_calc_theme_key), getString(R.string.p_calc_theme)); + if (!newThemeName.equals(themeName)) { + restart(); + } + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String s) { + dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, this)); CalculatorModel.instance.reset(this); final Boolean colorExpressionsInBracketsDefault = new BooleanMapper().parseValue(this.getString(R.string.p_calc_color_display)); assert colorExpressionsInBracketsDefault != null; - this.calculatorView.getEditor().setHighlightText(sharedPreferences.getBoolean(this.getString(R.string.p_calc_color_display_key), colorExpressionsInBracketsDefault)); + this.calculatorView.getEditor().setHighlightText(preferences.getBoolean(this.getString(R.string.p_calc_color_display_key), colorExpressionsInBracketsDefault)); this.calculatorView.evaluate(); } diff --git a/src/main/java/org/solovyev/android/view/widgets/DirectionDragButton.java b/src/main/java/org/solovyev/android/view/widgets/DirectionDragButton.java index 48e1b777..dd832552 100644 --- a/src/main/java/org/solovyev/android/view/widgets/DirectionDragButton.java +++ b/src/main/java/org/solovyev/android/view/widgets/DirectionDragButton.java @@ -13,6 +13,7 @@ import android.text.TextPaint; import android.util.AttributeSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.solovyev.android.calculator.R; import org.solovyev.common.utils.Point2d; import org.solovyev.common.utils.StringUtils; @@ -23,6 +24,9 @@ import org.solovyev.common.utils.StringUtils; */ public class DirectionDragButton extends DragButton { + @NotNull + private final static Float DEFAULT_DIRECTION_TEXT_SCALE = 0.33f; + @Nullable private String textUp; @@ -41,6 +45,9 @@ public class DirectionDragButton extends DragButton { @NotNull private TextPaint upDownTextPaint; + @Nullable + private Float directionTextScale = DEFAULT_DIRECTION_TEXT_SCALE; + public DirectionDragButton(Context context, @NotNull AttributeSet attrs) { super(context, attrs, false); init(context, attrs); @@ -76,12 +83,15 @@ public class DirectionDragButton extends DragButton { for (int i = 0; i < N; i++) { int attr = a.getIndex(i); switch (attr) { - case org.solovyev.android.calculator.R.styleable.DragButton_textUp: + case R.styleable.DragButton_textUp: this.textUp = a.getString(attr); break; - case org.solovyev.android.calculator.R.styleable.DragButton_textDown: + case R.styleable.DragButton_textDown: this.textDown = a.getString(attr); break; + case R.styleable.DragButton_directionTextScale: + this.directionTextScale = Float.valueOf(a.getString(attr)); + break; } } @@ -99,15 +109,15 @@ public class DirectionDragButton extends DragButton { initUpDownTextPaint(basePaint); if (textUp != null) { - textUpPosition = getTextPosition(upDownTextPaint, basePaint, textUp, getText(), 1, getWidth(), getHeight()); + textUpPosition = getTextPosition(upDownTextPaint, basePaint, textUp, getText(), 1, getWidth(), getHeight(), getDirectionTextScale()); } if (textDown != null) { - textDownPosition = getTextPosition(upDownTextPaint, basePaint, textDown, getText(), -1, getWidth(), getHeight()); + textDownPosition = getTextPosition(upDownTextPaint, basePaint, textDown, getText(), -1, getWidth(), getHeight(), getDirectionTextScale()); } - if ( textDownPosition != null && textUpPosition != null ) { - if ( textDownPosition.getX() > textUpPosition.getX() ) { + if (textDownPosition != null && textUpPosition != null) { + if (textDownPosition.getX() > textUpPosition.getX()) { textDownPosition.setX(textUpPosition.getX()); } else { textUpPosition.setX(textDownPosition.getX()); @@ -116,7 +126,7 @@ public class DirectionDragButton extends DragButton { } - public static Point2d getTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, @NotNull CharSequence text, CharSequence baseText, float direction, int w, int h) { + public static Point2d getTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, @NotNull CharSequence text, CharSequence baseText, float direction, int w, int h, float scale) { final Point2d result = new Point2d(); float width = paint.measureText(text.toString() + " "); @@ -157,15 +167,7 @@ public class DirectionDragButton extends DragButton { upDownTextPaint = new TextPaint(paint); upDownTextPaint.setAlpha(150); - upDownTextPaint.setTextSize(paint.getTextSize() / 3); - } - - private String getStyledUpDownText(@Nullable String text) { - return StringUtils.getNotEmpty(text, " "); - } - - public void setTextUp(@Nullable String textUp) { - this.textUp = textUp; + upDownTextPaint.setTextSize(paint.getTextSize() * getDirectionTextScale()); } @Nullable @@ -173,19 +175,11 @@ public class DirectionDragButton extends DragButton { return textUp; } - public void setTextDown(@Nullable String textDown) { - this.textDown = textDown; - } - @Nullable public String getTextDown() { return textDown; } - public void setTextMiddle(@Nullable String textMiddle) { - this.textMiddle = textMiddle; - } - @Nullable public String getTextMiddle() { return textMiddle; @@ -197,7 +191,7 @@ public class DirectionDragButton extends DragButton { if (direction == DragDirection.up) { result = getTextUp(); - } else if ( direction == DragDirection.down ) { + } else if (direction == DragDirection.down) { result = getTextDown(); } else { result = null; @@ -205,4 +199,10 @@ public class DirectionDragButton extends DragButton { return result; } + + @NotNull + public Float getDirectionTextScale() { + return directionTextScale == null ? DEFAULT_DIRECTION_TEXT_SCALE : directionTextScale; + } + } diff --git a/src/main/java/org/solovyev/android/view/widgets/SimpleOnDragListener.java b/src/main/java/org/solovyev/android/view/widgets/SimpleOnDragListener.java index 6c475c94..5d8c0eee 100644 --- a/src/main/java/org/solovyev/android/view/widgets/SimpleOnDragListener.java +++ b/src/main/java/org/solovyev/android/view/widgets/SimpleOnDragListener.java @@ -7,7 +7,6 @@ package org.solovyev.android.view.widgets; import android.content.Context; import android.content.SharedPreferences; -import android.preference.PreferenceManager; import android.util.Log; import android.view.MotionEvent; import org.jetbrains.annotations.NotNull; @@ -146,8 +145,7 @@ public class SimpleOnDragListener implements OnDragListener, DragPreferencesChan } @NotNull - public static Preferences getPreferences(@NotNull Context context) { - final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + public static Preferences getPreferences(@NotNull final SharedPreferences preferences, @NotNull Context context) { final Mapper> mapper = new NumberIntervalMapper(Float.class);