This commit is contained in:
serso 2012-10-02 12:29:56 +04:00
parent 999299d9bb
commit 327f43a323
39 changed files with 1564 additions and 1540 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 785 B

After

Width:  |  Height:  |  Size: 785 B

View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 807 B

After

Width:  |  Height:  |  Size: 807 B

View File

Before

Width:  |  Height:  |  Size: 630 B

After

Width:  |  Height:  |  Size: 630 B

View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

View File

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@ -1,113 +1,113 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android" xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator" xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:id="@+id/main_layout" a:id="@+id/main_layout"
a:orientation="vertical" a:orientation="vertical"
a:layout_gravity="center" a:layout_gravity="center"
a:background="#ff000000"> a:background="#ff000000">
<include layout="@layout/calc_editor"/> <include layout="@layout/calc_editor"/>
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp"> <LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
<org.solovyev.android.view.drag.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android" <org.solovyev.android.view.drag.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator" xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/leftButton" a:id="@+id/leftButton"
c:textUp="◀◀" c:textUp="◀◀"
a:text="◀" a:text="◀"
c:directionTextScale="0.5" c:directionTextScale="0.5"
style="?controlButtonStyle" style="?controlButtonStyle"
a:onClick="moveLeftButtonClickHandler" a:onClick="moveLeftButtonClickHandler"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:layout_weight="1"/> a:layout_weight="1"/>
<org.solovyev.android.view.ColorButton xmlns:a="http://schemas.android.com/apk/res/android" <org.solovyev.android.view.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator" xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/eraseButton" a:id="@+id/eraseButton"
a:drawableTop="@drawable/sym_keyboard_delete" a:drawableTop="@drawable/kb_delete"
style="?controlImageButtonStyle" style="?controlImageButtonStyle"
a:onClick="eraseButtonClickHandler" a:onClick="eraseButtonClickHandler"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:layout_weight="1"/> a:layout_weight="1"/>
<include layout="@layout/calc_display" <include layout="@layout/calc_display"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:layout_weight="4"/> a:layout_weight="4"/>
<org.solovyev.android.calculator.view.NumeralBasesButton xmlns:a="http://schemas.android.com/apk/res/android" <org.solovyev.android.calculator.view.NumeralBasesButton xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator" xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/clearButton" a:id="@+id/clearButton"
c:textUp="dec" c:textUp="dec"
a:text="@string/c_clear" a:text="@string/c_clear"
c:textDown="bin" c:textDown="bin"
c:textLeft="hex" c:textLeft="hex"
a:textStyle="bold" a:textStyle="bold"
style="?controlImageButtonStyle" style="?controlImageButtonStyle"
a:onClick="clearButtonClickHandler" a:onClick="clearButtonClickHandler"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:layout_weight="1"/> a:layout_weight="1"/>
<org.solovyev.android.view.drag.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android" <org.solovyev.android.view.drag.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator" xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/rightButton" a:id="@+id/rightButton"
c:textUp="▶▶" c:textUp="▶▶"
a:text="▶" a:text="▶"
c:directionTextScale="0.5" c:directionTextScale="0.5"
style="?controlButtonStyle" style="?controlButtonStyle"
a:onClick="moveRightButtonClickHandler" a:onClick="moveRightButtonClickHandler"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:layout_weight="1"/> a:layout_weight="1"/>
</LinearLayout> </LinearLayout>
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp"> <LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
<include layout="@layout/calc_vars_button"/> <include layout="@layout/calc_vars_button"/>
<include layout="@layout/calc_copy_button"/> <include layout="@layout/calc_copy_button"/>
<include layout="@layout/calc_one_digit_button"/> <include layout="@layout/calc_one_digit_button"/>
<include layout="@layout/calc_two_digit_button"/> <include layout="@layout/calc_two_digit_button"/>
<include layout="@layout/calc_three_digit_button"/> <include layout="@layout/calc_three_digit_button"/>
<include layout="@layout/calc_multiplication_button"/> <include layout="@layout/calc_multiplication_button"/>
<include layout="@layout/calc_division_button"/> <include layout="@layout/calc_division_button"/>
<include layout="@layout/calc_equals_button"/> <include layout="@layout/calc_equals_button"/>
</LinearLayout> </LinearLayout>
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp"> <LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
<include layout="@layout/calc_functions_button"/> <include layout="@layout/calc_functions_button"/>
<include layout="@layout/calc_paste_button"/> <include layout="@layout/calc_paste_button"/>
<include layout="@layout/calc_four_digit_button"/> <include layout="@layout/calc_four_digit_button"/>
<include layout="@layout/calc_five_digit_button"/> <include layout="@layout/calc_five_digit_button"/>
<include layout="@layout/calc_six_digit_button"/> <include layout="@layout/calc_six_digit_button"/>
<include layout="@layout/calc_plus_button"/> <include layout="@layout/calc_plus_button"/>
<include layout="@layout/calc_subtraction_button"/> <include layout="@layout/calc_subtraction_button"/>
<include layout="@layout/calc_round_brackets_button"/> <include layout="@layout/calc_round_brackets_button"/>
</LinearLayout> </LinearLayout>
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp"> <LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
<include layout="@layout/calc_operators_button"/> <include layout="@layout/calc_operators_button"/>
<include layout="@layout/calc_donate_button"/> <include layout="@layout/calc_donate_button"/>
<include layout="@layout/calc_seven_digit_button"/> <include layout="@layout/calc_seven_digit_button"/>
<include layout="@layout/calc_eight_digit_button"/> <include layout="@layout/calc_eight_digit_button"/>
<include layout="@layout/calc_nine_digit_button"/> <include layout="@layout/calc_nine_digit_button"/>
<include layout="@layout/calc_zero_digit_button"/> <include layout="@layout/calc_zero_digit_button"/>
<include layout="@layout/calc_dot_button"/> <include layout="@layout/calc_dot_button"/>
<include layout="@layout/calc_history_button"/> <include layout="@layout/calc_history_button"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -1,53 +1,68 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="match_parent" a:layout_height="match_parent"
a:orientation="vertical"> a:orientation="vertical">
<LinearLayout a:layout_weight="1" <LinearLayout a:layout_weight="1"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="0dp"> a:layout_height="0dp">
<include layout="@layout/calc_vars_button"/> <include layout="@layout/calc_left_button"/>
<include layout="@layout/calc_copy_button"/> <include layout="@layout/calc_erase_button"/>
<include layout="@layout/calc_seven_digit_button"/> <include layout="@layout/calc_empty_button"/>
<include layout="@layout/calc_eight_digit_button"/> <include layout="@layout/calc_empty_button"/>
<include layout="@layout/calc_nine_digit_button"/> <include layout="@layout/calc_empty_button"/>
<include layout="@layout/calc_multiplication_button"/> <include layout="@layout/calc_empty_button"/>
<include layout="@layout/calc_division_button"/> <include layout="@layout/calc_clear_button"/>
<include layout="@layout/calc_equals_button"/> <include layout="@layout/calc_right_button"/>
</LinearLayout> </LinearLayout>
<LinearLayout a:layout_weight="1" <LinearLayout a:layout_weight="1"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="0dp"> a:layout_height="0dp">
<include layout="@layout/calc_functions_button"/> <include layout="@layout/calc_vars_button"/>
<include layout="@layout/calc_paste_button"/> <include layout="@layout/calc_copy_button"/>
<include layout="@layout/calc_four_digit_button"/> <include layout="@layout/calc_seven_digit_button"/>
<include layout="@layout/calc_five_digit_button"/> <include layout="@layout/calc_eight_digit_button"/>
<include layout="@layout/calc_six_digit_button"/> <include layout="@layout/calc_nine_digit_button"/>
<include layout="@layout/calc_plus_button"/> <include layout="@layout/calc_multiplication_button"/>
<include layout="@layout/calc_subtraction_button"/> <include layout="@layout/calc_division_button"/>
<include layout="@layout/calc_round_brackets_button"/> <include layout="@layout/calc_equals_button"/>
</LinearLayout> </LinearLayout>
<LinearLayout a:layout_weight="1" <LinearLayout a:layout_weight="1"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="0dp"> a:layout_height="0dp">
<include layout="@layout/calc_operators_button"/> <include layout="@layout/calc_functions_button"/>
<include layout="@layout/calc_donate_button"/> <include layout="@layout/calc_paste_button"/>
<include layout="@layout/calc_one_digit_button"/> <include layout="@layout/calc_four_digit_button"/>
<include layout="@layout/calc_two_digit_button"/> <include layout="@layout/calc_five_digit_button"/>
<include layout="@layout/calc_three_digit_button"/> <include layout="@layout/calc_six_digit_button"/>
<include layout="@layout/calc_zero_digit_button"/> <include layout="@layout/calc_plus_button"/>
<include layout="@layout/calc_dot_button"/> <include layout="@layout/calc_subtraction_button"/>
<include layout="@layout/calc_history_button"/> <include layout="@layout/calc_round_brackets_button"/>
</LinearLayout> </LinearLayout>
<LinearLayout a:layout_weight="1"
a:layout_width="match_parent"
a:layout_height="0dp">
<include layout="@layout/calc_operators_button"/>
<include layout="@layout/calc_donate_button"/>
<include layout="@layout/calc_one_digit_button"/>
<include layout="@layout/calc_two_digit_button"/>
<include layout="@layout/calc_three_digit_button"/>
<include layout="@layout/calc_zero_digit_button"/>
<include layout="@layout/calc_dot_button"/>
<include layout="@layout/calc_history_button"/>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev. ~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com ~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org ~ or visit http://se.solovyev.org
--> -->
<org.solovyev.android.view.ColorButton xmlns:a="http://schemas.android.com/apk/res/android" <org.solovyev.android.view.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator" xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/pasteButton" a:id="@+id/pasteButton"
a:drawableTop="@drawable/copy" a:drawableTop="@drawable/kb_copy"
style="?controlImageButtonStyle" style="?controlImageButtonStyle"
a:onClick="copyButtonClickHandler"/> a:onClick="copyButtonClickHandler"/>

