This commit is contained in:
serso 2012-09-28 14:44:49 +04:00
parent c8440e18a5
commit abebb25e53
37 changed files with 2421 additions and 2317 deletions

View File

@ -15,6 +15,6 @@
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/second_pane_background"/>
<solid android:color="@color/pane_background"/>
<corners android:radius="1dp" />
</shape>

View File

@ -7,12 +7,9 @@
-->
<LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:id="@+id/main_layout"
a:orientation="vertical"
a:layout_gravity="center"
a:background="@color/default_background">
style="?mainLayoutStyle">
<include layout="@layout/main_first_pane"/>

View File

@ -7,12 +7,9 @@
-->
<LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:id="@+id/main_layout"
a:orientation="vertical"
a:background="@color/default_background"
a:baselineAligned="false">
style="?mainMultiPaneLayoutStyle">
<LinearLayout
a:layout_height="0dp"
@ -47,7 +44,7 @@
a:layout_width="0dp"
a:layout_weight="1"
a:orientation="vertical"
style="?secondPaneStyle"/>
style="?paneStyle"/>
</LinearLayout>
@ -55,6 +52,6 @@
a:layout_height="0dp"
a:layout_width="match_parent"
a:layout_weight="1"
style="?fragmentLayoutStyle"/>
style="?paneStyleTransparent"/>
</LinearLayout>

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical"
a:id="@+id/ad_parent_view"
style="?fragmentLayoutStyle"
a:layout_width="match_parent"
a:layout_height="match_parent">
<TextView a:id="@+id/fragmentTitle"
a:layout_height="wrap_content"
a:layout_width="match_parent"
style="?fragmentTitleStyle"/>
<ListView style="?fragmentListViewStyle"/>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical"
a:id="@+id/main_fragment_layout"
style="?fragmentLayoutStyle"
a:layout_width="match_parent"
a:layout_height="match_parent">
<TextView a:id="@+id/fragmentTitle"
a:layout_height="wrap_content"
a:layout_width="match_parent"
style="?fragmentTitleStyle"/>
<ListView style="?fragmentListViewStyle"/>
</LinearLayout>

View File

@ -12,8 +12,7 @@
a:layout_height="match_parent"
a:id="@+id/main_layout"
a:orientation="vertical"
a:layout_gravity="center"
a:background="@color/default_background">
style="?mainLayoutStyle">
<LinearLayout a:id="@+id/editorContainer"
a:layout_weight="2"

View File

@ -8,8 +8,7 @@
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/main_layout"
a:orientation="vertical"
a:layout_width="fill_parent"
a:layout_height="fill_parent">
style="?mainLayoutStyle"
a:orientation="vertical">
</LinearLayout>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/main_layout"
style="?mainMultiPaneLayoutStyle"
a:orientation="vertical">
</LinearLayout>

View File

@ -2,7 +2,7 @@
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical"
a:id="@+id/ad_parent_view"
a:id="@+id/main_fragment_layout"
style="?fragmentLayoutStyle"
a:layout_width="match_parent"
a:layout_height="match_parent">

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical"
a:id="@+id/main_fragment_layout"
style="?fragmentLayoutStyle"
a:layout_width="match_parent"
a:layout_height="match_parent">
<TextView a:id="@+id/fragmentTitle"
a:layout_height="wrap_content"
a:layout_width="match_parent"
style="?fragmentTitleStyle"/>
<ListView style="?fragmentListViewStyle"/>
</LinearLayout>

View File

@ -1,32 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical"
a:id="@+id/ad_parent_view"
style="?fragmentLayoutStyle"
a:layout_width="match_parent"
a:layout_height="match_parent">
<TextView a:id="@+id/fragmentTitle"
a:layout_height="wrap_content"
a:layout_width="match_parent"
style="?fragmentTitleStyle"/>
<ListView style="?fragmentListViewStyle"/>
<!-- todo serso: uncomment button-->
<!-- <Button
a:layout_width="wrap_content"
a:layout_height="wrap_content"
a:layout_gravity="center_horizontal"
a:text="@string/c_add"
style="?buttonStyle"
a:onClick="addVarButtonClickHandler"/>-->
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical"
a:id="@+id/main_fragment_layout"
style="?fragmentLayoutStyle"
a:layout_width="match_parent"
a:layout_height="match_parent">
<TextView a:id="@+id/fragmentTitle"
a:layout_height="wrap_content"
a:layout_width="match_parent"
style="?fragmentTitleStyle"/>
<ListView style="?fragmentListViewStyle"/>
<!--todo serso: uncomment-->
<!--<Button
a:id="@+id/add_var_button"
a:text="@string/c_add"
style="?buttonStyle"
a:onClick="addVarButtonClickHandler"
a:layout_marginBottom="@dimen/pane_padding"/>-->
</LinearLayout>

View File

@ -1,13 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<menu xmlns:a="http://schemas.android.com/apk/res/android">
<item a:id="@+id/var_menu_add_var"
a:title="@string/c_add"/>
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<menu xmlns:a="http://schemas.android.com/apk/res/android">
<item a:id="@+id/var_menu_add_var"
a:title="@string/c_add"
a:showAsAction="always"/>
</menu>

View File

@ -1,3 +1,3 @@
<resources>
<dimen name="button_text_size">20dp</dimen>
<resources>
<dimen name="keyboard_button_text_size">20dp</dimen>
</resources>

View File

@ -1,3 +1,3 @@
<resources>
<dimen name="button_text_size">40dp</dimen>
<resources>
<dimen name="keyboard_button_text_size">40dp</dimen>
</resources>

View File

@ -6,10 +6,12 @@
<attr name="controlImageButtonStyle" format="reference" />
<attr name="operationButtonStyle" format="reference" />
<attr name="fragmentLayoutStyle" format="reference" />
<attr name="secondPaneStyle" format="reference" />
<attr name="fragmentTitleStyle" format="reference" />
<attr name="fragmentListViewStyle" format="reference" />
<attr name="buttonStyle" format="reference" />
<attr name="paneStyle" format="reference" />
<attr name="paneStyleTransparent" format="reference" />
<attr name="mainLayoutStyle" format="reference" />
<attr name="mainMultiPaneLayoutStyle" format="reference" />
</resources>

View File

@ -1,18 +1,18 @@
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<resources>
<color name="magic_flame">#00ffffff</color>
<color name="button_text_color">#ffffffff</color>
<color name="button_operator_text_color">#ffffff99</color>
<color name="button_ce_text_color">#ffffffff</color>
<color name="default_text_color">#ffffffff</color>
<color name="display_error_text_color">#ff393939</color>
<color name="selected_angle_unit_text_color">#ffffff99</color>
<color name="default_background">#ff000000</color>
<color name="second_pane_background">#ff1f1f1f</color>
<color name="metro_button_background">#ff1f1f1f</color>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<resources>
<color name="magic_flame">#00ffffff</color>
<color name="button_text_color">#ffffffff</color>
<color name="button_operator_text_color">#ffffff99</color>
<color name="button_ce_text_color">#ffffffff</color>
<color name="default_text_color">#ffffffff</color>
<color name="display_error_text_color">#ff393939</color>
<color name="selected_angle_unit_text_color">#ffffff99</color>
<color name="default_background">#ff000000</color>
<color name="pane_background">#ff1f1f1f</color>
<color name="metro_button_background">#ff1f1f1f</color>
</resources>

View File

@ -1,7 +1,10 @@
<resources>
<dimen name="button_margin">0.5dp</dimen>
<dimen name="text_size">20sp</dimen>
<dimen name="button_text_size">30dp</dimen>
<dimen name="display_text_size">25sp</dimen>
<dimen name="editor_text_size">25sp</dimen>
<resources>
<dimen name="button_margin">0.5dp</dimen>
<dimen name="text_size">20sp</dimen>
<dimen name="keyboard_button_text_size">30dp</dimen>
<dimen name="button_text_size">20dp</dimen>
<dimen name="display_text_size">25sp</dimen>
<dimen name="editor_text_size">25sp</dimen>
<dimen name="pane_margin">5dp</dimen>
<dimen name="pane_padding">5dp</dimen>
</resources>

View File

@ -1,30 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<resources>
<style name="math_entity_text" parent="math_entity_text_parent">
<item name="android:paddingTop">6dp</item>
<item name="android:paddingLeft">6dp</item>
<item name="android:paddingRight">6dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@android:color/white</item>
</style>
<style name="math_entity_description" parent="math_entity_description_parent">
<item name="android:paddingTop">0dp</item>
<item name="android:paddingLeft">6dp</item>
<item name="android:paddingRight">6dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:textColor">#bebebe</item>
</style>
<style name="add_var_button" parent="add_var_button_parent">
</style>
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<resources>
<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:textColor">@android:color/white</item>
</style>
<style name="math_entity_description" parent="math_entity_description_parent">
<item name="android:padding">0dp</item>
<item name="android:textColor">#bebebe</item>
</style>
<style name="add_var_button" parent="add_var_button_parent">
</style>
</resources>

View File

@ -8,13 +8,20 @@
<resources>
<style name="button_style" parent="button_style_parent">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:focusable">true</item>
<item name="android:background">@drawable/default_button_dark</item>
<item name="android:layout_margin">@dimen/button_margin</item>
</style>
<item name="android:background">@drawable/metro_button_blue</item>
</style>
<style name="keyboard_button_style" parent="keyboard_button_style_parent">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:focusable">true</item>
<item name="android:background">@drawable/default_button_dark</item>
<item name="android:layout_margin">@dimen/button_margin</item>
</style>
<style name="editor_style" parent="editor_style_parent">
<item name="android:gravity">left|top</item>

View File

