diff --git a/calculatorpp/res/drawable-hdpi/heart.png b/calculatorpp/res/drawable-hdpi/heart.png
deleted file mode 100644
index b4608722..00000000
Binary files a/calculatorpp/res/drawable-hdpi/heart.png and /dev/null differ
diff --git a/calculatorpp/res/drawable-hdpi/copy.png b/calculatorpp/res/drawable-hdpi/kb_copy.png
similarity index 100%
rename from calculatorpp/res/drawable-hdpi/copy.png
rename to calculatorpp/res/drawable-hdpi/kb_copy.png
diff --git a/calculatorpp/res/drawable-hdpi/sym_keyboard_delete.png b/calculatorpp/res/drawable-hdpi/kb_delete.png
similarity index 100%
rename from calculatorpp/res/drawable-hdpi/sym_keyboard_delete.png
rename to calculatorpp/res/drawable-hdpi/kb_delete.png
diff --git a/calculatorpp/res/drawable-hdpi/heart2.png b/calculatorpp/res/drawable-hdpi/kb_heart.png
similarity index 100%
rename from calculatorpp/res/drawable-hdpi/heart2.png
rename to calculatorpp/res/drawable-hdpi/kb_heart.png
diff --git a/calculatorpp/res/drawable-hdpi/paste.png b/calculatorpp/res/drawable-hdpi/kb_paste.png
similarity index 100%
rename from calculatorpp/res/drawable-hdpi/paste.png
rename to calculatorpp/res/drawable-hdpi/kb_paste.png
diff --git a/calculatorpp/res/drawable-mdpi/copy.png b/calculatorpp/res/drawable-large-hdpi/kb_copy.png
similarity index 100%
rename from calculatorpp/res/drawable-mdpi/copy.png
rename to calculatorpp/res/drawable-large-hdpi/kb_copy.png
diff --git a/calculatorpp/res/drawable-mdpi/sym_keyboard_delete.png b/calculatorpp/res/drawable-large-hdpi/kb_delete.png
similarity index 100%
rename from calculatorpp/res/drawable-mdpi/sym_keyboard_delete.png
rename to calculatorpp/res/drawable-large-hdpi/kb_delete.png
diff --git a/calculatorpp/res/drawable-mdpi/heart2.png b/calculatorpp/res/drawable-large-hdpi/kb_heart.png
similarity index 100%
rename from calculatorpp/res/drawable-mdpi/heart2.png
rename to calculatorpp/res/drawable-large-hdpi/kb_heart.png
diff --git a/calculatorpp/res/drawable-mdpi/paste.png b/calculatorpp/res/drawable-large-hdpi/kb_paste.png
similarity index 100%
rename from calculatorpp/res/drawable-mdpi/paste.png
rename to calculatorpp/res/drawable-large-hdpi/kb_paste.png
diff --git a/calculatorpp/res/drawable-ldpi/copy.png b/calculatorpp/res/drawable-ldpi/kb_copy.png
similarity index 100%
rename from calculatorpp/res/drawable-ldpi/copy.png
rename to calculatorpp/res/drawable-ldpi/kb_copy.png
diff --git a/calculatorpp/res/drawable-ldpi/sym_keyboard_delete.png b/calculatorpp/res/drawable-ldpi/kb_delete.png
similarity index 100%
rename from calculatorpp/res/drawable-ldpi/sym_keyboard_delete.png
rename to calculatorpp/res/drawable-ldpi/kb_delete.png
diff --git a/calculatorpp/res/drawable-ldpi/heart2.png b/calculatorpp/res/drawable-ldpi/kb_heart.png
similarity index 100%
rename from calculatorpp/res/drawable-ldpi/heart2.png
rename to calculatorpp/res/drawable-ldpi/kb_heart.png
diff --git a/calculatorpp/res/drawable-ldpi/paste.png b/calculatorpp/res/drawable-ldpi/kb_paste.png
similarity index 100%
rename from calculatorpp/res/drawable-ldpi/paste.png
rename to calculatorpp/res/drawable-ldpi/kb_paste.png
diff --git a/calculatorpp/res/drawable-ldpi/heart.png b/calculatorpp/res/drawable-mdpi/kb_copy.png
similarity index 65%
rename from calculatorpp/res/drawable-ldpi/heart.png
rename to calculatorpp/res/drawable-mdpi/kb_copy.png
index 5e43812b..fcc9166d 100644
Binary files a/calculatorpp/res/drawable-ldpi/heart.png and b/calculatorpp/res/drawable-mdpi/kb_copy.png differ
diff --git a/calculatorpp/res/drawable-mdpi/kb_delete.png b/calculatorpp/res/drawable-mdpi/kb_delete.png
new file mode 100644
index 00000000..b6643eec
Binary files /dev/null and b/calculatorpp/res/drawable-mdpi/kb_delete.png differ
diff --git a/calculatorpp/res/drawable-mdpi/kb_heart.png b/calculatorpp/res/drawable-mdpi/kb_heart.png
new file mode 100644
index 00000000..c907e2e2
Binary files /dev/null and b/calculatorpp/res/drawable-mdpi/kb_heart.png differ
diff --git a/calculatorpp/res/drawable-mdpi/heart.png b/calculatorpp/res/drawable-mdpi/kb_paste.png
similarity index 54%
rename from calculatorpp/res/drawable-mdpi/heart.png
rename to calculatorpp/res/drawable-mdpi/kb_paste.png
index 1e0d1811..99b3e090 100644
Binary files a/calculatorpp/res/drawable-mdpi/heart.png and b/calculatorpp/res/drawable-mdpi/kb_paste.png differ
diff --git a/calculatorpp/res/drawable-xhdpi/heart.png b/calculatorpp/res/drawable-xhdpi/heart.png
deleted file mode 100644
index a97c85b0..00000000
Binary files a/calculatorpp/res/drawable-xhdpi/heart.png and /dev/null differ
diff --git a/calculatorpp/res/drawable-xhdpi/copy.png b/calculatorpp/res/drawable-xhdpi/kb_copy.png
similarity index 100%
rename from calculatorpp/res/drawable-xhdpi/copy.png
rename to calculatorpp/res/drawable-xhdpi/kb_copy.png
diff --git a/calculatorpp/res/drawable-xhdpi/sym_keyboard_delete.png b/calculatorpp/res/drawable-xhdpi/kb_delete.png
similarity index 100%
rename from calculatorpp/res/drawable-xhdpi/sym_keyboard_delete.png
rename to calculatorpp/res/drawable-xhdpi/kb_delete.png
diff --git a/calculatorpp/res/drawable-xhdpi/heart2.png b/calculatorpp/res/drawable-xhdpi/kb_heart.png
similarity index 100%
rename from calculatorpp/res/drawable-xhdpi/heart2.png
rename to calculatorpp/res/drawable-xhdpi/kb_heart.png
diff --git a/calculatorpp/res/drawable-xhdpi/paste.png b/calculatorpp/res/drawable-xhdpi/kb_paste.png
similarity index 100%
rename from calculatorpp/res/drawable-xhdpi/paste.png
rename to calculatorpp/res/drawable-xhdpi/kb_paste.png
diff --git a/calculatorpp/res/layout-land/main_cellphone.xml b/calculatorpp/res/layout-land/main_cellphone.xml
index 8b7e90d7..91fc9ba7 100644
--- a/calculatorpp/res/layout-land/main_cellphone.xml
+++ b/calculatorpp/res/layout-land/main_cellphone.xml
@@ -1,113 +1,113 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/calculatorpp/res/layout-large/calc_keyboard.xml b/calculatorpp/res/layout-large/calc_keyboard.xml
index 5bab90d8..29dd1bcc 100644
--- a/calculatorpp/res/layout-large/calc_keyboard.xml
+++ b/calculatorpp/res/layout-large/calc_keyboard.xml
@@ -1,53 +1,68 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/calculatorpp/res/layout/calc_copy_button.xml b/calculatorpp/res/layout/calc_copy_button.xml
index 5a8974f9..436572ce 100644
--- a/calculatorpp/res/layout/calc_copy_button.xml
+++ b/calculatorpp/res/layout/calc_copy_button.xml
@@ -1,14 +1,14 @@
-
-
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/calculatorpp/res/layout/calc_donate_button.xml b/calculatorpp/res/layout/calc_donate_button.xml
index 4796faed..a6d6d3f3 100644
--- a/calculatorpp/res/layout/calc_donate_button.xml
+++ b/calculatorpp/res/layout/calc_donate_button.xml
@@ -1,13 +1,13 @@
-
-
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/calculatorpp/res/layout/calc_erase_button.xml b/calculatorpp/res/layout/calc_erase_button.xml
index 679efc70..b1ac9606 100644
--- a/calculatorpp/res/layout/calc_erase_button.xml
+++ b/calculatorpp/res/layout/calc_erase_button.xml
@@ -1,14 +1,14 @@
-
-
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/calculatorpp/res/layout/calc_paste_button.xml b/calculatorpp/res/layout/calc_paste_button.xml
index b0b69e5c..bde5f9ed 100644
--- a/calculatorpp/res/layout/calc_paste_button.xml
+++ b/calculatorpp/res/layout/calc_paste_button.xml
@@ -1,14 +1,14 @@
-
-
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/calculatorpp/res/layout/math_entity.xml b/calculatorpp/res/layout/math_entity.xml
index eb2e088a..1007e1a4 100644
--- a/calculatorpp/res/layout/math_entity.xml
+++ b/calculatorpp/res/layout/math_entity.xml
@@ -7,20 +7,21 @@
-->
+ a:layout_height="wrap_content"
+ a:layout_width="match_parent"
+ a:paddingBottom="@dimen/pane_padding"
+ a:orientation="vertical">
-
-
+
+
-
-
+
+
\ No newline at end of file
diff --git a/calculatorpp/res/layout/var_edit.xml b/calculatorpp/res/layout/var_edit.xml
index 8c73e3ec..b5e1aa01 100644
--- a/calculatorpp/res/layout/var_edit.xml
+++ b/calculatorpp/res/layout/var_edit.xml
@@ -1,81 +1,81 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/calculatorpp/res/values-large/dimens.xml b/calculatorpp/res/values-large/dimens.xml
index 0e042942..df7ddf80 100644
--- a/calculatorpp/res/values-large/dimens.xml
+++ b/calculatorpp/res/values-large/dimens.xml
@@ -1,5 +1,7 @@
-
- 15sp
- 15sp
- 20dp
+
+ 15sp
+ 15sp
+ 20dp
+ 15sp
+ 10sp
\ No newline at end of file
diff --git a/calculatorpp/res/values/dimens.xml b/calculatorpp/res/values/dimens.xml
index 25aa0ba0..8c693f34 100644
--- a/calculatorpp/res/values/dimens.xml
+++ b/calculatorpp/res/values/dimens.xml
@@ -1,14 +1,16 @@
-
- 0.5dp
- 20sp
- 30dp
- 20dp
- 25sp
- 25sp
- 5dp
- 5dp
-
-
- 5dp
- 3dp
+
+ 0.5dp
+ 20sp
+ 30dp
+ 20dp
+ 25sp
+ 25sp
+ 5dp
+ 5dp
+ 20sp
+ 15sp
+
+
+ 5dp
+ 3dp
\ No newline at end of file
diff --git a/calculatorpp/res/values/styles-common-var.xml b/calculatorpp/res/values/styles-common-var.xml
index c79e8964..91630832 100644
--- a/calculatorpp/res/values/styles-common-var.xml
+++ b/calculatorpp/res/values/styles-common-var.xml
@@ -8,16 +8,11 @@
diff --git a/calculatorpp/res/values/styles.xml b/calculatorpp/res/values/styles.xml
index c75ea897..fbc965e5 100644
--- a/calculatorpp/res/values/styles.xml
+++ b/calculatorpp/res/values/styles.xml
@@ -1,63 +1,63 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java
index 4c56861b..c22a2cd2 100644
--- a/calculatorpp/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java
+++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/AbstractCalculatorHelper.java
@@ -1,225 +1,232 @@
-package org.solovyev.android.calculator;
-
-import android.app.Activity;
-import android.content.SharedPreferences;
-import android.os.Vibrator;
-import android.preference.PreferenceManager;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.View;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.solovyev.android.calculator.history.CalculatorHistoryState;
-import org.solovyev.android.calculator.view.AngleUnitsButton;
-import org.solovyev.android.calculator.view.NumeralBasesButton;
-import org.solovyev.android.calculator.view.OnDragListenerVibrator;
-import org.solovyev.android.history.HistoryDragProcessor;
-import org.solovyev.android.view.drag.*;
-import org.solovyev.common.Announcer;
-import org.solovyev.common.math.Point2d;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * User: serso
- * Date: 9/28/12
- * Time: 12:12 AM
- */
-public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSharedPreferenceChangeListener {
-
- @NotNull
- private CalculatorPreferences.Gui.Layout layout;
-
- @Nullable
- private Vibrator vibrator;
-
- @NotNull
- private final Announcer dpclRegister = new Announcer(DragPreferencesChangeListener.class);
-
- @NotNull
- private String logTag = "CalculatorActivity";
-
- protected AbstractCalculatorHelper() {
- }
-
- protected AbstractCalculatorHelper(@NotNull String logTag) {
- this.logTag = logTag;
- }
-
- protected void onCreate(@NotNull Activity activity) {
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
-
- vibrator = (Vibrator) activity.getSystemService(Activity.VIBRATOR_SERVICE);
- layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
-
- preferences.registerOnSharedPreferenceChangeListener(this);
- }
-
- public void logDebug(@NotNull String message) {
- Log.d(logTag, message);
- }
-
- public void processButtons(@NotNull final Activity activity, @NotNull View root) {
- dpclRegister.clear();
-
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
- final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, activity);
-
- setOnDragListeners(root, dragPreferences, preferences);
-
- final OnDragListener historyOnDragListener = new OnDragListenerVibrator(newOnDragListener(new HistoryDragProcessor(getCalculator()), dragPreferences), vibrator, preferences);
- final DragButton historyButton = getButton(root, R.id.historyButton);
- if (historyButton != null) {
- historyButton.setOnDragListener(historyOnDragListener);
- }
-
- final DragButton subtractionButton = getButton(root, R.id.subtractionButton);
- if (subtractionButton != null) {
- subtractionButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new SimpleOnDragListener.DragProcessor() {
- @Override
- public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
- if (dragDirection == DragDirection.down) {
- CalculatorActivity.operatorsButtonClickHandler(activity);
- return true;
- }
- return false;
- }
- }, dragPreferences), vibrator, preferences));
- }
-
- final OnDragListener toPositionOnDragListener = new OnDragListenerVibrator(new SimpleOnDragListener(new CursorDragProcessor(), dragPreferences), vibrator, preferences);
-
- final DragButton rightButton = getButton(root, R.id.rightButton);
- if (rightButton != null) {
- rightButton.setOnDragListener(toPositionOnDragListener);
- }
-
- final DragButton leftButton = getButton(root, R.id.leftButton);
- if (leftButton != null) {
- leftButton.setOnDragListener(toPositionOnDragListener);
- }
-
- final DragButton equalsButton = getButton(root, R.id.equalsButton);
- if (equalsButton != null) {
- equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EvalDragProcessor(), dragPreferences), vibrator, preferences));
- }
-
- final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) getButton(root, R.id.sixDigitButton);
- if (angleUnitsButton != null) {
- angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.AngleUnitsChanger(activity), dragPreferences), vibrator, preferences));
- }
-
- final NumeralBasesButton clearButton = (NumeralBasesButton) getButton(root, R.id.clearButton);
- if (clearButton != null) {
- clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.NumeralBasesChanger(activity), dragPreferences), vibrator, preferences));
- }
-
- final DragButton varsButton = getButton(root, R.id.varsButton);
- if (varsButton != null) {
- varsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.VarsDragProcessor(activity), dragPreferences), vibrator, preferences));
- }
-
- final DragButton roundBracketsButton = getButton(root, R.id.roundBracketsButton);
- if (roundBracketsButton != null) {
- roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences));
- }
-
- if (layout == CalculatorPreferences.Gui.Layout.simple) {
- toggleButtonDirectionText(root, R.id.oneDigitButton, false, DragDirection.up, DragDirection.down);
- toggleButtonDirectionText(root, R.id.twoDigitButton, false, DragDirection.up, DragDirection.down);
- toggleButtonDirectionText(root, R.id.threeDigitButton, false, DragDirection.up, DragDirection.down);
-
- toggleButtonDirectionText(root, R.id.sixDigitButton, false, DragDirection.up, DragDirection.down);
- toggleButtonDirectionText(root, R.id.sevenDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
- toggleButtonDirectionText(root, R.id.eightDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
-
- toggleButtonDirectionText(root, R.id.clearButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
-
- toggleButtonDirectionText(root, R.id.fourDigitButton, false, DragDirection.down);
- toggleButtonDirectionText(root, R.id.fiveDigitButton, false, DragDirection.down);
-
- toggleButtonDirectionText(root, R.id.nineDigitButton, false, DragDirection.left);
-
- toggleButtonDirectionText(root, R.id.multiplicationButton, false, DragDirection.left);
- toggleButtonDirectionText(root, R.id.plusButton, false, DragDirection.down, DragDirection.up);
- }
- }
-
- private void toggleButtonDirectionText(@NotNull View root, int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) {
- final View v = getButton(root, id);
- if (v instanceof DirectionDragButton ) {
- final DirectionDragButton button = (DirectionDragButton)v;
- for (DragDirection dragDirection : dragDirections) {
- button.showDirectionText(showDirectionText, dragDirection);
- }
- }
- }
-
- @NotNull
- private Calculator getCalculator() {
- return CalculatorLocatorImpl.getInstance().getCalculator();
- }
-
-
- private void setOnDragListeners(@NotNull View root, @NotNull SimpleOnDragListener.Preferences dragPreferences, @NotNull SharedPreferences preferences) {
- final OnDragListener onDragListener = new OnDragListenerVibrator(newOnDragListener(new DigitButtonDragProcessor(getKeyboard()), dragPreferences), vibrator, preferences);
-
- final List dragButtonIds = new ArrayList();
-
- for (Field field : R.id.class.getDeclaredFields()) {
- int modifiers = field.getModifiers();
- if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) {
- try {
- int viewId = field.getInt(R.id.class);
- final View view = root.findViewById(viewId);
- if (view instanceof DragButton) {
- dragButtonIds.add(viewId);
- }
- } catch (IllegalAccessException e) {
- Log.e(R.id.class.getName(), e.getMessage());
- }
- }
- }
-
- for (Integer dragButtonId : dragButtonIds) {
- final DragButton button = getButton(root, dragButtonId);
- if (button != null) {
- button.setOnDragListener(onDragListener);
- }
- }
- }
-
- @NotNull
- private CalculatorKeyboard getKeyboard() {
- return CalculatorLocatorImpl.getInstance().getKeyboard();
- }
-
- @Nullable
- private T getButton(@NotNull View root, int buttonId) {
- return (T) root.findViewById(buttonId);
- }
-
- @NotNull
- private SimpleOnDragListener newOnDragListener(@NotNull SimpleOnDragListener.DragProcessor dragProcessor,
- @NotNull SimpleOnDragListener.Preferences dragPreferences) {
- final SimpleOnDragListener onDragListener = new SimpleOnDragListener(dragProcessor, dragPreferences);
- dpclRegister.addListener(onDragListener);
- return onDragListener;
- }
-
- @Override
- public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
- if (key != null && key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) {
- dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, CalculatorApplication.getInstance()));
- }
- }
-
- public void onDestroy(@NotNull Activity activity) {
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
-
- preferences.unregisterOnSharedPreferenceChangeListener(this);
- }
-}
+package org.solovyev.android.calculator;
+
+import android.app.Activity;
+import android.content.SharedPreferences;
+import android.os.Vibrator;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.View;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.solovyev.android.calculator.history.CalculatorHistoryState;
+import org.solovyev.android.calculator.view.AngleUnitsButton;
+import org.solovyev.android.calculator.view.NumeralBasesButton;
+import org.solovyev.android.calculator.view.OnDragListenerVibrator;
+import org.solovyev.android.history.HistoryDragProcessor;
+import org.solovyev.android.view.drag.*;
+import org.solovyev.common.Announcer;
+import org.solovyev.common.math.Point2d;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * User: serso
+ * Date: 9/28/12
+ * Time: 12:12 AM
+ */
+public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSharedPreferenceChangeListener {
+
+ @NotNull
+ private CalculatorPreferences.Gui.Layout layout;
+
+ @NotNull
+ private CalculatorPreferences.Gui.Theme theme;
+
+ @Nullable
+ private Vibrator vibrator;
+
+ @NotNull
+ private final Announcer dpclRegister = new Announcer(DragPreferencesChangeListener.class);
+
+ @NotNull
+ private String logTag = "CalculatorActivity";
+
+ protected AbstractCalculatorHelper() {
+ }
+
+ protected AbstractCalculatorHelper(@NotNull String logTag) {
+ this.logTag = logTag;
+ }
+
+ protected void onCreate(@NotNull Activity activity) {
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
+
+ vibrator = (Vibrator) activity.getSystemService(Activity.VIBRATOR_SERVICE);
+ layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
+ theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences);
+
+ preferences.registerOnSharedPreferenceChangeListener(this);
+ }
+
+ public void logDebug(@NotNull String message) {
+ Log.d(logTag, message);
+ }
+
+ public void processButtons(@NotNull final Activity activity, @NotNull View root) {
+ dpclRegister.clear();
+
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
+ final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, activity);
+
+ setOnDragListeners(root, dragPreferences, preferences);
+
+ final OnDragListener historyOnDragListener = new OnDragListenerVibrator(newOnDragListener(new HistoryDragProcessor(getCalculator()), dragPreferences), vibrator, preferences);
+ final DragButton historyButton = getButton(root, R.id.historyButton);
+ if (historyButton != null) {
+ historyButton.setOnDragListener(historyOnDragListener);
+ }
+
+ final DragButton subtractionButton = getButton(root, R.id.subtractionButton);
+ if (subtractionButton != null) {
+ subtractionButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new SimpleOnDragListener.DragProcessor() {
+ @Override
+ public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
+ if (dragDirection == DragDirection.down) {
+ CalculatorActivity.operatorsButtonClickHandler(activity);
+ return true;
+ }
+ return false;
+ }
+ }, dragPreferences), vibrator, preferences));
+ }
+
+ final OnDragListener toPositionOnDragListener = new OnDragListenerVibrator(new SimpleOnDragListener(new CursorDragProcessor(), dragPreferences), vibrator, preferences);
+
+ final DragButton rightButton = getButton(root, R.id.rightButton);
+ if (rightButton != null) {
+ rightButton.setOnDragListener(toPositionOnDragListener);
+ }
+
+ final DragButton leftButton = getButton(root, R.id.leftButton);
+ if (leftButton != null) {
+ leftButton.setOnDragListener(toPositionOnDragListener);
+ }
+
+ final DragButton equalsButton = getButton(root, R.id.equalsButton);
+ if (equalsButton != null) {
+ equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EvalDragProcessor(), dragPreferences), vibrator, preferences));
+ }
+
+ final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) getButton(root, R.id.sixDigitButton);
+ if (angleUnitsButton != null) {
+ angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.AngleUnitsChanger(activity), dragPreferences), vibrator, preferences));
+ }
+
+ final NumeralBasesButton clearButton = (NumeralBasesButton) getButton(root, R.id.clearButton);
+ if (clearButton != null) {
+ clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.NumeralBasesChanger(activity), dragPreferences), vibrator, preferences));
+ }
+
+ final DragButton varsButton = getButton(root, R.id.varsButton);
+ if (varsButton != null) {
+ varsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.VarsDragProcessor(activity), dragPreferences), vibrator, preferences));
+ }
+
+ final DragButton roundBracketsButton = getButton(root, R.id.roundBracketsButton);
+ if (roundBracketsButton != null) {
+ roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences));
+ }
+
+ if (layout == CalculatorPreferences.Gui.Layout.simple) {
+ toggleButtonDirectionText(root, R.id.oneDigitButton, false, DragDirection.up, DragDirection.down);
+ toggleButtonDirectionText(root, R.id.twoDigitButton, false, DragDirection.up, DragDirection.down);
+ toggleButtonDirectionText(root, R.id.threeDigitButton, false, DragDirection.up, DragDirection.down);
+
+ toggleButtonDirectionText(root, R.id.sixDigitButton, false, DragDirection.up, DragDirection.down);
+ toggleButtonDirectionText(root, R.id.sevenDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
+ toggleButtonDirectionText(root, R.id.eightDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
+
+ toggleButtonDirectionText(root, R.id.clearButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
+
+ toggleButtonDirectionText(root, R.id.fourDigitButton, false, DragDirection.down);
+ toggleButtonDirectionText(root, R.id.fiveDigitButton, false, DragDirection.down);
+
+ toggleButtonDirectionText(root, R.id.nineDigitButton, false, DragDirection.left);
+
+ toggleButtonDirectionText(root, R.id.multiplicationButton, false, DragDirection.left);
+ toggleButtonDirectionText(root, R.id.plusButton, false, DragDirection.down, DragDirection.up);
+ }
+
+ CalculatorButtons.processButtons(true, theme, root);
+ CalculatorButtons.toggleEqualsButton(preferences, activity);
+ }
+
+ private void toggleButtonDirectionText(@NotNull View root, int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) {
+ final View v = getButton(root, id);
+ if (v instanceof DirectionDragButton ) {
+ final DirectionDragButton button = (DirectionDragButton)v;
+ for (DragDirection dragDirection : dragDirections) {
+ button.showDirectionText(showDirectionText, dragDirection);
+ }
+ }
+ }
+
+ @NotNull
+ private Calculator getCalculator() {
+ return CalculatorLocatorImpl.getInstance().getCalculator();
+ }
+
+
+ private void setOnDragListeners(@NotNull View root, @NotNull SimpleOnDragListener.Preferences dragPreferences, @NotNull SharedPreferences preferences) {
+ final OnDragListener onDragListener = new OnDragListenerVibrator(newOnDragListener(new DigitButtonDragProcessor(getKeyboard()), dragPreferences), vibrator, preferences);
+
+ final List dragButtonIds = new ArrayList();
+
+ for (Field field : R.id.class.getDeclaredFields()) {
+ int modifiers = field.getModifiers();
+ if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) {
+ try {
+ int viewId = field.getInt(R.id.class);
+ final View view = root.findViewById(viewId);
+ if (view instanceof DragButton) {
+ dragButtonIds.add(viewId);
+ }
+ } catch (IllegalAccessException e) {
+ Log.e(R.id.class.getName(), e.getMessage());
+ }
+ }
+ }
+
+ for (Integer dragButtonId : dragButtonIds) {
+ final DragButton button = getButton(root, dragButtonId);
+ if (button != null) {
+ button.setOnDragListener(onDragListener);
+ }
+ }
+ }
+
+ @NotNull
+ private CalculatorKeyboard getKeyboard() {
+ return CalculatorLocatorImpl.getInstance().getKeyboard();
+ }
+
+ @Nullable
+ private T getButton(@NotNull View root, int buttonId) {
+ return (T) root.findViewById(buttonId);
+ }
+
+ @NotNull
+ private SimpleOnDragListener newOnDragListener(@NotNull SimpleOnDragListener.DragProcessor dragProcessor,
+ @NotNull SimpleOnDragListener.Preferences dragPreferences) {
+ final SimpleOnDragListener onDragListener = new SimpleOnDragListener(dragProcessor, dragPreferences);
+ dpclRegister.addListener(onDragListener);
+ return onDragListener;
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
+ if (key != null && key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) {
+ dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, CalculatorApplication.getInstance()));
+ }
+ }
+
+ public void onDestroy(@NotNull Activity activity) {
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
+
+ preferences.unregisterOnSharedPreferenceChangeListener(this);
+ }
+}
diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java
index 1d4d9568..e3593c41 100644
--- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java
+++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivity.java
@@ -1,354 +1,352 @@
-/*
- * Copyright (c) 2009-2011. Created by serso aka se.solovyev.
- * For more information, please, contact se.solovyev@gmail.com
- */
-
-package org.solovyev.android.calculator;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.pm.ActivityInfo;
-import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.text.Html;
-import android.text.method.LinkMovementMethod;
-import android.util.Log;
-import android.view.KeyEvent;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.TextView;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-import net.robotmedia.billing.BillingController;
-import net.robotmedia.billing.IBillingObserver;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.solovyev.android.AndroidUtils;
-import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
-import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
-import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
-import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment;
-import org.solovyev.android.calculator.math.edit.CalculatorOperatorsFragment;
-import org.solovyev.android.calculator.math.edit.CalculatorVarsFragment;
-import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
-import org.solovyev.android.fragments.FragmentUtils;
-import org.solovyev.android.prefs.Preference;
-import org.solovyev.android.view.ColorButton;
-import org.solovyev.common.equals.EqualsTool;
-import org.solovyev.common.history.HistoryAction;
-import org.solovyev.common.text.StringUtils;
-
-public class CalculatorActivity extends SherlockFragmentActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
-
- @NotNull
- public static final String TAG = CalculatorActivity.class.getSimpleName();
-
- @Nullable
- private IBillingObserver billingObserver;
-
- private boolean useBackAsPrev;
-
- @NotNull
- private CalculatorActivityHelper activityHelper;
-
- /**
- * Called when the activity is first created.
- */
- @Override
- public void onCreate(@Nullable Bundle savedInstanceState) {
-
- CalculatorApplication.registerOnRemoteStackTrace();
-
- /*final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);*/
-
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
-
- final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
-
- activityHelper = CalculatorApplication.getInstance().createActivityHelper(layout.getLayoutId(), TAG);
- activityHelper.logDebug("onCreate");
- activityHelper.onCreate(this, savedInstanceState);
-
- super.onCreate(savedInstanceState);
- activityHelper.logDebug("super.onCreate");
-
- if (findViewById(R.id.main_second_pane) != null) {
- activityHelper.addTab(this, "history", CalculatorHistoryFragment.class, null, R.string.c_history, R.id.main_second_pane);
- activityHelper.addTab(this, "saved_history", CalculatorSavedHistoryFragment.class, null, R.string.c_saved_history, R.id.main_second_pane);
- activityHelper.addTab(this, "vars", CalculatorVarsFragment.class, null, R.string.c_vars, R.id.main_second_pane);
- activityHelper.addTab(this, "functions", CalculatorFunctionsFragment.class, null, R.string.c_functions, R.id.main_second_pane);
- activityHelper.addTab(this, "operators", CalculatorOperatorsFragment.class, null, R.string.c_operators, R.id.main_second_pane);
- activityHelper.addTab(this, "plot", CalculatorPlotFragment.class, null, R.string.c_plot, R.id.main_second_pane);
-
- activityHelper.restoreSavedTab(this);
- } else {
- getSupportActionBar().hide();
- }
-
- FragmentUtils.createFragment(this, CalculatorEditorFragment.class, R.id.editorContainer, "editor");
- FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display");
- FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
-
- /*if (customTitleSupported) {
- try {
- getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title);
- final CalculatorAdditionalTitle additionalAdditionalTitleText = (CalculatorAdditionalTitle)findViewById(R.id.additional_title_text);
- additionalAdditionalTitleText.init(preferences);
- preferences.registerOnSharedPreferenceChangeListener(additionalAdditionalTitleText);
- } catch (ClassCastException e) {
- // super fix for issue with class cast in android.view.Window.setFeatureInt() (see app error reports)
- Log.e(CalculatorActivity.class.getName(), e.getMessage(), e);
- }
- }*/
-
- billingObserver = new CalculatorBillingObserver(this);
- BillingController.registerObserver(billingObserver);
-
- this.useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
- firstTimeInit(preferences, this);
-
- // init billing controller
- BillingController.checkBillingSupported(this);
-
- toggleOrientationChange(preferences);
-
- CalculatorButtons.toggleEqualsButton(preferences, this, activityHelper.getTheme(), findViewById(R.id.main_layout));
-
- preferences.registerOnSharedPreferenceChangeListener(this);
- }
-
- @NotNull
- private AndroidCalculator getCalculator() {
- return ((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator());
- }
-
- private static void firstTimeInit(@NotNull SharedPreferences preferences, @NotNull Context context) {
- final Integer appOpenedCounter = CalculatorPreferences.appOpenedCounter.getPreference(preferences);
- if (appOpenedCounter != null) {
- CalculatorPreferences.appOpenedCounter.putPreference(preferences, appOpenedCounter + 1);
- }
-
- final Integer savedVersion = CalculatorPreferences.appVersion.getPreference(preferences);
-
- final int appVersion = AndroidUtils.getAppVersionCode(context, CalculatorActivity.class.getPackage().getName());
-
- CalculatorPreferences.appVersion.putPreference(preferences, appVersion);
-
- boolean dialogShown = false;
- if (EqualsTool.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
- // new start
- final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(R.string.c_first_start_text);
- builder.setPositiveButton(android.R.string.ok, null);
- builder.setTitle(R.string.c_first_start_text_title);
- builder.create().show();
- dialogShown = true;
- } else {
- if (savedVersion < appVersion) {
- final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
- if (showReleaseNotes) {
- final String releaseNotes = CalculatorReleaseNotesActivity.getReleaseNotes(context, savedVersion + 1);
- if (!StringUtils.isEmpty(releaseNotes)) {
- final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
- builder.setPositiveButton(android.R.string.ok, null);
- builder.setTitle(R.string.c_release_notes);
- builder.create().show();
- dialogShown = true;
- }
- }
- }
- }
-
-
- //Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!");
- if (!dialogShown) {
- if (appOpenedCounter != null && appOpenedCounter > 10) {
- dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.feedbackWindowShown, R.layout.feedback, R.id.feedbackText, context);
- }
- }
-
- if (!dialogShown) {
- dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.notesppAnnounceShown, R.layout.notespp_announce, R.id.notespp_announce, context);
- }
- }
-
- private static boolean showSpecialWindow(@NotNull SharedPreferences preferences, @NotNull Preference specialWindowShownPref, int layoutId, int textViewId, @NotNull Context context) {
- boolean result = false;
-
- final Boolean specialWindowShown = specialWindowShownPref.getPreference(preferences);
- if ( specialWindowShown != null && !specialWindowShown ) {
- final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
- final View view = layoutInflater.inflate(layoutId, null);
-
- final TextView feedbackTextView = (TextView) view.findViewById(textViewId);
- feedbackTextView.setMovementMethod(LinkMovementMethod.getInstance());
-
- final AlertDialog.Builder builder = new AlertDialog.Builder(context).setView(view);
- builder.setPositiveButton(android.R.string.ok, null);
- builder.create().show();
-
- result = true;
- specialWindowShownPref.putPreference(preferences, true);
- }
-
- return result;
- }
-
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_BACK) {
- if (useBackAsPrev) {
- getCalculator().doHistoryAction(HistoryAction.undo);
- return true;
- }
- }
- return super.onKeyDown(keyCode, event);
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void equalsButtonClickHandler(@NotNull View v) {
- getCalculator().evaluate();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
-
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
- final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences);
- if ( newLayout.getLayoutId() != activityHelper.getLayoutId() ) {
- AndroidUtils.restartActivity(this);
- }
-
- this.activityHelper.onResume(this);
- }
-
- @Override
- protected void onDestroy() {
- if (billingObserver != null) {
- BillingController.unregisterObserver(billingObserver);
- }
-
- activityHelper.onDestroy(this);
-
- super.onDestroy();
- }
-
- @Override
- public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
- if ( CalculatorPreferences.Gui.usePrevAsBack.getKey().equals(key) ) {
- useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
- }
-
- if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) {
- toggleOrientationChange(preferences);
- }
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
-
- activityHelper.onSaveInstanceState(this, outState);
- }
-
- private void toggleOrientationChange(@Nullable SharedPreferences preferences) {
- preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(this) : preferences;
- if (CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
- } else {
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- }
- }
-
- /*
- **********************************************************************
- *
- * BUTTON HANDLERS
- *
- **********************************************************************
- */
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void elementaryButtonClickHandler(@NotNull View v) {
- throw new UnsupportedOperationException("Not implemented yet!");
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void historyButtonClickHandler(@NotNull View v) {
- CalculatorActivityLauncher.showHistory(this);
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void eraseButtonClickHandler(@NotNull View v) {
- CalculatorLocatorImpl.getInstance().getEditor().erase();
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void simplifyButtonClickHandler(@NotNull View v) {
- throw new UnsupportedOperationException("Not implemented yet!");
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void moveLeftButtonClickHandler(@NotNull View v) {
- getKeyboard().moveCursorLeft();
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void moveRightButtonClickHandler(@NotNull View v) {
- getKeyboard().moveCursorRight();
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void pasteButtonClickHandler(@NotNull View v) {
- getKeyboard().pasteButtonPressed();
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void copyButtonClickHandler(@NotNull View v) {
- getKeyboard().copyButtonPressed();
- }
-
- @NotNull
- private static CalculatorKeyboard getKeyboard() {
- return CalculatorLocatorImpl.getInstance().getKeyboard();
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void clearButtonClickHandler(@NotNull View v) {
- getKeyboard().clearButtonPressed();
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void digitButtonClickHandler(@NotNull View v) {
- Log.d(String.valueOf(v.getId()), "digitButtonClickHandler() for: " + v.getId() + ". Pressed: " + v.isPressed());
- if (((ColorButton) v).isShowText()) {
- getKeyboard().digitButtonPressed(((ColorButton) v).getText().toString());
- }
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void functionsButtonClickHandler(@NotNull View v) {
- CalculatorActivityLauncher.showFunctions(this);
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void operatorsButtonClickHandler(@NotNull View v) {
- CalculatorActivityLauncher.showOperators(this);
- }
-
- public static void operatorsButtonClickHandler(@NotNull Activity activity) {
- CalculatorActivityLauncher.showOperators(activity);
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void varsButtonClickHandler(@NotNull View v) {
- CalculatorActivityLauncher.showVars(this);
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void donateButtonClickHandler(@NotNull View v) {
- CalculatorApplication.showDonationDialog(this);
- }
-
+/*
+ * Copyright (c) 2009-2011. Created by serso aka se.solovyev.
+ * For more information, please, contact se.solovyev@gmail.com
+ */
+
+package org.solovyev.android.calculator;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.pm.ActivityInfo;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.text.Html;
+import android.text.method.LinkMovementMethod;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextView;
+import com.actionbarsherlock.app.SherlockFragmentActivity;
+import net.robotmedia.billing.BillingController;
+import net.robotmedia.billing.IBillingObserver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.solovyev.android.AndroidUtils;
+import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
+import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
+import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
+import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment;
+import org.solovyev.android.calculator.math.edit.CalculatorOperatorsFragment;
+import org.solovyev.android.calculator.math.edit.CalculatorVarsFragment;
+import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
+import org.solovyev.android.fragments.FragmentUtils;
+import org.solovyev.android.prefs.Preference;
+import org.solovyev.android.view.ColorButton;
+import org.solovyev.common.equals.EqualsTool;
+import org.solovyev.common.history.HistoryAction;
+import org.solovyev.common.text.StringUtils;
+
+public class CalculatorActivity extends SherlockFragmentActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
+
+ @NotNull
+ public static final String TAG = CalculatorActivity.class.getSimpleName();
+
+ @Nullable
+ private IBillingObserver billingObserver;
+
+ private boolean useBackAsPrev;
+
+ @NotNull
+ private CalculatorActivityHelper activityHelper;
+
+ /**
+ * Called when the activity is first created.
+ */
+ @Override
+ public void onCreate(@Nullable Bundle savedInstanceState) {
+
+ CalculatorApplication.registerOnRemoteStackTrace();
+
+ /*final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);*/
+
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
+
+ activityHelper = CalculatorApplication.getInstance().createActivityHelper(layout.getLayoutId(), TAG);
+ activityHelper.logDebug("onCreate");
+ activityHelper.onCreate(this, savedInstanceState);
+
+ super.onCreate(savedInstanceState);
+ activityHelper.logDebug("super.onCreate");
+
+ if (findViewById(R.id.main_second_pane) != null) {
+ activityHelper.addTab(this, "history", CalculatorHistoryFragment.class, null, R.string.c_history, R.id.main_second_pane);
+ activityHelper.addTab(this, "saved_history", CalculatorSavedHistoryFragment.class, null, R.string.c_saved_history, R.id.main_second_pane);
+ activityHelper.addTab(this, "vars", CalculatorVarsFragment.class, null, R.string.c_vars, R.id.main_second_pane);
+ activityHelper.addTab(this, "functions", CalculatorFunctionsFragment.class, null, R.string.c_functions, R.id.main_second_pane);
+ activityHelper.addTab(this, "operators", CalculatorOperatorsFragment.class, null, R.string.c_operators, R.id.main_second_pane);
+ activityHelper.addTab(this, "plot", CalculatorPlotFragment.class, null, R.string.c_plot, R.id.main_second_pane);
+
+ activityHelper.restoreSavedTab(this);
+ } else {
+ getSupportActionBar().hide();
+ }
+
+ FragmentUtils.createFragment(this, CalculatorEditorFragment.class, R.id.editorContainer, "editor");
+ FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display");
+ FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
+
+ /*if (customTitleSupported) {
+ try {
+ getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title);
+ final CalculatorAdditionalTitle additionalAdditionalTitleText = (CalculatorAdditionalTitle)findViewById(R.id.additional_title_text);
+ additionalAdditionalTitleText.init(preferences);
+ preferences.registerOnSharedPreferenceChangeListener(additionalAdditionalTitleText);
+ } catch (ClassCastException e) {
+ // super fix for issue with class cast in android.view.Window.setFeatureInt() (see app error reports)
+ Log.e(CalculatorActivity.class.getName(), e.getMessage(), e);
+ }
+ }*/
+
+ billingObserver = new CalculatorBillingObserver(this);
+ BillingController.registerObserver(billingObserver);
+
+ this.useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
+ firstTimeInit(preferences, this);
+
+ // init billing controller
+ BillingController.checkBillingSupported(this);
+
+ toggleOrientationChange(preferences);
+
+ preferences.registerOnSharedPreferenceChangeListener(this);
+ }
+
+ @NotNull
+ private AndroidCalculator getCalculator() {
+ return ((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator());
+ }
+
+ private static void firstTimeInit(@NotNull SharedPreferences preferences, @NotNull Context context) {
+ final Integer appOpenedCounter = CalculatorPreferences.appOpenedCounter.getPreference(preferences);
+ if (appOpenedCounter != null) {
+ CalculatorPreferences.appOpenedCounter.putPreference(preferences, appOpenedCounter + 1);
+ }
+
+ final Integer savedVersion = CalculatorPreferences.appVersion.getPreference(preferences);
+
+ final int appVersion = AndroidUtils.getAppVersionCode(context, CalculatorActivity.class.getPackage().getName());
+
+ CalculatorPreferences.appVersion.putPreference(preferences, appVersion);
+
+ boolean dialogShown = false;
+ if (EqualsTool.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
+ // new start
+ final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(R.string.c_first_start_text);
+ builder.setPositiveButton(android.R.string.ok, null);
+ builder.setTitle(R.string.c_first_start_text_title);
+ builder.create().show();
+ dialogShown = true;
+ } else {
+ if (savedVersion < appVersion) {
+ final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
+ if (showReleaseNotes) {
+ final String releaseNotes = CalculatorReleaseNotesActivity.getReleaseNotes(context, savedVersion + 1);
+ if (!StringUtils.isEmpty(releaseNotes)) {
+ final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
+ builder.setPositiveButton(android.R.string.ok, null);
+ builder.setTitle(R.string.c_release_notes);
+ builder.create().show();
+ dialogShown = true;
+ }
+ }
+ }
+ }
+
+
+ //Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!");
+ if (!dialogShown) {
+ if (appOpenedCounter != null && appOpenedCounter > 10) {
+ dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.feedbackWindowShown, R.layout.feedback, R.id.feedbackText, context);
+ }
+ }
+
+ if (!dialogShown) {
+ dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.notesppAnnounceShown, R.layout.notespp_announce, R.id.notespp_announce, context);
+ }
+ }
+
+ private static boolean showSpecialWindow(@NotNull SharedPreferences preferences, @NotNull Preference specialWindowShownPref, int layoutId, int textViewId, @NotNull Context context) {
+ boolean result = false;
+
+ final Boolean specialWindowShown = specialWindowShownPref.getPreference(preferences);
+ if ( specialWindowShown != null && !specialWindowShown ) {
+ final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
+ final View view = layoutInflater.inflate(layoutId, null);
+
+ final TextView feedbackTextView = (TextView) view.findViewById(textViewId);
+ feedbackTextView.setMovementMethod(LinkMovementMethod.getInstance());
+
+ final AlertDialog.Builder builder = new AlertDialog.Builder(context).setView(view);
+ builder.setPositiveButton(android.R.string.ok, null);
+ builder.create().show();
+
+ result = true;
+ specialWindowShownPref.putPreference(preferences, true);
+ }
+
+ return result;
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ if (useBackAsPrev) {
+ getCalculator().doHistoryAction(HistoryAction.undo);
+ return true;
+ }
+ }
+ return super.onKeyDown(keyCode, event);
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void equalsButtonClickHandler(@NotNull View v) {
+ getCalculator().evaluate();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
+ final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences);
+ if ( newLayout.getLayoutId() != activityHelper.getLayoutId() ) {
+ AndroidUtils.restartActivity(this);
+ }
+
+ this.activityHelper.onResume(this);
+ }
+
+ @Override
+ protected void onDestroy() {
+ if (billingObserver != null) {
+ BillingController.unregisterObserver(billingObserver);
+ }
+
+ activityHelper.onDestroy(this);
+
+ super.onDestroy();
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
+ if ( CalculatorPreferences.Gui.usePrevAsBack.getKey().equals(key) ) {
+ useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
+ }
+
+ if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) {
+ toggleOrientationChange(preferences);
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+
+ activityHelper.onSaveInstanceState(this, outState);
+ }
+
+ private void toggleOrientationChange(@Nullable SharedPreferences preferences) {
+ preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(this) : preferences;
+ if (CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
+ } else {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ }
+ }
+
+ /*
+ **********************************************************************
+ *
+ * BUTTON HANDLERS
+ *
+ **********************************************************************
+ */
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void elementaryButtonClickHandler(@NotNull View v) {
+ throw new UnsupportedOperationException("Not implemented yet!");
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void historyButtonClickHandler(@NotNull View v) {
+ CalculatorActivityLauncher.showHistory(this);
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void eraseButtonClickHandler(@NotNull View v) {
+ CalculatorLocatorImpl.getInstance().getEditor().erase();
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void simplifyButtonClickHandler(@NotNull View v) {
+ throw new UnsupportedOperationException("Not implemented yet!");
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void moveLeftButtonClickHandler(@NotNull View v) {
+ getKeyboard().moveCursorLeft();
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void moveRightButtonClickHandler(@NotNull View v) {
+ getKeyboard().moveCursorRight();
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void pasteButtonClickHandler(@NotNull View v) {
+ getKeyboard().pasteButtonPressed();
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void copyButtonClickHandler(@NotNull View v) {
+ getKeyboard().copyButtonPressed();
+ }
+
+ @NotNull
+ private static CalculatorKeyboard getKeyboard() {
+ return CalculatorLocatorImpl.getInstance().getKeyboard();
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void clearButtonClickHandler(@NotNull View v) {
+ getKeyboard().clearButtonPressed();
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void digitButtonClickHandler(@NotNull View v) {
+ Log.d(String.valueOf(v.getId()), "digitButtonClickHandler() for: " + v.getId() + ". Pressed: " + v.isPressed());
+ if (((ColorButton) v).isShowText()) {
+ getKeyboard().digitButtonPressed(((ColorButton) v).getText().toString());
+ }
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void functionsButtonClickHandler(@NotNull View v) {
+ CalculatorActivityLauncher.showFunctions(this);
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void operatorsButtonClickHandler(@NotNull View v) {
+ CalculatorActivityLauncher.showOperators(this);
+ }
+
+ public static void operatorsButtonClickHandler(@NotNull Activity activity) {
+ CalculatorActivityLauncher.showOperators(activity);
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void varsButtonClickHandler(@NotNull View v) {
+ CalculatorActivityLauncher.showVars(this);
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void donateButtonClickHandler(@NotNull View v) {
+ CalculatorApplication.showDonationDialog(this);
+ }
+
}
\ No newline at end of file
diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java
index 62b8508b..1839880e 100644
--- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java
+++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorActivityHelperImpl.java
@@ -1,190 +1,195 @@
-package org.solovyev.android.calculator;
-
-import android.app.Activity;
-import android.content.SharedPreferences;
-import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.support.v4.app.Fragment;
-import android.util.Log;
-import android.view.View;
-import com.actionbarsherlock.app.ActionBar;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.solovyev.android.AndroidUtils;
-import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * User: serso
- * Date: 9/25/12
- * Time: 10:32 PM
- */
-public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper implements CalculatorActivityHelper {
-
- /*
- **********************************************************************
- *
- * CONSTANTS
- *
- **********************************************************************
- */
- private static final String SELECTED_NAV = "selected_nav";
-
- /*
- **********************************************************************
- *
- * FIELDS
- *
- **********************************************************************
- */
-
- private int layoutId;
-
- private boolean homeIcon = false;
-
- @NotNull
- private final List fragmentTags = new ArrayList();
-
- @NotNull
- private CalculatorPreferences.Gui.Theme theme;
- private int navPosition = 0;
-
-
- public CalculatorActivityHelperImpl(int layoutId, @NotNull String logTag) {
- super(logTag);
- this.layoutId = layoutId;
- }
-
- public CalculatorActivityHelperImpl(int layoutId, boolean homeIcon) {
- this.layoutId = layoutId;
- this.homeIcon = homeIcon;
- }
-
- @Override
- public void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState) {
- super.onCreate(activity);
-
- if ( activity instanceof CalculatorEventListener) {
- CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener)activity);
- }
-
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
-
- this.theme = CalculatorPreferences.Gui.getTheme(preferences);
- activity.setTheme(this.theme.getThemeId());
-
- activity.setContentView(layoutId);
-
- final View root = activity.findViewById(R.id.main_layout);
- if (root != null) {
- CalculatorButtons.processButtons(true, theme, root);
- } else {
- Log.e(CalculatorActivityHelperImpl.class.getSimpleName(), "Root is null for " + activity.getClass().getName());
- }
-
- if (savedInstanceState != null) {
- navPosition = savedInstanceState.getInt(SELECTED_NAV, 0);
- }
- }
-
- @Override
- public void onCreate(@NotNull final SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState) {
- this.onCreate((Activity) activity, savedInstanceState);
-
- final ActionBar actionBar = activity.getSupportActionBar();
- actionBar.setDisplayUseLogoEnabled(false);
- actionBar.setDisplayHomeAsUpEnabled(homeIcon);
- actionBar.setHomeButtonEnabled(false);
- actionBar.setDisplayShowHomeEnabled(true);
- if (activity instanceof CalculatorActivity) {
- actionBar.setDisplayShowTitleEnabled(false);
- } else {
- actionBar.setDisplayShowTitleEnabled(true);
- }
- actionBar.setIcon(R.drawable.icon_action_bar);
- }
-
- @Override
- public void restoreSavedTab(@NotNull SherlockFragmentActivity activity) {
- final ActionBar actionBar = activity.getSupportActionBar();
- if (navPosition >= 0 && navPosition < actionBar.getTabCount()) {
- activity.getSupportActionBar().setSelectedNavigationItem(navPosition);
- }
- }
-
- @Override
- public void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState) {
- onSaveInstanceState((Activity) activity, outState);
- outState.putInt(SELECTED_NAV, activity.getSupportActionBar().getSelectedNavigationIndex());
- }
-
- @Override
- public void onSaveInstanceState(@NotNull Activity activity, @NotNull Bundle outState) {
- }
-
- @Override
- public void onResume(@NotNull Activity activity) {
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
-
- final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences);
- if (!theme.equals(newTheme)) {
- AndroidUtils.restartActivity(activity);
- }
- }
-
- @Override
- public void onDestroy(@NotNull Activity activity) {
- super.onDestroy(activity);
-
- if ( activity instanceof CalculatorEventListener) {
- CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener)activity);
- }
- }
-
- @Override
- public void onDestroy(@NotNull SherlockFragmentActivity activity) {
- this.onDestroy((Activity)activity);
- }
-
- @Override
- public void addTab(@NotNull SherlockFragmentActivity activity,
- @NotNull String tag,
- @NotNull Class extends Fragment> fragmentClass,
- @Nullable Bundle fragmentArgs,
- int captionResId,
- int parentViewId) {
- activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
-
- final ActionBar actionBar = activity.getSupportActionBar();
- final ActionBar.Tab tab = actionBar.newTab();
- tab.setTag(tag);
- tab.setText(captionResId);
-
- final ActionBarFragmentTabListener listener = new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId);
- tab.setTabListener(listener);
- actionBar.addTab(tab);
-
- fragmentTags.add(tag);
-
- restoreSavedTab(activity);
- }
-
- @Override
- public int getLayoutId() {
- return layoutId;
- }
-
- @Override
- @NotNull
- public CalculatorPreferences.Gui.Theme getTheme() {
- return theme;
- }
-
- @Override
- public void onResume(@NotNull SherlockFragmentActivity activity) {
- onResume((Activity) activity);
- }
-}
+package org.solovyev.android.calculator;
+
+import android.app.Activity;
+import android.content.SharedPreferences;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.support.v4.app.Fragment;
+import android.util.Log;
+import android.view.View;
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.app.SherlockFragmentActivity;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.solovyev.android.AndroidUtils;
+import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * User: serso
+ * Date: 9/25/12
+ * Time: 10:32 PM
+ */
+public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper implements CalculatorActivityHelper {
+
+ /*
+ **********************************************************************
+ *
+ * CONSTANTS
+ *
+ **********************************************************************
+ */
+ private static final String SELECTED_NAV = "selected_nav";
+
+ /*
+ **********************************************************************
+ *
+ * FIELDS
+ *
+ **********************************************************************
+ */
+
+ private int layoutId;
+
+ private boolean homeIcon = false;
+
+ @NotNull
+ private final List fragmentTags = new ArrayList();
+
+ @NotNull
+ private CalculatorPreferences.Gui.Theme theme;
+ private int navPosition = 0;
+
+
+ public CalculatorActivityHelperImpl(int layoutId, @NotNull String logTag) {
+ super(logTag);
+ this.layoutId = layoutId;
+ }
+
+ public CalculatorActivityHelperImpl(int layoutId, boolean homeIcon) {
+ this.layoutId = layoutId;
+ this.homeIcon = homeIcon;
+ }
+
+ @Override
+ public void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState) {
+ super.onCreate(activity);
+
+ if ( activity instanceof CalculatorEventListener) {
+ CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener)activity);
+ }
+
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
+
+ this.theme = CalculatorPreferences.Gui.getTheme(preferences);
+ activity.setTheme(this.theme.getThemeId());
+
+ activity.setContentView(layoutId);
+
+ final View root = activity.findViewById(R.id.main_layout);
+ if (root != null) {
+ processButtons(activity, root);
+ } else {
+ Log.e(CalculatorActivityHelperImpl.class.getSimpleName(), "Root is null for " + activity.getClass().getName());
+ }
+
+ if (savedInstanceState != null) {
+ navPosition = savedInstanceState.getInt(SELECTED_NAV, 0);
+ }
+ }
+
+ @Override
+ public void onCreate(@NotNull final SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState) {
+ this.onCreate((Activity) activity, savedInstanceState);
+
+ final ActionBar actionBar = activity.getSupportActionBar();
+ actionBar.setDisplayUseLogoEnabled(false);
+ actionBar.setDisplayHomeAsUpEnabled(homeIcon);
+ actionBar.setHomeButtonEnabled(false);
+ actionBar.setDisplayShowHomeEnabled(true);
+
+ if (activity instanceof CalculatorActivity) {
+ if ( AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT ) {
+ actionBar.setDisplayShowTitleEnabled(true);
+ } else {
+ }
+ } else {
+ actionBar.setDisplayShowTitleEnabled(true);
+ }
+ actionBar.setIcon(R.drawable.icon_action_bar);
+ }
+
+ @Override
+ public void restoreSavedTab(@NotNull SherlockFragmentActivity activity) {
+ final ActionBar actionBar = activity.getSupportActionBar();
+ if (navPosition >= 0 && navPosition < actionBar.getTabCount()) {
+ activity.getSupportActionBar().setSelectedNavigationItem(navPosition);
+ }
+ }
+
+ @Override
+ public void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState) {
+ onSaveInstanceState((Activity) activity, outState);
+ outState.putInt(SELECTED_NAV, activity.getSupportActionBar().getSelectedNavigationIndex());
+ }
+
+ @Override
+ public void onSaveInstanceState(@NotNull Activity activity, @NotNull Bundle outState) {
+ }
+
+ @Override
+ public void onResume(@NotNull Activity activity) {
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
+
+ final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences);
+ if (!theme.equals(newTheme)) {
+ AndroidUtils.restartActivity(activity);
+ }
+ }
+
+ @Override
+ public void onDestroy(@NotNull Activity activity) {
+ super.onDestroy(activity);
+
+ if ( activity instanceof CalculatorEventListener) {
+ CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener)activity);
+ }
+ }
+
+ @Override
+ public void onDestroy(@NotNull SherlockFragmentActivity activity) {
+ this.onDestroy((Activity)activity);
+ }
+
+ @Override
+ public void addTab(@NotNull SherlockFragmentActivity activity,
+ @NotNull String tag,
+ @NotNull Class extends Fragment> fragmentClass,
+ @Nullable Bundle fragmentArgs,
+ int captionResId,
+ int parentViewId) {
+ activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+
+ final ActionBar actionBar = activity.getSupportActionBar();
+ final ActionBar.Tab tab = actionBar.newTab();
+ tab.setTag(tag);
+ tab.setText(captionResId);
+
+ final ActionBarFragmentTabListener listener = new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId);
+ tab.setTabListener(listener);
+ actionBar.addTab(tab);
+
+ fragmentTags.add(tag);
+
+ restoreSavedTab(activity);
+ }
+
+ @Override
+ public int getLayoutId() {
+ return layoutId;
+ }
+
+ @Override
+ @NotNull
+ public CalculatorPreferences.Gui.Theme getTheme() {
+ return theme;
+ }
+
+ @Override
+ public void onResume(@NotNull SherlockFragmentActivity activity) {
+ onResume((Activity) activity);
+ }
+}
diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java
index 30db923c..821ae971 100644
--- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java
+++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorButtons.java
@@ -1,244 +1,243 @@
-package org.solovyev.android.calculator;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.res.Configuration;
-import android.preference.PreferenceManager;
-import android.util.Log;
-import android.view.Display;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Button;
-import android.widget.LinearLayout;
-import android.widget.Toast;
-import jscl.AngleUnit;
-import jscl.NumeralBase;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.solovyev.android.AndroidUtils;
-import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
-import org.solovyev.android.calculator.view.AngleUnitsButton;
-import org.solovyev.android.calculator.view.NumeralBasesButton;
-import org.solovyev.android.view.ColorButton;
-import org.solovyev.android.view.drag.DragButton;
-import org.solovyev.android.view.drag.DragDirection;
-import org.solovyev.android.view.drag.SimpleOnDragListener;
-import org.solovyev.common.math.Point2d;
-
-/**
- * User: serso
- * Date: 9/28/12
- * Time: 12:06 AM
- */
-public final class CalculatorButtons {
-
- private CalculatorButtons () {
- }
-
-
- public static void processButtons(boolean fixMagicFlames,
- @NotNull CalculatorPreferences.Gui.Theme theme,
- @NotNull View root) {
- if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) {
-
- if (fixMagicFlames) {
- // for metro themes we should turn off magic flames
- AndroidUtils.processViewsOfType(root, ColorButton.class, new AndroidUtils.ViewProcessor() {
- @Override
- public void process(@NotNull ColorButton colorButton) {
- colorButton.setDrawMagicFlame(false);
- }
- });
- }
- }
- }
-
- static void initMultiplicationButton(@NotNull View root) {
- final View multiplicationButton = root.findViewById(R.id.multiplicationButton);
- if ( multiplicationButton instanceof Button) {
- ((Button) multiplicationButton).setText(CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign());
- }
- }
-
- public static void toggleEqualsButton(@Nullable SharedPreferences preferences,
- @NotNull Activity activity,
- @NotNull CalculatorPreferences.Gui.Theme theme,
- @NotNull View root) {
- preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences;
-
- if (AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT || !CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
- final Display display = activity.getWindowManager().getDefaultDisplay();
-
- final DragButton equalsButton = (DragButton)activity.findViewById(R.id.equalsButton);
- if (equalsButton != null) {
- if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) {
- equalsButton.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 1f));
- if (display.getWidth() <= 480) {
- // mobile phones
- final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
- if (calculatorDisplayView != null) {
- calculatorDisplayView.setBackgroundDrawable(null);
- }
- }
- } else {
- equalsButton.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 0f));
- if (display.getWidth() <= 480) {
- // mobile phones
- final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
- if (calculatorDisplayView != null) {
- calculatorDisplayView.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.equals9));
- }
- }
- }
- }
- }
- }
-
- @Nullable
- private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
- return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
- }
-
- /*
- **********************************************************************
- *
- * STATIC CLASSES
- *
- **********************************************************************
- */
-
- static class RoundBracketsDragProcessor implements SimpleOnDragListener.DragProcessor {
- @Override
- public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
- final boolean result;
-
- if (dragDirection == DragDirection.left) {
- getKeyboard().roundBracketsButtonPressed();
- result = true;
- } else {
- result = new DigitButtonDragProcessor(getKeyboard()).processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
- }
-
- return result;
- }
- }
-
- @NotNull
- private static CalculatorKeyboard getKeyboard() {
- return CalculatorLocatorImpl.getInstance().getKeyboard();
- }
-
- static class VarsDragProcessor implements SimpleOnDragListener.DragProcessor {
-
- @NotNull
- private Context context;
-
- VarsDragProcessor(Context context) {
- this.context = context;
- }
-
- @Override
- public boolean processDragEvent(@NotNull DragDirection dragDirection,
- @NotNull DragButton dragButton,
- @NotNull Point2d startPoint2d,
- @NotNull MotionEvent motionEvent) {
- boolean result = false;
-
- if (dragDirection == DragDirection.up) {
- CalculatorActivityLauncher.createVar(context, CalculatorLocatorImpl.getInstance().getDisplay());
- result = true;
- }
-
- return result;
- }
- }
-
- static class AngleUnitsChanger implements SimpleOnDragListener.DragProcessor {
-
- @NotNull
- private final DigitButtonDragProcessor processor;
-
- @NotNull
- private final Context context;
-
- AngleUnitsChanger(@NotNull Context context) {
- this.context = context;
- this.processor = new DigitButtonDragProcessor(CalculatorLocatorImpl.getInstance().getKeyboard());
- }
-
- @Override
- public boolean processDragEvent(@NotNull DragDirection dragDirection,
- @NotNull DragButton dragButton,
- @NotNull Point2d startPoint2d,
- @NotNull MotionEvent motionEvent) {
- boolean result = false;
-
- if (dragButton instanceof AngleUnitsButton) {
- if (dragDirection != DragDirection.left) {
- final String directionText = ((AngleUnitsButton) dragButton).getText(dragDirection);
- if (directionText != null) {
- try {
-
- final AngleUnit angleUnits = AngleUnit.valueOf(directionText);
-
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
-
- AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnits);
-
- Toast.makeText(context, context.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);
- }
- }
- } else if (dragDirection == DragDirection.left) {
- result = processor.processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
- }
- }
-
- return result;
- }
- }
-
- static class NumeralBasesChanger implements SimpleOnDragListener.DragProcessor {
-
- @NotNull
- private final Context context;
-
- NumeralBasesChanger(@NotNull Context context) {
- this.context = context;
- }
-
- @Override
- public boolean processDragEvent(@NotNull DragDirection dragDirection,
- @NotNull DragButton dragButton,
- @NotNull Point2d startPoint2d,
- @NotNull MotionEvent motionEvent) {
- boolean result = false;
-
- if (dragButton instanceof NumeralBasesButton) {
- final String directionText = ((NumeralBasesButton) dragButton).getText(dragDirection);
- if (directionText != null) {
- try {
-
- final NumeralBase numeralBase = NumeralBase.valueOf(directionText);
-
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
- AndroidCalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase);
-
- Toast.makeText(context, context.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);
- }
- }
- }
-
- return result;
- }
- }
-}
+package org.solovyev.android.calculator;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.res.Configuration;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.Display;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.Toast;
+import jscl.AngleUnit;
+import jscl.NumeralBase;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.solovyev.android.AndroidUtils;
+import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
+import org.solovyev.android.calculator.view.AngleUnitsButton;
+import org.solovyev.android.calculator.view.NumeralBasesButton;
+import org.solovyev.android.view.ColorButton;
+import org.solovyev.android.view.drag.DragButton;
+import org.solovyev.android.view.drag.DragDirection;
+import org.solovyev.android.view.drag.SimpleOnDragListener;
+import org.solovyev.common.math.Point2d;
+
+/**
+ * User: serso
+ * Date: 9/28/12
+ * Time: 12:06 AM
+ */
+public final class CalculatorButtons {
+
+ private CalculatorButtons () {
+ }
+
+
+ public static void processButtons(boolean fixMagicFlames,
+ @NotNull CalculatorPreferences.Gui.Theme theme,
+ @NotNull View root) {
+ if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) {
+
+ if (fixMagicFlames) {
+ // for metro themes we should turn off magic flames
+ AndroidUtils.processViewsOfType(root, ColorButton.class, new AndroidUtils.ViewProcessor() {
+ @Override
+ public void process(@NotNull ColorButton colorButton) {
+ colorButton.setDrawMagicFlame(false);
+ }
+ });
+ }
+ }
+ }
+
+ static void initMultiplicationButton(@NotNull View root) {
+ final View multiplicationButton = root.findViewById(R.id.multiplicationButton);
+ if ( multiplicationButton instanceof Button) {
+ ((Button) multiplicationButton).setText(CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign());
+ }
+ }
+
+ public static void toggleEqualsButton(@Nullable SharedPreferences preferences,
+ @NotNull Activity activity) {
+ preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences;
+
+ if (AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT || !CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
+ final Display display = activity.getWindowManager().getDefaultDisplay();
+
+ final DragButton equalsButton = (DragButton)activity.findViewById(R.id.equalsButton);
+ if (equalsButton != null) {
+ // todo serso: visibility should be changed only for some cases (like small screens)
+ if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) {
+ equalsButton.setVisibility(View.VISIBLE);
+ if (display.getWidth() <= 480) {
+ // mobile phones
+ final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
+ if (calculatorDisplayView != null) {
+ calculatorDisplayView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
+ }
+ }
+ } else {
+ equalsButton.setVisibility(View.GONE);
+ if (display.getWidth() <= 480) {
+ // mobile phones
+ final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
+ if (calculatorDisplayView != null) {
+ calculatorDisplayView.setCompoundDrawablesWithIntrinsicBounds(activity.getResources().getDrawable(R.drawable.equals9), null, null, null);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @Nullable
+ private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
+ return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
+ }
+
+ /*
+ **********************************************************************
+ *
+ * STATIC CLASSES
+ *
+ **********************************************************************
+ */
+
+ static class RoundBracketsDragProcessor implements SimpleOnDragListener.DragProcessor {
+ @Override
+ public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
+ final boolean result;
+
+ if (dragDirection == DragDirection.left) {
+ getKeyboard().roundBracketsButtonPressed();
+ result = true;
+ } else {
+ result = new DigitButtonDragProcessor(getKeyboard()).processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
+ }
+
+ return result;
+ }
+ }
+
+ @NotNull
+ private static CalculatorKeyboard getKeyboard() {
+ return CalculatorLocatorImpl.getInstance().getKeyboard();
+ }
+
+ static class VarsDragProcessor implements SimpleOnDragListener.DragProcessor {
+
+ @NotNull
+ private Context context;
+
+ VarsDragProcessor(Context context) {
+ this.context = context;
+ }
+
+ @Override
+ public boolean processDragEvent(@NotNull DragDirection dragDirection,
+ @NotNull DragButton dragButton,
+ @NotNull Point2d startPoint2d,
+ @NotNull MotionEvent motionEvent) {
+ boolean result = false;
+
+ if (dragDirection == DragDirection.up) {
+ CalculatorActivityLauncher.createVar(context, CalculatorLocatorImpl.getInstance().getDisplay());
+ result = true;
+ }
+
+ return result;
+ }
+ }
+
+ static class AngleUnitsChanger implements SimpleOnDragListener.DragProcessor {
+
+ @NotNull
+ private final DigitButtonDragProcessor processor;
+
+ @NotNull
+ private final Context context;
+
+ AngleUnitsChanger(@NotNull Context context) {
+ this.context = context;
+ this.processor = new DigitButtonDragProcessor(CalculatorLocatorImpl.getInstance().getKeyboard());
+ }
+
+ @Override
+ public boolean processDragEvent(@NotNull DragDirection dragDirection,
+ @NotNull DragButton dragButton,
+ @NotNull Point2d startPoint2d,
+ @NotNull MotionEvent motionEvent) {
+ boolean result = false;
+
+ if (dragButton instanceof AngleUnitsButton) {
+ if (dragDirection != DragDirection.left) {
+ final String directionText = ((AngleUnitsButton) dragButton).getText(dragDirection);
+ if (directionText != null) {
+ try {
+
+ final AngleUnit angleUnits = AngleUnit.valueOf(directionText);
+
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+
+ AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnits);
+
+ Toast.makeText(context, context.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);
+ }
+ }
+ } else if (dragDirection == DragDirection.left) {
+ result = processor.processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
+ }
+ }
+
+ return result;
+ }
+ }
+
+ static class NumeralBasesChanger implements SimpleOnDragListener.DragProcessor {
+
+ @NotNull
+ private final Context context;
+
+ NumeralBasesChanger(@NotNull Context context) {
+ this.context = context;
+ }
+
+ @Override
+ public boolean processDragEvent(@NotNull DragDirection dragDirection,
+ @NotNull DragButton dragButton,
+ @NotNull Point2d startPoint2d,
+ @NotNull MotionEvent motionEvent) {
+ boolean result = false;
+
+ if (dragButton instanceof NumeralBasesButton) {
+ final String directionText = ((NumeralBasesButton) dragButton).getText(dragDirection);
+ if (directionText != null) {
+ try {
+
+ final NumeralBase numeralBase = NumeralBase.valueOf(directionText);
+
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+ AndroidCalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase);
+
+ Toast.makeText(context, context.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);
+ }
+ }
+ }
+
+ return result;
+ }
+ }
+}
diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java
index abed0326..e55c7dbc 100644
--- a/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java
+++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/CalculatorKeyboardFragment.java
@@ -1,134 +1,134 @@
-package org.solovyev.android.calculator;
-
-import android.content.SharedPreferences;
-import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import com.actionbarsherlock.app.SherlockFragment;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
-
-/**
- * User: Solovyev_S
- * Date: 25.09.12
- * Time: 12:25
- */
-public class CalculatorKeyboardFragment extends SherlockFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
-
- @NotNull
- private NumeralBaseButtons numeralBaseButtons = new NumeralBaseButtons();
-
- @NotNull
- private CalculatorPreferences.Gui.Theme theme;
-
- @NotNull
- private CalculatorFragmentHelper fragmentHelper;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
-
- fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.calc_keyboard);
- fragmentHelper.onCreate(this);
-
- preferences.registerOnSharedPreferenceChangeListener(this);
-
- theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences);
-
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- return fragmentHelper.onCreateView(this, inflater, container);
- }
-
- @Override
- public void onViewCreated(View root, Bundle savedInstanceState) {
- super.onViewCreated(root, savedInstanceState);
-
- fragmentHelper.onViewCreated(this, root);
- }
-
-
- @Override
- public void onResume() {
- super.onResume();
-
- this.fragmentHelper.onResume(this);
- }
-
- @Override
- public void onPause() {
- this.fragmentHelper.onPause(this);
-
- super.onPause();
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
-
- fragmentHelper.onDestroy(this);
-
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
- preferences.unregisterOnSharedPreferenceChangeListener(this);
-
- }
-
- /* private static void setMarginsForView(@Nullable View view, int marginLeft, int marginBottom, @NotNull Context context) {
- // IMPORTANT: this is workaround for probably android bug
- // currently margin values set in styles are not applied for some reasons to the views (using include tag) => set them manually
-
- if (view != null) {
- final DisplayMetrics dm = context.getResources().getDisplayMetrics();
- if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
- final LinearLayout.LayoutParams oldParams = (LinearLayout.LayoutParams) view.getLayoutParams();
- final LinearLayout.LayoutParams newParams = new LinearLayout.LayoutParams(oldParams.width, oldParams.height, oldParams.weight);
- newParams.setMargins(AndroidUtils.toPixels(dm, marginLeft), 0, 0, AndroidUtils.toPixels(dm, marginBottom));
- view.setLayoutParams(newParams);
- }
- }
- }*/
-
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- }
-
- @Override
- public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
- if (AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key)) {
- numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
- }
-
- if ( CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key) ) {
- CalculatorButtons.toggleEqualsButton(preferences, this.getActivity(), theme, getView());
- }
-
- if ( AndroidCalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) {
- CalculatorButtons.initMultiplicationButton(getView());
- }
- }
-
-
- @Nullable
- private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
- return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
- }
-
- @NotNull
- private Calculator getCalculator() {
- return CalculatorLocatorImpl.getInstance().getCalculator();
- }
-
- @NotNull
- private static CalculatorKeyboard getKeyboard() {
- return CalculatorLocatorImpl.getInstance().getKeyboard();
- }
-}
-
+package org.solovyev.android.calculator;
+
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import com.actionbarsherlock.app.SherlockFragment;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
+
+/**
+ * User: Solovyev_S
+ * Date: 25.09.12
+ * Time: 12:25
+ */
+public class CalculatorKeyboardFragment extends SherlockFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
+
+ @NotNull
+ private NumeralBaseButtons numeralBaseButtons = new NumeralBaseButtons();
+
+ @NotNull
+ private CalculatorPreferences.Gui.Theme theme;
+
+ @NotNull
+ private CalculatorFragmentHelper fragmentHelper;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
+
+ fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.calc_keyboard);
+ fragmentHelper.onCreate(this);
+
+ preferences.registerOnSharedPreferenceChangeListener(this);
+
+ theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences);
+
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ return fragmentHelper.onCreateView(this, inflater, container);
+ }
+
+ @Override
+ public void onViewCreated(View root, Bundle savedInstanceState) {
+ super.onViewCreated(root, savedInstanceState);
+
+ fragmentHelper.onViewCreated(this, root);
+ }
+
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ this.fragmentHelper.onResume(this);
+ }
+
+ @Override
+ public void onPause() {
+ this.fragmentHelper.onPause(this);
+
+ super.onPause();
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+
+ fragmentHelper.onDestroy(this);
+
+ final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
+ preferences.unregisterOnSharedPreferenceChangeListener(this);
+
+ }
+
+ /* private static void setMarginsForView(@Nullable View view, int marginLeft, int marginBottom, @NotNull Context context) {
+ // IMPORTANT: this is workaround for probably android bug
+ // currently margin values set in styles are not applied for some reasons to the views (using include tag) => set them manually
+
+ if (view != null) {
+ final DisplayMetrics dm = context.getResources().getDisplayMetrics();
+ if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
+ final LinearLayout.LayoutParams oldParams = (LinearLayout.LayoutParams) view.getLayoutParams();
+ final LinearLayout.LayoutParams newParams = new LinearLayout.LayoutParams(oldParams.width, oldParams.height, oldParams.weight);
+ newParams.setMargins(AndroidUtils.toPixels(dm, marginLeft), 0, 0, AndroidUtils.toPixels(dm, marginBottom));
+ view.setLayoutParams(newParams);
+ }
+ }
+ }*/
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
+ if (AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key)) {
+ numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
+ }
+
+ if ( CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key) ) {
+ CalculatorButtons.toggleEqualsButton(preferences, this.getActivity());
+ }
+
+ if ( AndroidCalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) {
+ CalculatorButtons.initMultiplicationButton(getView());
+ }
+ }
+
+
+ @Nullable
+ private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
+ return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
+ }
+
+ @NotNull
+ private Calculator getCalculator() {
+ return CalculatorLocatorImpl.getInstance().getCalculator();
+ }
+
+ @NotNull
+ private static CalculatorKeyboard getKeyboard() {
+ return CalculatorLocatorImpl.getInstance().getKeyboard();
+ }
+}
+