View File

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev. ~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com ~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org ~ or visit http://se.solovyev.org
--> -->
<org.solovyev.android.view.ColorButton xmlns:a="http://schemas.android.com/apk/res/android" <org.solovyev.android.view.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/pasteButton" a:id="@+id/pasteButton"
a:drawableTop="@drawable/heart2" a:drawableTop="@drawable/kb_heart"
style="?controlImageButtonStyle" style="?controlImageButtonStyle"
a:onClick="donateButtonClickHandler"/> a:onClick="donateButtonClickHandler"/>

View File

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev. ~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com ~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org ~ or visit http://se.solovyev.org
--> -->
<org.solovyev.android.view.ColorButton xmlns:a="http://schemas.android.com/apk/res/android" <org.solovyev.android.view.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator" xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/eraseButton" a:id="@+id/eraseButton"
a:drawableTop="@drawable/sym_keyboard_delete" a:drawableTop="@drawable/kb_delete"
style="?controlImageButtonStyle" style="?controlImageButtonStyle"
a:onClick="eraseButtonClickHandler"/> a:onClick="eraseButtonClickHandler"/>

View File

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev. ~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com ~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org ~ or visit http://se.solovyev.org
--> -->
<org.solovyev.android.view.ColorButton xmlns:a="http://schemas.android.com/apk/res/android" <org.solovyev.android.view.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator" xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/pasteButton" a:id="@+id/pasteButton"
a:drawableTop="@drawable/paste" a:drawableTop="@drawable/kb_paste"
style="?controlImageButtonStyle" style="?controlImageButtonStyle"
a:onClick="pasteButtonClickHandler"/> a:onClick="pasteButtonClickHandler"/>

View File

@ -7,20 +7,21 @@
--> -->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical" a:layout_height="wrap_content"
a:layout_width="fill_parent" a:layout_width="match_parent"
a:layout_height="fill_parent"> a:paddingBottom="@dimen/pane_padding"
a:orientation="vertical">
<TextView a:id="@+id/math_entity_text" <TextView a:id="@+id/math_entity_text"
a:layout_width="fill_parent" a:layout_height="wrap_content"
a:layout_height="fill_parent" a:layout_width="match_parent"
style="@style/math_entity_text"> style="@style/math_entity_text">
</TextView> </TextView>
<TextView a:id="@+id/math_entity_description" <TextView a:id="@+id/math_entity_description"
a:layout_width="fill_parent" a:layout_height="wrap_content"
a:layout_height="fill_parent" a:layout_width="match_parent"
style="@style/math_entity_description"> style="@style/math_entity_description">
</TextView> </TextView>
</LinearLayout> </LinearLayout>

View File

@ -1,81 +1,81 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev. ~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com ~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org ~ or visit http://se.solovyev.org
--> -->
<ScrollView xmlns:a="http://schemas.android.com/apk/res/android" <ScrollView xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="match_parent" a:layout_width="match_parent"
a:minWidth="200dp"> a:minWidth="300dp">
<LinearLayout a:layout_height="wrap_content" <LinearLayout a:layout_height="wrap_content"
a:layout_width="match_parent" a:layout_width="match_parent"
a:orientation="vertical"> a:orientation="vertical">
<TextView a:layout_height="wrap_content" <TextView a:layout_height="wrap_content"
a:layout_width="match_parent" a:layout_width="match_parent"
a:padding="6dp" a:padding="6dp"
style="@style/default_text_size" style="@style/default_text_size"
a:text="@string/c_var_name"/> a:text="@string/c_var_name"/>
<EditText a:id="@+id/var_edit_name" <EditText a:id="@+id/var_edit_name"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="match_parent" a:layout_width="match_parent"
style="@style/default_text_size" style="@style/default_text_size"
a:inputType="text"/> a:inputType="text"/>
<TextView a:layout_height="wrap_content" <TextView a:layout_height="wrap_content"
a:layout_width="match_parent" a:layout_width="match_parent"
style="@style/default_text_size" style="@style/default_text_size"
a:padding="6dp" a:padding="6dp"
a:text="@string/c_var_value"/> a:text="@string/c_var_value"/>
<EditText a:id="@+id/var_edit_value" <EditText a:id="@+id/var_edit_value"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="match_parent" a:layout_width="match_parent"
style="@style/default_text_size" style="@style/default_text_size"
a:inputType="text"/> a:inputType="text"/>
<TextView a:layout_height="wrap_content" <TextView a:layout_height="wrap_content"
a:layout_width="match_parent" a:layout_width="match_parent"
a:padding="6dp" a:padding="6dp"
style="@style/default_text_size" style="@style/default_text_size"
a:text="@string/c_var_description"/> a:text="@string/c_var_description"/>
<EditText a:id="@+id/var_edit_description" <EditText a:id="@+id/var_edit_description"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="match_parent" a:layout_width="match_parent"
style="@style/default_text_size" style="@style/default_text_size"
a:inputType="text"/> a:inputType="text"/>
<LinearLayout <LinearLayout
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="match_parent"> a:layout_width="match_parent">
<Button a:id="@+id/cancel_button" <Button a:id="@+id/cancel_button"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_weight="1" a:layout_weight="1"
a:text="@string/c_cancel"/> a:text="@string/c_cancel"/>
<Button a:id="@+id/remove_button" <Button a:id="@+id/remove_button"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_weight="1" a:layout_weight="1"
a:text="@string/c_remove"/> a:text="@string/c_remove"/>
<Button a:id="@+id/save_button" <Button a:id="@+id/save_button"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_weight="1" a:layout_weight="1"
a:text="@string/c_save"/> a:text="@string/c_save"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -1,5 +1,7 @@
<resources> <resources>
<dimen name="editor_text_size">15sp</dimen> <dimen name="editor_text_size">15sp</dimen>
<dimen name="display_text_size">15sp</dimen> <dimen name="display_text_size">15sp</dimen>
<dimen name="keyboard_button_text_size">20dp</dimen> <dimen name="keyboard_button_text_size">20dp</dimen>
<dimen name="math_entity_text_size">15sp</dimen>
<dimen name="math_entity_description_text_size">10sp</dimen>
</resources> </resources>

View File

@ -1,14 +1,16 @@
<resources> <resources>
<dimen name="button_margin">0.5dp</dimen> <dimen name="button_margin">0.5dp</dimen>
<dimen name="text_size">20sp</dimen> <dimen name="text_size">20sp</dimen>
<dimen name="keyboard_button_text_size">30dp</dimen> <dimen name="keyboard_button_text_size">30dp</dimen>
<dimen name="button_text_size">20dp</dimen> <dimen name="button_text_size">20dp</dimen>
<dimen name="display_text_size">25sp</dimen> <dimen name="display_text_size">25sp</dimen>
<dimen name="editor_text_size">25sp</dimen> <dimen name="editor_text_size">25sp</dimen>
<dimen name="pane_margin">5dp</dimen> <dimen name="pane_margin">5dp</dimen>
<dimen name="pane_padding">5dp</dimen> <dimen name="pane_padding">5dp</dimen>
<dimen name="math_entity_text_size">20sp</dimen>
<!--only for not multipane--> <dimen name="math_entity_description_text_size">15sp</dimen>
<dimen name="editor_padding">5dp</dimen>
<dimen name="display_padding">3dp</dimen> <!--only for not multipane-->
<dimen name="editor_padding">5dp</dimen>
<dimen name="display_padding">3dp</dimen>
</resources> </resources>

View File

@ -8,16 +8,11 @@
<resources> <resources>
<style name="math_entity_text" parent="math_entity_text_parent"> <style name="math_entity_text" parent="math_entity_text_parent">
<item name="android:paddingTop">0dp</item>
<item name="android:paddingLeft">0dp</item>
<item name="android:paddingRight">0dp</item>
<item name="android:paddingBottom">@dimen/pane_padding</item>
<item name="android:textStyle">bold</item> <item name="android:textStyle">bold</item>
<item name="android:textColor">@android:color/white</item> <item name="android:textColor">@android:color/white</item>
</style> </style>
<style name="math_entity_description" parent="math_entity_description_parent"> <style name="math_entity_description" parent="math_entity_description_parent">
<item name="android:padding">0dp</item>
<item name="android:textColor">#bebebe</item> <item name="android:textColor">#bebebe</item>
</style> </style>

View File