@ -6,62 +6,91 @@
-->
<resources>
<style name="default_digit_button_style" parent="button_style">
<item name="android:background">@drawable/default_button</item>
</style>
<style name="default_digit_button_style" parent="keyboard_button_style">
<item name="android:background">@drawable/default_button</item>
</style>
<style name="default_control_button_style" parent="button_style"/>
<style name="default_control_button_style" parent="keyboard_button_style"/>
<style name="default_operation_button_style" parent="default_digit_button_style">
<item name="android:textColor">@color/button_operator_text_color</item>
</style>
<style name="default_operation_button_style" parent="default_digit_button_style">
<item name="android:textColor">@color/button_operator_text_color</item>
</style>
<style name="default_control_image_button_style" parent="default_control_button_style">
<item name="android:padding">6dp</item>
</style>
<style name="default_pane_style" parent="default_fragment_layout_style">
<item name="android:background">@drawable/second_pane_background</item>
<item name="android:padding">5dp</item>
<style name="default_control_image_button_style" parent="default_control_button_style">
<item name="android:padding">6dp</item>
</style>
<style name="default_fragment_list_view_style">
<item name="android:id">@android:id/list</item>
<item name="android:divider">@null</item>
<item name="android:dividerHeight">0dp</item>
<item name="android:cacheColorHint">@android:color/transparent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:id">@android:id/list</item>
<item name="android:divider">@null</item>
<item name="android:dividerHeight">0dp</item>
<item name="android:cacheColorHint">@android:color/transparent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:fadingEdge">none</item>
<item name="android:layout_marginBottom">@dimen/pane_padding</item>
</style>
<style name="default_fragment_title_style">
<item name="android:textColor">@android:color/white</item>
<item name="android:textSize">25sp</item>
<item name="android:layout_marginLeft">6dp</item>
</style>
<style name="default_button_style" parent="button_style">
<item name="android:background">@drawable/metro_button_blue</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">10dp</item>
</style>
<style name="default_pane_style_transparent" parent="default_pane_style">
<item name="android:background">@android:color/transparent</item>
<item name="android:padding">0dp</item>
</style>
<style name="default_pane_style">
<item name="android:layout_marginLeft">@dimen/pane_margin</item>
<item name="android:layout_marginTop">@dimen/pane_margin</item>
<item name="android:padding">@dimen/pane_padding</item>
<item name="android:background">@drawable/pane_background</item>
</style>
<style name="default_main_multi_pane_layout_style" parent="default_main_layout_style">
<item name="android:paddingRight">@dimen/pane_padding</item>
<item name="android:paddingBottom">@dimen/pane_padding</item>
</style>
<style name="default_fragment_multi_pane_layout_style" parent="default_fragment_layout_style">
</style>
<style name="default_fragment_layout_style">
<item name="android:layout_marginBottom">0dp</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginLeft">5dp</item>
<item name="android:layout_marginRight">0dp</item>
<item name="android:layout_margin">0dp</item>
<item name="android:padding">0dp</item>
</style>
<style name="default_theme" parent="Theme.Sherlock">
<item name="digitButtonStyle">@style/default_digit_button_style</item>
<item name="controlButtonStyle">@style/default_control_button_style</item>
<item name="controlImageButtonStyle">@style/default_control_image_button_style</item>
<item name="operationButtonStyle">@style/default_operation_button_style</item>
<item name="fragmentLayoutStyle">@style/default_fragment_layout_style</item>
<item name="paneStyle">@style/default_pane_style</item>
<item name="secondPaneStyle">@style/default_pane_style</item>
<item name="fragmentTitleStyle">@style/default_fragment_title_style</item>
<item name="fragmentListViewStyle">@style/default_fragment_list_view_style</item>
<item name="buttonStyle">@style/default_button_style</item>
</style>
<style name="default_main_layout_style">
<item name="android:background">@color/default_background</item>
<item name="android:baselineAligned">false</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_width">match_parent</item>
</style>
<style name="default_theme" parent="Theme.Sherlock">
<item name="digitButtonStyle">@style/default_digit_button_style</item>
<item name="controlButtonStyle">@style/default_control_button_style</item>
<item name="controlImageButtonStyle">@style/default_control_image_button_style</item>
<item name="operationButtonStyle">@style/default_operation_button_style</item>
<item name="fragmentTitleStyle">@style/default_fragment_title_style</item>
<item name="fragmentListViewStyle">@style/default_fragment_list_view_style</item>
<item name="buttonStyle">@style/default_button_style</item>
<item name="mainLayoutStyle">@style/default_main_layout_style</item>
<item name="mainMultiPaneLayoutStyle">@style/default_main_multi_pane_layout_style</item>
<item name="fragmentLayoutStyle">@style/default_fragment_layout_style</item>
<item name="paneStyle">@style/default_pane_style</item>
<item name="paneStyleTransparent">@style/default_pane_style_transparent</item>
</style>
</resources>

View File

@ -1,33 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<resources>
<style name="light_blue_digit_button_style" parent="button_style">
<item name="android:background">@drawable/blue_button</item>
</style>
<style name="light_blue_control_button_style" parent="button_style">
<item name="android:background">@drawable/blue_button_dark</item>
</style>
<style name="light_blue_operation_button_style" parent="light_blue_digit_button_style">
<item name="android:textColor">@color/button_operator_text_color</item>
</style>
<style name="light_blue_control_image_button_style" parent="light_blue_control_button_style">
<item name="android:padding">6dp</item>
</style>
<style name="light_blue_theme" parent="default_theme">
<item name="digitButtonStyle">@style/light_blue_digit_button_style</item>
<item name="controlButtonStyle">@style/light_blue_control_button_style</item>
<item name="controlImageButtonStyle">@style/light_blue_control_image_button_style</item>
<item name="operationButtonStyle">@style/light_blue_operation_button_style</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<resources>
<style name="light_blue_digit_button_style" parent="keyboard_button_style">
<item name="android:background">@drawable/blue_button</item>
</style>
<style name="light_blue_control_button_style" parent="keyboard_button_style">
<item name="android:background">@drawable/blue_button_dark</item>
</style>
<style name="light_blue_operation_button_style" parent="light_blue_digit_button_style">
<item name="android:textColor">@color/button_operator_text_color</item>
</style>
<style name="light_blue_control_image_button_style" parent="light_blue_control_button_style">
<item name="android:padding">6dp</item>
</style>
<style name="light_blue_theme" parent="default_theme">
<item name="digitButtonStyle">@style/light_blue_digit_button_style</item>
<item name="controlButtonStyle">@style/light_blue_control_button_style</item>
<item name="controlImageButtonStyle">@style/light_blue_control_image_button_style</item>
<item name="operationButtonStyle">@style/light_blue_operation_button_style</item>
</style>
</resources>

View File

@ -1,26 +1,26 @@
<resources>
<style name="metro_digit_button_style" parent="button_style">
<item name="android:background">@drawable/metro_button_dark</item>
</style>
<style name="metro_control_button_style" parent="metro_digit_button_style">
<item name="android:background">@drawable/metro_button_light</item>
</style>
<style name="metro_blue_operation_button_style" parent="metro_digit_button_style">
<item name="android:background">@drawable/metro_button_blue</item>
</style>
<style name="metro_control_image_button_style" parent="metro_control_button_style">
<item name="android:padding">6dp</item>
</style>
<style name="metro_blue_theme" parent="default_theme">
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
<item name="controlButtonStyle">@style/metro_control_button_style</item>
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
<item name="operationButtonStyle">@style/metro_blue_operation_button_style</item>
</style>
<resources>
<style name="metro_digit_button_style" parent="keyboard_button_style">
<item name="android:background">@drawable/metro_button_dark</item>
</style>
<style name="metro_control_button_style" parent="metro_digit_button_style">
<item name="android:background">@drawable/metro_button_light</item>
</style>
<style name="metro_blue_operation_button_style" parent="metro_digit_button_style">
<item name="android:background">@drawable/metro_button_blue</item>
</style>
<style name="metro_control_image_button_style" parent="metro_control_button_style">
<item name="android:padding">6dp</item>
</style>
<style name="metro_blue_theme" parent="default_theme">
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
<item name="controlButtonStyle">@style/metro_control_button_style</item>
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
<item name="operationButtonStyle">@style/metro_blue_operation_button_style</item>
</style>
</resources>

View File

@ -1,26 +1,26 @@
<resources>
<style name="metro_digit_button_style" parent="button_style">
<item name="android:background">@drawable/metro_button_dark</item>
</style>
<style name="metro_control_button_style" parent="metro_digit_button_style">
<item name="android:background">@drawable/metro_button_light</item>
</style>
<style name="metro_green_operation_button_style" parent="metro_digit_button_style">
<item name="android:background">@drawable/metro_button_green</item>
</style>
<style name="metro_control_image_button_style" parent="metro_control_button_style">
<item name="android:padding">6dp</item>
</style>
<style name="metro_green_theme" parent="default_theme">
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
<item name="controlButtonStyle">@style/metro_control_button_style</item>
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
<item name="operationButtonStyle">@style/metro_green_operation_button_style</item>
</style>
<resources>
<style name="metro_digit_button_style" parent="keyboard_button_style">
<item name="android:background">@drawable/metro_button_dark</item>
</style>
<style name="metro_control_button_style" parent="metro_digit_button_style">
<item name="android:background">@drawable/metro_button_light</item>
</style>
<style name="metro_green_operation_button_style" parent="metro_digit_button_style">
<item name="android:background">@drawable/metro_button_green</item>
</style>
<style name="metro_control_image_button_style" parent="metro_control_button_style">
<item name="android:padding">6dp</item>
</style>
<style name="metro_green_theme" parent="default_theme">
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
<item name="controlButtonStyle">@style/metro_control_button_style</item>
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
<item name="operationButtonStyle">@style/metro_green_operation_button_style</item>
</style>
</resources>

View File

@ -1,26 +1,26 @@
<resources>
<style name="metro_digit_button_style" parent="button_style">
<item name="android:background">@drawable/metro_button_dark</item>
</style>
<style name="metro_control_button_style" parent="metro_digit_button_style">
<item name="android:background">@drawable/metro_button_light</item>
</style>
<style name="metro_purple_operation_button_style" parent="metro_digit_button_style">
<item name="android:background">@drawable/metro_button_purple</item>
</style>
<style name="metro_control_image_button_style" parent="metro_control_button_style">
<item name="android:padding">6dp</item>
</style>
<style name="metro_purple_theme" parent="default_theme">
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
<item name="controlButtonStyle">@style/metro_control_button_style</item>
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
<item name="operationButtonStyle">@style/metro_purple_operation_button_style</item>
</style>
<resources>
<style name="metro_digit_button_style" parent="keyboard_button_style">
<item name="android:background">@drawable/metro_button_dark</item>
</style>
<style name="metro_control_button_style" parent="metro_digit_button_style">
<item name="android:background">@drawable/metro_button_light</item>
</style>
<style name="metro_purple_operation_button_style" parent="metro_digit_button_style">
<item name="android:background">@drawable/metro_button_purple</item>
</style>
<style name="metro_control_image_button_style" parent="metro_control_button_style">
<item name="android:padding">6dp</item>
</style>
<style name="metro_purple_theme" parent="default_theme">
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
<item name="controlButtonStyle">@style/metro_control_button_style</item>
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
<item name="operationButtonStyle">@style/metro_purple_operation_button_style</item>
</style>
</resources>

View File

