messages on angle units/numeral bases changes

This commit is contained in:
Sergey Solovyev 2012-02-11 00:57:55 +04:00
parent 1adc977d44
commit 6c2270fd73
3 changed files with 73 additions and 20 deletions

View File

@ -110,6 +110,7 @@
<string name="c_calc_layout">Раскладка</string> <string name="c_calc_layout">Раскладка</string>
<string name="p_layout_cellphone">Телефон</string> <string name="p_layout_cellphone">Телефон</string>
<string name="p_layout_calculator">Калькулятор</string> <string name="p_layout_calculator">Калькулятор</string>
<string name="p_layout_simple">Простая</string>
<string name="c_calc_layout_summary">Устанавливает раскладку кнопок</string> <string name="c_calc_layout_summary">Устанавливает раскладку кнопок</string>
<string name="c_calc_haptic_feedback_title">Отклик на нажатие</string> <string name="c_calc_haptic_feedback_title">Отклик на нажатие</string>
@ -182,4 +183,8 @@
Пожалуйста, оцените Калькулятор++ \nна <a href="https://market.android.com/details?id=org.solovyev.android.calculator">андроид.маркете</a>,\n оставьте комментарий или \nобсудите приложение \nна нашем <a href="http://calculatorpp.com/forum/">форуме</a> Пожалуйста, оцените Калькулятор++ \nна <a href="https://market.android.com/details?id=org.solovyev.android.calculator">андроид.маркете</a>,\n оставьте комментарий или \nобсудите приложение \nна нашем <a href="http://calculatorpp.com/forum/">форуме</a>
</string> </string>
<string name="c_angle_units_changed_to">Единицы измерения углов изменены на \'%s\'!</string>
<string name="c_numeral_base_changed_to">Система счисления изменена на \'%s\'!</string>
</resources> </resources>

View File

@ -110,6 +110,7 @@
<string name="c_calc_layout">Layout</string> <string name="c_calc_layout">Layout</string>
<string name="p_layout_cellphone">Cellphone</string> <string name="p_layout_cellphone">Cellphone</string>
<string name="p_layout_calculator">Calculator</string> <string name="p_layout_calculator">Calculator</string>
<string name="p_layout_simple">Simple</string>
<string name="c_calc_layout_summary">Sets layout of buttons</string> <string name="c_calc_layout_summary">Sets layout of buttons</string>
<string name="c_calc_haptic_feedback_title">Haptic feedback</string> <string name="c_calc_haptic_feedback_title">Haptic feedback</string>
@ -182,4 +183,8 @@
Please rate Calculator++ \non <a href="https://market.android.com/details?id=org.solovyev.android.calculator">android.market</a>,\n leave a comment or \ndiscuss application \non our <a href="http://calculatorpp.com/forum/">forum</a> Please rate Calculator++ \non <a href="https://market.android.com/details?id=org.solovyev.android.calculator">android.market</a>,\n leave a comment or \ndiscuss application \non our <a href="http://calculatorpp.com/forum/">forum</a>
</string> </string>
<string name="c_angle_units_changed_to">Angle units changed to \'%s\'!</string>
<string name="c_numeral_base_changed_to">Numeral base changed to \'%s\'!</string>
</resources> </resources>

View File

@ -19,10 +19,7 @@ import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.*; import android.view.*;
import android.widget.Button; import android.widget.*;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.ads.AdView; import com.google.ads.AdView;
import jscl.AngleUnit; import jscl.AngleUnit;
import jscl.NumeralBase; import jscl.NumeralBase;
@ -55,7 +52,6 @@ import org.solovyev.common.utils.history.HistoryAction;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener { public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
@ -100,6 +96,22 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
other 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 { public static class Preferences {
@NotNull @NotNull
private static final String APP_VERSION_P_KEY = "application.version"; 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<Integer> appOpenedCounter = new IntegerPreference(APP_OPENED_COUNTER_P_KEY, APP_OPENED_COUNTER_P_DEFAULT); private static final Preference<Integer> appOpenedCounter = new IntegerPreference(APP_OPENED_COUNTER_P_KEY, APP_OPENED_COUNTER_P_DEFAULT);
private static final Preference<Boolean> feedbackWindowShown = new BooleanPreference(FEEDBACK_WINDOW_SHOWN_P_KEY, FEEDBACK_WINDOW_SHOWN_P_DEFAULT); private static final Preference<Boolean> feedbackWindowShown = new BooleanPreference(FEEDBACK_WINDOW_SHOWN_P_KEY, FEEDBACK_WINDOW_SHOWN_P_DEFAULT);
private static final Preference<Theme> theme = StringPreference.newInstance(THEME_P_KEY, THEME_P_DEFAULT, Theme.class); private static final Preference<Theme> theme = StringPreference.newInstance(THEME_P_KEY, THEME_P_DEFAULT, Theme.class);
private static final Preference<Layout> 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 @NotNull
private static final String THEME_P_KEY = "org.solovyev.android.calculator.CalculatorActivity_calc_theme"; 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; 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; private Theme theme;
@NotNull @NotNull
private String layoutName; private Layout layout;
@Nullable @Nullable
private Vibrator vibrator; private Vibrator vibrator;
@ -267,9 +284,38 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
fixMargins(1, 1); 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); 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) { private void fixMargins(int marginLeft, int marginBottom) {
// sad but true // sad but true
@ -329,6 +375,8 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
CalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnits); 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; result = true;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Log.d(this.getClass().getName(), "Unsupported angle units: " + directionText); 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); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorActivity.this);
CalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase); 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; result = true;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Log.d(this.getClass().getName(), "Unsupported numeral base: " + directionText); 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) { private synchronized void setLayout(@NotNull SharedPreferences preferences) {
final Map<String, Integer> layouts = ResourceCache.instance.getNameToIdCache(R.layout.class); try {
layout = Preferences.layout.getPreference(preferences);
layoutName = preferences.getString(getString(R.string.p_calc_layout_key), getString(R.string.p_calc_layout)); } catch (IllegalArgumentException e) {
layout = LAYOUT_P_DEFAULT;
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);
} }
setContentView(layoutId); setContentView(layout.getLayoutId());
} }
private synchronized void setTheme(@NotNull SharedPreferences preferences) { private synchronized void setTheme(@NotNull SharedPreferences preferences) {
try { try {
theme = Preferences.theme.getPreference(preferences); theme = Preferences.theme.getPreference(preferences);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
@ -717,9 +760,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); 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); final Theme newTheme = Preferences.theme.getPreference(preferences);
if (!theme.equals(newTheme) || !layoutName.equals(newLayoutName)) { if (!theme.equals(newTheme) || !layout.equals(newLayout)) {
AndroidUtils.restartActivity(this); AndroidUtils.restartActivity(this);
} }