@ -1,63 +1,63 @@
<!-- <!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev. ~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com ~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org ~ or visit http://se.solovyev.org
--> -->
<resources> <resources>
<style name="WindowTitle"> <style name="WindowTitle">
<item name="android:singleLine">true</item> <item name="android:singleLine">true</item>
<item name="android:textAppearance">@style/TextAppearance_WindowTitle</item> <item name="android:textAppearance">@style/TextAppearance_WindowTitle</item>
<item name="android:shadowColor">#BB000000</item> <item name="android:shadowColor">#BB000000</item>
<item name="android:shadowRadius">2.75</item> <item name="android:shadowRadius">2.75</item>
</style> </style>
<style name="TextAppearance_WindowTitle"> <style name="TextAppearance_WindowTitle">
<item name="android:textColor">#fff</item> <item name="android:textColor">#fff</item>
<item name="android:textSize">14sp</item> <item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item> <item name="android:textStyle">bold</item>
</style> </style>
<style name="default_text_size"> <style name="default_text_size">
<item name="android:textSize">@dimen/text_size</item> <item name="android:textSize">@dimen/text_size</item>
</style> </style>
<style name="keyboard_button_style_parent"> <style name="keyboard_button_style_parent">
<item name="android:textSize">@dimen/keyboard_button_text_size</item> <item name="android:textSize">@dimen/keyboard_button_text_size</item>
<item name="android:textColor">@color/button_text_color</item> <item name="android:textColor">@color/button_text_color</item>
</style> </style>
<style name="button_style_parent"> <style name="button_style_parent">
<item name="android:textSize">@dimen/button_text_size</item> <item name="android:textSize">@dimen/button_text_size</item>
<item name="android:textColor">@color/button_text_color</item> <item name="android:textColor">@color/button_text_color</item>
</style> </style>
<style name="display_style_parent" parent="default_text"> <style name="display_style_parent" parent="default_text">
<item name="android:textSize">@dimen/display_text_size</item> <item name="android:textSize">@dimen/display_text_size</item>
</style> </style>
<style name="editor_style_parent" parent="default_text"> <style name="editor_style_parent" parent="default_text">
<item name="android:textSize">@dimen/editor_text_size</item> <item name="android:textSize">@dimen/editor_text_size</item>
</style> </style>
<style name="about_style_parent" parent="default_text"> <style name="about_style_parent" parent="default_text">
<item name="android:textSize">15dp</item> <item name="android:textSize">15dp</item>
<item name="android:padding">5dp</item> <item name="android:padding">5dp</item>
</style> </style>
<style name="math_entity_text_parent"> <style name="math_entity_text_parent">
<item name="android:textSize">20dp</item> <item name="android:textSize">@dimen/math_entity_text_size</item>
</style> </style>
<style name="math_entity_description_parent"> <style name="math_entity_description_parent">
<item name="android:textSize">15dp</item> <item name="android:textSize">@dimen/math_entity_description_text_size</item>
</style> </style>
<style name="add_var_button_parent"> <style name="add_var_button_parent">
<item name="android:paddingLeft">40dp</item> <item name="android:paddingLeft">40dp</item>
<item name="android:paddingRight">40dp</item> <item name="android:paddingRight">40dp</item>
</style> </style>
</resources> </resources>

View File