@ -1,31 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<resources>
<style name="violet_digit_button_style" parent="button_style">
<item name="android:background">@drawable/violet_button</item>
</style>
<style name="violet_operation_button_style" parent="violet_digit_button_style">
<item name="android:textColor">@color/button_operator_text_color</item>
</style>
<style name="violet_control_button_style" parent="button_style">
<item name="android:background">@drawable/violet_button_dark</item>
</style>
<style name="violet_control_image_button_style" parent="violet_control_button_style">
<item name="android:padding">6dp</item>
</style>
<style name="violet_theme" parent="default_theme">
<item name="digitButtonStyle">@style/violet_digit_button_style</item>
<item name="controlButtonStyle">@style/violet_control_button_style</item>
<item name="controlImageButtonStyle">@style/violet_control_image_button_style</item>
<item name="operationButtonStyle">@style/violet_operation_button_style</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<resources>
<style name="violet_digit_button_style" parent="keyboard_button_style">
<item name="android:background">@drawable/violet_button</item>
</style>
<style name="violet_operation_button_style" parent="violet_digit_button_style">
<item name="android:textColor">@color/button_operator_text_color</item>
</style>
<style name="violet_control_button_style" parent="keyboard_button_style">
<item name="android:background">@drawable/violet_button_dark</item>
</style>
<style name="violet_control_image_button_style" parent="violet_control_button_style">
<item name="android:padding">6dp</item>
</style>
<style name="violet_theme" parent="default_theme">
<item name="digitButtonStyle">@style/violet_digit_button_style</item>
<item name="controlButtonStyle">@style/violet_control_button_style</item>
<item name="controlImageButtonStyle">@style/violet_control_image_button_style</item>
<item name="operationButtonStyle">@style/violet_operation_button_style</item>
</style>
</resources>

View File

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

View File

@ -17,6 +17,7 @@ import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.text.TextProcessor;
import org.solovyev.android.calculator.view.TextHighlighter;
import org.solovyev.android.view.AutoResizeTextView;
import org.solovyev.common.text.StringUtils;
/**
* User: serso

View File

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

View File

@ -1,158 +1,160 @@
package org.solovyev.android.calculator;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.AndroidUtils;
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
import java.util.ArrayList;
import java.util.List;
/**
* User: serso
* Date: 9/25/12
* Time: 10:32 PM
*/
public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper implements CalculatorActivityHelper {
/*
**********************************************************************
*
* CONSTANTS
*
**********************************************************************
*/
private static final String SELECTED_NAV = "selected_nav";
/*
**********************************************************************
*
* FIELDS
*
**********************************************************************
*/
private int layoutId;
private boolean homeIcon = false;
@NotNull
private final List<String> fragmentTags = new ArrayList<String>();
@NotNull
private CalculatorPreferences.Gui.Theme theme;
private int navPosition = 0;
public CalculatorActivityHelperImpl(int layoutId, @NotNull String logTag) {
super(logTag);
this.layoutId = layoutId;
}
public CalculatorActivityHelperImpl(int layoutId, boolean homeIcon) {
this.layoutId = layoutId;
this.homeIcon = homeIcon;
}
@Override
public void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState) {
super.onCreate(activity);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
this.theme = CalculatorPreferences.Gui.getTheme(preferences);
activity.setTheme(this.theme.getThemeId());
activity.setContentView(layoutId);
}
@Override
public void onCreate(@NotNull final SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState) {
this.onCreate((Activity) activity, savedInstanceState);
final ActionBar actionBar = activity.getSupportActionBar();
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(homeIcon);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
if (savedInstanceState != null) {
navPosition = savedInstanceState.getInt(SELECTED_NAV, 0);
}
}
@Override
public void restoreSavedTab(@NotNull SherlockFragmentActivity activity) {
final ActionBar actionBar = activity.getSupportActionBar();
if (navPosition >= 0 && navPosition < actionBar.getTabCount()) {
activity.getSupportActionBar().setSelectedNavigationItem(navPosition);
}
}
@Override
public void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState) {
onSaveInstanceState((Activity) activity, outState);
outState.putInt(SELECTED_NAV, activity.getSupportActionBar().getSelectedNavigationIndex());
}
@Override
public void onSaveInstanceState(@NotNull Activity activity, @NotNull Bundle outState) {
}
@Override
public void onResume(@NotNull Activity activity) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences);
if (!theme.equals(newTheme)) {
AndroidUtils.restartActivity(activity);
}
}
@Override
public void onDestroy(@NotNull SherlockFragmentActivity activity) {
super.onDestroy(activity);
}
@Override
public void addTab(@NotNull SherlockFragmentActivity activity,
@NotNull String tag,
@NotNull Class<? extends Fragment> fragmentClass,
@Nullable Bundle fragmentArgs,
int captionResId,
int parentViewId) {
activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
final ActionBar actionBar = activity.getSupportActionBar();
final ActionBar.Tab tab = actionBar.newTab();
tab.setTag(tag);
tab.setText(captionResId);
tab.setTabListener(new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId));
actionBar.addTab(tab);
fragmentTags.add(tag);
}
@Override
public int getLayoutId() {
return layoutId;
}
@Override
@NotNull
public CalculatorPreferences.Gui.Theme getTheme() {
return theme;
}
@Override
public void onResume(@NotNull SherlockFragmentActivity activity) {
onResume((Activity) activity);
}
}
package org.solovyev.android.calculator;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.AndroidUtils;
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
import java.util.ArrayList;
import java.util.List;
/**
* User: serso
* Date: 9/25/12
* Time: 10:32 PM
*/
public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper implements CalculatorActivityHelper {
/*
**********************************************************************
*
* CONSTANTS
*
**********************************************************************
*/
private static final String SELECTED_NAV = "selected_nav";
/*
**********************************************************************
*
* FIELDS
*
**********************************************************************
*/
private int layoutId;
private boolean homeIcon = false;
@NotNull
private final List<String> fragmentTags = new ArrayList<String>();
@NotNull
private CalculatorPreferences.Gui.Theme theme;
private int navPosition = 0;
public CalculatorActivityHelperImpl(int layoutId, @NotNull String logTag) {
super(logTag);
this.layoutId = layoutId;
}
public CalculatorActivityHelperImpl(int layoutId, boolean homeIcon) {
this.layoutId = layoutId;
this.homeIcon = homeIcon;
}
@Override
public void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState) {
super.onCreate(activity);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
this.theme = CalculatorPreferences.Gui.getTheme(preferences);
activity.setTheme(this.theme.getThemeId());
activity.setContentView(layoutId);
CalculatorButtons.processButtons(true, theme, activity.getWindow().getDecorView());
}
@Override
public void onCreate(@NotNull final SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState) {
this.onCreate((Activity) activity, savedInstanceState);
final ActionBar actionBar = activity.getSupportActionBar();
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(homeIcon);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
if (savedInstanceState != null) {
navPosition = savedInstanceState.getInt(SELECTED_NAV, 0);
}
}
@Override
public void restoreSavedTab(@NotNull SherlockFragmentActivity activity) {
final ActionBar actionBar = activity.getSupportActionBar();
if (navPosition >= 0 && navPosition < actionBar.getTabCount()) {
activity.getSupportActionBar().setSelectedNavigationItem(navPosition);
}
}
@Override
public void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState) {
onSaveInstanceState((Activity) activity, outState);
outState.putInt(SELECTED_NAV, activity.getSupportActionBar().getSelectedNavigationIndex());
}
@Override
public void onSaveInstanceState(@NotNull Activity activity, @NotNull Bundle outState) {
}
@Override
public void onResume(@NotNull Activity activity) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences);
if (!theme.equals(newTheme)) {
AndroidUtils.restartActivity(activity);
}
}
@Override
public void onDestroy(@NotNull SherlockFragmentActivity activity) {
super.onDestroy(activity);
}
@Override
public void addTab(@NotNull SherlockFragmentActivity activity,
@NotNull String tag,
@NotNull Class<? extends Fragment> fragmentClass,
@Nullable Bundle fragmentArgs,
int captionResId,
int parentViewId) {
activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
final ActionBar actionBar = activity.getSupportActionBar();
final ActionBar.Tab tab = actionBar.newTab();
tab.setTag(tag);
tab.setText(captionResId);
tab.setTabListener(new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId));
actionBar.addTab(tab);
fragmentTags.add(tag);
}
@Override
public int getLayoutId() {
return layoutId;
}
@Override
@NotNull
public CalculatorPreferences.Gui.Theme getTheme() {
return theme;
}
@Override
public void onResume(@NotNull SherlockFragmentActivity activity) {
onResume((Activity) activity);
}
}

View File

