From 6c2270fd73d948ba4ffc830164056040a8a1d627 Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Sat, 11 Feb 2012 00:57:55 +0400 Subject: [PATCH] messages on angle units/numeral bases changes --- res/values-ru/text_strings.xml | 5 ++ res/values/text_strings.xml | 5 ++ .../calculator/CalculatorActivity.java | 83 ++++++++++++++----- 3 files changed, 73 insertions(+), 20 deletions(-) diff --git a/res/values-ru/text_strings.xml b/res/values-ru/text_strings.xml index 437b9fcd..0f542a07 100644 --- a/res/values-ru/text_strings.xml +++ b/res/values-ru/text_strings.xml @@ -110,6 +110,7 @@ Раскладка Телефон Калькулятор + Простая Устанавливает раскладку кнопок Отклик на нажатие @@ -182,4 +183,8 @@ Пожалуйста, оцените Калькулятор++ \nна андроид.маркете,\n оставьте комментарий или \nобсудите приложение \nна нашем форуме + Единицы измерения углов изменены на \'%s\'! + Система счисления изменена на \'%s\'! + + \ No newline at end of file diff --git a/res/values/text_strings.xml b/res/values/text_strings.xml index 0ed5b3fb..5ac941cd 100644 --- a/res/values/text_strings.xml +++ b/res/values/text_strings.xml @@ -110,6 +110,7 @@ Layout Cellphone Calculator + Simple Sets layout of buttons Haptic feedback @@ -182,4 +183,8 @@ Please rate Calculator++ \non android.market,\n leave a comment or \ndiscuss application \non our forum + Angle units changed to \'%s\'! + Numeral base changed to \'%s\'! + + \ No newline at end of file diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java index 3c662f45..1d9952d3 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java @@ -19,10 +19,7 @@ import android.util.DisplayMetrics; import android.util.Log; import android.util.TypedValue; import android.view.*; -import android.widget.Button; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.TextView; +import android.widget.*; import com.google.ads.AdView; import jscl.AngleUnit; import jscl.NumeralBase; @@ -55,7 +52,6 @@ import org.solovyev.common.utils.history.HistoryAction; import java.text.DecimalFormatSymbols; import java.util.Locale; -import java.util.Map; public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener { @@ -100,6 +96,22 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh other } + public static enum Layout { + main_calculator(R.layout.main_calculator), + main_cellphone(R.layout.main_cellphone), + simple(R.layout.main_calculator); + + private final int layoutId; + + Layout(int layoutId) { + this.layoutId = layoutId; + } + + public int getLayoutId() { + return layoutId; + } + } + public static class Preferences { @NotNull private static final String APP_VERSION_P_KEY = "application.version"; @@ -109,8 +121,13 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh private static final Preference appOpenedCounter = new IntegerPreference(APP_OPENED_COUNTER_P_KEY, APP_OPENED_COUNTER_P_DEFAULT); private static final Preference feedbackWindowShown = new BooleanPreference(FEEDBACK_WINDOW_SHOWN_P_KEY, FEEDBACK_WINDOW_SHOWN_P_DEFAULT); private static final Preference theme = StringPreference.newInstance(THEME_P_KEY, THEME_P_DEFAULT, Theme.class); + private static final Preference layout = StringPreference.newInstance(LAYOUT_P_KEY, LAYOUT_P_DEFAULT, Layout.class); } + @NotNull + private static final String LAYOUT_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_calc_layout"; + private static final Layout LAYOUT_P_DEFAULT = Layout.main_calculator; + @NotNull private static final String THEME_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_calc_theme"; private static final Theme THEME_P_DEFAULT = Theme.metro_blue_theme; @@ -143,7 +160,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh private Theme theme; @NotNull - private String layoutName; + private Layout layout; @Nullable private Vibrator vibrator; @@ -267,9 +284,38 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh fixMargins(1, 1); } + if (layout == Layout.simple) { + toggleButtonDirectionText(R.id.oneDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down); + toggleButtonDirectionText(R.id.twoDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down); + toggleButtonDirectionText(R.id.threeDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down); + + toggleButtonDirectionText(R.id.sevenDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down); + toggleButtonDirectionText(R.id.eightDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down); + + toggleButtonDirectionText(R.id.fourDigitButton, false, DragDirection.left, DragDirection.down); + toggleButtonDirectionText(R.id.fiveDigitButton, false, DragDirection.left, DragDirection.down); + toggleButtonDirectionText(R.id.sixDigitButton, false, DragDirection.left); + + toggleButtonDirectionText(R.id.nineDigitButton, false, DragDirection.left); + + toggleButtonDirectionText(R.id.multiplicationButton, false, DragDirection.left); + toggleButtonDirectionText(R.id.plusButton, false, DragDirection.down, DragDirection.up); + + } + preferences.registerOnSharedPreferenceChangeListener(this); } + private void toggleButtonDirectionText(int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) { + final View v = findViewById(id); + if (v instanceof DirectionDragButton ) { + final DirectionDragButton button = (DirectionDragButton)v; + for (DragDirection dragDirection : dragDirections) { + button.showDirectionText(showDirectionText, dragDirection); + } + } + } + private void fixMargins(int marginLeft, int marginBottom) { // sad but true @@ -329,6 +375,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh CalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnits); + Toast.makeText(CalculatorActivity.this, CalculatorActivity.this.getString(R.string.c_angle_units_changed_to, angleUnits.name()), Toast.LENGTH_LONG).show(); + result = true; } catch (IllegalArgumentException e) { Log.d(this.getClass().getName(), "Unsupported angle units: " + directionText); @@ -362,6 +410,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorActivity.this); CalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase); + Toast.makeText(CalculatorActivity.this, CalculatorActivity.this.getString(R.string.c_numeral_base_changed_to, numeralBase.name()), Toast.LENGTH_LONG).show(); + result = true; } catch (IllegalArgumentException e) { Log.d(this.getClass().getName(), "Unsupported numeral base: " + directionText); @@ -463,23 +513,16 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh private synchronized void setLayout(@NotNull SharedPreferences preferences) { - final Map layouts = ResourceCache.instance.getNameToIdCache(R.layout.class); - - layoutName = preferences.getString(getString(R.string.p_calc_layout_key), getString(R.string.p_calc_layout)); - - Integer layoutId = layouts.get(layoutName); - if (layoutId == null) { - Log.d(this.getClass().getName(), "No saved layout found => applying default layout: " + R.layout.main_calculator); - layoutId = R.layout.main_calculator; - } else { - Log.d(this.getClass().getName(), "Saved layout found: " + layoutId); + try { + layout = Preferences.layout.getPreference(preferences); + } catch (IllegalArgumentException e) { + layout = LAYOUT_P_DEFAULT; } - setContentView(layoutId); + setContentView(layout.getLayoutId()); } private synchronized void setTheme(@NotNull SharedPreferences preferences) { - try { theme = Preferences.theme.getPreference(preferences); } catch (IllegalArgumentException e) { @@ -717,9 +760,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); - final String newLayoutName = preferences.getString(getString(R.string.p_calc_layout_key), getString(R.string.p_calc_layout)); + final Layout newLayout = Preferences.layout.getPreference(preferences); final Theme newTheme = Preferences.theme.getPreference(preferences); - if (!theme.equals(newTheme) || !layoutName.equals(newLayoutName)) { + if (!theme.equals(newTheme) || !layout.equals(newLayout)) { AndroidUtils.restartActivity(this); }