@ -1,225 +1,232 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Vibrator; import android.os.Vibrator;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.history.CalculatorHistoryState; import org.solovyev.android.calculator.history.CalculatorHistoryState;
import org.solovyev.android.calculator.view.AngleUnitsButton; import org.solovyev.android.calculator.view.AngleUnitsButton;
import org.solovyev.android.calculator.view.NumeralBasesButton; import org.solovyev.android.calculator.view.NumeralBasesButton;
import org.solovyev.android.calculator.view.OnDragListenerVibrator; import org.solovyev.android.calculator.view.OnDragListenerVibrator;
import org.solovyev.android.history.HistoryDragProcessor; import org.solovyev.android.history.HistoryDragProcessor;
import org.solovyev.android.view.drag.*; import org.solovyev.android.view.drag.*;
import org.solovyev.common.Announcer; import org.solovyev.common.Announcer;
import org.solovyev.common.math.Point2d; import org.solovyev.common.math.Point2d;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* User: serso * User: serso
* Date: 9/28/12 * Date: 9/28/12
* Time: 12:12 AM * Time: 12:12 AM
*/ */
public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSharedPreferenceChangeListener { public abstract class AbstractCalculatorHelper implements SharedPreferences.OnSharedPreferenceChangeListener {
@NotNull @NotNull
private CalculatorPreferences.Gui.Layout layout; private CalculatorPreferences.Gui.Layout layout;
@Nullable @NotNull
private Vibrator vibrator; private CalculatorPreferences.Gui.Theme theme;
@NotNull @Nullable
private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class); private Vibrator vibrator;
@NotNull @NotNull
private String logTag = "CalculatorActivity"; private final Announcer<DragPreferencesChangeListener> dpclRegister = new Announcer<DragPreferencesChangeListener>(DragPreferencesChangeListener.class);
protected AbstractCalculatorHelper() { @NotNull
} private String logTag = "CalculatorActivity";
protected AbstractCalculatorHelper(@NotNull String logTag) { protected AbstractCalculatorHelper() {
this.logTag = logTag; }
}
protected AbstractCalculatorHelper(@NotNull String logTag) {
protected void onCreate(@NotNull Activity activity) { this.logTag = logTag;
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); }
vibrator = (Vibrator) activity.getSystemService(Activity.VIBRATOR_SERVICE); protected void onCreate(@NotNull Activity activity) {
layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
preferences.registerOnSharedPreferenceChangeListener(this); vibrator = (Vibrator) activity.getSystemService(Activity.VIBRATOR_SERVICE);
} layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences);
public void logDebug(@NotNull String message) {
Log.d(logTag, message); preferences.registerOnSharedPreferenceChangeListener(this);
} }
public void processButtons(@NotNull final Activity activity, @NotNull View root) { public void logDebug(@NotNull String message) {
dpclRegister.clear(); Log.d(logTag, message);
}
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, activity); public void processButtons(@NotNull final Activity activity, @NotNull View root) {
dpclRegister.clear();
setOnDragListeners(root, dragPreferences, preferences);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
final OnDragListener historyOnDragListener = new OnDragListenerVibrator(newOnDragListener(new HistoryDragProcessor<CalculatorHistoryState>(getCalculator()), dragPreferences), vibrator, preferences); final SimpleOnDragListener.Preferences dragPreferences = SimpleOnDragListener.getPreferences(preferences, activity);
final DragButton historyButton = getButton(root, R.id.historyButton);
if (historyButton != null) { setOnDragListeners(root, dragPreferences, preferences);
historyButton.setOnDragListener(historyOnDragListener);
} final OnDragListener historyOnDragListener = new OnDragListenerVibrator(newOnDragListener(new HistoryDragProcessor<CalculatorHistoryState>(getCalculator()), dragPreferences), vibrator, preferences);
final DragButton historyButton = getButton(root, R.id.historyButton);
final DragButton subtractionButton = getButton(root, R.id.subtractionButton); if (historyButton != null) {
if (subtractionButton != null) { historyButton.setOnDragListener(historyOnDragListener);
subtractionButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new SimpleOnDragListener.DragProcessor() { }
@Override
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) { final DragButton subtractionButton = getButton(root, R.id.subtractionButton);
if (dragDirection == DragDirection.down) { if (subtractionButton != null) {
CalculatorActivity.operatorsButtonClickHandler(activity); subtractionButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new SimpleOnDragListener.DragProcessor() {
return true; @Override
} public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
return false; if (dragDirection == DragDirection.down) {
} CalculatorActivity.operatorsButtonClickHandler(activity);
}, dragPreferences), vibrator, preferences)); return true;
} }
return false;
final OnDragListener toPositionOnDragListener = new OnDragListenerVibrator(new SimpleOnDragListener(new CursorDragProcessor(), dragPreferences), vibrator, preferences); }
}, dragPreferences), vibrator, preferences));
final DragButton rightButton = getButton(root, R.id.rightButton); }
if (rightButton != null) {
rightButton.setOnDragListener(toPositionOnDragListener); final OnDragListener toPositionOnDragListener = new OnDragListenerVibrator(new SimpleOnDragListener(new CursorDragProcessor(), dragPreferences), vibrator, preferences);
}
final DragButton rightButton = getButton(root, R.id.rightButton);
final DragButton leftButton = getButton(root, R.id.leftButton); if (rightButton != null) {
if (leftButton != null) { rightButton.setOnDragListener(toPositionOnDragListener);
leftButton.setOnDragListener(toPositionOnDragListener); }
}
final DragButton leftButton = getButton(root, R.id.leftButton);
final DragButton equalsButton = getButton(root, R.id.equalsButton); if (leftButton != null) {
if (equalsButton != null) { leftButton.setOnDragListener(toPositionOnDragListener);
equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EvalDragProcessor(), dragPreferences), vibrator, preferences)); }
}
final DragButton equalsButton = getButton(root, R.id.equalsButton);
final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) getButton(root, R.id.sixDigitButton); if (equalsButton != null) {
if (angleUnitsButton != null) { equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EvalDragProcessor(), dragPreferences), vibrator, preferences));
angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.AngleUnitsChanger(activity), dragPreferences), vibrator, preferences)); }
}
final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) getButton(root, R.id.sixDigitButton);
final NumeralBasesButton clearButton = (NumeralBasesButton) getButton(root, R.id.clearButton); if (angleUnitsButton != null) {
if (clearButton != null) { angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.AngleUnitsChanger(activity), dragPreferences), vibrator, preferences));
clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.NumeralBasesChanger(activity), dragPreferences), vibrator, preferences)); }
}
final NumeralBasesButton clearButton = (NumeralBasesButton) getButton(root, R.id.clearButton);
final DragButton varsButton = getButton(root, R.id.varsButton); if (clearButton != null) {
if (varsButton != null) { clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.NumeralBasesChanger(activity), dragPreferences), vibrator, preferences));
varsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.VarsDragProcessor(activity), dragPreferences), vibrator, preferences)); }
}
final DragButton varsButton = getButton(root, R.id.varsButton);
final DragButton roundBracketsButton = getButton(root, R.id.roundBracketsButton); if (varsButton != null) {
if (roundBracketsButton != null) { varsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.VarsDragProcessor(activity), dragPreferences), vibrator, preferences));
roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences)); }
}
final DragButton roundBracketsButton = getButton(root, R.id.roundBracketsButton);
if (layout == CalculatorPreferences.Gui.Layout.simple) { if (roundBracketsButton != null) {
toggleButtonDirectionText(root, R.id.oneDigitButton, false, DragDirection.up, DragDirection.down); roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new CalculatorButtons.RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences));
toggleButtonDirectionText(root, R.id.twoDigitButton, false, DragDirection.up, DragDirection.down); }
toggleButtonDirectionText(root, R.id.threeDigitButton, false, DragDirection.up, DragDirection.down);
if (layout == CalculatorPreferences.Gui.Layout.simple) {
toggleButtonDirectionText(root, R.id.sixDigitButton, false, DragDirection.up, DragDirection.down); toggleButtonDirectionText(root, R.id.oneDigitButton, false, DragDirection.up, DragDirection.down);
toggleButtonDirectionText(root, R.id.sevenDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down); toggleButtonDirectionText(root, R.id.twoDigitButton, false, DragDirection.up, DragDirection.down);
toggleButtonDirectionText(root, R.id.eightDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down); toggleButtonDirectionText(root, R.id.threeDigitButton, false, DragDirection.up, DragDirection.down);
toggleButtonDirectionText(root, R.id.clearButton, false, DragDirection.left, 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.fourDigitButton, false, DragDirection.down); toggleButtonDirectionText(root, R.id.eightDigitButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
toggleButtonDirectionText(root, R.id.fiveDigitButton, false, DragDirection.down);
toggleButtonDirectionText(root, R.id.clearButton, false, DragDirection.left, DragDirection.up, DragDirection.down);
toggleButtonDirectionText(root, R.id.nineDigitButton, false, DragDirection.left);
toggleButtonDirectionText(root, R.id.fourDigitButton, false, DragDirection.down);
toggleButtonDirectionText(root, R.id.multiplicationButton, false, DragDirection.left); toggleButtonDirectionText(root, R.id.fiveDigitButton, false, DragDirection.down);
toggleButtonDirectionText(root, R.id.plusButton, false, DragDirection.down, DragDirection.up);
} toggleButtonDirectionText(root, R.id.nineDigitButton, false, DragDirection.left);
}
toggleButtonDirectionText(root, R.id.multiplicationButton, false, DragDirection.left);
private void toggleButtonDirectionText(@NotNull View root, int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) { toggleButtonDirectionText(root, R.id.plusButton, false, DragDirection.down, DragDirection.up);
final View v = getButton(root, id); }
if (v instanceof DirectionDragButton ) {
final DirectionDragButton button = (DirectionDragButton)v; CalculatorButtons.processButtons(true, theme, root);
for (DragDirection dragDirection : dragDirections) { CalculatorButtons.toggleEqualsButton(preferences, activity);
button.showDirectionText(showDirectionText, dragDirection); }
}
} private void toggleButtonDirectionText(@NotNull View root, int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) {
} final View v = getButton(root, id);
if (v instanceof DirectionDragButton ) {
@NotNull final DirectionDragButton button = (DirectionDragButton)v;
private Calculator getCalculator() { for (DragDirection dragDirection : dragDirections) {
return CalculatorLocatorImpl.getInstance().getCalculator(); button.showDirectionText(showDirectionText, dragDirection);
} }
}
}
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); @NotNull
private Calculator getCalculator() {
final List<Integer> dragButtonIds = new ArrayList<Integer>(); return CalculatorLocatorImpl.getInstance().getCalculator();
}
for (Field field : R.id.class.getDeclaredFields()) {
int modifiers = field.getModifiers();
if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) { private void setOnDragListeners(@NotNull View root, @NotNull SimpleOnDragListener.Preferences dragPreferences, @NotNull SharedPreferences preferences) {
try { final OnDragListener onDragListener = new OnDragListenerVibrator(newOnDragListener(new DigitButtonDragProcessor(getKeyboard()), dragPreferences), vibrator, preferences);
int viewId = field.getInt(R.id.class);
final View view = root.findViewById(viewId); final List<Integer> dragButtonIds = new ArrayList<Integer>();
if (view instanceof DragButton) {
dragButtonIds.add(viewId); for (Field field : R.id.class.getDeclaredFields()) {
} int modifiers = field.getModifiers();
} catch (IllegalAccessException e) { if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) {
Log.e(R.id.class.getName(), e.getMessage()); try {
} int viewId = field.getInt(R.id.class);
} final View view = root.findViewById(viewId);
} if (view instanceof DragButton) {
dragButtonIds.add(viewId);
for (Integer dragButtonId : dragButtonIds) { }
final DragButton button = getButton(root, dragButtonId); } catch (IllegalAccessException e) {
if (button != null) { Log.e(R.id.class.getName(), e.getMessage());
button.setOnDragListener(onDragListener); }
} }
} }
}
for (Integer dragButtonId : dragButtonIds) {
@NotNull final DragButton button = getButton(root, dragButtonId);
private CalculatorKeyboard getKeyboard() { if (button != null) {
return CalculatorLocatorImpl.getInstance().getKeyboard(); button.setOnDragListener(onDragListener);
} }
}
@Nullable }
private <T extends DragButton> T getButton(@NotNull View root, int buttonId) {
return (T) root.findViewById(buttonId); @NotNull
} private CalculatorKeyboard getKeyboard() {
return CalculatorLocatorImpl.getInstance().getKeyboard();
@NotNull }
private SimpleOnDragListener newOnDragListener(@NotNull SimpleOnDragListener.DragProcessor dragProcessor,
@NotNull SimpleOnDragListener.Preferences dragPreferences) { @Nullable
final SimpleOnDragListener onDragListener = new SimpleOnDragListener(dragProcessor, dragPreferences); private <T extends DragButton> T getButton(@NotNull View root, int buttonId) {
dpclRegister.addListener(onDragListener); return (T) root.findViewById(buttonId);
return onDragListener; }
}
@NotNull
@Override private SimpleOnDragListener newOnDragListener(@NotNull SimpleOnDragListener.DragProcessor dragProcessor,
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { @NotNull SimpleOnDragListener.Preferences dragPreferences) {
if (key != null && key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) { final SimpleOnDragListener onDragListener = new SimpleOnDragListener(dragProcessor, dragPreferences);
dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, CalculatorApplication.getInstance())); dpclRegister.addListener(onDragListener);
} return onDragListener;
} }
public void onDestroy(@NotNull Activity activity) { @Override
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (key != null && key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) {
preferences.unregisterOnSharedPreferenceChangeListener(this); dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, CalculatorApplication.getInstance()));
} }
} }
public void onDestroy(@NotNull Activity activity) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
preferences.unregisterOnSharedPreferenceChangeListener(this);
}
}

View File