@ -1,122 +1,122 @@
package org.solovyev.android.calculator;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import net.robotmedia.billing.BillingController;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.ads.AdsController;
import org.solovyev.android.calculator.history.AndroidCalculatorHistory;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
/**
* User: serso
* Date: 12/1/11
* Time: 1:21 PM
*/
public class CalculatorApplication extends android.app.Application {
private static final String paypalDonateUrl = "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=se%2esolovyev%40gmail%2ecom&lc=RU&item_name=Android%20Calculator&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted";
public static final String AD_FREE_PRODUCT_ID = "ad_free";
public static final String AD_FREE_P_KEY = "org.solovyev.android.calculator_ad_free";
public static final String ADMOB_USER_ID = "a14f02cf9c80cbc";
public static final String REMOTE_STACK_TRACE_URL = "http://calculatorpp.com/crash_reports/upload.php";
@NotNull
private static CalculatorApplication instance;
public CalculatorApplication() {
instance = this;
}
@NotNull
public static CalculatorApplication getInstance() {
return instance;
}
@Override
public void onCreate() {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
setTheme(preferences);
super.onCreate();
final AndroidCalculator calculator = new AndroidCalculator();
CalculatorLocatorImpl.getInstance().init(calculator,
new AndroidCalculatorEngine(this),
new AndroidCalculatorClipboard(this),
new AndroidCalculatorNotifier(this),
new AndroidCalculatorHistory(this, calculator));
CalculatorLocatorImpl.getInstance().getCalculator().init();
AdsController.getInstance().init(ADMOB_USER_ID, AD_FREE_PRODUCT_ID, new BillingController.IConfiguration() {
@Override
public byte[] getObfuscationSalt() {
return new byte[]{81, -114, 32, -127, -32, -104, -40, -15, -47, 57, -13, -41, -33, 67, -114, 7, -11, 53, 126, 82};
}
@Override
public String getPublicKey() {
return CalculatorSecurity.getPK();
}
});
CalculatorPreferences.setDefaultValues(preferences);
}
private void setTheme(@NotNull SharedPreferences preferences) {
final CalculatorPreferences.Gui.Theme theme = CalculatorPreferences.Gui.getTheme(preferences);
setTheme(theme.getThemeId());
}
public static void showDonationDialog(@NotNull final Context context) {
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
final View view = layoutInflater.inflate(R.layout.donate, null);
final TextView donate = (TextView) view.findViewById(R.id.donateText);
donate.setMovementMethod(LinkMovementMethod.getInstance());
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setCancelable(true)
.setNegativeButton(R.string.c_cancel, null)
.setPositiveButton(R.string.c_donate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(paypalDonateUrl));
context.startActivity(i);
}
})
.setView(view);
builder.create().show();
}
public static void registerOnRemoteStackTrace() {
//Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(null, REMOTE_STACK_TRACE_URL));
}
@NotNull
public CalculatorActivityHelper createActivityHelper(int layoutResId, @NotNull String logTag) {
return new CalculatorActivityHelperImpl(layoutResId, logTag);
}
@NotNull
public CalculatorFragmentHelper createFragmentHelper() {
return new CalculatorFragmentHelperImpl();
}
}
package org.solovyev.android.calculator;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import net.robotmedia.billing.BillingController;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.ads.AdsController;
import org.solovyev.android.calculator.history.AndroidCalculatorHistory;
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
/**
* User: serso
* Date: 12/1/11
* Time: 1:21 PM
*/
public class CalculatorApplication extends android.app.Application {
private static final String paypalDonateUrl = "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=se%2esolovyev%40gmail%2ecom&lc=RU&item_name=Android%20Calculator&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted";
public static final String AD_FREE_PRODUCT_ID = "ad_free";
public static final String AD_FREE_P_KEY = "org.solovyev.android.calculator_ad_free";
public static final String ADMOB_USER_ID = "a14f02cf9c80cbc";
public static final String REMOTE_STACK_TRACE_URL = "http://calculatorpp.com/crash_reports/upload.php";
@NotNull
private static CalculatorApplication instance;
public CalculatorApplication() {
instance = this;
}
@NotNull
public static CalculatorApplication getInstance() {
return instance;
}
@Override
public void onCreate() {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
setTheme(preferences);
super.onCreate();
final AndroidCalculator calculator = new AndroidCalculator();
CalculatorLocatorImpl.getInstance().init(calculator,
new AndroidCalculatorEngine(this),
new AndroidCalculatorClipboard(this),
new AndroidCalculatorNotifier(this),
new AndroidCalculatorHistory(this, calculator));
CalculatorLocatorImpl.getInstance().getCalculator().init();
AdsController.getInstance().init(ADMOB_USER_ID, AD_FREE_PRODUCT_ID, new BillingController.IConfiguration() {
@Override
public byte[] getObfuscationSalt() {
return new byte[]{81, -114, 32, -127, -32, -104, -40, -15, -47, 57, -13, -41, -33, 67, -114, 7, -11, 53, 126, 82};
}
@Override
public String getPublicKey() {
return CalculatorSecurity.getPK();
}
});
CalculatorPreferences.setDefaultValues(preferences);
}
private void setTheme(@NotNull SharedPreferences preferences) {
final CalculatorPreferences.Gui.Theme theme = CalculatorPreferences.Gui.getTheme(preferences);
setTheme(theme.getThemeId());
}
public static void showDonationDialog(@NotNull final Context context) {
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
final View view = layoutInflater.inflate(R.layout.donate, null);
final TextView donate = (TextView) view.findViewById(R.id.donateText);
donate.setMovementMethod(LinkMovementMethod.getInstance());
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setCancelable(true)
.setNegativeButton(R.string.c_cancel, null)
.setPositiveButton(R.string.c_donate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(paypalDonateUrl));
context.startActivity(i);
}
})
.setView(view);
builder.create().show();
}
public static void registerOnRemoteStackTrace() {
//Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(null, REMOTE_STACK_TRACE_URL));
}
@NotNull
public CalculatorActivityHelper createActivityHelper(int layoutResId, @NotNull String logTag) {
return new CalculatorActivityHelperImpl(layoutResId, logTag);
}
@NotNull
public CalculatorFragmentHelper createFragmentHelper(int layoutId) {
return new CalculatorFragmentHelperImpl(layoutId);
}
}

View File

@ -1,23 +1,30 @@
package org.solovyev.android.calculator;
import android.support.v4.app.Fragment;
import android.view.View;
import org.jetbrains.annotations.NotNull;
/**
* User: serso
* Date: 9/26/12
* Time: 10:14 PM
*/
public interface CalculatorFragmentHelper {
boolean isPane(@NotNull Fragment fragment);
void setPaneTitle(@NotNull Fragment fragment, int titleResId);
void processButtons(@NotNull Fragment fragment, @NotNull View root);
void onCreate(@NotNull Fragment fragment);
void onDestroy(@NotNull Fragment fragment);
}
package org.solovyev.android.calculator;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.math.edit.AbstractMathEntityListFragment;
/**
* User: serso
* Date: 9/26/12
* Time: 10:14 PM
*/
public interface CalculatorFragmentHelper {
boolean isPane(@NotNull Fragment fragment);
void setPaneTitle(@NotNull Fragment fragment, int titleResId);
void onCreate(@NotNull Fragment fragment);
void onViewCreated(@NotNull Fragment fragment, @NotNull View root);
void onDestroy(@NotNull Fragment fragment);
@NotNull
View onCreateView(@NotNull Fragment fragment, @NotNull LayoutInflater inflater, @Nullable ViewGroup container);
}

View File

@ -1,45 +1,76 @@
package org.solovyev.android.calculator;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.TextView;
import org.jetbrains.annotations.NotNull;
/**
* User: serso
* Date: 9/26/12
* Time: 10:14 PM
*/
public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper implements CalculatorFragmentHelper {
@Override
public boolean isPane(@NotNull Fragment fragment) {
return fragment.getActivity() instanceof CalculatorActivity;
}
public void setPaneTitle(@NotNull Fragment fragment, int titleResId) {
final TextView fragmentTitle = (TextView) fragment.getView().findViewById(R.id.fragmentTitle);
if (fragmentTitle != null) {
if (!isPane(fragment)) {
fragmentTitle.setVisibility(View.GONE);
} else {
fragmentTitle.setText(fragment.getString(titleResId).toUpperCase());
}
}
}
@Override
public void processButtons(@NotNull Fragment fragment, @NotNull View root) {
super.processButtons(fragment.getActivity(), root);
}
@Override
public void onCreate(@NotNull Fragment fragment) {
super.onCreate(fragment.getActivity());
}
@Override
public void onDestroy(@NotNull Fragment fragment) {
super.onDestroy(fragment.getActivity());
}
}
package org.solovyev.android.calculator;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.ads.AdView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.ads.AdsController;
/**
* User: serso
* Date: 9/26/12
* Time: 10:14 PM
*/
public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper implements CalculatorFragmentHelper {
@Nullable
private AdView adView;
private int layoutId;
public CalculatorFragmentHelperImpl(int layoutId) {
this.layoutId = layoutId;
}
@Override
public boolean isPane(@NotNull Fragment fragment) {
return fragment.getActivity() instanceof CalculatorActivity;
}
public void setPaneTitle(@NotNull Fragment fragment, int titleResId) {
final TextView fragmentTitle = (TextView) fragment.getView().findViewById(R.id.fragmentTitle);
if (fragmentTitle != null) {
if (!isPane(fragment)) {
fragmentTitle.setVisibility(View.GONE);
} else {
fragmentTitle.setText(fragment.getString(titleResId).toUpperCase());
}
}
}
@Override
public void onCreate(@NotNull Fragment fragment) {
super.onCreate(fragment.getActivity());
}
@Override
public void onViewCreated(@NotNull Fragment fragment, @NotNull View root) {
final ViewGroup mainFragmentLayout = (ViewGroup) root.findViewById(R.id.main_fragment_layout);
if (mainFragmentLayout != null) {
adView = AdsController.getInstance().inflateAd(fragment.getActivity(), mainFragmentLayout, R.id.main_fragment_layout);
}
processButtons(fragment.getActivity(), root);
}
@Override
public void onDestroy(@NotNull Fragment fragment) {
super.onDestroy(fragment.getActivity());
if (this.adView != null) {
this.adView.destroy();
}
}
@NotNull
@Override
public View onCreateView(@NotNull Fragment fragment, @NotNull LayoutInflater inflater, @Nullable ViewGroup container) {
return inflater.inflate(layoutId, container, false);
}
}

View File

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

View File

@ -1,336 +1,324 @@
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.history;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.actionbarsherlock.app.SherlockListFragment;
import com.google.ads.AdView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.ads.AdsController;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.menu.AMenuBuilder;
import org.solovyev.android.menu.MenuImpl;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.equals.Equalizer;
import org.solovyev.common.filter.Filter;
import org.solovyev.common.filter.FilterRule;
import org.solovyev.common.filter.FilterRulesChain;
import org.solovyev.common.text.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* User: serso
* Date: 10/15/11
* Time: 1:13 PM
*/
public abstract class AbstractCalculatorHistoryFragment extends SherlockListFragment implements CalculatorEventListener {
/*
**********************************************************************
*
* CONSTANTS
*
**********************************************************************
*/
@NotNull
private static final String TAG = "CalculatorHistoryFragment";
public static final Comparator<CalculatorHistoryState> COMPARATOR = new Comparator<CalculatorHistoryState>() {
@Override
public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) {
if (state1.isSaved() == state2.isSaved()) {
long l = state2.getTime() - state1.getTime();
return l > 0l ? 1 : (l < 0l ? -1 : 0);
} else if (state1.isSaved()) {
return -1;
} else if (state2.isSaved()) {
return 1;
}
return 0;
}
};
/*
**********************************************************************
*
* FIELDS
*
**********************************************************************
*/
@NotNull
private ArrayAdapter<CalculatorHistoryState> adapter;
@Nullable
private AdView adView;
@NotNull
private CalculatorFragmentHelper fragmentHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper();
fragmentHelper.onCreate(this);
logDebug("onCreate");
}
private int logDebug(@NotNull String msg) {
return Log.d(TAG + ": " + getTag(), msg);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View result = inflater.inflate(R.layout.history_fragment, container, false);
logDebug("onCreateView");
return result;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
logDebug("onViewCreated");
fragmentHelper.setPaneTitle(this, getTitleResId());
adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), R.id.history_item, new ArrayList<CalculatorHistoryState>());
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(final AdapterView<?> parent,
final View view,
final int position,
final long id) {
useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position));
}
});
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
final CalculatorHistoryState historyState = (CalculatorHistoryState) parent.getItemAtPosition(position);
final Context context = getActivity();
final HistoryItemMenuData data = new HistoryItemMenuData(historyState, adapter);
final List<HistoryItemMenuItem> menuItems = CollectionsUtils.asList(HistoryItemMenuItem.values());
if (historyState.isSaved()) {
menuItems.remove(HistoryItemMenuItem.save);
} else {
if (isAlreadySaved(historyState)) {
menuItems.remove(HistoryItemMenuItem.save);
}
menuItems.remove(HistoryItemMenuItem.remove);
menuItems.remove(HistoryItemMenuItem.edit);
}
if (historyState.getDisplayState().isValid() && StringUtils.isEmpty(historyState.getDisplayState().getEditorState().getText())) {
menuItems.remove(HistoryItemMenuItem.copy_result);
}
final AMenuBuilder<HistoryItemMenuItem, HistoryItemMenuData> menuBuilder = AMenuBuilder.newInstance(context, MenuImpl.newInstance(menuItems));
menuBuilder.create(data).show();
return true;
}
});
adView = AdsController.getInstance().inflateAd(this.getActivity(), (ViewGroup)view.findViewById(R.id.ad_parent_view), R.id.ad_parent_view);
}
protected abstract int getTitleResId();
@Override
public void onDestroy() {
logDebug("onDestroy");
if ( this.adView != null ) {
this.adView.destroy();
}
fragmentHelper.onDestroy(this);
super.onDestroy();
}
protected abstract int getItemLayoutId();
@Override
public void onResume() {
logDebug("onResume");
super.onResume();
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
updateAdapter();
}
@Override
public void onPause() {
logDebug("onPause");
super.onPause();
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
}
private void updateAdapter() {
final List<CalculatorHistoryState> historyList = getHistoryList();
final ArrayAdapter<CalculatorHistoryState> adapter = getAdapter();
try {
adapter.setNotifyOnChange(false);
adapter.clear();
for (CalculatorHistoryState historyState : historyList) {
adapter.add(historyState);
}
} finally {
adapter.setNotifyOnChange(true);
}
adapter.notifyDataSetChanged();
}
public static boolean isAlreadySaved(@NotNull CalculatorHistoryState historyState) {
assert !historyState.isSaved();
boolean result = false;
try {
historyState.setSaved(true);
if ( CollectionsUtils.contains(historyState, CalculatorLocatorImpl.getInstance().getHistory().getSavedHistory(), new Equalizer<CalculatorHistoryState>() {
@Override
public boolean equals(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
return first != null && second != null &&
first.getTime() == second.getTime() &&
first.getDisplayState().equals(second.getDisplayState()) &&
first.getEditorState().equals(second.getEditorState());
}
}) ) {
result = true;
}
} finally {
historyState.setSaved(false);
}
return result;
}
public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_history_state, historyState);
}
@NotNull
private List<CalculatorHistoryState> getHistoryList() {
final List<CalculatorHistoryState> calculatorHistoryStates = getHistoryItems();
Collections.sort(calculatorHistoryStates, COMPARATOR);
final FilterRulesChain<CalculatorHistoryState> filterRulesChain = new FilterRulesChain<CalculatorHistoryState>();
filterRulesChain.addFilterRule(new FilterRule<CalculatorHistoryState>() {
@Override
public boolean isFiltered(CalculatorHistoryState object) {
return object == null || StringUtils.isEmpty(object.getEditorState().getText());
}
});
new Filter<CalculatorHistoryState>(filterRulesChain).filter(calculatorHistoryStates.iterator());
return calculatorHistoryStates;
}
@NotNull
protected abstract List<CalculatorHistoryState> getHistoryItems();
@NotNull
public static String getHistoryText(@NotNull CalculatorHistoryState state) {
final StringBuilder result = new StringBuilder();
result.append(state.getEditorState().getText());
result.append(getIdentitySign(state.getDisplayState().getJsclOperation()));
final String expressionResult = state.getDisplayState().getEditorState().getText();
if (expressionResult != null) {
result.append(expressionResult);
}
return result.toString();
}
@NotNull
private static String getIdentitySign(@NotNull JsclOperation jsclOperation) {
return jsclOperation == JsclOperation.simplify ? "" : "=";
}
// todo serso: menu
/* @Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
final MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.history_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
boolean result;
switch (item.getItemId()) {
case R.id.history_menu_clear_history:
clearHistory();
result = true;
break;
default:
result = super.onOptionsItemSelected(item);
}
return result;
}*/
protected abstract void clearHistory();
@NotNull
protected ArrayAdapter<CalculatorHistoryState> getAdapter() {
return adapter;
}
@Override
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
if ( calculatorEventType == CalculatorEventType.history_state_added ) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
logDebug("onCalculatorEvent");
updateAdapter();
}
});
}
}
}
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.history;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.actionbarsherlock.app.SherlockListFragment;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.menu.AMenuBuilder;
import org.solovyev.android.menu.MenuImpl;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.equals.Equalizer;
import org.solovyev.common.filter.Filter;
import org.solovyev.common.filter.FilterRule;
import org.solovyev.common.filter.FilterRulesChain;
import org.solovyev.common.text.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* User: serso
* Date: 10/15/11
* Time: 1:13 PM
*/
public abstract class AbstractCalculatorHistoryFragment extends SherlockListFragment implements CalculatorEventListener {
/*
**********************************************************************
*
* CONSTANTS
*
**********************************************************************
*/
@NotNull
private static final String TAG = "CalculatorHistoryFragment";
public static final Comparator<CalculatorHistoryState> COMPARATOR = new Comparator<CalculatorHistoryState>() {
@Override
public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) {
if (state1.isSaved() == state2.isSaved()) {
long l = state2.getTime() - state1.getTime();
return l > 0l ? 1 : (l < 0l ? -1 : 0);
} else if (state1.isSaved()) {
return -1;
} else if (state2.isSaved()) {
return 1;
}
return 0;
}
};
/*
**********************************************************************
*
* FIELDS
*
**********************************************************************
*/
@NotNull
private ArrayAdapter<CalculatorHistoryState> adapter;
@NotNull
private CalculatorFragmentHelper fragmentHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.history_fragment);
fragmentHelper.onCreate(this);
logDebug("onCreate");
}
private int logDebug(@NotNull String msg) {
return Log.d(TAG + ": " + getTag(), msg);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return fragmentHelper.onCreateView(this, inflater, container);
}
@Override
public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
logDebug("onViewCreated");
fragmentHelper.onViewCreated(this, root);
fragmentHelper.setPaneTitle(this, getTitleResId());
adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), R.id.history_item, new ArrayList<CalculatorHistoryState>());
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(final AdapterView<?> parent,
final View view,
final int position,
final long id) {
useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position));
}
});
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
final CalculatorHistoryState historyState = (CalculatorHistoryState) parent.getItemAtPosition(position);
final Context context = getActivity();
final HistoryItemMenuData data = new HistoryItemMenuData(historyState, adapter);
final List<HistoryItemMenuItem> menuItems = CollectionsUtils.asList(HistoryItemMenuItem.values());
if (historyState.isSaved()) {
menuItems.remove(HistoryItemMenuItem.save);
} else {
if (isAlreadySaved(historyState)) {
menuItems.remove(HistoryItemMenuItem.save);
}
menuItems.remove(HistoryItemMenuItem.remove);
menuItems.remove(HistoryItemMenuItem.edit);
}
if (historyState.getDisplayState().isValid() && StringUtils.isEmpty(historyState.getDisplayState().getEditorState().getText())) {
menuItems.remove(HistoryItemMenuItem.copy_result);
}
final AMenuBuilder<HistoryItemMenuItem, HistoryItemMenuData> menuBuilder = AMenuBuilder.newInstance(context, MenuImpl.newInstance(menuItems));
menuBuilder.create(data).show();
return true;
}
});
}
protected abstract int getTitleResId();
@Override
public void onDestroy() {
logDebug("onDestroy");
fragmentHelper.onDestroy(this);
super.onDestroy();
}
protected abstract int getItemLayoutId();
@Override
public void onResume() {
logDebug("onResume");
super.onResume();
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
updateAdapter();
}
@Override
public void onPause() {
logDebug("onPause");
super.onPause();
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
}
private void updateAdapter() {
final List<CalculatorHistoryState> historyList = getHistoryList();
final ArrayAdapter<CalculatorHistoryState> adapter = getAdapter();
try {
adapter.setNotifyOnChange(false);
adapter.clear();
for (CalculatorHistoryState historyState : historyList) {
adapter.add(historyState);
}
} finally {
adapter.setNotifyOnChange(true);
}
adapter.notifyDataSetChanged();
}
public static boolean isAlreadySaved(@NotNull CalculatorHistoryState historyState) {
assert !historyState.isSaved();
boolean result = false;
try {
historyState.setSaved(true);
if ( CollectionsUtils.contains(historyState, CalculatorLocatorImpl.getInstance().getHistory().getSavedHistory(), new Equalizer<CalculatorHistoryState>() {
@Override
public boolean equals(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
return first != null && second != null &&
first.getTime() == second.getTime() &&
first.getDisplayState().equals(second.getDisplayState()) &&
first.getEditorState().equals(second.getEditorState());
}
}) ) {
result = true;
}
} finally {
historyState.setSaved(false);
}
return result;
}
public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_history_state, historyState);
}
@NotNull
private List<CalculatorHistoryState> getHistoryList() {
final List<CalculatorHistoryState> calculatorHistoryStates = getHistoryItems();
Collections.sort(calculatorHistoryStates, COMPARATOR);
final FilterRulesChain<CalculatorHistoryState> filterRulesChain = new FilterRulesChain<CalculatorHistoryState>();
filterRulesChain.addFilterRule(new FilterRule<CalculatorHistoryState>() {
@Override
public boolean isFiltered(CalculatorHistoryState object) {
return object == null || StringUtils.isEmpty(object.getEditorState().getText());
}
});
new Filter<CalculatorHistoryState>(filterRulesChain).filter(calculatorHistoryStates.iterator());
return calculatorHistoryStates;
}
@NotNull
protected abstract List<CalculatorHistoryState> getHistoryItems();
@NotNull
public static String getHistoryText(@NotNull CalculatorHistoryState state) {
final StringBuilder result = new StringBuilder();
result.append(state.getEditorState().getText());
result.append(getIdentitySign(state.getDisplayState().getJsclOperation()));
final String expressionResult = state.getDisplayState().getEditorState().getText();
if (expressionResult != null) {
result.append(expressionResult);
}
return result.toString();
}
@NotNull
private static String getIdentitySign(@NotNull JsclOperation jsclOperation) {
return jsclOperation == JsclOperation.simplify ? "" : "=";
}
// todo serso: menu
/* @Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
final MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.history_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
boolean result;
switch (item.getItemId()) {
case R.id.history_menu_clear_history:
clearHistory();
result = true;
break;
default:
result = super.onOptionsItemSelected(item);
}
return result;
}*/
protected abstract void clearHistory();
@NotNull
protected ArrayAdapter<CalculatorHistoryState> getAdapter() {
return adapter;
}
@Override
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
if ( calculatorEventType == CalculatorEventType.history_state_added ) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
logDebug("onCalculatorEvent");
updateAdapter();
}
});
}
}
}