@ -1,354 +1,352 @@
/* /*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev. * Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com * For more information, please, contact se.solovyev@gmail.com
*/ */
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.app.SherlockFragmentActivity;
import net.robotmedia.billing.BillingController; import net.robotmedia.billing.BillingController;
import net.robotmedia.billing.IBillingObserver; import net.robotmedia.billing.IBillingObserver;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.AndroidUtils; import org.solovyev.android.AndroidUtils;
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity; import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
import org.solovyev.android.calculator.history.CalculatorHistoryFragment; import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment; import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment; import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment;
import org.solovyev.android.calculator.math.edit.CalculatorOperatorsFragment; import org.solovyev.android.calculator.math.edit.CalculatorOperatorsFragment;
import org.solovyev.android.calculator.math.edit.CalculatorVarsFragment; import org.solovyev.android.calculator.math.edit.CalculatorVarsFragment;
import org.solovyev.android.calculator.plot.CalculatorPlotFragment; import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
import org.solovyev.android.fragments.FragmentUtils; import org.solovyev.android.fragments.FragmentUtils;
import org.solovyev.android.prefs.Preference; import org.solovyev.android.prefs.Preference;
import org.solovyev.android.view.ColorButton; import org.solovyev.android.view.ColorButton;
import org.solovyev.common.equals.EqualsTool; import org.solovyev.common.equals.EqualsTool;
import org.solovyev.common.history.HistoryAction; import org.solovyev.common.history.HistoryAction;
import org.solovyev.common.text.StringUtils; import org.solovyev.common.text.StringUtils;
public class CalculatorActivity extends SherlockFragmentActivity implements SharedPreferences.OnSharedPreferenceChangeListener { public class CalculatorActivity extends SherlockFragmentActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
@NotNull @NotNull
public static final String TAG = CalculatorActivity.class.getSimpleName(); public static final String TAG = CalculatorActivity.class.getSimpleName();
@Nullable @Nullable
private IBillingObserver billingObserver; private IBillingObserver billingObserver;
private boolean useBackAsPrev; private boolean useBackAsPrev;
@NotNull @NotNull
private CalculatorActivityHelper activityHelper; private CalculatorActivityHelper activityHelper;
/** /**
* Called when the activity is first created. * Called when the activity is first created.
*/ */
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
CalculatorApplication.registerOnRemoteStackTrace(); CalculatorApplication.registerOnRemoteStackTrace();
/*final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);*/ /*final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);*/
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences); final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
activityHelper = CalculatorApplication.getInstance().createActivityHelper(layout.getLayoutId(), TAG); activityHelper = CalculatorApplication.getInstance().createActivityHelper(layout.getLayoutId(), TAG);
activityHelper.logDebug("onCreate"); activityHelper.logDebug("onCreate");
activityHelper.onCreate(this, savedInstanceState); activityHelper.onCreate(this, savedInstanceState);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
activityHelper.logDebug("super.onCreate"); activityHelper.logDebug("super.onCreate");
if (findViewById(R.id.main_second_pane) != null) { 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, "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, "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, "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, "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, "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.addTab(this, "plot", CalculatorPlotFragment.class, null, R.string.c_plot, R.id.main_second_pane);
activityHelper.restoreSavedTab(this); activityHelper.restoreSavedTab(this);
} else { } else {
getSupportActionBar().hide(); getSupportActionBar().hide();
} }
FragmentUtils.createFragment(this, CalculatorEditorFragment.class, R.id.editorContainer, "editor"); FragmentUtils.createFragment(this, CalculatorEditorFragment.class, R.id.editorContainer, "editor");
FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display"); FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display");
FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard"); FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
/*if (customTitleSupported) { /*if (customTitleSupported) {
try { try {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title);
final CalculatorAdditionalTitle additionalAdditionalTitleText = (CalculatorAdditionalTitle)findViewById(R.id.additional_title_text); final CalculatorAdditionalTitle additionalAdditionalTitleText = (CalculatorAdditionalTitle)findViewById(R.id.additional_title_text);
additionalAdditionalTitleText.init(preferences); additionalAdditionalTitleText.init(preferences);
preferences.registerOnSharedPreferenceChangeListener(additionalAdditionalTitleText); preferences.registerOnSharedPreferenceChangeListener(additionalAdditionalTitleText);
} catch (ClassCastException e) { } catch (ClassCastException e) {
// super fix for issue with class cast in android.view.Window.setFeatureInt() (see app error reports) // super fix for issue with class cast in android.view.Window.setFeatureInt() (see app error reports)
Log.e(CalculatorActivity.class.getName(), e.getMessage(), e); Log.e(CalculatorActivity.class.getName(), e.getMessage(), e);
} }
}*/ }*/
billingObserver = new CalculatorBillingObserver(this); billingObserver = new CalculatorBillingObserver(this);
BillingController.registerObserver(billingObserver); BillingController.registerObserver(billingObserver);
this.useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences); this.useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
firstTimeInit(preferences, this); firstTimeInit(preferences, this);
// init billing controller // init billing controller
BillingController.checkBillingSupported(this); BillingController.checkBillingSupported(this);
toggleOrientationChange(preferences); toggleOrientationChange(preferences);
CalculatorButtons.toggleEqualsButton(preferences, this, activityHelper.getTheme(), findViewById(R.id.main_layout)); preferences.registerOnSharedPreferenceChangeListener(this);
}
preferences.registerOnSharedPreferenceChangeListener(this);
} @NotNull
private AndroidCalculator getCalculator() {
@NotNull return ((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator());
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);
private static void firstTimeInit(@NotNull SharedPreferences preferences, @NotNull Context context) { if (appOpenedCounter != null) {
final Integer appOpenedCounter = CalculatorPreferences.appOpenedCounter.getPreference(preferences); CalculatorPreferences.appOpenedCounter.putPreference(preferences, appOpenedCounter + 1);
if (appOpenedCounter != null) { }
CalculatorPreferences.appOpenedCounter.putPreference(preferences, appOpenedCounter + 1);
} final Integer savedVersion = CalculatorPreferences.appVersion.getPreference(preferences);
final Integer savedVersion = CalculatorPreferences.appVersion.getPreference(preferences); final int appVersion = AndroidUtils.getAppVersionCode(context, CalculatorActivity.class.getPackage().getName());
final int appVersion = AndroidUtils.getAppVersionCode(context, CalculatorActivity.class.getPackage().getName()); CalculatorPreferences.appVersion.putPreference(preferences, appVersion);
CalculatorPreferences.appVersion.putPreference(preferences, appVersion); boolean dialogShown = false;
if (EqualsTool.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
boolean dialogShown = false; // new start
if (EqualsTool.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) { final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(R.string.c_first_start_text);
// new start builder.setPositiveButton(android.R.string.ok, null);
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(R.string.c_first_start_text); builder.setTitle(R.string.c_first_start_text_title);
builder.setPositiveButton(android.R.string.ok, null); builder.create().show();
builder.setTitle(R.string.c_first_start_text_title); dialogShown = true;
builder.create().show(); } else {
dialogShown = true; if (savedVersion < appVersion) {
} else { final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
if (savedVersion < appVersion) { if (showReleaseNotes) {
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences); final String releaseNotes = CalculatorReleaseNotesActivity.getReleaseNotes(context, savedVersion + 1);
if (showReleaseNotes) { if (!StringUtils.isEmpty(releaseNotes)) {
final String releaseNotes = CalculatorReleaseNotesActivity.getReleaseNotes(context, savedVersion + 1); final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
if (!StringUtils.isEmpty(releaseNotes)) { builder.setPositiveButton(android.R.string.ok, null);
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes)); builder.setTitle(R.string.c_release_notes);
builder.setPositiveButton(android.R.string.ok, null); builder.create().show();
builder.setTitle(R.string.c_release_notes); dialogShown = true;
builder.create().show(); }
dialogShown = true; }
} }
} }
}
}
//Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!");
if (!dialogShown) {
//Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!"); if (appOpenedCounter != null && appOpenedCounter > 10) {
if (!dialogShown) { dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.feedbackWindowShown, R.layout.feedback, R.id.feedbackText, context);
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);
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<Boolean> specialWindowShownPref, int layoutId, int textViewId, @NotNull Context context) {
boolean result = false;
private static boolean showSpecialWindow(@NotNull SharedPreferences preferences, @NotNull Preference<Boolean> specialWindowShownPref, int layoutId, int textViewId, @NotNull Context context) {
boolean result = false; final Boolean specialWindowShown = specialWindowShownPref.getPreference(preferences);
if ( specialWindowShown != null && !specialWindowShown ) {
final Boolean specialWindowShown = specialWindowShownPref.getPreference(preferences); final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
if ( specialWindowShown != null && !specialWindowShown ) { final View view = layoutInflater.inflate(layoutId, null);
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 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);
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setView(view); builder.create().show();
builder.setPositiveButton(android.R.string.ok, null);
builder.create().show(); result = true;
specialWindowShownPref.putPreference(preferences, true);
result = true; }
specialWindowShownPref.putPreference(preferences, true);
} return result;
}
return result;
} @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
@Override if (keyCode == KeyEvent.KEYCODE_BACK) {
public boolean onKeyDown(int keyCode, KeyEvent event) { if (useBackAsPrev) {
if (keyCode == KeyEvent.KEYCODE_BACK) { getCalculator().doHistoryAction(HistoryAction.undo);
if (useBackAsPrev) { return true;
getCalculator().doHistoryAction(HistoryAction.undo); }
return true; }
} return super.onKeyDown(keyCode, event);
} }
return super.onKeyDown(keyCode, event);
} @SuppressWarnings({"UnusedDeclaration"})
public void equalsButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) getCalculator().evaluate();
public void equalsButtonClickHandler(@NotNull View v) { }
getCalculator().evaluate();
} @Override
protected void onResume() {
@Override super.onResume();
protected void onResume() {
super.onResume(); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); if ( newLayout.getLayoutId() != activityHelper.getLayoutId() ) {
final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences); AndroidUtils.restartActivity(this);
if ( newLayout.getLayoutId() != activityHelper.getLayoutId() ) { }
AndroidUtils.restartActivity(this);
} this.activityHelper.onResume(this);
}
this.activityHelper.onResume(this);
} @Override
protected void onDestroy() {
@Override if (billingObserver != null) {
protected void onDestroy() { BillingController.unregisterObserver(billingObserver);
if (billingObserver != null) { }
BillingController.unregisterObserver(billingObserver);
} activityHelper.onDestroy(this);
activityHelper.onDestroy(this); super.onDestroy();
}
super.onDestroy();
} @Override
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
@Override if ( CalculatorPreferences.Gui.usePrevAsBack.getKey().equals(key) ) {
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) { useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
if ( CalculatorPreferences.Gui.usePrevAsBack.getKey().equals(key) ) { }
useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
} if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) {
toggleOrientationChange(preferences);
if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) { }
toggleOrientationChange(preferences); }
}
} @Override
protected void onSaveInstanceState(Bundle outState) {
@Override super.onSaveInstanceState(outState);
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); activityHelper.onSaveInstanceState(this, outState);
}
activityHelper.onSaveInstanceState(this, outState);
} private void toggleOrientationChange(@Nullable SharedPreferences preferences) {
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(this) : preferences;
private void toggleOrientationChange(@Nullable SharedPreferences preferences) { if (CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(this) : preferences; setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
if (CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) { } else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else { }
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }
}
} /*
**********************************************************************
/* *
********************************************************************** * BUTTON HANDLERS
* *
* BUTTON HANDLERS **********************************************************************
* */
**********************************************************************
*/ @SuppressWarnings({"UnusedDeclaration"})
public void elementaryButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) throw new UnsupportedOperationException("Not implemented yet!");
public void elementaryButtonClickHandler(@NotNull View v) { }
throw new UnsupportedOperationException("Not implemented yet!");
} @SuppressWarnings({"UnusedDeclaration"})
public void historyButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) CalculatorActivityLauncher.showHistory(this);
public void historyButtonClickHandler(@NotNull View v) { }
CalculatorActivityLauncher.showHistory(this);
} @SuppressWarnings({"UnusedDeclaration"})
public void eraseButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) CalculatorLocatorImpl.getInstance().getEditor().erase();
public void eraseButtonClickHandler(@NotNull View v) { }
CalculatorLocatorImpl.getInstance().getEditor().erase();
} @SuppressWarnings({"UnusedDeclaration"})
public void simplifyButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) throw new UnsupportedOperationException("Not implemented yet!");
public void simplifyButtonClickHandler(@NotNull View v) { }
throw new UnsupportedOperationException("Not implemented yet!");
} @SuppressWarnings({"UnusedDeclaration"})
public void moveLeftButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) getKeyboard().moveCursorLeft();
public void moveLeftButtonClickHandler(@NotNull View v) { }
getKeyboard().moveCursorLeft();
} @SuppressWarnings({"UnusedDeclaration"})
public void moveRightButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) getKeyboard().moveCursorRight();
public void moveRightButtonClickHandler(@NotNull View v) { }
getKeyboard().moveCursorRight();
} @SuppressWarnings({"UnusedDeclaration"})
public void pasteButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) getKeyboard().pasteButtonPressed();
public void pasteButtonClickHandler(@NotNull View v) { }
getKeyboard().pasteButtonPressed();
} @SuppressWarnings({"UnusedDeclaration"})
public void copyButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) getKeyboard().copyButtonPressed();
public void copyButtonClickHandler(@NotNull View v) { }
getKeyboard().copyButtonPressed();
} @NotNull
private static CalculatorKeyboard getKeyboard() {
@NotNull return CalculatorLocatorImpl.getInstance().getKeyboard();
private static CalculatorKeyboard getKeyboard() { }
return CalculatorLocatorImpl.getInstance().getKeyboard();
} @SuppressWarnings({"UnusedDeclaration"})
public void clearButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) getKeyboard().clearButtonPressed();
public void clearButtonClickHandler(@NotNull View v) { }
getKeyboard().clearButtonPressed();
} @SuppressWarnings({"UnusedDeclaration"})
public void digitButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) Log.d(String.valueOf(v.getId()), "digitButtonClickHandler() for: " + v.getId() + ". Pressed: " + v.isPressed());
public void digitButtonClickHandler(@NotNull View v) { if (((ColorButton) v).isShowText()) {
Log.d(String.valueOf(v.getId()), "digitButtonClickHandler() for: " + v.getId() + ". Pressed: " + v.isPressed()); getKeyboard().digitButtonPressed(((ColorButton) v).getText().toString());
if (((ColorButton) v).isShowText()) { }
getKeyboard().digitButtonPressed(((ColorButton) v).getText().toString()); }
}
} @SuppressWarnings({"UnusedDeclaration"})
public void functionsButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) CalculatorActivityLauncher.showFunctions(this);
public void functionsButtonClickHandler(@NotNull View v) { }
CalculatorActivityLauncher.showFunctions(this);
} @SuppressWarnings({"UnusedDeclaration"})
public void operatorsButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) CalculatorActivityLauncher.showOperators(this);
public void operatorsButtonClickHandler(@NotNull View v) { }
CalculatorActivityLauncher.showOperators(this);
} public static void operatorsButtonClickHandler(@NotNull Activity activity) {
CalculatorActivityLauncher.showOperators(activity);
public static void operatorsButtonClickHandler(@NotNull Activity activity) { }
CalculatorActivityLauncher.showOperators(activity);
} @SuppressWarnings({"UnusedDeclaration"})
public void varsButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) CalculatorActivityLauncher.showVars(this);
public void varsButtonClickHandler(@NotNull View v) { }
CalculatorActivityLauncher.showVars(this);
} @SuppressWarnings({"UnusedDeclaration"})
public void donateButtonClickHandler(@NotNull View v) {
@SuppressWarnings({"UnusedDeclaration"}) CalculatorApplication.showDonationDialog(this);
public void donateButtonClickHandler(@NotNull View v) { }
CalculatorApplication.showDonationDialog(this);
}
} }