View File

@ -1,326 +1,321 @@
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.math.edit;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.actionbarsherlock.app.SherlockListFragment;
import com.google.ads.AdView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.ads.AdsController;
import org.solovyev.android.calculator.*;
import org.solovyev.android.menu.AMenuBuilder;
import org.solovyev.android.menu.LabeledMenuItem;
import org.solovyev.android.menu.MenuImpl;
import org.solovyev.common.equals.EqualsTool;
import org.solovyev.common.filter.Filter;
import org.solovyev.common.filter.FilterRule;
import org.solovyev.common.math.MathEntity;
import org.solovyev.common.text.StringUtils;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
/**
* User: serso
* Date: 12/21/11
* Time: 9:24 PM
*/
public abstract class AbstractMathEntityListFragment<T extends MathEntity> extends SherlockListFragment {
/*
**********************************************************************
*
* CONSTANTS
*
**********************************************************************
*/
public static final String MATH_ENTITY_CATEGORY_EXTRA_STRING = "org.solovyev.android.calculator.CalculatorVarsActivity_math_entity_category";
protected final static List<Character> acceptableChars = Arrays.asList(StringUtils.toObject("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_".toCharArray()));
/*
**********************************************************************
*
* FIELDS
*
**********************************************************************
*/
@Nullable
private MathEntityArrayAdapter<T> adapter;
@Nullable
private String category;
@Nullable
private AdView adView;
@NotNull
private CalculatorFragmentHelper fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper();
protected int getLayoutResId() {
return R.layout.math_entities;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Bundle bundle = getArguments();
if ( bundle != null ) {
category = bundle.getString(MATH_ENTITY_CATEGORY_EXTRA_STRING);
}
fragmentHelper.onCreate(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(getLayoutResId(), container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
this.fragmentHelper.setPaneTitle(this, getTitleResId());
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(final AdapterView<?> parent,
final View view,
final int position,
final long id) {
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(((MathEntity) parent.getItemAtPosition(position)).getName());
}
});
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
final T item = (T) parent.getItemAtPosition(position);
final List<LabeledMenuItem<T>> menuItems = getMenuItemsOnLongClick(item);
if (!menuItems.isEmpty()) {
final AMenuBuilder<LabeledMenuItem<T>, T> menuBuilder = AMenuBuilder.newInstance(AbstractMathEntityListFragment.this.getActivity(), MenuImpl.newInstance(menuItems));
menuBuilder.create(item).show();
}
return true;
}
});
adView = AdsController.getInstance().inflateAd(this.getActivity(), (ViewGroup)view.findViewById(R.id.ad_parent_view), R.id.ad_parent_view);
}
protected abstract int getTitleResId();
@Override
public void onDestroy() {
if (this.adView != null) {
this.adView.destroy();
}
fragmentHelper.onDestroy(this);
super.onDestroy();
}
@NotNull
protected abstract List<LabeledMenuItem<T>> getMenuItemsOnLongClick(@NotNull T item);
@Override
public void onResume() {
super.onResume();
adapter = new MathEntityArrayAdapter<T>(getDescriptionGetter(), this.getActivity(), R.layout.math_entity, R.id.math_entity_text, getMathEntitiesByCategory());
setListAdapter(adapter);
sort();
}
@NotNull
private List<T> getMathEntitiesByCategory() {
final List<T> result = getMathEntities();
new Filter<T>(new FilterRule<T>() {
@Override
public boolean isFiltered(T t) {
return !isInCategory(t);
}
}).filter(result.iterator());
return result;
}
protected boolean isInCategory(@Nullable T t) {
return t != null && (category == null || EqualsTool.areEqual(getMathEntityCategory(t), category));
}
@NotNull
protected abstract MathEntityDescriptionGetter getDescriptionGetter();
@NotNull
protected abstract List<T> getMathEntities();
@Nullable
abstract String getMathEntityCategory(@NotNull T t);
protected void sort() {
final MathEntityArrayAdapter<T> localAdapter = adapter;
if (localAdapter != null) {
localAdapter.sort(new Comparator<T>() {
@Override
public int compare(T function1, T function2) {
return function1.getName().compareTo(function2.getName());
}
});
localAdapter.notifyDataSetChanged();
}
}
protected static class MathEntityArrayAdapter<T extends MathEntity> extends ArrayAdapter<T> {
@NotNull
private final MathEntityDescriptionGetter descriptionGetter;
private MathEntityArrayAdapter(@NotNull MathEntityDescriptionGetter descriptionGetter,
@NotNull Context context,
int resource,
int textViewResourceId,
@NotNull List<T> objects) {
super(context, resource, textViewResourceId, objects);
this.descriptionGetter = descriptionGetter;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewGroup result = (ViewGroup) super.getView(position, convertView, parent);
final T mathEntity = getItem(position);
final String mathEntityDescription = descriptionGetter.getDescription(getContext(), mathEntity.getName());
if (!StringUtils.isEmpty(mathEntityDescription)) {
TextView description = (TextView) result.findViewById(R.id.math_entity_description);
if (description == null) {
final LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final ViewGroup itemView = (ViewGroup) layoutInflater.inflate(R.layout.math_entity, null);
description = (TextView) itemView.findViewById(R.id.math_entity_description);
itemView.removeView(description);
result.addView(description);
}
description.setText(mathEntityDescription);
} else {
TextView description = (TextView) result.findViewById(R.id.math_entity_description);
if (description != null) {
result.removeView(description);
}
}
return result;
}
}
protected static class MathEntityDescriptionGetterImpl implements MathEntityDescriptionGetter {
@NotNull
private final CalculatorMathRegistry<?> mathRegistry;
public MathEntityDescriptionGetterImpl(@NotNull CalculatorMathRegistry<?> mathRegistry) {
this.mathRegistry = mathRegistry;
}
@Override
public String getDescription(@NotNull Context context, @NotNull String mathEntityName) {
return this.mathRegistry.getDescription(mathEntityName);
}
}
protected static interface MathEntityDescriptionGetter {
@Nullable
String getDescription(@NotNull Context context, @NotNull String mathEntityName);
}
public void addToAdapter(@NotNull T mathEntity) {
if (this.adapter != null) {
this.adapter.add(mathEntity);
}
}
public void removeFromAdapter(@NotNull T mathEntity) {
if (this.adapter != null) {
this.adapter.remove(mathEntity);
}
}
public void notifyAdapter() {
if (this.adapter != null) {
this.adapter.notifyDataSetChanged();
}
}
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
static void createTab(@NotNull Context context,
@NotNull TabHost tabHost,
@NotNull String tabId,
@NotNull String categoryId,
int tabCaptionId,
@NotNull Class<? extends Activity> activityClass,
@Nullable Intent parentIntent) {
TabHost.TabSpec spec;
final Intent intent;
if (parentIntent != null) {
intent = new Intent(parentIntent);
} else {
intent = new Intent();
}
intent.setClass(context, activityClass);
intent.putExtra(MATH_ENTITY_CATEGORY_EXTRA_STRING, categoryId);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec(tabId).setIndicator(context.getString(tabCaptionId)).setContent(intent);
tabHost.addTab(spec);
}
@NotNull
public static Bundle createBundleFor(@NotNull String categoryId) {
final Bundle result = new Bundle(1);
result.putString(MATH_ENTITY_CATEGORY_EXTRA_STRING, categoryId);
return result;
}
}
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.math.edit;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.actionbarsherlock.app.SherlockListFragment;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
import org.solovyev.android.menu.AMenuBuilder;
import org.solovyev.android.menu.LabeledMenuItem;
import org.solovyev.android.menu.MenuImpl;
import org.solovyev.common.equals.EqualsTool;
import org.solovyev.common.filter.Filter;
import org.solovyev.common.filter.FilterRule;
import org.solovyev.common.math.MathEntity;
import org.solovyev.common.text.StringUtils;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
/**
* User: serso
* Date: 12/21/11
* Time: 9:24 PM
*/
public abstract class AbstractMathEntityListFragment<T extends MathEntity> extends SherlockListFragment {
/*
**********************************************************************
*
* CONSTANTS
*
**********************************************************************
*/
public static final String MATH_ENTITY_CATEGORY_EXTRA_STRING = "org.solovyev.android.calculator.CalculatorVarsActivity_math_entity_category";
protected final static List<Character> acceptableChars = Arrays.asList(StringUtils.toObject("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_".toCharArray()));
/*
**********************************************************************
*
* FIELDS
*
**********************************************************************
*/
@Nullable
private MathEntityArrayAdapter<T> adapter;
@Nullable
private String category;
@NotNull
private CalculatorFragmentHelper fragmentHelper;
protected int getLayoutId() {
return R.layout.math_entities_fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Bundle bundle = getArguments();
if ( bundle != null ) {
category = bundle.getString(MATH_ENTITY_CATEGORY_EXTRA_STRING);
}
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(getLayoutId());
fragmentHelper.onCreate(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return fragmentHelper.onCreateView(this, inflater, container);
}
@Override
public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
fragmentHelper.onViewCreated(this, root);
this.fragmentHelper.setPaneTitle(this, getTitleResId());
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(final AdapterView<?> parent,
final View view,
final int position,
final long id) {
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(((MathEntity) parent.getItemAtPosition(position)).getName());
getActivity().finish();
}
});
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
final T item = (T) parent.getItemAtPosition(position);
final List<LabeledMenuItem<T>> menuItems = getMenuItemsOnLongClick(item);
if (!menuItems.isEmpty()) {
final AMenuBuilder<LabeledMenuItem<T>, T> menuBuilder = AMenuBuilder.newInstance(AbstractMathEntityListFragment.this.getActivity(), MenuImpl.newInstance(menuItems));
menuBuilder.create(item).show();
}
return true;
}
});
}
protected abstract int getTitleResId();
@Override
public void onDestroy() {
fragmentHelper.onDestroy(this);
super.onDestroy();
}
@NotNull
protected abstract List<LabeledMenuItem<T>> getMenuItemsOnLongClick(@NotNull T item);
@Override
public void onResume() {
super.onResume();
adapter = new MathEntityArrayAdapter<T>(getDescriptionGetter(), this.getActivity(), R.layout.math_entity, R.id.math_entity_text, getMathEntitiesByCategory());
setListAdapter(adapter);
sort();
}
@NotNull
private List<T> getMathEntitiesByCategory() {
final List<T> result = getMathEntities();
new Filter<T>(new FilterRule<T>() {
@Override
public boolean isFiltered(T t) {
return !isInCategory(t);
}
}).filter(result.iterator());
return result;
}
protected boolean isInCategory(@Nullable T t) {
return t != null && (category == null || EqualsTool.areEqual(getMathEntityCategory(t), category));
}
@NotNull
protected abstract MathEntityDescriptionGetter getDescriptionGetter();
@NotNull
protected abstract List<T> getMathEntities();
@Nullable
abstract String getMathEntityCategory(@NotNull T t);
protected void sort() {
final MathEntityArrayAdapter<T> localAdapter = adapter;
if (localAdapter != null) {
localAdapter.sort(new Comparator<T>() {
@Override
public int compare(T function1, T function2) {
return function1.getName().compareTo(function2.getName());
}
});
localAdapter.notifyDataSetChanged();
}
}
protected static class MathEntityArrayAdapter<T extends MathEntity> extends ArrayAdapter<T> {
@NotNull
private final MathEntityDescriptionGetter descriptionGetter;
private MathEntityArrayAdapter(@NotNull MathEntityDescriptionGetter descriptionGetter,
@NotNull Context context,
int resource,
int textViewResourceId,
@NotNull List<T> objects) {
super(context, resource, textViewResourceId, objects);
this.descriptionGetter = descriptionGetter;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewGroup result = (ViewGroup) super.getView(position, convertView, parent);
final T mathEntity = getItem(position);
final String mathEntityDescription = descriptionGetter.getDescription(getContext(), mathEntity.getName());
if (!StringUtils.isEmpty(mathEntityDescription)) {
TextView description = (TextView) result.findViewById(R.id.math_entity_description);
if (description == null) {
final LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final ViewGroup itemView = (ViewGroup) layoutInflater.inflate(R.layout.math_entity, null);
description = (TextView) itemView.findViewById(R.id.math_entity_description);
itemView.removeView(description);
result.addView(description);
}
description.setText(mathEntityDescription);
} else {
TextView description = (TextView) result.findViewById(R.id.math_entity_description);
if (description != null) {
result.removeView(description);
}
}
return result;
}
}
protected static class MathEntityDescriptionGetterImpl implements MathEntityDescriptionGetter {
@NotNull
private final CalculatorMathRegistry<?> mathRegistry;
public MathEntityDescriptionGetterImpl(@NotNull CalculatorMathRegistry<?> mathRegistry) {
this.mathRegistry = mathRegistry;
}
@Override
public String getDescription(@NotNull Context context, @NotNull String mathEntityName) {
return this.mathRegistry.getDescription(mathEntityName);
}
}
protected static interface MathEntityDescriptionGetter {
@Nullable
String getDescription(@NotNull Context context, @NotNull String mathEntityName);
}
public void addToAdapter(@NotNull T mathEntity) {
if (this.adapter != null) {
this.adapter.add(mathEntity);
}
}
public void removeFromAdapter(@NotNull T mathEntity) {
if (this.adapter != null) {
this.adapter.remove(mathEntity);
}
}
public void notifyAdapter() {
if (this.adapter != null) {
this.adapter.notifyDataSetChanged();
}
}
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
static void createTab(@NotNull Context context,
@NotNull TabHost tabHost,
@NotNull String tabId,
@NotNull String categoryId,
int tabCaptionId,
@NotNull Class<? extends Activity> activityClass,
@Nullable Intent parentIntent) {
TabHost.TabSpec spec;
final Intent intent;
if (parentIntent != null) {
intent = new Intent(parentIntent);
} else {
intent = new Intent();
}
intent.setClass(context, activityClass);
intent.putExtra(MATH_ENTITY_CATEGORY_EXTRA_STRING, categoryId);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec(tabId).setIndicator(context.getString(tabCaptionId)).setContent(intent);
tabHost.addTab(spec);
}
@NotNull
public static Bundle createBundleFor(@NotNull String categoryId) {
final Bundle result = new Bundle(1);
putCategory(result, categoryId);
return result;
}
static void putCategory(@NotNull Bundle bundle, @NotNull String categoryId) {
bundle.putString(MATH_ENTITY_CATEGORY_EXTRA_STRING, categoryId);
}
}