View File

@ -1,190 +1,195 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.content.res.Configuration;
import android.preference.PreferenceManager; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.preference.PreferenceManager;
import android.util.Log; import android.support.v4.app.Fragment;
import android.view.View; import android.util.Log;
import com.actionbarsherlock.app.ActionBar; import android.view.View;
import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.app.ActionBar;
import org.jetbrains.annotations.NotNull; import com.actionbarsherlock.app.SherlockFragmentActivity;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.NotNull;
import org.solovyev.android.AndroidUtils; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener; import org.solovyev.android.AndroidUtils;
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
import java.util.ArrayList;
import java.util.List; import java.util.ArrayList;
import java.util.List;
/**
* User: serso /**
* Date: 9/25/12 * User: serso
* Time: 10:32 PM * Date: 9/25/12
*/ * Time: 10:32 PM
public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper implements CalculatorActivityHelper { */
public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper implements CalculatorActivityHelper {
/*
********************************************************************** /*
* **********************************************************************
* CONSTANTS *
* * CONSTANTS
********************************************************************** *
*/ **********************************************************************
private static final String SELECTED_NAV = "selected_nav"; */
private static final String SELECTED_NAV = "selected_nav";
/*
********************************************************************** /*
* **********************************************************************
* FIELDS *
* * FIELDS
********************************************************************** *
*/ **********************************************************************
*/
private int layoutId;
private int layoutId;
private boolean homeIcon = false;
private boolean homeIcon = false;
@NotNull
private final List<String> fragmentTags = new ArrayList<String>(); @NotNull
private final List<String> fragmentTags = new ArrayList<String>();
@NotNull
private CalculatorPreferences.Gui.Theme theme; @NotNull
private int navPosition = 0; private CalculatorPreferences.Gui.Theme theme;
private int navPosition = 0;
public CalculatorActivityHelperImpl(int layoutId, @NotNull String logTag) {
super(logTag); public CalculatorActivityHelperImpl(int layoutId, @NotNull String logTag) {
this.layoutId = layoutId; super(logTag);
} this.layoutId = layoutId;
}
public CalculatorActivityHelperImpl(int layoutId, boolean homeIcon) {
this.layoutId = layoutId; public CalculatorActivityHelperImpl(int layoutId, boolean homeIcon) {
this.homeIcon = homeIcon; this.layoutId = layoutId;
} this.homeIcon = homeIcon;
}
@Override
public void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState) { @Override
super.onCreate(activity); public void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState) {
super.onCreate(activity);
if ( activity instanceof CalculatorEventListener) {
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener)activity); if ( activity instanceof CalculatorEventListener) {
} CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener((CalculatorEventListener)activity);
}
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
this.theme = CalculatorPreferences.Gui.getTheme(preferences);
activity.setTheme(this.theme.getThemeId()); this.theme = CalculatorPreferences.Gui.getTheme(preferences);
activity.setTheme(this.theme.getThemeId());
activity.setContentView(layoutId);
activity.setContentView(layoutId);
final View root = activity.findViewById(R.id.main_layout);
if (root != null) { final View root = activity.findViewById(R.id.main_layout);
CalculatorButtons.processButtons(true, theme, root); if (root != null) {
} else { processButtons(activity, root);
Log.e(CalculatorActivityHelperImpl.class.getSimpleName(), "Root is null for " + activity.getClass().getName()); } else {
} Log.e(CalculatorActivityHelperImpl.class.getSimpleName(), "Root is null for " + activity.getClass().getName());
}
if (savedInstanceState != null) {
navPosition = savedInstanceState.getInt(SELECTED_NAV, 0); if (savedInstanceState != null) {
} navPosition = savedInstanceState.getInt(SELECTED_NAV, 0);
} }
}
@Override
public void onCreate(@NotNull final SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState) { @Override
this.onCreate((Activity) activity, savedInstanceState); public void onCreate(@NotNull final SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState) {
this.onCreate((Activity) activity, savedInstanceState);
final ActionBar actionBar = activity.getSupportActionBar();
actionBar.setDisplayUseLogoEnabled(false); final ActionBar actionBar = activity.getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(homeIcon); actionBar.setDisplayUseLogoEnabled(false);
actionBar.setHomeButtonEnabled(false); actionBar.setDisplayHomeAsUpEnabled(homeIcon);
actionBar.setDisplayShowHomeEnabled(true); actionBar.setHomeButtonEnabled(false);
if (activity instanceof CalculatorActivity) { actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
} else { if (activity instanceof CalculatorActivity) {
actionBar.setDisplayShowTitleEnabled(true); if ( AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT ) {
} actionBar.setDisplayShowTitleEnabled(true);
actionBar.setIcon(R.drawable.icon_action_bar); } else {
} }
} else {
@Override actionBar.setDisplayShowTitleEnabled(true);
public void restoreSavedTab(@NotNull SherlockFragmentActivity activity) { }
final ActionBar actionBar = activity.getSupportActionBar(); actionBar.setIcon(R.drawable.icon_action_bar);
if (navPosition >= 0 && navPosition < actionBar.getTabCount()) { }
activity.getSupportActionBar().setSelectedNavigationItem(navPosition);
} @Override
} public void restoreSavedTab(@NotNull SherlockFragmentActivity activity) {
final ActionBar actionBar = activity.getSupportActionBar();
@Override if (navPosition >= 0 && navPosition < actionBar.getTabCount()) {
public void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState) { activity.getSupportActionBar().setSelectedNavigationItem(navPosition);
onSaveInstanceState((Activity) activity, outState); }
outState.putInt(SELECTED_NAV, activity.getSupportActionBar().getSelectedNavigationIndex()); }
}
@Override
@Override public void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState) {
public void onSaveInstanceState(@NotNull Activity activity, @NotNull Bundle outState) { onSaveInstanceState((Activity) activity, outState);
} outState.putInt(SELECTED_NAV, activity.getSupportActionBar().getSelectedNavigationIndex());
}
@Override
public void onResume(@NotNull Activity activity) { @Override
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); public void onSaveInstanceState(@NotNull Activity activity, @NotNull Bundle outState) {
}
final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences);
if (!theme.equals(newTheme)) { @Override
AndroidUtils.restartActivity(activity); public void onResume(@NotNull Activity activity) {
} final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
}
final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences);
@Override if (!theme.equals(newTheme)) {
public void onDestroy(@NotNull Activity activity) { AndroidUtils.restartActivity(activity);
super.onDestroy(activity); }
}
if ( activity instanceof CalculatorEventListener) {
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener)activity); @Override
} public void onDestroy(@NotNull Activity activity) {
} super.onDestroy(activity);
@Override if ( activity instanceof CalculatorEventListener) {
public void onDestroy(@NotNull SherlockFragmentActivity activity) { CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener)activity);
this.onDestroy((Activity)activity); }
} }
@Override @Override
public void addTab(@NotNull SherlockFragmentActivity activity, public void onDestroy(@NotNull SherlockFragmentActivity activity) {
@NotNull String tag, this.onDestroy((Activity)activity);
@NotNull Class<? extends Fragment> fragmentClass, }
@Nullable Bundle fragmentArgs,
int captionResId, @Override
int parentViewId) { public void addTab(@NotNull SherlockFragmentActivity activity,
activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); @NotNull String tag,
@NotNull Class<? extends Fragment> fragmentClass,
final ActionBar actionBar = activity.getSupportActionBar(); @Nullable Bundle fragmentArgs,
final ActionBar.Tab tab = actionBar.newTab(); int captionResId,
tab.setTag(tag); int parentViewId) {
tab.setText(captionResId); activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
final ActionBarFragmentTabListener listener = new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId); final ActionBar actionBar = activity.getSupportActionBar();
tab.setTabListener(listener); final ActionBar.Tab tab = actionBar.newTab();
actionBar.addTab(tab); tab.setTag(tag);
tab.setText(captionResId);
fragmentTags.add(tag);
final ActionBarFragmentTabListener listener = new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId);
restoreSavedTab(activity); tab.setTabListener(listener);
} actionBar.addTab(tab);
@Override fragmentTags.add(tag);
public int getLayoutId() {
return layoutId; restoreSavedTab(activity);
} }
@Override @Override
@NotNull public int getLayoutId() {
public CalculatorPreferences.Gui.Theme getTheme() { return layoutId;
return theme; }
}
@Override
@Override @NotNull
public void onResume(@NotNull SherlockFragmentActivity activity) { public CalculatorPreferences.Gui.Theme getTheme() {
onResume((Activity) activity); return theme;
} }
}
@Override
public void onResume(@NotNull SherlockFragmentActivity activity) {
onResume((Activity) activity);
}
}