View File

@ -1,69 +1,68 @@
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.math.edit;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
import org.solovyev.android.calculator.model.AndroidFunctionsMathRegistry;
/**
* User: serso
* Date: 12/21/11
* Time: 10:33 PM
*/
public class CalculatorFunctionsFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
@NotNull
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activityHelper.onCreate(this, savedInstanceState);
for (AndroidFunctionsMathRegistry.Category category : AndroidFunctionsMathRegistry.Category.getCategoriesByTabOrder()) {
activityHelper.addTab(this, category.name(), CalculatorHistoryFragment.class, null, category.getCaptionId(), R.id.main_layout);
}
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
activityHelper.onSaveInstanceState(this, outState);
}
@Override
protected void onResume() {
super.onResume();
activityHelper.onResume(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
this.activityHelper.onDestroy(this);
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
}
@Override
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
//To change body of implemented methods use File | Settings | File Templates.
}
}
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.math.edit;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
import org.solovyev.android.calculator.model.AndroidFunctionsMathRegistry;
/**
* User: serso
* Date: 12/21/11
* Time: 10:33 PM
*/
public class CalculatorFunctionsFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
@NotNull
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activityHelper.onCreate(this, savedInstanceState);
for (AndroidFunctionsMathRegistry.Category category : AndroidFunctionsMathRegistry.Category.getCategoriesByTabOrder()) {
activityHelper.addTab(this, category.name(), CalculatorFunctionsFragment.class, AbstractMathEntityListFragment.createBundleFor(category.name()), category.getCaptionId(), R.id.main_layout);
}
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
activityHelper.onSaveInstanceState(this, outState);
}
@Override
protected void onResume() {
super.onResume();
activityHelper.onResume(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
this.activityHelper.onDestroy(this);
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
}
@Override
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
//To change body of implemented methods use File | Settings | File Templates.
}
}

View File

@ -1,310 +1,320 @@
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.math.edit;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.text.ClipboardManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import jscl.math.function.IConstant;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.model.Var;
import org.solovyev.android.menu.LabeledMenuItem;
import org.solovyev.common.JPredicate;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.text.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* User: serso
* Date: 9/28/11
* Time: 10:55 PM
*/
public class CalculatorVarsFragment extends AbstractMathEntityListFragment<IConstant> {
public static final String CREATE_VAR_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorVarsTabActivity_create_var";
@Override
protected int getLayoutResId() {
return R.layout.vars_fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Bundle bundle = getArguments();
if (bundle != null) {
final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING);
if (!StringUtils.isEmpty(varValue)) {
createEditVariableDialog(this, null, null, varValue, null);
// in order to stop intent for other tabs
bundle.remove(CREATE_VAR_EXTRA_STRING);
}
}
}
@Override
protected int getTitleResId() {
return R.string.c_vars;
}
@NotNull
@Override
protected List<LabeledMenuItem<IConstant>> getMenuItemsOnLongClick(@NotNull IConstant item) {
final List<LabeledMenuItem<IConstant>> result = new ArrayList<LabeledMenuItem<IConstant>>(Arrays.asList(LongClickMenuItem.values()));
if ( item.isSystem() ) {
result.remove(LongClickMenuItem.edit);
result.remove(LongClickMenuItem.remove);
}
if ( StringUtils.isEmpty(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getDescription(item.getName())) ) {
result.remove(LongClickMenuItem.copy_description);
}
if ( StringUtils.isEmpty(item.getValue()) ) {
result.remove(LongClickMenuItem.copy_value);
}
return result;
}
@NotNull
@Override
protected MathEntityDescriptionGetter getDescriptionGetter() {
return new MathEntityDescriptionGetterImpl(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry());
}
@SuppressWarnings({"UnusedDeclaration"})
public void addVarButtonClickHandler(@NotNull View v) {
createEditVariableDialog(this, null, null, null, null);
}
@NotNull
@Override
protected List<IConstant> getMathEntities() {
final List<IConstant> result = new ArrayList<IConstant>(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getEntities());
CollectionsUtils.removeAll(result, new JPredicate<IConstant>() {
@Override
public boolean apply(@Nullable IConstant var) {
return var != null && CollectionsUtils.contains(var.getName(), MathType.INFINITY_JSCL, MathType.NAN);
}
});
return result;
}
@Override
protected String getMathEntityCategory(@NotNull IConstant var) {
return CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getCategory(var);
}
private static void createEditVariableDialog(@NotNull final AbstractMathEntityListFragment<IConstant> fragment,
@Nullable final IConstant var,
@Nullable final String name,
@Nullable final String value,
@Nullable final String description) {
final FragmentActivity activity = fragment.getActivity();
if (var == null || !var.isSystem()) {
final LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final View editView = layoutInflater.inflate(R.layout.var_edit, null);
final String errorMsg = fragment.getString(R.string.c_char_is_not_accepted);
final EditText editName = (EditText) editView.findViewById(R.id.var_edit_name);
editName.setText(name);
editName.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (!acceptableChars.contains(c)) {
s.delete(i, i + 1);
Toast.makeText(activity, String.format(errorMsg, c), Toast.LENGTH_SHORT).show();
}
}
}
});
final EditText editValue = (EditText) editView.findViewById(R.id.var_edit_value);
if (!StringUtils.isEmpty(value)) {
editValue.setText(value);
}
final EditText editDescription = (EditText) editView.findViewById(R.id.var_edit_description);
editDescription.setText(description);
final Var.Builder varBuilder;
if (var != null) {
varBuilder = new Var.Builder(var);
} else {
varBuilder = new Var.Builder();
}
final AlertDialog.Builder builder = new AlertDialog.Builder(activity)
.setCancelable(true)
.setNegativeButton(R.string.c_cancel, null)
.setPositiveButton(R.string.c_save, new VarEditorSaver<IConstant>(varBuilder, var, editView, fragment, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), new VarEditorSaver.EditorCreator<IConstant>() {
@Override
public void showEditor(@NotNull AbstractMathEntityListFragment<IConstant> activity, @Nullable IConstant editedInstance, @Nullable String name, @Nullable String value, @Nullable String description) {
createEditVariableDialog(activity, editedInstance, name, value, description);
}
}))
.setView(editView);
if (var != null) {
// EDIT mode
builder.setTitle(R.string.c_var_edit_var);
builder.setNeutralButton(R.string.c_remove, new MathEntityRemover<IConstant>(var, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
createEditVariableDialog(fragment, var, name, value, description);
}
}, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), fragment));
} else {
// CREATE mode
builder.setTitle(R.string.c_var_create_var);
}
builder.create().show();
} else {
Toast.makeText(activity, fragment.getString(R.string.c_sys_var_cannot_be_changed), Toast.LENGTH_LONG).show();
}
}
public static boolean isValidValue(@NotNull String value) {
// now every string might be constant
return true;
}
// todo serso: menu
/* @Override
public boolean onCreateOptionsMenu(Menu menu) {
final MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.var_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
boolean result;
switch (item.getItemId()) {
case R.id.var_menu_add_var:
createEditVariableDialog(this, null, null, null, null);
result = true;
break;
default:
result = super.onOptionsItemSelected(item);
}
return result;
}*/
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
private static enum LongClickMenuItem implements LabeledMenuItem<IConstant>{
use(R.string.c_use) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(data.getName());
if (context instanceof Activity) {
((Activity) context).finish();
}
}
},
edit(R.string.c_edit) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
/*if (context instanceof AbstractMathEntityListFragment) {
createEditVariableDialog((AbstractMathEntityListFragment<IConstant>)context, data, data.getName(), StringUtils.getNotEmpty(data.getValue(), ""), data.getDescription());
}*/
}
},
remove(R.string.c_remove) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
/*if (context instanceof AbstractMathEntityListFragment) {
new MathEntityRemover<IConstant>(data, null, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), ((AbstractMathEntityListFragment<IConstant>) context)).showConfirmationDialog();
}*/
}
},
copy_value(R.string.c_copy_value) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
final String text = data.getValue();
if (!StringUtils.isEmpty(text)) {
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
clipboard.setText(text);
}
}
},
copy_description(R.string.c_copy_description) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
final String text = CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getDescription(data.getName());
if (!StringUtils.isEmpty(text)) {
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
clipboard.setText(text);
}
}
};
private final int captionId;
LongClickMenuItem(int captionId) {
this.captionId = captionId;
}
@NotNull
@Override
public String getCaption(@NotNull Context context) {
return context.getString(captionId);
}
}
}
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.math.edit;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.text.ClipboardManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import jscl.math.function.IConstant;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.model.Var;
import org.solovyev.android.menu.LabeledMenuItem;
import org.solovyev.common.JPredicate;
import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.common.text.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* User: serso
* Date: 9/28/11
* Time: 10:55 PM
*/
public class CalculatorVarsFragment extends AbstractMathEntityListFragment<IConstant> {
public static final String CREATE_VAR_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorVarsTabActivity_create_var";
@Override
protected int getLayoutId() {
return R.layout.vars_fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Bundle bundle = getArguments();
if (bundle != null) {
final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING);
if (!StringUtils.isEmpty(varValue)) {
createEditVariableDialog(this, null, null, varValue, null);
// in order to stop intent for other tabs
bundle.remove(CREATE_VAR_EXTRA_STRING);
}
}
setHasOptionsMenu(true);
}
@Override
protected int getTitleResId() {
return R.string.c_vars;
}
@NotNull
@Override
protected List<LabeledMenuItem<IConstant>> getMenuItemsOnLongClick(@NotNull IConstant item) {
final List<LabeledMenuItem<IConstant>> result = new ArrayList<LabeledMenuItem<IConstant>>(Arrays.asList(LongClickMenuItem.values()));
if ( item.isSystem() ) {
result.remove(LongClickMenuItem.edit);
result.remove(LongClickMenuItem.remove);
}
if ( StringUtils.isEmpty(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getDescription(item.getName())) ) {
result.remove(LongClickMenuItem.copy_description);
}
if ( StringUtils.isEmpty(item.getValue()) ) {
result.remove(LongClickMenuItem.copy_value);
}
return result;
}
@NotNull
@Override
protected MathEntityDescriptionGetter getDescriptionGetter() {
return new MathEntityDescriptionGetterImpl(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry());
}
@SuppressWarnings({"UnusedDeclaration"})
public void addVarButtonClickHandler(@NotNull View v) {
createEditVariableDialog(this, null, null, null, null);
}
@NotNull
@Override
protected List<IConstant> getMathEntities() {
final List<IConstant> result = new ArrayList<IConstant>(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getEntities());
CollectionsUtils.removeAll(result, new JPredicate<IConstant>() {
@Override
public boolean apply(@Nullable IConstant var) {
return var != null && CollectionsUtils.contains(var.getName(), MathType.INFINITY_JSCL, MathType.NAN);
}
});
return result;
}
@Override
protected String getMathEntityCategory(@NotNull IConstant var) {
return CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getCategory(var);
}
private static void createEditVariableDialog(@NotNull final AbstractMathEntityListFragment<IConstant> fragment,
@Nullable final IConstant var,
@Nullable final String name,
@Nullable final String value,
@Nullable final String description) {
final FragmentActivity activity = fragment.getActivity();
if (var == null || !var.isSystem()) {
final LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final View editView = layoutInflater.inflate(R.layout.var_edit, null);
final String errorMsg = fragment.getString(R.string.c_char_is_not_accepted);
final EditText editName = (EditText) editView.findViewById(R.id.var_edit_name);
editName.setText(name);
editName.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (!acceptableChars.contains(c)) {
s.delete(i, i + 1);
Toast.makeText(activity, String.format(errorMsg, c), Toast.LENGTH_SHORT).show();
}
}
}
});
final EditText editValue = (EditText) editView.findViewById(R.id.var_edit_value);
if (!StringUtils.isEmpty(value)) {
editValue.setText(value);
}
final EditText editDescription = (EditText) editView.findViewById(R.id.var_edit_description);
editDescription.setText(description);
final Var.Builder varBuilder;
if (var != null) {
varBuilder = new Var.Builder(var);
} else {
varBuilder = new Var.Builder();
}
final AlertDialog.Builder builder = new AlertDialog.Builder(activity)
.setCancelable(true)
.setNegativeButton(R.string.c_cancel, null)
.setPositiveButton(R.string.c_save, new VarEditorSaver<IConstant>(varBuilder, var, editView, fragment, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), new VarEditorSaver.EditorCreator<IConstant>() {
@Override
public void showEditor(@NotNull AbstractMathEntityListFragment<IConstant> activity, @Nullable IConstant editedInstance, @Nullable String name, @Nullable String value, @Nullable String description) {
createEditVariableDialog(activity, editedInstance, name, value, description);
}
}))
.setView(editView);
if (var != null) {
// EDIT mode
builder.setTitle(R.string.c_var_edit_var);
builder.setNeutralButton(R.string.c_remove, new MathEntityRemover<IConstant>(var, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
createEditVariableDialog(fragment, var, name, value, description);
}
}, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), fragment));
} else {
// CREATE mode
builder.setTitle(R.string.c_var_create_var);
}
builder.create().show();
} else {
Toast.makeText(activity, fragment.getString(R.string.c_sys_var_cannot_be_changed), Toast.LENGTH_LONG).show();
}
}
public static boolean isValidValue(@NotNull String value) {
// now every string might be constant
return true;
}
/*
**********************************************************************
*
* MENU
*
**********************************************************************
*/
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.var_menu, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
boolean result;
switch (item.getItemId()) {
case R.id.var_menu_add_var:
createEditVariableDialog(this, null, null, null, null);
result = true;
break;
default:
result = super.onOptionsItemSelected(item);
}
return result;
}
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
private static enum LongClickMenuItem implements LabeledMenuItem<IConstant>{
use(R.string.c_use) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(data.getName());
if (context instanceof Activity) {
((Activity) context).finish();
}
}
},
edit(R.string.c_edit) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
/*if (context instanceof AbstractMathEntityListFragment) {
createEditVariableDialog((AbstractMathEntityListFragment<IConstant>)context, data, data.getName(), StringUtils.getNotEmpty(data.getValue(), ""), data.getDescription());
}*/
}
},
remove(R.string.c_remove) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
/*if (context instanceof AbstractMathEntityListFragment) {
new MathEntityRemover<IConstant>(data, null, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), ((AbstractMathEntityListFragment<IConstant>) context)).showConfirmationDialog();
}*/
}
},
copy_value(R.string.c_copy_value) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
final String text = data.getValue();
if (!StringUtils.isEmpty(text)) {
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
clipboard.setText(text);
}
}
},
copy_description(R.string.c_copy_description) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
final String text = CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getDescription(data.getName());
if (!StringUtils.isEmpty(text)) {
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
clipboard.setText(text);
}
}
};
private final int captionId;
LongClickMenuItem(int captionId) {
this.captionId = captionId;
}
@NotNull
@Override
public String getCaption(@NotNull Context context) {
return context.getString(captionId);
}
}
}

View File

@ -1,82 +1,89 @@
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.math.edit;
import android.content.Intent;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
import org.solovyev.android.calculator.model.VarCategory;
/**
* User: serso
* Date: 12/21/11
* Time: 11:05 PM
*/
public class CalculatorVarsFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
@NotNull
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activityHelper.onCreate(this, savedInstanceState);
final Bundle bundle;
final Intent intent = getIntent();
if (intent != null) {
bundle = intent.getExtras();
} else {
bundle = null;
}
for (VarCategory category : VarCategory.getCategoriesByTabOrder()) {
if (category == VarCategory.my) {
activityHelper.addTab(this, category.name(), CalculatorHistoryFragment.class, bundle, category.getCaptionId(), R.id.main_layout);
} else {
activityHelper.addTab(this, category.name(), CalculatorHistoryFragment.class, null, category.getCaptionId(), R.id.main_layout);
}
}
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
activityHelper.onSaveInstanceState(this, outState);
}
@Override
protected void onResume() {
super.onResume();
activityHelper.onResume(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
this.activityHelper.onDestroy(this);
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
}
@Override
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
//To change body of implemented methods use File | Settings | File Templates.
}
}
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.calculator.math.edit;
import android.content.Intent;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
import org.solovyev.android.calculator.model.VarCategory;
/**
* User: serso
* Date: 12/21/11
* Time: 11:05 PM
*/
public class CalculatorVarsFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
@NotNull
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activityHelper.onCreate(this, savedInstanceState);
final Bundle bundle;
final Intent intent = getIntent();
if (intent != null) {
bundle = intent.getExtras();
} else {
bundle = null;
}
for (VarCategory category : VarCategory.getCategoriesByTabOrder()) {
final Bundle fragmentParameters;
if (category == VarCategory.my && bundle != null) {
AbstractMathEntityListFragment.putCategory(bundle, category.name());
fragmentParameters = bundle;
} else {
fragmentParameters = AbstractMathEntityListFragment.createBundleFor(category.name());
}
activityHelper.addTab(this, category.name(), CalculatorVarsFragment.class, fragmentParameters, category.getCaptionId(), R.id.main_layout);
}
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
activityHelper.onSaveInstanceState(this, outState);
}
@Override
protected void onResume() {
super.onResume();
activityHelper.onResume(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
this.activityHelper.onDestroy(this);
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
}
@Override
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
//To change body of implemented methods use File | Settings | File Templates.
}
}