View File

@ -1,244 +1,243 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.Display; import android.view.Display;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.Toast; import android.widget.Toast;
import jscl.AngleUnit; import jscl.AngleUnit;
import jscl.NumeralBase; import jscl.NumeralBase;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.AndroidUtils; import org.solovyev.android.AndroidUtils;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine; import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
import org.solovyev.android.calculator.view.AngleUnitsButton; import org.solovyev.android.calculator.view.AngleUnitsButton;
import org.solovyev.android.calculator.view.NumeralBasesButton; import org.solovyev.android.calculator.view.NumeralBasesButton;
import org.solovyev.android.view.ColorButton; import org.solovyev.android.view.ColorButton;
import org.solovyev.android.view.drag.DragButton; import org.solovyev.android.view.drag.DragButton;
import org.solovyev.android.view.drag.DragDirection; import org.solovyev.android.view.drag.DragDirection;
import org.solovyev.android.view.drag.SimpleOnDragListener; import org.solovyev.android.view.drag.SimpleOnDragListener;
import org.solovyev.common.math.Point2d; import org.solovyev.common.math.Point2d;
/** /**
* User: serso * User: serso
* Date: 9/28/12 * Date: 9/28/12
* Time: 12:06 AM * Time: 12:06 AM
*/ */
public final class CalculatorButtons { public final class CalculatorButtons {
private CalculatorButtons () { private CalculatorButtons () {
} }
public static void processButtons(boolean fixMagicFlames, public static void processButtons(boolean fixMagicFlames,
@NotNull CalculatorPreferences.Gui.Theme theme, @NotNull CalculatorPreferences.Gui.Theme theme,
@NotNull View root) { @NotNull View root) {
if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) { if (theme.getThemeType() == CalculatorPreferences.Gui.ThemeType.metro) {
if (fixMagicFlames) { if (fixMagicFlames) {
// for metro themes we should turn off magic flames // for metro themes we should turn off magic flames
AndroidUtils.processViewsOfType(root, ColorButton.class, new AndroidUtils.ViewProcessor<ColorButton>() { AndroidUtils.processViewsOfType(root, ColorButton.class, new AndroidUtils.ViewProcessor<ColorButton>() {
@Override @Override
public void process(@NotNull ColorButton colorButton) { public void process(@NotNull ColorButton colorButton) {
colorButton.setDrawMagicFlame(false); colorButton.setDrawMagicFlame(false);
} }
}); });
} }
} }
} }
static void initMultiplicationButton(@NotNull View root) { static void initMultiplicationButton(@NotNull View root) {
final View multiplicationButton = root.findViewById(R.id.multiplicationButton); final View multiplicationButton = root.findViewById(R.id.multiplicationButton);
if ( multiplicationButton instanceof Button) { if ( multiplicationButton instanceof Button) {
((Button) multiplicationButton).setText(CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign()); ((Button) multiplicationButton).setText(CalculatorLocatorImpl.getInstance().getEngine().getMultiplicationSign());
} }
} }
public static void toggleEqualsButton(@Nullable SharedPreferences preferences, public static void toggleEqualsButton(@Nullable SharedPreferences preferences,
@NotNull Activity activity, @NotNull Activity activity) {
@NotNull CalculatorPreferences.Gui.Theme theme, preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences;
@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();
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) {
final DragButton equalsButton = (DragButton)activity.findViewById(R.id.equalsButton); // todo serso: visibility should be changed only for some cases (like small screens)
if (equalsButton != null) { if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) {
if (CalculatorPreferences.Gui.showEqualsButton.getPreference(preferences)) { equalsButton.setVisibility(View.VISIBLE);
equalsButton.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 1f)); if (display.getWidth() <= 480) {
if (display.getWidth() <= 480) { // mobile phones
// mobile phones final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView(); if (calculatorDisplayView != null) {
if (calculatorDisplayView != null) { calculatorDisplayView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
calculatorDisplayView.setBackgroundDrawable(null); }
} }
} } else {
} else { equalsButton.setVisibility(View.GONE);
equalsButton.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT, 0f)); if (display.getWidth() <= 480) {
if (display.getWidth() <= 480) { // mobile phones
// mobile phones final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView();
final AndroidCalculatorDisplayView calculatorDisplayView = getCalculatorDisplayView(); if (calculatorDisplayView != null) {
if (calculatorDisplayView != null) { calculatorDisplayView.setCompoundDrawablesWithIntrinsicBounds(activity.getResources().getDrawable(R.drawable.equals9), null, null, null);
calculatorDisplayView.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.equals9)); }
} }
} }
} }
} }
} }
}
@Nullable
@Nullable private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
private static AndroidCalculatorDisplayView getCalculatorDisplayView() { return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView(); }
}
/*
/* **********************************************************************
********************************************************************** *
* * STATIC CLASSES
* STATIC CLASSES *
* **********************************************************************
********************************************************************** */
*/
static class RoundBracketsDragProcessor implements SimpleOnDragListener.DragProcessor {
static class RoundBracketsDragProcessor implements SimpleOnDragListener.DragProcessor { @Override
@Override public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) { final boolean result;
final boolean result;
if (dragDirection == DragDirection.left) {
if (dragDirection == DragDirection.left) { getKeyboard().roundBracketsButtonPressed();
getKeyboard().roundBracketsButtonPressed(); result = true;
result = true; } else {
} else { result = new DigitButtonDragProcessor(getKeyboard()).processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
result = new DigitButtonDragProcessor(getKeyboard()).processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent); }
}
return result;
return result; }
} }
}
@NotNull
@NotNull private static CalculatorKeyboard getKeyboard() {
private static CalculatorKeyboard getKeyboard() { return CalculatorLocatorImpl.getInstance().getKeyboard();
return CalculatorLocatorImpl.getInstance().getKeyboard(); }
}
static class VarsDragProcessor implements SimpleOnDragListener.DragProcessor {
static class VarsDragProcessor implements SimpleOnDragListener.DragProcessor {
@NotNull
@NotNull private Context context;
private Context context;
VarsDragProcessor(Context context) {
VarsDragProcessor(Context context) { this.context = context;
this.context = context; }
}
@Override
@Override public boolean processDragEvent(@NotNull DragDirection dragDirection,
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton,
@NotNull DragButton dragButton, @NotNull Point2d startPoint2d,
@NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
@NotNull MotionEvent motionEvent) { boolean result = false;
boolean result = false;
if (dragDirection == DragDirection.up) {
if (dragDirection == DragDirection.up) { CalculatorActivityLauncher.createVar(context, CalculatorLocatorImpl.getInstance().getDisplay());
CalculatorActivityLauncher.createVar(context, CalculatorLocatorImpl.getInstance().getDisplay()); result = true;
result = true; }
}
return result;
return result; }
} }
}
static class AngleUnitsChanger implements SimpleOnDragListener.DragProcessor {
static class AngleUnitsChanger implements SimpleOnDragListener.DragProcessor {
@NotNull
@NotNull private final DigitButtonDragProcessor processor;
private final DigitButtonDragProcessor processor;
@NotNull
@NotNull private final Context context;
private final Context context;
AngleUnitsChanger(@NotNull Context context) {
AngleUnitsChanger(@NotNull Context context) { this.context = context;
this.context = context; this.processor = new DigitButtonDragProcessor(CalculatorLocatorImpl.getInstance().getKeyboard());
this.processor = new DigitButtonDragProcessor(CalculatorLocatorImpl.getInstance().getKeyboard()); }
}
@Override
@Override public boolean processDragEvent(@NotNull DragDirection dragDirection,
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton,
@NotNull DragButton dragButton, @NotNull Point2d startPoint2d,
@NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
@NotNull MotionEvent motionEvent) { boolean result = false;
boolean result = false;
if (dragButton instanceof AngleUnitsButton) {
if (dragButton instanceof AngleUnitsButton) { if (dragDirection != DragDirection.left) {
if (dragDirection != DragDirection.left) { final String directionText = ((AngleUnitsButton) dragButton).getText(dragDirection);
final String directionText = ((AngleUnitsButton) dragButton).getText(dragDirection); if (directionText != null) {
if (directionText != null) { try {
try {
final AngleUnit angleUnits = AngleUnit.valueOf(directionText);
final AngleUnit angleUnits = AngleUnit.valueOf(directionText);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnits);
AndroidCalculatorEngine.Preferences.angleUnit.putPreference(preferences, angleUnits);
Toast.makeText(context, context.getString(R.string.c_angle_units_changed_to, angleUnits.name()), Toast.LENGTH_LONG).show();
Toast.makeText(context, context.getString(R.string.c_angle_units_changed_to, angleUnits.name()), Toast.LENGTH_LONG).show();
result = true;
result = true; } catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) { Log.d(this.getClass().getName(), "Unsupported angle units: " + directionText);
Log.d(this.getClass().getName(), "Unsupported angle units: " + directionText); }
} }
} } else if (dragDirection == DragDirection.left) {
} else if (dragDirection == DragDirection.left) { result = processor.processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
result = processor.processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent); }
} }
}
return result;
return result; }
} }
}
static class NumeralBasesChanger implements SimpleOnDragListener.DragProcessor {
static class NumeralBasesChanger implements SimpleOnDragListener.DragProcessor {
@NotNull
@NotNull private final Context context;
private final Context context;
NumeralBasesChanger(@NotNull Context context) {
NumeralBasesChanger(@NotNull Context context) { this.context = context;
this.context = context; }
}
@Override
@Override public boolean processDragEvent(@NotNull DragDirection dragDirection,
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton,
@NotNull DragButton dragButton, @NotNull Point2d startPoint2d,
@NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
@NotNull MotionEvent motionEvent) { boolean result = false;
boolean result = false;
if (dragButton instanceof NumeralBasesButton) {
if (dragButton instanceof NumeralBasesButton) { final String directionText = ((NumeralBasesButton) dragButton).getText(dragDirection);
final String directionText = ((NumeralBasesButton) dragButton).getText(dragDirection); if (directionText != null) {
if (directionText != null) { try {
try {
final NumeralBase numeralBase = NumeralBase.valueOf(directionText);
final NumeralBase numeralBase = NumeralBase.valueOf(directionText);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); AndroidCalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase);
AndroidCalculatorEngine.Preferences.numeralBase.putPreference(preferences, numeralBase);
Toast.makeText(context, context.getString(R.string.c_numeral_base_changed_to, numeralBase.name()), Toast.LENGTH_LONG).show();
Toast.makeText(context, context.getString(R.string.c_numeral_base_changed_to, numeralBase.name()), Toast.LENGTH_LONG).show();
result = true;
result = true; } catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) { Log.d(this.getClass().getName(), "Unsupported numeral base: " + directionText);
Log.d(this.getClass().getName(), "Unsupported numeral base: " + directionText); }
} }
} }
}
return result;
return result; }
} }
} }
}

View File

@ -1,134 +1,134 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.app.SherlockFragment;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine; import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
/** /**
* User: Solovyev_S * User: Solovyev_S
* Date: 25.09.12 * Date: 25.09.12
* Time: 12:25 * Time: 12:25
*/ */
public class CalculatorKeyboardFragment extends SherlockFragment implements SharedPreferences.OnSharedPreferenceChangeListener { public class CalculatorKeyboardFragment extends SherlockFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
@NotNull @NotNull
private NumeralBaseButtons numeralBaseButtons = new NumeralBaseButtons(); private NumeralBaseButtons numeralBaseButtons = new NumeralBaseButtons();
@NotNull @NotNull
private CalculatorPreferences.Gui.Theme theme; private CalculatorPreferences.Gui.Theme theme;
@NotNull @NotNull
private CalculatorFragmentHelper fragmentHelper; private CalculatorFragmentHelper fragmentHelper;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity()); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.calc_keyboard); fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.calc_keyboard);
fragmentHelper.onCreate(this); fragmentHelper.onCreate(this);
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences); theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences);
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return fragmentHelper.onCreateView(this, inflater, container); return fragmentHelper.onCreateView(this, inflater, container);
} }
@Override @Override
public void onViewCreated(View root, Bundle savedInstanceState) { public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState); super.onViewCreated(root, savedInstanceState);
fragmentHelper.onViewCreated(this, root); fragmentHelper.onViewCreated(this, root);
} }
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
this.fragmentHelper.onResume(this); this.fragmentHelper.onResume(this);
} }
@Override @Override
public void onPause() { public void onPause() {
this.fragmentHelper.onPause(this); this.fragmentHelper.onPause(this);
super.onPause(); super.onPause();
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
fragmentHelper.onDestroy(this); fragmentHelper.onDestroy(this);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity()); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
preferences.unregisterOnSharedPreferenceChangeListener(this); preferences.unregisterOnSharedPreferenceChangeListener(this);
} }
/* private static void setMarginsForView(@Nullable View view, int marginLeft, int marginBottom, @NotNull Context context) { /* private static void setMarginsForView(@Nullable View view, int marginLeft, int marginBottom, @NotNull Context context) {
// IMPORTANT: this is workaround for probably android bug // 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 // currently margin values set in styles are not applied for some reasons to the views (using include tag) => set them manually
if (view != null) { if (view != null) {
final DisplayMetrics dm = context.getResources().getDisplayMetrics(); final DisplayMetrics dm = context.getResources().getDisplayMetrics();
if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) { if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
final LinearLayout.LayoutParams oldParams = (LinearLayout.LayoutParams) view.getLayoutParams(); final LinearLayout.LayoutParams oldParams = (LinearLayout.LayoutParams) view.getLayoutParams();
final LinearLayout.LayoutParams newParams = new LinearLayout.LayoutParams(oldParams.width, oldParams.height, oldParams.weight); 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)); newParams.setMargins(AndroidUtils.toPixels(dm, marginLeft), 0, 0, AndroidUtils.toPixels(dm, marginBottom));
view.setLayoutParams(newParams); view.setLayoutParams(newParams);
} }
} }
}*/ }*/
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
} }
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key)) { if (AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key)) {
numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences); numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
} }
if ( CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key) ) { if ( CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key) ) {
CalculatorButtons.toggleEqualsButton(preferences, this.getActivity(), theme, getView()); CalculatorButtons.toggleEqualsButton(preferences, this.getActivity());
} }
if ( AndroidCalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) { if ( AndroidCalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) {
CalculatorButtons.initMultiplicationButton(getView()); CalculatorButtons.initMultiplicationButton(getView());
} }
} }
@Nullable @Nullable
private static AndroidCalculatorDisplayView getCalculatorDisplayView() { private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView(); return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
} }
@NotNull @NotNull
private Calculator getCalculator() { private Calculator getCalculator() {
return CalculatorLocatorImpl.getInstance().getCalculator(); return CalculatorLocatorImpl.getInstance().getCalculator();
} }
@NotNull @NotNull
private static CalculatorKeyboard getKeyboard() { private static CalculatorKeyboard getKeyboard() {
return CalculatorLocatorImpl.getInstance().getKeyboard(); return CalculatorLocatorImpl.getInstance().getKeyboard();
} }
} }