changes
This commit is contained in:
parent
c8440e18a5
commit
abebb25e53
@ -15,6 +15,6 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
<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" />
|
<corners android:radius="1dp" />
|
||||||
</shape>
|
</shape>
|
@ -7,12 +7,9 @@
|
|||||||
-->
|
-->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
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:id="@+id/main_layout"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:layout_gravity="center"
|
style="?mainLayoutStyle">
|
||||||
a:background="@color/default_background">
|
|
||||||
|
|
||||||
<include layout="@layout/main_first_pane"/>
|
<include layout="@layout/main_first_pane"/>
|
||||||
|
|
||||||
|
@ -7,12 +7,9 @@
|
|||||||
-->
|
-->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
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:id="@+id/main_layout"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:background="@color/default_background"
|
style="?mainMultiPaneLayoutStyle">
|
||||||
a:baselineAligned="false">
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
a:layout_height="0dp"
|
a:layout_height="0dp"
|
||||||
@ -47,7 +44,7 @@
|
|||||||
a:layout_width="0dp"
|
a:layout_width="0dp"
|
||||||
a:layout_weight="1"
|
a:layout_weight="1"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
style="?secondPaneStyle"/>
|
style="?paneStyle"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
@ -55,6 +52,6 @@
|
|||||||
a:layout_height="0dp"
|
a:layout_height="0dp"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_weight="1"
|
a:layout_weight="1"
|
||||||
style="?fragmentLayoutStyle"/>
|
style="?paneStyleTransparent"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:id="@+id/ad_parent_view"
|
a:id="@+id/main_fragment_layout"
|
||||||
style="?fragmentLayoutStyle"
|
style="?fragmentLayoutStyle"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="match_parent">
|
a:layout_height="match_parent">
|
||||||
|
|
||||||
<TextView a:id="@+id/fragmentTitle"
|
<TextView a:id="@+id/fragmentTitle"
|
||||||
a:layout_height="wrap_content"
|
a:layout_height="wrap_content"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
style="?fragmentTitleStyle"/>
|
style="?fragmentTitleStyle"/>
|
||||||
|
|
||||||
<ListView style="?fragmentListViewStyle"/>
|
<ListView style="?fragmentListViewStyle"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -12,8 +12,7 @@
|
|||||||
a:layout_height="match_parent"
|
a:layout_height="match_parent"
|
||||||
a:id="@+id/main_layout"
|
a:id="@+id/main_layout"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:layout_gravity="center"
|
style="?mainLayoutStyle">
|
||||||
a:background="@color/default_background">
|
|
||||||
|
|
||||||
<LinearLayout a:id="@+id/editorContainer"
|
<LinearLayout a:id="@+id/editorContainer"
|
||||||
a:layout_weight="2"
|
a:layout_weight="2"
|
||||||
|
@ -8,8 +8,7 @@
|
|||||||
|
|
||||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/main_layout"
|
a:id="@+id/main_layout"
|
||||||
a:orientation="vertical"
|
style="?mainLayoutStyle"
|
||||||
a:layout_width="fill_parent"
|
a:orientation="vertical">
|
||||||
a:layout_height="fill_parent">
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
14
calculatorpp/res/layout/main_empty_multi_pane.xml
Normal file
14
calculatorpp/res/layout/main_empty_multi_pane.xml
Normal 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>
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:id="@+id/ad_parent_view"
|
a:id="@+id/main_fragment_layout"
|
||||||
style="?fragmentLayoutStyle"
|
style="?fragmentLayoutStyle"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="match_parent">
|
a:layout_height="match_parent">
|
||||||
|
17
calculatorpp/res/layout/math_entities_fragment.xml
Normal file
17
calculatorpp/res/layout/math_entities_fragment.xml
Normal 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>
|
@ -1,32 +1,31 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:id="@+id/ad_parent_view"
|
a:id="@+id/main_fragment_layout"
|
||||||
style="?fragmentLayoutStyle"
|
style="?fragmentLayoutStyle"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="match_parent">
|
a:layout_height="match_parent">
|
||||||
|
|
||||||
<TextView a:id="@+id/fragmentTitle"
|
<TextView a:id="@+id/fragmentTitle"
|
||||||
a:layout_height="wrap_content"
|
a:layout_height="wrap_content"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
style="?fragmentTitleStyle"/>
|
style="?fragmentTitleStyle"/>
|
||||||
|
|
||||||
<ListView style="?fragmentListViewStyle"/>
|
<ListView style="?fragmentListViewStyle"/>
|
||||||
|
|
||||||
<!-- todo serso: uncomment button-->
|
<!--todo serso: uncomment-->
|
||||||
<!-- <Button
|
<!--<Button
|
||||||
a:layout_width="wrap_content"
|
a:id="@+id/add_var_button"
|
||||||
a:layout_height="wrap_content"
|
a:text="@string/c_add"
|
||||||
a:layout_gravity="center_horizontal"
|
style="?buttonStyle"
|
||||||
a:text="@string/c_add"
|
a:onClick="addVarButtonClickHandler"
|
||||||
style="?buttonStyle"
|
a:layout_marginBottom="@dimen/pane_padding"/>-->
|
||||||
a:onClick="addVarButtonClickHandler"/>-->
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -1,13 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<menu xmlns:a="http://schemas.android.com/apk/res/android">
|
<menu xmlns:a="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item a:id="@+id/var_menu_add_var"
|
<item a:id="@+id/var_menu_add_var"
|
||||||
a:title="@string/c_add"/>
|
a:title="@string/c_add"
|
||||||
|
a:showAsAction="always"/>
|
||||||
</menu>
|
</menu>
|
@ -1,3 +1,3 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<dimen name="button_text_size">20dp</dimen>
|
<dimen name="keyboard_button_text_size">20dp</dimen>
|
||||||
</resources>
|
</resources>
|
@ -1,3 +1,3 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<dimen name="button_text_size">40dp</dimen>
|
<dimen name="keyboard_button_text_size">40dp</dimen>
|
||||||
</resources>
|
</resources>
|
@ -6,10 +6,12 @@
|
|||||||
<attr name="controlImageButtonStyle" format="reference" />
|
<attr name="controlImageButtonStyle" format="reference" />
|
||||||
<attr name="operationButtonStyle" format="reference" />
|
<attr name="operationButtonStyle" format="reference" />
|
||||||
<attr name="fragmentLayoutStyle" format="reference" />
|
<attr name="fragmentLayoutStyle" format="reference" />
|
||||||
<attr name="secondPaneStyle" format="reference" />
|
|
||||||
<attr name="fragmentTitleStyle" format="reference" />
|
<attr name="fragmentTitleStyle" format="reference" />
|
||||||
<attr name="fragmentListViewStyle" format="reference" />
|
<attr name="fragmentListViewStyle" format="reference" />
|
||||||
<attr name="buttonStyle" format="reference" />
|
<attr name="buttonStyle" format="reference" />
|
||||||
<attr name="paneStyle" format="reference" />
|
<attr name="paneStyle" format="reference" />
|
||||||
|
<attr name="paneStyleTransparent" format="reference" />
|
||||||
|
<attr name="mainLayoutStyle" format="reference" />
|
||||||
|
<attr name="mainMultiPaneLayoutStyle" format="reference" />
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<color name="magic_flame">#00ffffff</color>
|
<color name="magic_flame">#00ffffff</color>
|
||||||
<color name="button_text_color">#ffffffff</color>
|
<color name="button_text_color">#ffffffff</color>
|
||||||
<color name="button_operator_text_color">#ffffff99</color>
|
<color name="button_operator_text_color">#ffffff99</color>
|
||||||
<color name="button_ce_text_color">#ffffffff</color>
|
<color name="button_ce_text_color">#ffffffff</color>
|
||||||
<color name="default_text_color">#ffffffff</color>
|
<color name="default_text_color">#ffffffff</color>
|
||||||
<color name="display_error_text_color">#ff393939</color>
|
<color name="display_error_text_color">#ff393939</color>
|
||||||
<color name="selected_angle_unit_text_color">#ffffff99</color>
|
<color name="selected_angle_unit_text_color">#ffffff99</color>
|
||||||
<color name="default_background">#ff000000</color>
|
<color name="default_background">#ff000000</color>
|
||||||
<color name="second_pane_background">#ff1f1f1f</color>
|
<color name="pane_background">#ff1f1f1f</color>
|
||||||
<color name="metro_button_background">#ff1f1f1f</color>
|
<color name="metro_button_background">#ff1f1f1f</color>
|
||||||
</resources>
|
</resources>
|
@ -1,7 +1,10 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<dimen name="button_margin">0.5dp</dimen>
|
<dimen name="button_margin">0.5dp</dimen>
|
||||||
<dimen name="text_size">20sp</dimen>
|
<dimen name="text_size">20sp</dimen>
|
||||||
<dimen name="button_text_size">30dp</dimen>
|
<dimen name="keyboard_button_text_size">30dp</dimen>
|
||||||
<dimen name="display_text_size">25sp</dimen>
|
<dimen name="button_text_size">20dp</dimen>
|
||||||
<dimen name="editor_text_size">25sp</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>
|
</resources>
|
@ -1,30 +1,27 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="math_entity_text" parent="math_entity_text_parent">
|
<style name="math_entity_text" parent="math_entity_text_parent">
|
||||||
<item name="android:paddingTop">6dp</item>
|
<item name="android:paddingTop">0dp</item>
|
||||||
<item name="android:paddingLeft">6dp</item>
|
<item name="android:paddingLeft">0dp</item>
|
||||||
<item name="android:paddingRight">6dp</item>
|
<item name="android:paddingRight">0dp</item>
|
||||||
<item name="android:paddingBottom">0dp</item>
|
<item name="android:paddingBottom">@dimen/pane_padding</item>
|
||||||
<item name="android:textStyle">bold</item>
|
<item name="android:textStyle">bold</item>
|
||||||
<item name="android:textColor">@android:color/white</item>
|
<item name="android:textColor">@android:color/white</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="math_entity_description" parent="math_entity_description_parent">
|
<style name="math_entity_description" parent="math_entity_description_parent">
|
||||||
<item name="android:paddingTop">0dp</item>
|
<item name="android:padding">0dp</item>
|
||||||
<item name="android:paddingLeft">6dp</item>
|
<item name="android:textColor">#bebebe</item>
|
||||||
<item name="android:paddingRight">6dp</item>
|
</style>
|
||||||
<item name="android:paddingBottom">0dp</item>
|
|
||||||
<item name="android:textColor">#bebebe</item>
|
<style name="add_var_button" parent="add_var_button_parent">
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="add_var_button" parent="add_var_button_parent">
|
|
||||||
</style>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -8,13 +8,20 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="button_style" parent="button_style_parent">
|
<style name="button_style" parent="button_style_parent">
|
||||||
<item name="android:layout_width">fill_parent</item>
|
<item name="android:layout_width">wrap_content</item>
|
||||||
<item name="android:layout_height">fill_parent</item>
|
<item name="android:layout_height">wrap_content</item>
|
||||||
<item name="android:layout_weight">1</item>
|
|
||||||
<item name="android:focusable">true</item>
|
<item name="android:focusable">true</item>
|
||||||
<item name="android:background">@drawable/default_button_dark</item>
|
<item name="android:background">@drawable/metro_button_blue</item>
|
||||||
<item name="android:layout_margin">@dimen/button_margin</item>
|
</style>
|
||||||
</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">
|
<style name="editor_style" parent="editor_style_parent">
|
||||||
<item name="android:gravity">left|top</item>
|
<item name="android:gravity">left|top</item>
|
||||||
|
@ -6,62 +6,91 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<style name="default_digit_button_style" parent="button_style">
|
<style name="default_digit_button_style" parent="keyboard_button_style">
|
||||||
<item name="android:background">@drawable/default_button</item>
|
<item name="android:background">@drawable/default_button</item>
|
||||||
</style>
|
</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">
|
<style name="default_operation_button_style" parent="default_digit_button_style">
|
||||||
<item name="android:textColor">@color/button_operator_text_color</item>
|
<item name="android:textColor">@color/button_operator_text_color</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="default_control_image_button_style" parent="default_control_button_style">
|
<style name="default_control_image_button_style" parent="default_control_button_style">
|
||||||
<item name="android:padding">6dp</item>
|
<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>
|
</style>
|
||||||
|
|
||||||
<style name="default_fragment_list_view_style">
|
<style name="default_fragment_list_view_style">
|
||||||
<item name="android:id">@android:id/list</item>
|
<item name="android:id">@android:id/list</item>
|
||||||
<item name="android:divider">@null</item>
|
<item name="android:divider">@null</item>
|
||||||
<item name="android:dividerHeight">0dp</item>
|
<item name="android:dividerHeight">0dp</item>
|
||||||
<item name="android:cacheColorHint">@android:color/transparent</item>
|
<item name="android:cacheColorHint">@android:color/transparent</item>
|
||||||
<item name="android:layout_height">match_parent</item>
|
<item name="android:layout_height">match_parent</item>
|
||||||
<item name="android:layout_width">match_parent</item>
|
<item name="android:layout_width">match_parent</item>
|
||||||
<item name="android:layout_weight">1</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>
|
||||||
|
|
||||||
<style name="default_fragment_title_style">
|
<style name="default_fragment_title_style">
|
||||||
<item name="android:textColor">@android:color/white</item>
|
<item name="android:textColor">@android:color/white</item>
|
||||||
<item name="android:textSize">25sp</item>
|
<item name="android:textSize">25sp</item>
|
||||||
<item name="android:layout_marginLeft">6dp</item>
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="default_button_style" parent="button_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>
|
||||||
|
|
||||||
<style name="default_fragment_layout_style">
|
<style name="default_fragment_layout_style">
|
||||||
<item name="android:layout_marginBottom">0dp</item>
|
<item name="android:layout_margin">0dp</item>
|
||||||
<item name="android:layout_marginTop">5dp</item>
|
<item name="android:padding">0dp</item>
|
||||||
<item name="android:layout_marginLeft">5dp</item>
|
|
||||||
<item name="android:layout_marginRight">0dp</item>
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="default_theme" parent="Theme.Sherlock">
|
<style name="default_main_layout_style">
|
||||||
<item name="digitButtonStyle">@style/default_digit_button_style</item>
|
<item name="android:background">@color/default_background</item>
|
||||||
<item name="controlButtonStyle">@style/default_control_button_style</item>
|
<item name="android:baselineAligned">false</item>
|
||||||
<item name="controlImageButtonStyle">@style/default_control_image_button_style</item>
|
<item name="android:layout_height">match_parent</item>
|
||||||
<item name="operationButtonStyle">@style/default_operation_button_style</item>
|
<item name="android:layout_width">match_parent</item>
|
||||||
<item name="fragmentLayoutStyle">@style/default_fragment_layout_style</item>
|
</style>
|
||||||
<item name="paneStyle">@style/default_pane_style</item>
|
|
||||||
<item name="secondPaneStyle">@style/default_pane_style</item>
|
<style name="default_theme" parent="Theme.Sherlock">
|
||||||
<item name="fragmentTitleStyle">@style/default_fragment_title_style</item>
|
<item name="digitButtonStyle">@style/default_digit_button_style</item>
|
||||||
<item name="fragmentListViewStyle">@style/default_fragment_list_view_style</item>
|
<item name="controlButtonStyle">@style/default_control_button_style</item>
|
||||||
<item name="buttonStyle">@style/default_button_style</item>
|
<item name="controlImageButtonStyle">@style/default_control_image_button_style</item>
|
||||||
</style>
|
<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>
|
</resources>
|
@ -1,33 +1,33 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="light_blue_digit_button_style" parent="button_style">
|
<style name="light_blue_digit_button_style" parent="keyboard_button_style">
|
||||||
<item name="android:background">@drawable/blue_button</item>
|
<item name="android:background">@drawable/blue_button</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="light_blue_control_button_style" parent="button_style">
|
<style name="light_blue_control_button_style" parent="keyboard_button_style">
|
||||||
<item name="android:background">@drawable/blue_button_dark</item>
|
<item name="android:background">@drawable/blue_button_dark</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="light_blue_operation_button_style" parent="light_blue_digit_button_style">
|
<style name="light_blue_operation_button_style" parent="light_blue_digit_button_style">
|
||||||
<item name="android:textColor">@color/button_operator_text_color</item>
|
<item name="android:textColor">@color/button_operator_text_color</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="light_blue_control_image_button_style" parent="light_blue_control_button_style">
|
<style name="light_blue_control_image_button_style" parent="light_blue_control_button_style">
|
||||||
<item name="android:padding">6dp</item>
|
<item name="android:padding">6dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="light_blue_theme" parent="default_theme">
|
<style name="light_blue_theme" parent="default_theme">
|
||||||
<item name="digitButtonStyle">@style/light_blue_digit_button_style</item>
|
<item name="digitButtonStyle">@style/light_blue_digit_button_style</item>
|
||||||
<item name="controlButtonStyle">@style/light_blue_control_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="controlImageButtonStyle">@style/light_blue_control_image_button_style</item>
|
||||||
<item name="operationButtonStyle">@style/light_blue_operation_button_style</item>
|
<item name="operationButtonStyle">@style/light_blue_operation_button_style</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -1,26 +1,26 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="metro_digit_button_style" parent="button_style">
|
<style name="metro_digit_button_style" parent="keyboard_button_style">
|
||||||
<item name="android:background">@drawable/metro_button_dark</item>
|
<item name="android:background">@drawable/metro_button_dark</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_control_button_style" parent="metro_digit_button_style">
|
<style name="metro_control_button_style" parent="metro_digit_button_style">
|
||||||
<item name="android:background">@drawable/metro_button_light</item>
|
<item name="android:background">@drawable/metro_button_light</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_blue_operation_button_style" parent="metro_digit_button_style">
|
<style name="metro_blue_operation_button_style" parent="metro_digit_button_style">
|
||||||
<item name="android:background">@drawable/metro_button_blue</item>
|
<item name="android:background">@drawable/metro_button_blue</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_control_image_button_style" parent="metro_control_button_style">
|
<style name="metro_control_image_button_style" parent="metro_control_button_style">
|
||||||
<item name="android:padding">6dp</item>
|
<item name="android:padding">6dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_blue_theme" parent="default_theme">
|
<style name="metro_blue_theme" parent="default_theme">
|
||||||
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
|
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
|
||||||
<item name="controlButtonStyle">@style/metro_control_button_style</item>
|
<item name="controlButtonStyle">@style/metro_control_button_style</item>
|
||||||
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
|
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
|
||||||
<item name="operationButtonStyle">@style/metro_blue_operation_button_style</item>
|
<item name="operationButtonStyle">@style/metro_blue_operation_button_style</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -1,26 +1,26 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="metro_digit_button_style" parent="button_style">
|
<style name="metro_digit_button_style" parent="keyboard_button_style">
|
||||||
<item name="android:background">@drawable/metro_button_dark</item>
|
<item name="android:background">@drawable/metro_button_dark</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_control_button_style" parent="metro_digit_button_style">
|
<style name="metro_control_button_style" parent="metro_digit_button_style">
|
||||||
<item name="android:background">@drawable/metro_button_light</item>
|
<item name="android:background">@drawable/metro_button_light</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_green_operation_button_style" parent="metro_digit_button_style">
|
<style name="metro_green_operation_button_style" parent="metro_digit_button_style">
|
||||||
<item name="android:background">@drawable/metro_button_green</item>
|
<item name="android:background">@drawable/metro_button_green</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_control_image_button_style" parent="metro_control_button_style">
|
<style name="metro_control_image_button_style" parent="metro_control_button_style">
|
||||||
<item name="android:padding">6dp</item>
|
<item name="android:padding">6dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_green_theme" parent="default_theme">
|
<style name="metro_green_theme" parent="default_theme">
|
||||||
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
|
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
|
||||||
<item name="controlButtonStyle">@style/metro_control_button_style</item>
|
<item name="controlButtonStyle">@style/metro_control_button_style</item>
|
||||||
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
|
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
|
||||||
<item name="operationButtonStyle">@style/metro_green_operation_button_style</item>
|
<item name="operationButtonStyle">@style/metro_green_operation_button_style</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -1,26 +1,26 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="metro_digit_button_style" parent="button_style">
|
<style name="metro_digit_button_style" parent="keyboard_button_style">
|
||||||
<item name="android:background">@drawable/metro_button_dark</item>
|
<item name="android:background">@drawable/metro_button_dark</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_control_button_style" parent="metro_digit_button_style">
|
<style name="metro_control_button_style" parent="metro_digit_button_style">
|
||||||
<item name="android:background">@drawable/metro_button_light</item>
|
<item name="android:background">@drawable/metro_button_light</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_purple_operation_button_style" parent="metro_digit_button_style">
|
<style name="metro_purple_operation_button_style" parent="metro_digit_button_style">
|
||||||
<item name="android:background">@drawable/metro_button_purple</item>
|
<item name="android:background">@drawable/metro_button_purple</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_control_image_button_style" parent="metro_control_button_style">
|
<style name="metro_control_image_button_style" parent="metro_control_button_style">
|
||||||
<item name="android:padding">6dp</item>
|
<item name="android:padding">6dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_purple_theme" parent="default_theme">
|
<style name="metro_purple_theme" parent="default_theme">
|
||||||
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
|
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
|
||||||
<item name="controlButtonStyle">@style/metro_control_button_style</item>
|
<item name="controlButtonStyle">@style/metro_control_button_style</item>
|
||||||
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
|
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
|
||||||
<item name="operationButtonStyle">@style/metro_purple_operation_button_style</item>
|
<item name="operationButtonStyle">@style/metro_purple_operation_button_style</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -1,31 +1,31 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<style name="violet_digit_button_style" parent="button_style">
|
<style name="violet_digit_button_style" parent="keyboard_button_style">
|
||||||
<item name="android:background">@drawable/violet_button</item>
|
<item name="android:background">@drawable/violet_button</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="violet_operation_button_style" parent="violet_digit_button_style">
|
<style name="violet_operation_button_style" parent="violet_digit_button_style">
|
||||||
<item name="android:textColor">@color/button_operator_text_color</item>
|
<item name="android:textColor">@color/button_operator_text_color</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="violet_control_button_style" parent="button_style">
|
<style name="violet_control_button_style" parent="keyboard_button_style">
|
||||||
<item name="android:background">@drawable/violet_button_dark</item>
|
<item name="android:background">@drawable/violet_button_dark</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="violet_control_image_button_style" parent="violet_control_button_style">
|
<style name="violet_control_image_button_style" parent="violet_control_button_style">
|
||||||
<item name="android:padding">6dp</item>
|
<item name="android:padding">6dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="violet_theme" parent="default_theme">
|
<style name="violet_theme" parent="default_theme">
|
||||||
<item name="digitButtonStyle">@style/violet_digit_button_style</item>
|
<item name="digitButtonStyle">@style/violet_digit_button_style</item>
|
||||||
<item name="controlButtonStyle">@style/violet_control_button_style</item>
|
<item name="controlButtonStyle">@style/violet_control_button_style</item>
|
||||||
<item name="controlImageButtonStyle">@style/violet_control_image_button_style</item>
|
<item name="controlImageButtonStyle">@style/violet_control_image_button_style</item>
|
||||||
<item name="operationButtonStyle">@style/violet_operation_button_style</item>
|
<item name="operationButtonStyle">@style/violet_operation_button_style</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
@ -1,60 +1,65 @@
|
|||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="WindowTitle">
|
<style name="WindowTitle">
|
||||||
<item name="android:singleLine">true</item>
|
<item name="android:singleLine">true</item>
|
||||||
<item name="android:textAppearance">@style/TextAppearance_WindowTitle</item>
|
<item name="android:textAppearance">@style/TextAppearance_WindowTitle</item>
|
||||||
<item name="android:shadowColor">#BB000000</item>
|
<item name="android:shadowColor">#BB000000</item>
|
||||||
<item name="android:shadowRadius">2.75</item>
|
<item name="android:shadowRadius">2.75</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="TextAppearance_WindowTitle">
|
<style name="TextAppearance_WindowTitle">
|
||||||
<item name="android:textColor">#fff</item>
|
<item name="android:textColor">#fff</item>
|
||||||
<item name="android:textSize">14sp</item>
|
<item name="android:textSize">14sp</item>
|
||||||
<item name="android:textStyle">bold</item>
|
<item name="android:textStyle">bold</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
||||||
<style name="default_text_size">
|
<style name="default_text_size">
|
||||||
<item name="android:textSize">@dimen/text_size</item>
|
<item name="android:textSize">@dimen/text_size</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="button_style_parent">
|
<style name="keyboard_button_style_parent">
|
||||||
<item name="android:textSize">@dimen/button_text_size</item>
|
<item name="android:textSize">@dimen/keyboard_button_text_size</item>
|
||||||
<item name="android:textColor">@color/button_text_color</item>
|
<item name="android:textColor">@color/button_text_color</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="display_style_parent" parent="default_text">
|
<style name="button_style_parent">
|
||||||
<item name="android:textSize">@dimen/display_text_size</item>
|
<item name="android:textSize">@dimen/button_text_size</item>
|
||||||
<item name="android:padding">3dp</item>
|
<item name="android:textColor">@color/button_text_color</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="editor_style_parent" parent="default_text">
|
<style name="display_style_parent" parent="default_text">
|
||||||
<item name="android:textSize">@dimen/editor_text_size</item>
|
<item name="android:textSize">@dimen/display_text_size</item>
|
||||||
<item name="android:padding">5dp</item>
|
<item name="android:padding">3dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="about_style_parent" parent="default_text">
|
<style name="editor_style_parent" parent="default_text">
|
||||||
<item name="android:textSize">15dp</item>
|
<item name="android:textSize">@dimen/editor_text_size</item>
|
||||||
<item name="android:padding">5dp</item>
|
<item name="android:padding">5dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="math_entity_text_parent">
|
<style name="about_style_parent" parent="default_text">
|
||||||
<item name="android:textSize">20dp</item>
|
<item name="android:textSize">15dp</item>
|
||||||
</style>
|
<item name="android:padding">5dp</item>
|
||||||
|
</style>
|
||||||
<style name="math_entity_description_parent">
|
|
||||||
<item name="android:textSize">15dp</item>
|
<style name="math_entity_text_parent">
|
||||||
</style>
|
<item name="android:textSize">20dp</item>
|
||||||
|
</style>
|
||||||
<style name="add_var_button_parent">
|
|
||||||
<item name="android:paddingLeft">40dp</item>
|
<style name="math_entity_description_parent">
|
||||||
<item name="android:paddingRight">40dp</item>
|
<item name="android:textSize">15dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="add_var_button_parent">
|
||||||
|
<item name="android:paddingLeft">40dp</item>
|
||||||
|
<item name="android:paddingRight">40dp</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -17,6 +17,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.solovyev.android.calculator.text.TextProcessor;
|
import org.solovyev.android.calculator.text.TextProcessor;
|
||||||
import org.solovyev.android.calculator.view.TextHighlighter;
|
import org.solovyev.android.calculator.view.TextHighlighter;
|
||||||
import org.solovyev.android.view.AutoResizeTextView;
|
import org.solovyev.android.view.AutoResizeTextView;
|
||||||
|
import org.solovyev.common.text.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
|
@ -1,354 +1,352 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import net.robotmedia.billing.BillingController;
|
import net.robotmedia.billing.BillingController;
|
||||||
import net.robotmedia.billing.IBillingObserver;
|
import net.robotmedia.billing.IBillingObserver;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.AndroidUtils;
|
import org.solovyev.android.AndroidUtils;
|
||||||
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
||||||
import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
|
import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
|
||||||
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment;
|
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment;
|
||||||
import org.solovyev.android.calculator.math.edit.CalculatorOperatorsFragment;
|
import org.solovyev.android.calculator.math.edit.CalculatorOperatorsFragment;
|
||||||
import org.solovyev.android.calculator.math.edit.CalculatorVarsFragment;
|
import org.solovyev.android.calculator.math.edit.CalculatorVarsFragment;
|
||||||
import org.solovyev.android.fragments.FragmentUtils;
|
import org.solovyev.android.fragments.FragmentUtils;
|
||||||
import org.solovyev.android.prefs.Preference;
|
import org.solovyev.android.prefs.Preference;
|
||||||
import org.solovyev.android.view.ColorButton;
|
import org.solovyev.android.view.ColorButton;
|
||||||
import org.solovyev.common.equals.EqualsTool;
|
import org.solovyev.common.equals.EqualsTool;
|
||||||
import org.solovyev.common.history.HistoryAction;
|
import org.solovyev.common.history.HistoryAction;
|
||||||
import org.solovyev.common.text.StringUtils;
|
import org.solovyev.common.text.StringUtils;
|
||||||
|
|
||||||
public class CalculatorActivity extends SherlockFragmentActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class CalculatorActivity extends SherlockFragmentActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static final String TAG = CalculatorActivity.class.getSimpleName();
|
public static final String TAG = CalculatorActivity.class.getSimpleName();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private IBillingObserver billingObserver;
|
private IBillingObserver billingObserver;
|
||||||
|
|
||||||
private boolean useBackAsPrev;
|
private boolean useBackAsPrev;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorActivityHelper activityHelper;
|
private CalculatorActivityHelper activityHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the activity is first created.
|
* Called when the activity is first created.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
|
||||||
CalculatorApplication.registerOnRemoteStackTrace();
|
CalculatorApplication.registerOnRemoteStackTrace();
|
||||||
|
|
||||||
/*final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);*/
|
/*final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);*/
|
||||||
|
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
||||||
|
|
||||||
activityHelper = CalculatorApplication.getInstance().createActivityHelper(layout.getLayoutId(), TAG);
|
activityHelper = CalculatorApplication.getInstance().createActivityHelper(layout.getLayoutId(), TAG);
|
||||||
activityHelper.logDebug("onCreate");
|
activityHelper.logDebug("onCreate");
|
||||||
activityHelper.onCreate(this, savedInstanceState);
|
activityHelper.onCreate(this, savedInstanceState);
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
activityHelper.logDebug("super.onCreate");
|
activityHelper.logDebug("super.onCreate");
|
||||||
|
|
||||||
if (findViewById(R.id.main_second_pane) != null) {
|
if (findViewById(R.id.main_second_pane) != null) {
|
||||||
activityHelper.addTab(this, "history", CalculatorHistoryFragment.class, null, R.string.c_history, R.id.main_second_pane);
|
activityHelper.addTab(this, "history", CalculatorHistoryFragment.class, null, R.string.c_history, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, "saved_history", CalculatorSavedHistoryFragment.class, null, R.string.c_saved_history, R.id.main_second_pane);
|
activityHelper.addTab(this, "saved_history", CalculatorSavedHistoryFragment.class, null, R.string.c_saved_history, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, "vars", CalculatorVarsFragment.class, null, R.string.c_vars, R.id.main_second_pane);
|
activityHelper.addTab(this, "vars", CalculatorVarsFragment.class, null, R.string.c_vars, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, "functions", CalculatorFunctionsFragment.class, null, R.string.c_functions, R.id.main_second_pane);
|
activityHelper.addTab(this, "functions", CalculatorFunctionsFragment.class, null, R.string.c_functions, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, "operators", CalculatorOperatorsFragment.class, null, R.string.c_operators, R.id.main_second_pane);
|
activityHelper.addTab(this, "operators", CalculatorOperatorsFragment.class, null, R.string.c_operators, R.id.main_second_pane);
|
||||||
|
|
||||||
activityHelper.restoreSavedTab(this);
|
activityHelper.restoreSavedTab(this);
|
||||||
} else {
|
} else {
|
||||||
getSupportActionBar().hide();
|
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, CalculatorEditorFragment.class, R.id.editorContainer, "editor");
|
FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
|
||||||
FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display");
|
|
||||||
FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
|
/*if (customTitleSupported) {
|
||||||
|
try {
|
||||||
/*if (customTitleSupported) {
|
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title);
|
||||||
try {
|
final CalculatorAdditionalTitle additionalAdditionalTitleText = (CalculatorAdditionalTitle)findViewById(R.id.additional_title_text);
|
||||||
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title);
|
additionalAdditionalTitleText.init(preferences);
|
||||||
final CalculatorAdditionalTitle additionalAdditionalTitleText = (CalculatorAdditionalTitle)findViewById(R.id.additional_title_text);
|
preferences.registerOnSharedPreferenceChangeListener(additionalAdditionalTitleText);
|
||||||
additionalAdditionalTitleText.init(preferences);
|
} catch (ClassCastException e) {
|
||||||
preferences.registerOnSharedPreferenceChangeListener(additionalAdditionalTitleText);
|
// super fix for issue with class cast in android.view.Window.setFeatureInt() (see app error reports)
|
||||||
} catch (ClassCastException e) {
|
Log.e(CalculatorActivity.class.getName(), e.getMessage(), 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);
|
||||||
billingObserver = new CalculatorBillingObserver(this);
|
|
||||||
BillingController.registerObserver(billingObserver);
|
this.useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
|
||||||
|
firstTimeInit(preferences, this);
|
||||||
this.useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
|
|
||||||
firstTimeInit(preferences, this);
|
// init billing controller
|
||||||
|
BillingController.checkBillingSupported(this);
|
||||||
// init billing controller
|
|
||||||
BillingController.checkBillingSupported(this);
|
toggleOrientationChange(preferences);
|
||||||
|
|
||||||
toggleOrientationChange(preferences);
|
CalculatorButtons.toggleEqualsButton(preferences, this, activityHelper.getTheme(), findViewById(R.id.main_layout));
|
||||||
|
|
||||||
CalculatorButtons.toggleEqualsButton(preferences, this, activityHelper.getTheme(), findViewById(R.id.main_layout));
|
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
|
||||||
}
|
@NotNull
|
||||||
|
private AndroidCalculator getCalculator() {
|
||||||
@NotNull
|
return ((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator());
|
||||||
private AndroidCalculator getCalculator() {
|
}
|
||||||
return ((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator());
|
|
||||||
}
|
private static void firstTimeInit(@NotNull SharedPreferences preferences, @NotNull Context context) {
|
||||||
|
final Integer appOpenedCounter = CalculatorPreferences.appOpenedCounter.getPreference(preferences);
|
||||||
private static void firstTimeInit(@NotNull SharedPreferences preferences, @NotNull Context context) {
|
if (appOpenedCounter != null) {
|
||||||
final Integer appOpenedCounter = CalculatorPreferences.appOpenedCounter.getPreference(preferences);
|
CalculatorPreferences.appOpenedCounter.putPreference(preferences, appOpenedCounter + 1);
|
||||||
if (appOpenedCounter != null) {
|
}
|
||||||
CalculatorPreferences.appOpenedCounter.putPreference(preferences, appOpenedCounter + 1);
|
|
||||||
}
|
final Integer savedVersion = CalculatorPreferences.appVersion.getPreference(preferences);
|
||||||
|
|
||||||
final Integer savedVersion = CalculatorPreferences.appVersion.getPreference(preferences);
|
final int appVersion = AndroidUtils.getAppVersionCode(context, CalculatorActivity.class.getPackage().getName());
|
||||||
|
|
||||||
final int appVersion = AndroidUtils.getAppVersionCode(context, CalculatorActivity.class.getPackage().getName());
|
CalculatorPreferences.appVersion.putPreference(preferences, appVersion);
|
||||||
|
|
||||||
CalculatorPreferences.appVersion.putPreference(preferences, appVersion);
|
boolean dialogShown = false;
|
||||||
|
if (EqualsTool.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
|
||||||
boolean dialogShown = false;
|
// new start
|
||||||
if (EqualsTool.areEqual(savedVersion, CalculatorPreferences.appVersion.getDefaultValue())) {
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(R.string.c_first_start_text);
|
||||||
// new start
|
builder.setPositiveButton(android.R.string.ok, null);
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(R.string.c_first_start_text);
|
builder.setTitle(R.string.c_first_start_text_title);
|
||||||
builder.setPositiveButton(android.R.string.ok, null);
|
builder.create().show();
|
||||||
builder.setTitle(R.string.c_first_start_text_title);
|
dialogShown = true;
|
||||||
builder.create().show();
|
} else {
|
||||||
dialogShown = true;
|
if (savedVersion < appVersion) {
|
||||||
} else {
|
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
|
||||||
if (savedVersion < appVersion) {
|
if (showReleaseNotes) {
|
||||||
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
|
final String releaseNotes = CalculatorReleaseNotesActivity.getReleaseNotes(context, savedVersion + 1);
|
||||||
if (showReleaseNotes) {
|
if (!StringUtils.isEmpty(releaseNotes)) {
|
||||||
final String releaseNotes = CalculatorReleaseNotesActivity.getReleaseNotes(context, savedVersion + 1);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
|
||||||
if (!StringUtils.isEmpty(releaseNotes)) {
|
builder.setPositiveButton(android.R.string.ok, null);
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
|
builder.setTitle(R.string.c_release_notes);
|
||||||
builder.setPositiveButton(android.R.string.ok, null);
|
builder.create().show();
|
||||||
builder.setTitle(R.string.c_release_notes);
|
dialogShown = true;
|
||||||
builder.create().show();
|
}
|
||||||
dialogShown = true;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
//Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!");
|
||||||
|
if (!dialogShown) {
|
||||||
//Log.d(this.getClass().getName(), "Application was opened " + appOpenedCounter + " time!");
|
if (appOpenedCounter != null && appOpenedCounter > 10) {
|
||||||
if (!dialogShown) {
|
dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.feedbackWindowShown, R.layout.feedback, R.id.feedbackText, context);
|
||||||
if (appOpenedCounter != null && appOpenedCounter > 10) {
|
}
|
||||||
dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.feedbackWindowShown, R.layout.feedback, R.id.feedbackText, context);
|
}
|
||||||
}
|
|
||||||
}
|
if (!dialogShown) {
|
||||||
|
dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.notesppAnnounceShown, R.layout.notespp_announce, R.id.notespp_announce, context);
|
||||||
if (!dialogShown) {
|
}
|
||||||
dialogShown = showSpecialWindow(preferences, CalculatorPreferences.Gui.notesppAnnounceShown, R.layout.notespp_announce, R.id.notespp_announce, context);
|
}
|
||||||
}
|
|
||||||
}
|
private static boolean showSpecialWindow(@NotNull SharedPreferences preferences, @NotNull Preference<Boolean> specialWindowShownPref, int layoutId, int textViewId, @NotNull Context context) {
|
||||||
|
boolean result = false;
|
||||||
private static boolean showSpecialWindow(@NotNull SharedPreferences preferences, @NotNull Preference<Boolean> specialWindowShownPref, int layoutId, int textViewId, @NotNull Context context) {
|
|
||||||
boolean result = false;
|
final Boolean specialWindowShown = specialWindowShownPref.getPreference(preferences);
|
||||||
|
if ( specialWindowShown != null && !specialWindowShown ) {
|
||||||
final Boolean specialWindowShown = specialWindowShownPref.getPreference(preferences);
|
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||||
if ( specialWindowShown != null && !specialWindowShown ) {
|
final View view = layoutInflater.inflate(layoutId, null);
|
||||||
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
|
|
||||||
final View view = layoutInflater.inflate(layoutId, null);
|
final TextView feedbackTextView = (TextView) view.findViewById(textViewId);
|
||||||
|
feedbackTextView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
final TextView feedbackTextView = (TextView) view.findViewById(textViewId);
|
|
||||||
feedbackTextView.setMovementMethod(LinkMovementMethod.getInstance());
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setView(view);
|
||||||
|
builder.setPositiveButton(android.R.string.ok, null);
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setView(view);
|
builder.create().show();
|
||||||
builder.setPositiveButton(android.R.string.ok, null);
|
|
||||||
builder.create().show();
|
result = true;
|
||||||
|
specialWindowShownPref.putPreference(preferences, true);
|
||||||
result = true;
|
}
|
||||||
specialWindowShownPref.putPreference(preferences, true);
|
|
||||||
}
|
return result;
|
||||||
|
}
|
||||||
return result;
|
|
||||||
}
|
@Override
|
||||||
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
@Override
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
if (useBackAsPrev) {
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
getCalculator().doHistoryAction(HistoryAction.undo);
|
||||||
if (useBackAsPrev) {
|
return true;
|
||||||
getCalculator().doHistoryAction(HistoryAction.undo);
|
}
|
||||||
return true;
|
}
|
||||||
}
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event);
|
|
||||||
}
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void equalsButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
getCalculator().evaluate();
|
||||||
public void equalsButtonClickHandler(@NotNull View v) {
|
}
|
||||||
getCalculator().evaluate();
|
|
||||||
}
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
@Override
|
super.onResume();
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences);
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
if ( newLayout.getLayoutId() != activityHelper.getLayoutId() ) {
|
||||||
final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences);
|
AndroidUtils.restartActivity(this);
|
||||||
if ( newLayout.getLayoutId() != activityHelper.getLayoutId() ) {
|
}
|
||||||
AndroidUtils.restartActivity(this);
|
|
||||||
}
|
this.activityHelper.onResume(this);
|
||||||
|
}
|
||||||
this.activityHelper.onResume(this);
|
|
||||||
}
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
@Override
|
if (billingObserver != null) {
|
||||||
protected void onDestroy() {
|
BillingController.unregisterObserver(billingObserver);
|
||||||
if (billingObserver != null) {
|
}
|
||||||
BillingController.unregisterObserver(billingObserver);
|
|
||||||
}
|
activityHelper.onDestroy(this);
|
||||||
|
|
||||||
activityHelper.onDestroy(this);
|
super.onDestroy();
|
||||||
|
}
|
||||||
super.onDestroy();
|
|
||||||
}
|
@Override
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
|
||||||
@Override
|
if ( CalculatorPreferences.Gui.usePrevAsBack.getKey().equals(key) ) {
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
|
useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
|
||||||
if ( CalculatorPreferences.Gui.usePrevAsBack.getKey().equals(key) ) {
|
}
|
||||||
useBackAsPrev = CalculatorPreferences.Gui.usePrevAsBack.getPreference(preferences);
|
|
||||||
}
|
if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) {
|
||||||
|
toggleOrientationChange(preferences);
|
||||||
if ( CalculatorPreferences.Gui.autoOrientation.getKey().equals(key) ) {
|
}
|
||||||
toggleOrientationChange(preferences);
|
}
|
||||||
}
|
|
||||||
}
|
@Override
|
||||||
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
@Override
|
super.onSaveInstanceState(outState);
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
activityHelper.onSaveInstanceState(this, outState);
|
||||||
|
}
|
||||||
activityHelper.onSaveInstanceState(this, outState);
|
|
||||||
}
|
private void toggleOrientationChange(@Nullable SharedPreferences preferences) {
|
||||||
|
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(this) : preferences;
|
||||||
private void toggleOrientationChange(@Nullable SharedPreferences preferences) {
|
if (CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
|
||||||
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(this) : preferences;
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||||
if (CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
|
} else {
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
} else {
|
}
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
}
|
||||||
}
|
|
||||||
}
|
/*
|
||||||
|
**********************************************************************
|
||||||
/*
|
*
|
||||||
**********************************************************************
|
* BUTTON HANDLERS
|
||||||
*
|
*
|
||||||
* BUTTON HANDLERS
|
**********************************************************************
|
||||||
*
|
*/
|
||||||
**********************************************************************
|
|
||||||
*/
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void elementaryButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
throw new UnsupportedOperationException("Not implemented yet!");
|
||||||
public void elementaryButtonClickHandler(@NotNull View v) {
|
}
|
||||||
throw new UnsupportedOperationException("Not implemented yet!");
|
|
||||||
}
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void historyButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
CalculatorActivityLauncher.showHistory(this);
|
||||||
public void historyButtonClickHandler(@NotNull View v) {
|
}
|
||||||
CalculatorActivityLauncher.showHistory(this);
|
|
||||||
}
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void eraseButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
CalculatorLocatorImpl.getInstance().getEditor().erase();
|
||||||
public void eraseButtonClickHandler(@NotNull View v) {
|
}
|
||||||
CalculatorLocatorImpl.getInstance().getEditor().erase();
|
|
||||||
}
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void simplifyButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
throw new UnsupportedOperationException("Not implemented yet!");
|
||||||
public void simplifyButtonClickHandler(@NotNull View v) {
|
}
|
||||||
throw new UnsupportedOperationException("Not implemented yet!");
|
|
||||||
}
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void moveLeftButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
getKeyboard().moveCursorLeft();
|
||||||
public void moveLeftButtonClickHandler(@NotNull View v) {
|
}
|
||||||
getKeyboard().moveCursorLeft();
|
|
||||||
}
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void moveRightButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
getKeyboard().moveCursorRight();
|
||||||
public void moveRightButtonClickHandler(@NotNull View v) {
|
}
|
||||||
getKeyboard().moveCursorRight();
|
|
||||||
}
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void pasteButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
getKeyboard().pasteButtonPressed();
|
||||||
public void pasteButtonClickHandler(@NotNull View v) {
|
}
|
||||||
getKeyboard().pasteButtonPressed();
|
|
||||||
}
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void copyButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
getKeyboard().copyButtonPressed();
|
||||||
public void copyButtonClickHandler(@NotNull View v) {
|
}
|
||||||
getKeyboard().copyButtonPressed();
|
|
||||||
}
|
@NotNull
|
||||||
|
private static CalculatorKeyboard getKeyboard() {
|
||||||
@NotNull
|
return CalculatorLocatorImpl.getInstance().getKeyboard();
|
||||||
private static CalculatorKeyboard getKeyboard() {
|
}
|
||||||
return CalculatorLocatorImpl.getInstance().getKeyboard();
|
|
||||||
}
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void clearButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
getKeyboard().clearButtonPressed();
|
||||||
public void clearButtonClickHandler(@NotNull View v) {
|
}
|
||||||
getKeyboard().clearButtonPressed();
|
|
||||||
}
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void digitButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
Log.d(String.valueOf(v.getId()), "digitButtonClickHandler() for: " + v.getId() + ". Pressed: " + v.isPressed());
|
||||||
public void digitButtonClickHandler(@NotNull View v) {
|
if (((ColorButton) v).isShowText()) {
|
||||||
Log.d(String.valueOf(v.getId()), "digitButtonClickHandler() for: " + v.getId() + ". Pressed: " + v.isPressed());
|
getKeyboard().digitButtonPressed(((ColorButton) v).getText().toString());
|
||||||
if (((ColorButton) v).isShowText()) {
|
}
|
||||||
getKeyboard().digitButtonPressed(((ColorButton) v).getText().toString());
|
}
|
||||||
}
|
|
||||||
}
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void functionsButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
CalculatorActivityLauncher.showFunctions(this);
|
||||||
public void functionsButtonClickHandler(@NotNull View v) {
|
}
|
||||||
CalculatorActivityLauncher.showFunctions(this);
|
|
||||||
}
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void operatorsButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
CalculatorActivityLauncher.showOperators(this);
|
||||||
public void operatorsButtonClickHandler(@NotNull View v) {
|
}
|
||||||
CalculatorActivityLauncher.showOperators(this);
|
|
||||||
}
|
public static void operatorsButtonClickHandler(@NotNull Activity activity) {
|
||||||
|
CalculatorActivityLauncher.showOperators(activity);
|
||||||
public static void operatorsButtonClickHandler(@NotNull Activity activity) {
|
}
|
||||||
CalculatorActivityLauncher.showOperators(activity);
|
|
||||||
}
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void varsButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
CalculatorActivityLauncher.showVars(this);
|
||||||
public void varsButtonClickHandler(@NotNull View v) {
|
}
|
||||||
CalculatorActivityLauncher.showVars(this);
|
|
||||||
}
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
|
public void donateButtonClickHandler(@NotNull View v) {
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
CalculatorApplication.showDonationDialog(this);
|
||||||
public void donateButtonClickHandler(@NotNull View v) {
|
}
|
||||||
CalculatorApplication.showDonationDialog(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,158 +1,160 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import com.actionbarsherlock.app.ActionBar;
|
import com.actionbarsherlock.app.ActionBar;
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.AndroidUtils;
|
import org.solovyev.android.AndroidUtils;
|
||||||
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
|
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 9/25/12
|
* Date: 9/25/12
|
||||||
* Time: 10:32 PM
|
* Time: 10:32 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper implements CalculatorActivityHelper {
|
public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper implements CalculatorActivityHelper {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*
|
*
|
||||||
* CONSTANTS
|
* CONSTANTS
|
||||||
*
|
*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*/
|
*/
|
||||||
private static final String SELECTED_NAV = "selected_nav";
|
private static final String SELECTED_NAV = "selected_nav";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*
|
*
|
||||||
* FIELDS
|
* FIELDS
|
||||||
*
|
*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private int layoutId;
|
private int layoutId;
|
||||||
|
|
||||||
private boolean homeIcon = false;
|
private boolean homeIcon = false;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final List<String> fragmentTags = new ArrayList<String>();
|
private final List<String> fragmentTags = new ArrayList<String>();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorPreferences.Gui.Theme theme;
|
private CalculatorPreferences.Gui.Theme theme;
|
||||||
private int navPosition = 0;
|
private int navPosition = 0;
|
||||||
|
|
||||||
|
|
||||||
public CalculatorActivityHelperImpl(int layoutId, @NotNull String logTag) {
|
public CalculatorActivityHelperImpl(int layoutId, @NotNull String logTag) {
|
||||||
super(logTag);
|
super(logTag);
|
||||||
this.layoutId = layoutId;
|
this.layoutId = layoutId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CalculatorActivityHelperImpl(int layoutId, boolean homeIcon) {
|
public CalculatorActivityHelperImpl(int layoutId, boolean homeIcon) {
|
||||||
this.layoutId = layoutId;
|
this.layoutId = layoutId;
|
||||||
this.homeIcon = homeIcon;
|
this.homeIcon = homeIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState) {
|
public void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(activity);
|
super.onCreate(activity);
|
||||||
|
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
|
|
||||||
this.theme = CalculatorPreferences.Gui.getTheme(preferences);
|
this.theme = CalculatorPreferences.Gui.getTheme(preferences);
|
||||||
activity.setTheme(this.theme.getThemeId());
|
activity.setTheme(this.theme.getThemeId());
|
||||||
|
|
||||||
activity.setContentView(layoutId);
|
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);
|
@Override
|
||||||
|
public void onCreate(@NotNull final SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState) {
|
||||||
final ActionBar actionBar = activity.getSupportActionBar();
|
this.onCreate((Activity) activity, savedInstanceState);
|
||||||
actionBar.setDisplayUseLogoEnabled(false);
|
|
||||||
actionBar.setDisplayHomeAsUpEnabled(homeIcon);
|
final ActionBar actionBar = activity.getSupportActionBar();
|
||||||
actionBar.setDisplayShowHomeEnabled(true);
|
actionBar.setDisplayUseLogoEnabled(false);
|
||||||
actionBar.setDisplayShowTitleEnabled(true);
|
actionBar.setDisplayHomeAsUpEnabled(homeIcon);
|
||||||
|
actionBar.setDisplayShowHomeEnabled(true);
|
||||||
if (savedInstanceState != null) {
|
actionBar.setDisplayShowTitleEnabled(true);
|
||||||
navPosition = savedInstanceState.getInt(SELECTED_NAV, 0);
|
|
||||||
}
|
if (savedInstanceState != null) {
|
||||||
}
|
navPosition = savedInstanceState.getInt(SELECTED_NAV, 0);
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public void restoreSavedTab(@NotNull SherlockFragmentActivity activity) {
|
|
||||||
final ActionBar actionBar = activity.getSupportActionBar();
|
@Override
|
||||||
if (navPosition >= 0 && navPosition < actionBar.getTabCount()) {
|
public void restoreSavedTab(@NotNull SherlockFragmentActivity activity) {
|
||||||
activity.getSupportActionBar().setSelectedNavigationItem(navPosition);
|
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);
|
@Override
|
||||||
outState.putInt(SELECTED_NAV, activity.getSupportActionBar().getSelectedNavigationIndex());
|
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 onSaveInstanceState(@NotNull Activity activity, @NotNull Bundle outState) {
|
||||||
@Override
|
}
|
||||||
public void onResume(@NotNull Activity activity) {
|
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
@Override
|
||||||
|
public void onResume(@NotNull Activity activity) {
|
||||||
final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
if (!theme.equals(newTheme)) {
|
|
||||||
AndroidUtils.restartActivity(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 onDestroy(@NotNull SherlockFragmentActivity activity) {
|
||||||
|
super.onDestroy(activity);
|
||||||
@Override
|
}
|
||||||
public void addTab(@NotNull SherlockFragmentActivity activity,
|
|
||||||
@NotNull String tag,
|
@Override
|
||||||
@NotNull Class<? extends Fragment> fragmentClass,
|
public void addTab(@NotNull SherlockFragmentActivity activity,
|
||||||
@Nullable Bundle fragmentArgs,
|
@NotNull String tag,
|
||||||
int captionResId,
|
@NotNull Class<? extends Fragment> fragmentClass,
|
||||||
int parentViewId) {
|
@Nullable Bundle fragmentArgs,
|
||||||
activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
int captionResId,
|
||||||
|
int parentViewId) {
|
||||||
final ActionBar actionBar = activity.getSupportActionBar();
|
activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||||
final ActionBar.Tab tab = actionBar.newTab();
|
|
||||||
tab.setTag(tag);
|
final ActionBar actionBar = activity.getSupportActionBar();
|
||||||
tab.setText(captionResId);
|
final ActionBar.Tab tab = actionBar.newTab();
|
||||||
tab.setTabListener(new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId));
|
tab.setTag(tag);
|
||||||
actionBar.addTab(tab);
|
tab.setText(captionResId);
|
||||||
|
tab.setTabListener(new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId));
|
||||||
fragmentTags.add(tag);
|
actionBar.addTab(tab);
|
||||||
}
|
|
||||||
|
fragmentTags.add(tag);
|
||||||
@Override
|
}
|
||||||
public int getLayoutId() {
|
|
||||||
return layoutId;
|
@Override
|
||||||
}
|
public int getLayoutId() {
|
||||||
|
return layoutId;
|
||||||
@Override
|
}
|
||||||
@NotNull
|
|
||||||
public CalculatorPreferences.Gui.Theme getTheme() {
|
@Override
|
||||||
return theme;
|
@NotNull
|
||||||
}
|
public CalculatorPreferences.Gui.Theme getTheme() {
|
||||||
|
return theme;
|
||||||
@Override
|
}
|
||||||
public void onResume(@NotNull SherlockFragmentActivity activity) {
|
|
||||||
onResume((Activity) activity);
|
@Override
|
||||||
}
|
public void onResume(@NotNull SherlockFragmentActivity activity) {
|
||||||
}
|
onResume((Activity) activity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,122 +1,122 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import net.robotmedia.billing.BillingController;
|
import net.robotmedia.billing.BillingController;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.ads.AdsController;
|
import org.solovyev.android.ads.AdsController;
|
||||||
import org.solovyev.android.calculator.history.AndroidCalculatorHistory;
|
import org.solovyev.android.calculator.history.AndroidCalculatorHistory;
|
||||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 12/1/11
|
* Date: 12/1/11
|
||||||
* Time: 1:21 PM
|
* Time: 1:21 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorApplication extends android.app.Application {
|
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¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted";
|
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¤cy_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_PRODUCT_ID = "ad_free";
|
||||||
public static final String AD_FREE_P_KEY = "org.solovyev.android.calculator_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 ADMOB_USER_ID = "a14f02cf9c80cbc";
|
||||||
public static final String REMOTE_STACK_TRACE_URL = "http://calculatorpp.com/crash_reports/upload.php";
|
public static final String REMOTE_STACK_TRACE_URL = "http://calculatorpp.com/crash_reports/upload.php";
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static CalculatorApplication instance;
|
private static CalculatorApplication instance;
|
||||||
|
|
||||||
public CalculatorApplication() {
|
public CalculatorApplication() {
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static CalculatorApplication getInstance() {
|
public static CalculatorApplication getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
setTheme(preferences);
|
setTheme(preferences);
|
||||||
|
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
final AndroidCalculator calculator = new AndroidCalculator();
|
final AndroidCalculator calculator = new AndroidCalculator();
|
||||||
|
|
||||||
CalculatorLocatorImpl.getInstance().init(calculator,
|
CalculatorLocatorImpl.getInstance().init(calculator,
|
||||||
new AndroidCalculatorEngine(this),
|
new AndroidCalculatorEngine(this),
|
||||||
new AndroidCalculatorClipboard(this),
|
new AndroidCalculatorClipboard(this),
|
||||||
new AndroidCalculatorNotifier(this),
|
new AndroidCalculatorNotifier(this),
|
||||||
new AndroidCalculatorHistory(this, calculator));
|
new AndroidCalculatorHistory(this, calculator));
|
||||||
|
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().init();
|
CalculatorLocatorImpl.getInstance().getCalculator().init();
|
||||||
|
|
||||||
AdsController.getInstance().init(ADMOB_USER_ID, AD_FREE_PRODUCT_ID, new BillingController.IConfiguration() {
|
AdsController.getInstance().init(ADMOB_USER_ID, AD_FREE_PRODUCT_ID, new BillingController.IConfiguration() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getObfuscationSalt() {
|
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};
|
return new byte[]{81, -114, 32, -127, -32, -104, -40, -15, -47, 57, -13, -41, -33, 67, -114, 7, -11, 53, 126, 82};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPublicKey() {
|
public String getPublicKey() {
|
||||||
return CalculatorSecurity.getPK();
|
return CalculatorSecurity.getPK();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
CalculatorPreferences.setDefaultValues(preferences);
|
CalculatorPreferences.setDefaultValues(preferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTheme(@NotNull SharedPreferences preferences) {
|
private void setTheme(@NotNull SharedPreferences preferences) {
|
||||||
final CalculatorPreferences.Gui.Theme theme = CalculatorPreferences.Gui.getTheme(preferences);
|
final CalculatorPreferences.Gui.Theme theme = CalculatorPreferences.Gui.getTheme(preferences);
|
||||||
setTheme(theme.getThemeId());
|
setTheme(theme.getThemeId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showDonationDialog(@NotNull final Context context) {
|
public static void showDonationDialog(@NotNull final Context context) {
|
||||||
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
|
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||||
final View view = layoutInflater.inflate(R.layout.donate, null);
|
final View view = layoutInflater.inflate(R.layout.donate, null);
|
||||||
|
|
||||||
final TextView donate = (TextView) view.findViewById(R.id.donateText);
|
final TextView donate = (TextView) view.findViewById(R.id.donateText);
|
||||||
donate.setMovementMethod(LinkMovementMethod.getInstance());
|
donate.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setNegativeButton(R.string.c_cancel, null)
|
.setNegativeButton(R.string.c_cancel, null)
|
||||||
.setPositiveButton(R.string.c_donate, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.c_donate, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
final Intent i = new Intent(Intent.ACTION_VIEW);
|
final Intent i = new Intent(Intent.ACTION_VIEW);
|
||||||
i.setData(Uri.parse(paypalDonateUrl));
|
i.setData(Uri.parse(paypalDonateUrl));
|
||||||
context.startActivity(i);
|
context.startActivity(i);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setView(view);
|
.setView(view);
|
||||||
|
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerOnRemoteStackTrace() {
|
public static void registerOnRemoteStackTrace() {
|
||||||
//Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(null, REMOTE_STACK_TRACE_URL));
|
//Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(null, REMOTE_STACK_TRACE_URL));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CalculatorActivityHelper createActivityHelper(int layoutResId, @NotNull String logTag) {
|
public CalculatorActivityHelper createActivityHelper(int layoutResId, @NotNull String logTag) {
|
||||||
return new CalculatorActivityHelperImpl(layoutResId, logTag);
|
return new CalculatorActivityHelperImpl(layoutResId, logTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CalculatorFragmentHelper createFragmentHelper() {
|
public CalculatorFragmentHelper createFragmentHelper(int layoutId) {
|
||||||
return new CalculatorFragmentHelperImpl();
|
return new CalculatorFragmentHelperImpl(layoutId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,30 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.view.View;
|
import android.view.LayoutInflater;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
/**
|
import org.jetbrains.annotations.NotNull;
|
||||||
* User: serso
|
import org.jetbrains.annotations.Nullable;
|
||||||
* Date: 9/26/12
|
import org.solovyev.android.calculator.math.edit.AbstractMathEntityListFragment;
|
||||||
* Time: 10:14 PM
|
|
||||||
*/
|
/**
|
||||||
public interface CalculatorFragmentHelper {
|
* User: serso
|
||||||
|
* Date: 9/26/12
|
||||||
boolean isPane(@NotNull Fragment fragment);
|
* Time: 10:14 PM
|
||||||
|
*/
|
||||||
void setPaneTitle(@NotNull Fragment fragment, int titleResId);
|
public interface CalculatorFragmentHelper {
|
||||||
|
|
||||||
void processButtons(@NotNull Fragment fragment, @NotNull View root);
|
boolean isPane(@NotNull Fragment fragment);
|
||||||
|
|
||||||
void onCreate(@NotNull Fragment fragment);
|
void setPaneTitle(@NotNull Fragment fragment, int titleResId);
|
||||||
|
|
||||||
void onDestroy(@NotNull Fragment fragment);
|
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);
|
||||||
|
}
|
||||||
|
@ -1,45 +1,76 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.view.View;
|
import android.view.LayoutInflater;
|
||||||
import android.widget.TextView;
|
import android.view.View;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewParent;
|
||||||
/**
|
import android.widget.LinearLayout;
|
||||||
* User: serso
|
import android.widget.TextView;
|
||||||
* Date: 9/26/12
|
import com.google.ads.AdView;
|
||||||
* Time: 10:14 PM
|
import org.jetbrains.annotations.NotNull;
|
||||||
*/
|
import org.jetbrains.annotations.Nullable;
|
||||||
public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper implements CalculatorFragmentHelper {
|
import org.solovyev.android.ads.AdsController;
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public boolean isPane(@NotNull Fragment fragment) {
|
* User: serso
|
||||||
return fragment.getActivity() instanceof CalculatorActivity;
|
* Date: 9/26/12
|
||||||
}
|
* Time: 10:14 PM
|
||||||
|
*/
|
||||||
public void setPaneTitle(@NotNull Fragment fragment, int titleResId) {
|
public class CalculatorFragmentHelperImpl extends AbstractCalculatorHelper implements CalculatorFragmentHelper {
|
||||||
final TextView fragmentTitle = (TextView) fragment.getView().findViewById(R.id.fragmentTitle);
|
|
||||||
if (fragmentTitle != null) {
|
@Nullable
|
||||||
if (!isPane(fragment)) {
|
private AdView adView;
|
||||||
fragmentTitle.setVisibility(View.GONE);
|
|
||||||
} else {
|
private int layoutId;
|
||||||
fragmentTitle.setText(fragment.getString(titleResId).toUpperCase());
|
|
||||||
}
|
public CalculatorFragmentHelperImpl(int layoutId) {
|
||||||
}
|
this.layoutId = layoutId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processButtons(@NotNull Fragment fragment, @NotNull View root) {
|
public boolean isPane(@NotNull Fragment fragment) {
|
||||||
super.processButtons(fragment.getActivity(), root);
|
return fragment.getActivity() instanceof CalculatorActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setPaneTitle(@NotNull Fragment fragment, int titleResId) {
|
||||||
public void onCreate(@NotNull Fragment fragment) {
|
final TextView fragmentTitle = (TextView) fragment.getView().findViewById(R.id.fragmentTitle);
|
||||||
super.onCreate(fragment.getActivity());
|
if (fragmentTitle != null) {
|
||||||
}
|
if (!isPane(fragment)) {
|
||||||
|
fragmentTitle.setVisibility(View.GONE);
|
||||||
@Override
|
} else {
|
||||||
public void onDestroy(@NotNull Fragment fragment) {
|
fragmentTitle.setText(fragment.getString(titleResId).toUpperCase());
|
||||||
super.onDestroy(fragment.getActivity());
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,119 +1,119 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import com.actionbarsherlock.app.SherlockFragment;
|
import com.actionbarsherlock.app.SherlockFragment;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: Solovyev_S
|
* User: Solovyev_S
|
||||||
* Date: 25.09.12
|
* Date: 25.09.12
|
||||||
* Time: 12:25
|
* Time: 12:25
|
||||||
*/
|
*/
|
||||||
public class CalculatorKeyboardFragment extends SherlockFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class CalculatorKeyboardFragment extends SherlockFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private NumeralBaseButtons numeralBaseButtons = new NumeralBaseButtons();
|
private NumeralBaseButtons numeralBaseButtons = new NumeralBaseButtons();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorPreferences.Gui.Theme theme;
|
private CalculatorPreferences.Gui.Theme theme;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorFragmentHelper fragmentHelper;
|
private CalculatorFragmentHelper fragmentHelper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
||||||
|
|
||||||
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper();
|
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.calc_keyboard);
|
||||||
fragmentHelper.onCreate(this);
|
fragmentHelper.onCreate(this);
|
||||||
|
|
||||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences);
|
theme = CalculatorPreferences.Gui.theme.getPreferenceNoError(preferences);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.calc_keyboard, container, false);
|
return fragmentHelper.onCreateView(this, inflater, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(root, savedInstanceState);
|
super.onViewCreated(root, savedInstanceState);
|
||||||
|
|
||||||
fragmentHelper.processButtons(this, root);
|
fragmentHelper.onViewCreated(this, root);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
||||||
fragmentHelper.onDestroy(this);
|
fragmentHelper.onDestroy(this);
|
||||||
|
|
||||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
||||||
preferences.unregisterOnSharedPreferenceChangeListener(this);
|
preferences.unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* private static void setMarginsForView(@Nullable View view, int marginLeft, int marginBottom, @NotNull Context context) {
|
/* private static void setMarginsForView(@Nullable View view, int marginLeft, int marginBottom, @NotNull Context context) {
|
||||||
// IMPORTANT: this is workaround for probably android bug
|
// IMPORTANT: this is workaround for probably android bug
|
||||||
// currently margin values set in styles are not applied for some reasons to the views (using include tag) => set them manually
|
// currently margin values set in styles are not applied for some reasons to the views (using include tag) => set them manually
|
||||||
|
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
final DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
final DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||||
if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
|
if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
|
||||||
final LinearLayout.LayoutParams oldParams = (LinearLayout.LayoutParams) view.getLayoutParams();
|
final LinearLayout.LayoutParams oldParams = (LinearLayout.LayoutParams) view.getLayoutParams();
|
||||||
final LinearLayout.LayoutParams newParams = new LinearLayout.LayoutParams(oldParams.width, oldParams.height, oldParams.weight);
|
final LinearLayout.LayoutParams newParams = new LinearLayout.LayoutParams(oldParams.width, oldParams.height, oldParams.weight);
|
||||||
newParams.setMargins(AndroidUtils.toPixels(dm, marginLeft), 0, 0, AndroidUtils.toPixels(dm, marginBottom));
|
newParams.setMargins(AndroidUtils.toPixels(dm, marginLeft), 0, 0, AndroidUtils.toPixels(dm, marginBottom));
|
||||||
view.setLayoutParams(newParams);
|
view.setLayoutParams(newParams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||||
if (AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key)) {
|
if (AndroidCalculatorEngine.Preferences.numeralBase.getKey().equals(key)) {
|
||||||
numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
|
numeralBaseButtons.toggleNumericDigits(this.getActivity(), preferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key) ) {
|
if ( CalculatorPreferences.Gui.showEqualsButton.getKey().equals(key) ) {
|
||||||
CalculatorButtons.toggleEqualsButton(preferences, this.getActivity(), theme, getView());
|
CalculatorButtons.toggleEqualsButton(preferences, this.getActivity(), theme, getView());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( AndroidCalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) {
|
if ( AndroidCalculatorEngine.Preferences.multiplicationSign.getKey().equals(key) ) {
|
||||||
CalculatorButtons.initMultiplicationButton(getView());
|
CalculatorButtons.initMultiplicationButton(getView());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
|
private static AndroidCalculatorDisplayView getCalculatorDisplayView() {
|
||||||
return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
|
return (AndroidCalculatorDisplayView) CalculatorLocatorImpl.getInstance().getDisplay().getView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Calculator getCalculator() {
|
private Calculator getCalculator() {
|
||||||
return CalculatorLocatorImpl.getInstance().getCalculator();
|
return CalculatorLocatorImpl.getInstance().getCalculator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static CalculatorKeyboard getKeyboard() {
|
private static CalculatorKeyboard getKeyboard() {
|
||||||
return CalculatorLocatorImpl.getInstance().getKeyboard();
|
return CalculatorLocatorImpl.getInstance().getKeyboard();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,336 +1,324 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
* or visit http://se.solovyev.org
|
* or visit http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import com.actionbarsherlock.app.SherlockListFragment;
|
import com.actionbarsherlock.app.SherlockListFragment;
|
||||||
import com.google.ads.AdView;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.ads.AdsController;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.menu.AMenuBuilder;
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.menu.MenuImpl;
|
||||||
import org.solovyev.android.menu.AMenuBuilder;
|
import org.solovyev.common.collections.CollectionsUtils;
|
||||||
import org.solovyev.android.menu.MenuImpl;
|
import org.solovyev.common.equals.Equalizer;
|
||||||
import org.solovyev.common.collections.CollectionsUtils;
|
import org.solovyev.common.filter.Filter;
|
||||||
import org.solovyev.common.equals.Equalizer;
|
import org.solovyev.common.filter.FilterRule;
|
||||||
import org.solovyev.common.filter.Filter;
|
import org.solovyev.common.filter.FilterRulesChain;
|
||||||
import org.solovyev.common.filter.FilterRule;
|
import org.solovyev.common.text.StringUtils;
|
||||||
import org.solovyev.common.filter.FilterRulesChain;
|
|
||||||
import org.solovyev.common.text.StringUtils;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.ArrayList;
|
import java.util.Comparator;
|
||||||
import java.util.Collections;
|
import java.util.List;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
/**
|
||||||
|
* User: serso
|
||||||
/**
|
* Date: 10/15/11
|
||||||
* User: serso
|
* Time: 1:13 PM
|
||||||
* Date: 10/15/11
|
*/
|
||||||
* Time: 1:13 PM
|
public abstract class AbstractCalculatorHistoryFragment extends SherlockListFragment implements CalculatorEventListener {
|
||||||
*/
|
|
||||||
public abstract class AbstractCalculatorHistoryFragment extends SherlockListFragment implements CalculatorEventListener {
|
/*
|
||||||
|
**********************************************************************
|
||||||
/*
|
*
|
||||||
**********************************************************************
|
* CONSTANTS
|
||||||
*
|
*
|
||||||
* CONSTANTS
|
**********************************************************************
|
||||||
*
|
*/
|
||||||
**********************************************************************
|
|
||||||
*/
|
@NotNull
|
||||||
|
private static final String TAG = "CalculatorHistoryFragment";
|
||||||
@NotNull
|
|
||||||
private static final String TAG = "CalculatorHistoryFragment";
|
public static final Comparator<CalculatorHistoryState> COMPARATOR = new Comparator<CalculatorHistoryState>() {
|
||||||
|
@Override
|
||||||
public static final Comparator<CalculatorHistoryState> COMPARATOR = new Comparator<CalculatorHistoryState>() {
|
public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) {
|
||||||
@Override
|
if (state1.isSaved() == state2.isSaved()) {
|
||||||
public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) {
|
long l = state2.getTime() - state1.getTime();
|
||||||
if (state1.isSaved() == state2.isSaved()) {
|
return l > 0l ? 1 : (l < 0l ? -1 : 0);
|
||||||
long l = state2.getTime() - state1.getTime();
|
} else if (state1.isSaved()) {
|
||||||
return l > 0l ? 1 : (l < 0l ? -1 : 0);
|
return -1;
|
||||||
} else if (state1.isSaved()) {
|
} else if (state2.isSaved()) {
|
||||||
return -1;
|
return 1;
|
||||||
} else if (state2.isSaved()) {
|
}
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
return 0;
|
};
|
||||||
}
|
|
||||||
};
|
/*
|
||||||
|
**********************************************************************
|
||||||
/*
|
*
|
||||||
**********************************************************************
|
* FIELDS
|
||||||
*
|
*
|
||||||
* FIELDS
|
**********************************************************************
|
||||||
*
|
*/
|
||||||
**********************************************************************
|
|
||||||
*/
|
|
||||||
|
@NotNull
|
||||||
|
private ArrayAdapter<CalculatorHistoryState> adapter;
|
||||||
@NotNull
|
|
||||||
private ArrayAdapter<CalculatorHistoryState> adapter;
|
@NotNull
|
||||||
|
private CalculatorFragmentHelper fragmentHelper;
|
||||||
@Nullable
|
|
||||||
private AdView adView;
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@NotNull
|
super.onCreate(savedInstanceState);
|
||||||
private CalculatorFragmentHelper fragmentHelper;
|
|
||||||
|
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.history_fragment);
|
||||||
@Override
|
fragmentHelper.onCreate(this);
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
logDebug("onCreate");
|
||||||
|
}
|
||||||
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper();
|
|
||||||
fragmentHelper.onCreate(this);
|
private int logDebug(@NotNull String msg) {
|
||||||
|
return Log.d(TAG + ": " + getTag(), msg);
|
||||||
logDebug("onCreate");
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
private int logDebug(@NotNull String msg) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
return Log.d(TAG + ": " + getTag(), msg);
|
return fragmentHelper.onCreateView(this, inflater, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||||
final View result = inflater.inflate(R.layout.history_fragment, container, false);
|
super.onViewCreated(root, savedInstanceState);
|
||||||
logDebug("onCreateView");
|
|
||||||
return result;
|
logDebug("onViewCreated");
|
||||||
}
|
|
||||||
|
fragmentHelper.onViewCreated(this, root);
|
||||||
@Override
|
fragmentHelper.setPaneTitle(this, getTitleResId());
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
|
||||||
super.onViewCreated(view, savedInstanceState);
|
adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), R.id.history_item, new ArrayList<CalculatorHistoryState>());
|
||||||
|
setListAdapter(adapter);
|
||||||
logDebug("onViewCreated");
|
|
||||||
|
final ListView lv = getListView();
|
||||||
fragmentHelper.setPaneTitle(this, getTitleResId());
|
lv.setTextFilterEnabled(true);
|
||||||
|
|
||||||
adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), R.id.history_item, new ArrayList<CalculatorHistoryState>());
|
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
setListAdapter(adapter);
|
public void onItemClick(final AdapterView<?> parent,
|
||||||
|
final View view,
|
||||||
final ListView lv = getListView();
|
final int position,
|
||||||
lv.setTextFilterEnabled(true);
|
final long id) {
|
||||||
|
|
||||||
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position));
|
||||||
public void onItemClick(final AdapterView<?> parent,
|
}
|
||||||
final View view,
|
});
|
||||||
final int position,
|
|
||||||
final long id) {
|
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||||
|
@Override
|
||||||
useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position));
|
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
|
||||||
}
|
final CalculatorHistoryState historyState = (CalculatorHistoryState) parent.getItemAtPosition(position);
|
||||||
});
|
|
||||||
|
final Context context = getActivity();
|
||||||
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
|
||||||
@Override
|
final HistoryItemMenuData data = new HistoryItemMenuData(historyState, adapter);
|
||||||
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
|
|
||||||
final CalculatorHistoryState historyState = (CalculatorHistoryState) parent.getItemAtPosition(position);
|
final List<HistoryItemMenuItem> menuItems = CollectionsUtils.asList(HistoryItemMenuItem.values());
|
||||||
|
|
||||||
final Context context = getActivity();
|
if (historyState.isSaved()) {
|
||||||
|
menuItems.remove(HistoryItemMenuItem.save);
|
||||||
final HistoryItemMenuData data = new HistoryItemMenuData(historyState, adapter);
|
} else {
|
||||||
|
if (isAlreadySaved(historyState)) {
|
||||||
final List<HistoryItemMenuItem> menuItems = CollectionsUtils.asList(HistoryItemMenuItem.values());
|
menuItems.remove(HistoryItemMenuItem.save);
|
||||||
|
}
|
||||||
if (historyState.isSaved()) {
|
menuItems.remove(HistoryItemMenuItem.remove);
|
||||||
menuItems.remove(HistoryItemMenuItem.save);
|
menuItems.remove(HistoryItemMenuItem.edit);
|
||||||
} else {
|
}
|
||||||
if (isAlreadySaved(historyState)) {
|
|
||||||
menuItems.remove(HistoryItemMenuItem.save);
|
if (historyState.getDisplayState().isValid() && StringUtils.isEmpty(historyState.getDisplayState().getEditorState().getText())) {
|
||||||
}
|
menuItems.remove(HistoryItemMenuItem.copy_result);
|
||||||
menuItems.remove(HistoryItemMenuItem.remove);
|
}
|
||||||
menuItems.remove(HistoryItemMenuItem.edit);
|
|
||||||
}
|
final AMenuBuilder<HistoryItemMenuItem, HistoryItemMenuData> menuBuilder = AMenuBuilder.newInstance(context, MenuImpl.newInstance(menuItems));
|
||||||
|
menuBuilder.create(data).show();
|
||||||
if (historyState.getDisplayState().isValid() && StringUtils.isEmpty(historyState.getDisplayState().getEditorState().getText())) {
|
|
||||||
menuItems.remove(HistoryItemMenuItem.copy_result);
|
return true;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
final AMenuBuilder<HistoryItemMenuItem, HistoryItemMenuData> menuBuilder = AMenuBuilder.newInstance(context, MenuImpl.newInstance(menuItems));
|
}
|
||||||
menuBuilder.create(data).show();
|
|
||||||
|
protected abstract int getTitleResId();
|
||||||
return true;
|
|
||||||
}
|
@Override
|
||||||
});
|
public void onDestroy() {
|
||||||
|
logDebug("onDestroy");
|
||||||
adView = AdsController.getInstance().inflateAd(this.getActivity(), (ViewGroup)view.findViewById(R.id.ad_parent_view), R.id.ad_parent_view);
|
|
||||||
}
|
fragmentHelper.onDestroy(this);
|
||||||
|
|
||||||
protected abstract int getTitleResId();
|
super.onDestroy();
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
protected abstract int getItemLayoutId();
|
||||||
logDebug("onDestroy");
|
|
||||||
|
@Override
|
||||||
if ( this.adView != null ) {
|
public void onResume() {
|
||||||
this.adView.destroy();
|
logDebug("onResume");
|
||||||
}
|
|
||||||
|
super.onResume();
|
||||||
fragmentHelper.onDestroy(this);
|
|
||||||
|
|
||||||
super.onDestroy();
|
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
|
||||||
}
|
|
||||||
|
updateAdapter();
|
||||||
protected abstract int getItemLayoutId();
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onPause() {
|
||||||
logDebug("onResume");
|
logDebug("onPause");
|
||||||
|
|
||||||
super.onResume();
|
super.onPause();
|
||||||
|
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
|
|
||||||
|
}
|
||||||
updateAdapter();
|
|
||||||
}
|
private void updateAdapter() {
|
||||||
|
final List<CalculatorHistoryState> historyList = getHistoryList();
|
||||||
@Override
|
|
||||||
public void onPause() {
|
final ArrayAdapter<CalculatorHistoryState> adapter = getAdapter();
|
||||||
logDebug("onPause");
|
try {
|
||||||
|
adapter.setNotifyOnChange(false);
|
||||||
super.onPause();
|
adapter.clear();
|
||||||
|
for (CalculatorHistoryState historyState : historyList) {
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
|
adapter.add(historyState);
|
||||||
|
}
|
||||||
}
|
} finally {
|
||||||
|
adapter.setNotifyOnChange(true);
|
||||||
private void updateAdapter() {
|
}
|
||||||
final List<CalculatorHistoryState> historyList = getHistoryList();
|
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
final ArrayAdapter<CalculatorHistoryState> adapter = getAdapter();
|
}
|
||||||
try {
|
|
||||||
adapter.setNotifyOnChange(false);
|
public static boolean isAlreadySaved(@NotNull CalculatorHistoryState historyState) {
|
||||||
adapter.clear();
|
assert !historyState.isSaved();
|
||||||
for (CalculatorHistoryState historyState : historyList) {
|
|
||||||
adapter.add(historyState);
|
boolean result = false;
|
||||||
}
|
try {
|
||||||
} finally {
|
historyState.setSaved(true);
|
||||||
adapter.setNotifyOnChange(true);
|
if ( CollectionsUtils.contains(historyState, CalculatorLocatorImpl.getInstance().getHistory().getSavedHistory(), new Equalizer<CalculatorHistoryState>() {
|
||||||
}
|
@Override
|
||||||
|
public boolean equals(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
|
||||||
adapter.notifyDataSetChanged();
|
return first != null && second != null &&
|
||||||
}
|
first.getTime() == second.getTime() &&
|
||||||
|
first.getDisplayState().equals(second.getDisplayState()) &&
|
||||||
public static boolean isAlreadySaved(@NotNull CalculatorHistoryState historyState) {
|
first.getEditorState().equals(second.getEditorState());
|
||||||
assert !historyState.isSaved();
|
}
|
||||||
|
}) ) {
|
||||||
boolean result = false;
|
result = true;
|
||||||
try {
|
}
|
||||||
historyState.setSaved(true);
|
} finally {
|
||||||
if ( CollectionsUtils.contains(historyState, CalculatorLocatorImpl.getInstance().getHistory().getSavedHistory(), new Equalizer<CalculatorHistoryState>() {
|
historyState.setSaved(false);
|
||||||
@Override
|
}
|
||||||
public boolean equals(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
|
return result;
|
||||||
return first != null && second != null &&
|
}
|
||||||
first.getTime() == second.getTime() &&
|
|
||||||
first.getDisplayState().equals(second.getDisplayState()) &&
|
public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState) {
|
||||||
first.getEditorState().equals(second.getEditorState());
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_history_state, historyState);
|
||||||
}
|
}
|
||||||
}) ) {
|
|
||||||
result = true;
|
@NotNull
|
||||||
}
|
private List<CalculatorHistoryState> getHistoryList() {
|
||||||
} finally {
|
final List<CalculatorHistoryState> calculatorHistoryStates = getHistoryItems();
|
||||||
historyState.setSaved(false);
|
|
||||||
}
|
Collections.sort(calculatorHistoryStates, COMPARATOR);
|
||||||
return result;
|
|
||||||
}
|
final FilterRulesChain<CalculatorHistoryState> filterRulesChain = new FilterRulesChain<CalculatorHistoryState>();
|
||||||
|
filterRulesChain.addFilterRule(new FilterRule<CalculatorHistoryState>() {
|
||||||
public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState) {
|
@Override
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_history_state, historyState);
|
public boolean isFiltered(CalculatorHistoryState object) {
|
||||||
}
|
return object == null || StringUtils.isEmpty(object.getEditorState().getText());
|
||||||
|
}
|
||||||
@NotNull
|
});
|
||||||
private List<CalculatorHistoryState> getHistoryList() {
|
|
||||||
final List<CalculatorHistoryState> calculatorHistoryStates = getHistoryItems();
|
new Filter<CalculatorHistoryState>(filterRulesChain).filter(calculatorHistoryStates.iterator());
|
||||||
|
|
||||||
Collections.sort(calculatorHistoryStates, COMPARATOR);
|
return calculatorHistoryStates;
|
||||||
|
}
|
||||||
final FilterRulesChain<CalculatorHistoryState> filterRulesChain = new FilterRulesChain<CalculatorHistoryState>();
|
|
||||||
filterRulesChain.addFilterRule(new FilterRule<CalculatorHistoryState>() {
|
@NotNull
|
||||||
@Override
|
protected abstract List<CalculatorHistoryState> getHistoryItems();
|
||||||
public boolean isFiltered(CalculatorHistoryState object) {
|
|
||||||
return object == null || StringUtils.isEmpty(object.getEditorState().getText());
|
@NotNull
|
||||||
}
|
public static String getHistoryText(@NotNull CalculatorHistoryState state) {
|
||||||
});
|
final StringBuilder result = new StringBuilder();
|
||||||
|
result.append(state.getEditorState().getText());
|
||||||
new Filter<CalculatorHistoryState>(filterRulesChain).filter(calculatorHistoryStates.iterator());
|
result.append(getIdentitySign(state.getDisplayState().getJsclOperation()));
|
||||||
|
final String expressionResult = state.getDisplayState().getEditorState().getText();
|
||||||
return calculatorHistoryStates;
|
if (expressionResult != null) {
|
||||||
}
|
result.append(expressionResult);
|
||||||
|
}
|
||||||
@NotNull
|
return result.toString();
|
||||||
protected abstract List<CalculatorHistoryState> getHistoryItems();
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String getHistoryText(@NotNull CalculatorHistoryState state) {
|
private static String getIdentitySign(@NotNull JsclOperation jsclOperation) {
|
||||||
final StringBuilder result = new StringBuilder();
|
return jsclOperation == JsclOperation.simplify ? "≡" : "=";
|
||||||
result.append(state.getEditorState().getText());
|
}
|
||||||
result.append(getIdentitySign(state.getDisplayState().getJsclOperation()));
|
|
||||||
final String expressionResult = state.getDisplayState().getEditorState().getText();
|
// todo serso: menu
|
||||||
if (expressionResult != null) {
|
/* @Override
|
||||||
result.append(expressionResult);
|
public boolean onCreateOptionsMenu(android.view.Menu menu) {
|
||||||
}
|
final MenuInflater menuInflater = getMenuInflater();
|
||||||
return result.toString();
|
menuInflater.inflate(R.menu.history_menu, menu);
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
@NotNull
|
|
||||||
private static String getIdentitySign(@NotNull JsclOperation jsclOperation) {
|
@Override
|
||||||
return jsclOperation == JsclOperation.simplify ? "≡" : "=";
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
}
|
boolean result;
|
||||||
|
|
||||||
// todo serso: menu
|
switch (item.getItemId()) {
|
||||||
/* @Override
|
case R.id.history_menu_clear_history:
|
||||||
public boolean onCreateOptionsMenu(android.view.Menu menu) {
|
clearHistory();
|
||||||
final MenuInflater menuInflater = getMenuInflater();
|
result = true;
|
||||||
menuInflater.inflate(R.menu.history_menu, menu);
|
break;
|
||||||
return true;
|
default:
|
||||||
}
|
result = super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
return result;
|
||||||
boolean result;
|
}*/
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
protected abstract void clearHistory();
|
||||||
case R.id.history_menu_clear_history:
|
|
||||||
clearHistory();
|
@NotNull
|
||||||
result = true;
|
protected ArrayAdapter<CalculatorHistoryState> getAdapter() {
|
||||||
break;
|
return adapter;
|
||||||
default:
|
}
|
||||||
result = super.onOptionsItemSelected(item);
|
|
||||||
}
|
@Override
|
||||||
|
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||||
return result;
|
if ( calculatorEventType == CalculatorEventType.history_state_added ) {
|
||||||
}*/
|
|
||||||
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
protected abstract void clearHistory();
|
@Override
|
||||||
|
public void run() {
|
||||||
@NotNull
|
logDebug("onCalculatorEvent");
|
||||||
protected ArrayAdapter<CalculatorHistoryState> getAdapter() {
|
updateAdapter();
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,326 +1,321 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
* or visit http://se.solovyev.org
|
* or visit http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.math.edit;
|
package org.solovyev.android.calculator.math.edit;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import com.actionbarsherlock.app.SherlockListFragment;
|
import com.actionbarsherlock.app.SherlockListFragment;
|
||||||
import com.google.ads.AdView;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.ads.AdsController;
|
import org.solovyev.android.menu.AMenuBuilder;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
import org.solovyev.android.menu.AMenuBuilder;
|
import org.solovyev.android.menu.MenuImpl;
|
||||||
import org.solovyev.android.menu.LabeledMenuItem;
|
import org.solovyev.common.equals.EqualsTool;
|
||||||
import org.solovyev.android.menu.MenuImpl;
|
import org.solovyev.common.filter.Filter;
|
||||||
import org.solovyev.common.equals.EqualsTool;
|
import org.solovyev.common.filter.FilterRule;
|
||||||
import org.solovyev.common.filter.Filter;
|
import org.solovyev.common.math.MathEntity;
|
||||||
import org.solovyev.common.filter.FilterRule;
|
import org.solovyev.common.text.StringUtils;
|
||||||
import org.solovyev.common.math.MathEntity;
|
|
||||||
import org.solovyev.common.text.StringUtils;
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Arrays;
|
import java.util.List;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
/**
|
||||||
|
* User: serso
|
||||||
/**
|
* Date: 12/21/11
|
||||||
* User: serso
|
* Time: 9:24 PM
|
||||||
* Date: 12/21/11
|
*/
|
||||||
* Time: 9:24 PM
|
public abstract class AbstractMathEntityListFragment<T extends MathEntity> extends SherlockListFragment {
|
||||||
*/
|
|
||||||
public abstract class AbstractMathEntityListFragment<T extends MathEntity> extends SherlockListFragment {
|
/*
|
||||||
|
**********************************************************************
|
||||||
/*
|
*
|
||||||
**********************************************************************
|
* CONSTANTS
|
||||||
*
|
*
|
||||||
* CONSTANTS
|
**********************************************************************
|
||||||
*
|
*/
|
||||||
**********************************************************************
|
|
||||||
*/
|
public static final String MATH_ENTITY_CATEGORY_EXTRA_STRING = "org.solovyev.android.calculator.CalculatorVarsActivity_math_entity_category";
|
||||||
|
|
||||||
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()));
|
||||||
|
|
||||||
protected final static List<Character> acceptableChars = Arrays.asList(StringUtils.toObject("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_".toCharArray()));
|
|
||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
/*
|
*
|
||||||
**********************************************************************
|
* FIELDS
|
||||||
*
|
*
|
||||||
* FIELDS
|
**********************************************************************
|
||||||
*
|
*/
|
||||||
**********************************************************************
|
|
||||||
*/
|
@Nullable
|
||||||
|
private MathEntityArrayAdapter<T> adapter;
|
||||||
@Nullable
|
|
||||||
private MathEntityArrayAdapter<T> adapter;
|
@Nullable
|
||||||
|
private String category;
|
||||||
@Nullable
|
|
||||||
private String category;
|
@NotNull
|
||||||
|
private CalculatorFragmentHelper fragmentHelper;
|
||||||
@Nullable
|
|
||||||
private AdView adView;
|
|
||||||
|
protected int getLayoutId() {
|
||||||
@NotNull
|
return R.layout.math_entities_fragment;
|
||||||
private CalculatorFragmentHelper fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected int getLayoutResId() {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
return R.layout.math_entities;
|
super.onCreate(savedInstanceState);
|
||||||
}
|
|
||||||
|
final Bundle bundle = getArguments();
|
||||||
|
if ( bundle != null ) {
|
||||||
@Override
|
category = bundle.getString(MATH_ENTITY_CATEGORY_EXTRA_STRING);
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
}
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(getLayoutId());
|
||||||
final Bundle bundle = getArguments();
|
fragmentHelper.onCreate(this);
|
||||||
if ( bundle != null ) {
|
}
|
||||||
category = bundle.getString(MATH_ENTITY_CATEGORY_EXTRA_STRING);
|
|
||||||
}
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
fragmentHelper.onCreate(this);
|
return fragmentHelper.onCreateView(this, inflater, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||||
return inflater.inflate(getLayoutResId(), container, false);
|
super.onViewCreated(root, savedInstanceState);
|
||||||
}
|
|
||||||
|
fragmentHelper.onViewCreated(this, root);
|
||||||
@Override
|
this.fragmentHelper.setPaneTitle(this, getTitleResId());
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
|
||||||
super.onViewCreated(view, savedInstanceState);
|
final ListView lv = getListView();
|
||||||
|
lv.setTextFilterEnabled(true);
|
||||||
this.fragmentHelper.setPaneTitle(this, getTitleResId());
|
|
||||||
|
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
final ListView lv = getListView();
|
public void onItemClick(final AdapterView<?> parent,
|
||||||
lv.setTextFilterEnabled(true);
|
final View view,
|
||||||
|
final int position,
|
||||||
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
final long id) {
|
||||||
public void onItemClick(final AdapterView<?> parent,
|
|
||||||
final View view,
|
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(((MathEntity) parent.getItemAtPosition(position)).getName());
|
||||||
final int position,
|
getActivity().finish();
|
||||||
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) {
|
||||||
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
final T item = (T) parent.getItemAtPosition(position);
|
||||||
@Override
|
|
||||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
final List<LabeledMenuItem<T>> menuItems = getMenuItemsOnLongClick(item);
|
||||||
final T item = (T) parent.getItemAtPosition(position);
|
|
||||||
|
if (!menuItems.isEmpty()) {
|
||||||
final List<LabeledMenuItem<T>> menuItems = getMenuItemsOnLongClick(item);
|
final AMenuBuilder<LabeledMenuItem<T>, T> menuBuilder = AMenuBuilder.newInstance(AbstractMathEntityListFragment.this.getActivity(), MenuImpl.newInstance(menuItems));
|
||||||
|
menuBuilder.create(item).show();
|
||||||
if (!menuItems.isEmpty()) {
|
}
|
||||||
final AMenuBuilder<LabeledMenuItem<T>, T> menuBuilder = AMenuBuilder.newInstance(AbstractMathEntityListFragment.this.getActivity(), MenuImpl.newInstance(menuItems));
|
|
||||||
menuBuilder.create(item).show();
|
return true;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
});
|
protected abstract int getTitleResId();
|
||||||
|
|
||||||
adView = AdsController.getInstance().inflateAd(this.getActivity(), (ViewGroup)view.findViewById(R.id.ad_parent_view), R.id.ad_parent_view);
|
@Override
|
||||||
}
|
public void onDestroy() {
|
||||||
|
fragmentHelper.onDestroy(this);
|
||||||
protected abstract int getTitleResId();
|
|
||||||
|
super.onDestroy();
|
||||||
@Override
|
}
|
||||||
public void onDestroy() {
|
|
||||||
if (this.adView != null) {
|
@NotNull
|
||||||
this.adView.destroy();
|
protected abstract List<LabeledMenuItem<T>> getMenuItemsOnLongClick(@NotNull T item);
|
||||||
}
|
|
||||||
|
@Override
|
||||||
fragmentHelper.onDestroy(this);
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
super.onDestroy();
|
|
||||||
}
|
adapter = new MathEntityArrayAdapter<T>(getDescriptionGetter(), this.getActivity(), R.layout.math_entity, R.id.math_entity_text, getMathEntitiesByCategory());
|
||||||
|
setListAdapter(adapter);
|
||||||
@NotNull
|
|
||||||
protected abstract List<LabeledMenuItem<T>> getMenuItemsOnLongClick(@NotNull T item);
|
sort();
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void onResume() {
|
@NotNull
|
||||||
super.onResume();
|
private List<T> getMathEntitiesByCategory() {
|
||||||
|
final List<T> result = getMathEntities();
|
||||||
adapter = new MathEntityArrayAdapter<T>(getDescriptionGetter(), this.getActivity(), R.layout.math_entity, R.id.math_entity_text, getMathEntitiesByCategory());
|
|
||||||
setListAdapter(adapter);
|
new Filter<T>(new FilterRule<T>() {
|
||||||
|
@Override
|
||||||
sort();
|
public boolean isFiltered(T t) {
|
||||||
}
|
return !isInCategory(t);
|
||||||
|
}
|
||||||
@NotNull
|
}).filter(result.iterator());
|
||||||
private List<T> getMathEntitiesByCategory() {
|
|
||||||
final List<T> result = getMathEntities();
|
return result;
|
||||||
|
}
|
||||||
new Filter<T>(new FilterRule<T>() {
|
|
||||||
@Override
|
protected boolean isInCategory(@Nullable T t) {
|
||||||
public boolean isFiltered(T t) {
|
return t != null && (category == null || EqualsTool.areEqual(getMathEntityCategory(t), category));
|
||||||
return !isInCategory(t);
|
}
|
||||||
}
|
|
||||||
}).filter(result.iterator());
|
@NotNull
|
||||||
|
protected abstract MathEntityDescriptionGetter getDescriptionGetter();
|
||||||
return result;
|
|
||||||
}
|
@NotNull
|
||||||
|
protected abstract List<T> getMathEntities();
|
||||||
protected boolean isInCategory(@Nullable T t) {
|
|
||||||
return t != null && (category == null || EqualsTool.areEqual(getMathEntityCategory(t), category));
|
@Nullable
|
||||||
}
|
abstract String getMathEntityCategory(@NotNull T t);
|
||||||
|
|
||||||
@NotNull
|
protected void sort() {
|
||||||
protected abstract MathEntityDescriptionGetter getDescriptionGetter();
|
final MathEntityArrayAdapter<T> localAdapter = adapter;
|
||||||
|
if (localAdapter != null) {
|
||||||
@NotNull
|
localAdapter.sort(new Comparator<T>() {
|
||||||
protected abstract List<T> getMathEntities();
|
@Override
|
||||||
|
public int compare(T function1, T function2) {
|
||||||
@Nullable
|
return function1.getName().compareTo(function2.getName());
|
||||||
abstract String getMathEntityCategory(@NotNull T t);
|
}
|
||||||
|
});
|
||||||
protected void sort() {
|
|
||||||
final MathEntityArrayAdapter<T> localAdapter = adapter;
|
localAdapter.notifyDataSetChanged();
|
||||||
if (localAdapter != null) {
|
}
|
||||||
localAdapter.sort(new Comparator<T>() {
|
}
|
||||||
@Override
|
|
||||||
public int compare(T function1, T function2) {
|
protected static class MathEntityArrayAdapter<T extends MathEntity> extends ArrayAdapter<T> {
|
||||||
return function1.getName().compareTo(function2.getName());
|
|
||||||
}
|
@NotNull
|
||||||
});
|
private final MathEntityDescriptionGetter descriptionGetter;
|
||||||
|
|
||||||
localAdapter.notifyDataSetChanged();
|
private MathEntityArrayAdapter(@NotNull MathEntityDescriptionGetter descriptionGetter,
|
||||||
}
|
@NotNull Context context,
|
||||||
}
|
int resource,
|
||||||
|
int textViewResourceId,
|
||||||
protected static class MathEntityArrayAdapter<T extends MathEntity> extends ArrayAdapter<T> {
|
@NotNull List<T> objects) {
|
||||||
|
|
||||||
@NotNull
|
super(context, resource, textViewResourceId, objects);
|
||||||
private final MathEntityDescriptionGetter descriptionGetter;
|
this.descriptionGetter = descriptionGetter;
|
||||||
|
}
|
||||||
private MathEntityArrayAdapter(@NotNull MathEntityDescriptionGetter descriptionGetter,
|
|
||||||
@NotNull Context context,
|
@Override
|
||||||
int resource,
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
int textViewResourceId,
|
final ViewGroup result = (ViewGroup) super.getView(position, convertView, parent);
|
||||||
@NotNull List<T> objects) {
|
|
||||||
|
final T mathEntity = getItem(position);
|
||||||
super(context, resource, textViewResourceId, objects);
|
|
||||||
this.descriptionGetter = descriptionGetter;
|
final String mathEntityDescription = descriptionGetter.getDescription(getContext(), mathEntity.getName());
|
||||||
}
|
if (!StringUtils.isEmpty(mathEntityDescription)) {
|
||||||
|
TextView description = (TextView) result.findViewById(R.id.math_entity_description);
|
||||||
@Override
|
if (description == null) {
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
final LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
|
||||||
final ViewGroup result = (ViewGroup) super.getView(position, convertView, parent);
|
final ViewGroup itemView = (ViewGroup) layoutInflater.inflate(R.layout.math_entity, null);
|
||||||
|
description = (TextView) itemView.findViewById(R.id.math_entity_description);
|
||||||
final T mathEntity = getItem(position);
|
itemView.removeView(description);
|
||||||
|
result.addView(description);
|
||||||
final String mathEntityDescription = descriptionGetter.getDescription(getContext(), mathEntity.getName());
|
}
|
||||||
if (!StringUtils.isEmpty(mathEntityDescription)) {
|
description.setText(mathEntityDescription);
|
||||||
TextView description = (TextView) result.findViewById(R.id.math_entity_description);
|
} else {
|
||||||
if (description == null) {
|
TextView description = (TextView) result.findViewById(R.id.math_entity_description);
|
||||||
final LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
|
if (description != null) {
|
||||||
final ViewGroup itemView = (ViewGroup) layoutInflater.inflate(R.layout.math_entity, null);
|
result.removeView(description);
|
||||||
description = (TextView) itemView.findViewById(R.id.math_entity_description);
|
}
|
||||||
itemView.removeView(description);
|
}
|
||||||
result.addView(description);
|
|
||||||
}
|
|
||||||
description.setText(mathEntityDescription);
|
return result;
|
||||||
} else {
|
}
|
||||||
TextView description = (TextView) result.findViewById(R.id.math_entity_description);
|
}
|
||||||
if (description != null) {
|
|
||||||
result.removeView(description);
|
protected static class MathEntityDescriptionGetterImpl implements MathEntityDescriptionGetter {
|
||||||
}
|
|
||||||
}
|
@NotNull
|
||||||
|
private final CalculatorMathRegistry<?> mathRegistry;
|
||||||
|
|
||||||
return result;
|
public MathEntityDescriptionGetterImpl(@NotNull CalculatorMathRegistry<?> mathRegistry) {
|
||||||
}
|
this.mathRegistry = mathRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class MathEntityDescriptionGetterImpl implements MathEntityDescriptionGetter {
|
@Override
|
||||||
|
public String getDescription(@NotNull Context context, @NotNull String mathEntityName) {
|
||||||
@NotNull
|
return this.mathRegistry.getDescription(mathEntityName);
|
||||||
private final CalculatorMathRegistry<?> mathRegistry;
|
}
|
||||||
|
}
|
||||||
public MathEntityDescriptionGetterImpl(@NotNull CalculatorMathRegistry<?> mathRegistry) {
|
|
||||||
this.mathRegistry = mathRegistry;
|
protected static interface MathEntityDescriptionGetter {
|
||||||
}
|
|
||||||
|
@Nullable
|
||||||
@Override
|
String getDescription(@NotNull Context context, @NotNull String mathEntityName);
|
||||||
public String getDescription(@NotNull Context context, @NotNull String mathEntityName) {
|
}
|
||||||
return this.mathRegistry.getDescription(mathEntityName);
|
|
||||||
}
|
public void addToAdapter(@NotNull T mathEntity) {
|
||||||
}
|
if (this.adapter != null) {
|
||||||
|
this.adapter.add(mathEntity);
|
||||||
protected static interface MathEntityDescriptionGetter {
|
}
|
||||||
|
}
|
||||||
@Nullable
|
|
||||||
String getDescription(@NotNull Context context, @NotNull String mathEntityName);
|
public void removeFromAdapter(@NotNull T mathEntity) {
|
||||||
}
|
if (this.adapter != null) {
|
||||||
|
this.adapter.remove(mathEntity);
|
||||||
public void addToAdapter(@NotNull T mathEntity) {
|
}
|
||||||
if (this.adapter != null) {
|
}
|
||||||
this.adapter.add(mathEntity);
|
|
||||||
}
|
public void notifyAdapter() {
|
||||||
}
|
if (this.adapter != null) {
|
||||||
|
this.adapter.notifyDataSetChanged();
|
||||||
public void removeFromAdapter(@NotNull T mathEntity) {
|
}
|
||||||
if (this.adapter != null) {
|
}
|
||||||
this.adapter.remove(mathEntity);
|
|
||||||
}
|
/*
|
||||||
}
|
**********************************************************************
|
||||||
|
*
|
||||||
public void notifyAdapter() {
|
* STATIC
|
||||||
if (this.adapter != null) {
|
*
|
||||||
this.adapter.notifyDataSetChanged();
|
**********************************************************************
|
||||||
}
|
*/
|
||||||
}
|
|
||||||
|
static void createTab(@NotNull Context context,
|
||||||
/*
|
@NotNull TabHost tabHost,
|
||||||
**********************************************************************
|
@NotNull String tabId,
|
||||||
*
|
@NotNull String categoryId,
|
||||||
* STATIC
|
int tabCaptionId,
|
||||||
*
|
@NotNull Class<? extends Activity> activityClass,
|
||||||
**********************************************************************
|
@Nullable Intent parentIntent) {
|
||||||
*/
|
|
||||||
|
TabHost.TabSpec spec;
|
||||||
static void createTab(@NotNull Context context,
|
|
||||||
@NotNull TabHost tabHost,
|
final Intent intent;
|
||||||
@NotNull String tabId,
|
if (parentIntent != null) {
|
||||||
@NotNull String categoryId,
|
intent = new Intent(parentIntent);
|
||||||
int tabCaptionId,
|
} else {
|
||||||
@NotNull Class<? extends Activity> activityClass,
|
intent = new Intent();
|
||||||
@Nullable Intent parentIntent) {
|
}
|
||||||
|
intent.setClass(context, activityClass);
|
||||||
TabHost.TabSpec spec;
|
intent.putExtra(MATH_ENTITY_CATEGORY_EXTRA_STRING, categoryId);
|
||||||
|
|
||||||
final Intent intent;
|
// Initialize a TabSpec for each tab and add it to the TabHost
|
||||||
if (parentIntent != null) {
|
spec = tabHost.newTabSpec(tabId).setIndicator(context.getString(tabCaptionId)).setContent(intent);
|
||||||
intent = new Intent(parentIntent);
|
|
||||||
} else {
|
tabHost.addTab(spec);
|
||||||
intent = new Intent();
|
}
|
||||||
}
|
|
||||||
intent.setClass(context, activityClass);
|
@NotNull
|
||||||
intent.putExtra(MATH_ENTITY_CATEGORY_EXTRA_STRING, categoryId);
|
public static Bundle createBundleFor(@NotNull String categoryId) {
|
||||||
|
final Bundle result = new Bundle(1);
|
||||||
// Initialize a TabSpec for each tab and add it to the TabHost
|
putCategory(result, categoryId);
|
||||||
spec = tabHost.newTabSpec(tabId).setIndicator(context.getString(tabCaptionId)).setContent(intent);
|
return result;
|
||||||
|
}
|
||||||
tabHost.addTab(spec);
|
|
||||||
}
|
static void putCategory(@NotNull Bundle bundle, @NotNull String categoryId) {
|
||||||
|
bundle.putString(MATH_ENTITY_CATEGORY_EXTRA_STRING, categoryId);
|
||||||
@NotNull
|
}
|
||||||
public static Bundle createBundleFor(@NotNull String categoryId) {
|
}
|
||||||
final Bundle result = new Bundle(1);
|
|
||||||
result.putString(MATH_ENTITY_CATEGORY_EXTRA_STRING, categoryId);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,69 +1,68 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
* or visit http://se.solovyev.org
|
* or visit http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.math.edit;
|
package org.solovyev.android.calculator.math.edit;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
|
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
|
||||||
import org.solovyev.android.calculator.model.AndroidFunctionsMathRegistry;
|
import org.solovyev.android.calculator.model.AndroidFunctionsMathRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 12/21/11
|
* Date: 12/21/11
|
||||||
* Time: 10:33 PM
|
* Time: 10:33 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorFunctionsFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
public class CalculatorFunctionsFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
|
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
activityHelper.onCreate(this, savedInstanceState);
|
activityHelper.onCreate(this, savedInstanceState);
|
||||||
|
|
||||||
for (AndroidFunctionsMathRegistry.Category category : AndroidFunctionsMathRegistry.Category.getCategoriesByTabOrder()) {
|
for (AndroidFunctionsMathRegistry.Category category : AndroidFunctionsMathRegistry.Category.getCategoriesByTabOrder()) {
|
||||||
activityHelper.addTab(this, category.name(), CalculatorHistoryFragment.class, null, category.getCaptionId(), R.id.main_layout);
|
activityHelper.addTab(this, category.name(), CalculatorFunctionsFragment.class, AbstractMathEntityListFragment.createBundleFor(category.name()), category.getCaptionId(), R.id.main_layout);
|
||||||
|
}
|
||||||
}
|
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
super.onSaveInstanceState(outState);
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
|
activityHelper.onSaveInstanceState(this, outState);
|
||||||
activityHelper.onSaveInstanceState(this, outState);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
protected void onResume() {
|
||||||
protected void onResume() {
|
super.onResume();
|
||||||
super.onResume();
|
|
||||||
|
activityHelper.onResume(this);
|
||||||
activityHelper.onResume(this);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
protected void onDestroy() {
|
||||||
protected void onDestroy() {
|
super.onDestroy();
|
||||||
super.onDestroy();
|
|
||||||
|
this.activityHelper.onDestroy(this);
|
||||||
this.activityHelper.onDestroy(this);
|
|
||||||
|
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
//To change body of implemented methods use File | Settings | File Templates.
|
||||||
//To change body of implemented methods use File | Settings | File Templates.
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -1,310 +1,320 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
* or visit http://se.solovyev.org
|
* or visit http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.math.edit;
|
package org.solovyev.android.calculator.math.edit;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.text.ClipboardManager;
|
import android.text.ClipboardManager;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import jscl.math.function.IConstant;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
import jscl.math.function.IConstant;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.math.MathType;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.model.Var;
|
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||||
import org.solovyev.android.menu.LabeledMenuItem;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.common.JPredicate;
|
import org.solovyev.android.calculator.math.MathType;
|
||||||
import org.solovyev.common.collections.CollectionsUtils;
|
import org.solovyev.android.calculator.model.Var;
|
||||||
import org.solovyev.common.text.StringUtils;
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
|
import org.solovyev.common.JPredicate;
|
||||||
import java.util.ArrayList;
|
import org.solovyev.common.collections.CollectionsUtils;
|
||||||
import java.util.Arrays;
|
import org.solovyev.common.text.StringUtils;
|
||||||
import java.util.List;
|
|
||||||
|
import java.util.ArrayList;
|
||||||
/**
|
import java.util.Arrays;
|
||||||
* User: serso
|
import java.util.List;
|
||||||
* Date: 9/28/11
|
|
||||||
* Time: 10:55 PM
|
/**
|
||||||
*/
|
* User: serso
|
||||||
public class CalculatorVarsFragment extends AbstractMathEntityListFragment<IConstant> {
|
* Date: 9/28/11
|
||||||
|
* Time: 10:55 PM
|
||||||
public static final String CREATE_VAR_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorVarsTabActivity_create_var";
|
*/
|
||||||
|
public class CalculatorVarsFragment extends AbstractMathEntityListFragment<IConstant> {
|
||||||
@Override
|
|
||||||
protected int getLayoutResId() {
|
public static final String CREATE_VAR_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorVarsTabActivity_create_var";
|
||||||
return R.layout.vars_fragment;
|
|
||||||
}
|
@Override
|
||||||
|
protected int getLayoutId() {
|
||||||
@Override
|
return R.layout.vars_fragment;
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
}
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
@Override
|
||||||
final Bundle bundle = getArguments();
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
if (bundle != null) {
|
super.onCreate(savedInstanceState);
|
||||||
final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING);
|
|
||||||
if (!StringUtils.isEmpty(varValue)) {
|
final Bundle bundle = getArguments();
|
||||||
createEditVariableDialog(this, null, null, varValue, null);
|
if (bundle != null) {
|
||||||
|
final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING);
|
||||||
// in order to stop intent for other tabs
|
if (!StringUtils.isEmpty(varValue)) {
|
||||||
bundle.remove(CREATE_VAR_EXTRA_STRING);
|
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;
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@Override
|
||||||
@Override
|
protected int getTitleResId() {
|
||||||
protected List<LabeledMenuItem<IConstant>> getMenuItemsOnLongClick(@NotNull IConstant item) {
|
return R.string.c_vars;
|
||||||
final List<LabeledMenuItem<IConstant>> result = new ArrayList<LabeledMenuItem<IConstant>>(Arrays.asList(LongClickMenuItem.values()));
|
}
|
||||||
|
|
||||||
if ( item.isSystem() ) {
|
@NotNull
|
||||||
result.remove(LongClickMenuItem.edit);
|
@Override
|
||||||
result.remove(LongClickMenuItem.remove);
|
protected List<LabeledMenuItem<IConstant>> getMenuItemsOnLongClick(@NotNull IConstant item) {
|
||||||
}
|
final List<LabeledMenuItem<IConstant>> result = new ArrayList<LabeledMenuItem<IConstant>>(Arrays.asList(LongClickMenuItem.values()));
|
||||||
|
|
||||||
if ( StringUtils.isEmpty(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getDescription(item.getName())) ) {
|
if ( item.isSystem() ) {
|
||||||
result.remove(LongClickMenuItem.copy_description);
|
result.remove(LongClickMenuItem.edit);
|
||||||
}
|
result.remove(LongClickMenuItem.remove);
|
||||||
|
}
|
||||||
if ( StringUtils.isEmpty(item.getValue()) ) {
|
|
||||||
result.remove(LongClickMenuItem.copy_value);
|
if ( StringUtils.isEmpty(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getDescription(item.getName())) ) {
|
||||||
}
|
result.remove(LongClickMenuItem.copy_description);
|
||||||
|
}
|
||||||
return result;
|
|
||||||
}
|
if ( StringUtils.isEmpty(item.getValue()) ) {
|
||||||
|
result.remove(LongClickMenuItem.copy_value);
|
||||||
@NotNull
|
}
|
||||||
@Override
|
|
||||||
protected MathEntityDescriptionGetter getDescriptionGetter() {
|
return result;
|
||||||
return new MathEntityDescriptionGetterImpl(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry());
|
}
|
||||||
}
|
|
||||||
|
@NotNull
|
||||||
@SuppressWarnings({"UnusedDeclaration"})
|
@Override
|
||||||
public void addVarButtonClickHandler(@NotNull View v) {
|
protected MathEntityDescriptionGetter getDescriptionGetter() {
|
||||||
createEditVariableDialog(this, null, null, null, null);
|
return new MathEntityDescriptionGetterImpl(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
@Override
|
public void addVarButtonClickHandler(@NotNull View v) {
|
||||||
protected List<IConstant> getMathEntities() {
|
createEditVariableDialog(this, null, null, null, null);
|
||||||
final List<IConstant> result = new ArrayList<IConstant>(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getEntities());
|
}
|
||||||
|
|
||||||
CollectionsUtils.removeAll(result, new JPredicate<IConstant>() {
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(@Nullable IConstant var) {
|
protected List<IConstant> getMathEntities() {
|
||||||
return var != null && CollectionsUtils.contains(var.getName(), MathType.INFINITY_JSCL, MathType.NAN);
|
final List<IConstant> result = new ArrayList<IConstant>(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getEntities());
|
||||||
}
|
|
||||||
});
|
CollectionsUtils.removeAll(result, new JPredicate<IConstant>() {
|
||||||
|
@Override
|
||||||
return result;
|
public boolean apply(@Nullable IConstant var) {
|
||||||
}
|
return var != null && CollectionsUtils.contains(var.getName(), MathType.INFINITY_JSCL, MathType.NAN);
|
||||||
|
}
|
||||||
@Override
|
});
|
||||||
protected String getMathEntityCategory(@NotNull IConstant var) {
|
|
||||||
return CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getCategory(var);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createEditVariableDialog(@NotNull final AbstractMathEntityListFragment<IConstant> fragment,
|
@Override
|
||||||
@Nullable final IConstant var,
|
protected String getMathEntityCategory(@NotNull IConstant var) {
|
||||||
@Nullable final String name,
|
return CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getCategory(var);
|
||||||
@Nullable final String value,
|
}
|
||||||
@Nullable final String description) {
|
|
||||||
final FragmentActivity activity = fragment.getActivity();
|
private static void createEditVariableDialog(@NotNull final AbstractMathEntityListFragment<IConstant> fragment,
|
||||||
|
@Nullable final IConstant var,
|
||||||
if (var == null || !var.isSystem()) {
|
@Nullable final String name,
|
||||||
|
@Nullable final String value,
|
||||||
final LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
|
@Nullable final String description) {
|
||||||
final View editView = layoutInflater.inflate(R.layout.var_edit, null);
|
final FragmentActivity activity = fragment.getActivity();
|
||||||
|
|
||||||
final String errorMsg = fragment.getString(R.string.c_char_is_not_accepted);
|
if (var == null || !var.isSystem()) {
|
||||||
|
|
||||||
final EditText editName = (EditText) editView.findViewById(R.id.var_edit_name);
|
final LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
|
||||||
editName.setText(name);
|
final View editView = layoutInflater.inflate(R.layout.var_edit, null);
|
||||||
editName.addTextChangedListener(new TextWatcher() {
|
|
||||||
|
final String errorMsg = fragment.getString(R.string.c_char_is_not_accepted);
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
final EditText editName = (EditText) editView.findViewById(R.id.var_edit_name);
|
||||||
}
|
editName.setText(name);
|
||||||
|
editName.addTextChangedListener(new TextWatcher() {
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
@Override
|
||||||
}
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
@Override
|
||||||
for (int i = 0; i < s.length(); i++) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
char c = s.charAt(i);
|
}
|
||||||
if (!acceptableChars.contains(c)) {
|
|
||||||
s.delete(i, i + 1);
|
@Override
|
||||||
Toast.makeText(activity, String.format(errorMsg, c), Toast.LENGTH_SHORT).show();
|
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);
|
final EditText editValue = (EditText) editView.findViewById(R.id.var_edit_value);
|
||||||
editDescription.setText(description);
|
if (!StringUtils.isEmpty(value)) {
|
||||||
|
editValue.setText(value);
|
||||||
final Var.Builder varBuilder;
|
}
|
||||||
if (var != null) {
|
|
||||||
varBuilder = new Var.Builder(var);
|
final EditText editDescription = (EditText) editView.findViewById(R.id.var_edit_description);
|
||||||
} else {
|
editDescription.setText(description);
|
||||||
varBuilder = new Var.Builder();
|
|
||||||
}
|
final Var.Builder varBuilder;
|
||||||
|
if (var != null) {
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(activity)
|
varBuilder = new Var.Builder(var);
|
||||||
.setCancelable(true)
|
} else {
|
||||||
.setNegativeButton(R.string.c_cancel, null)
|
varBuilder = new Var.Builder();
|
||||||
.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) {
|
final AlertDialog.Builder builder = new AlertDialog.Builder(activity)
|
||||||
createEditVariableDialog(activity, editedInstance, name, value, description);
|
.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>() {
|
||||||
.setView(editView);
|
@Override
|
||||||
|
public void showEditor(@NotNull AbstractMathEntityListFragment<IConstant> activity, @Nullable IConstant editedInstance, @Nullable String name, @Nullable String value, @Nullable String description) {
|
||||||
if (var != null) {
|
createEditVariableDialog(activity, editedInstance, name, value, description);
|
||||||
// EDIT mode
|
}
|
||||||
|
}))
|
||||||
builder.setTitle(R.string.c_var_edit_var);
|
.setView(editView);
|
||||||
builder.setNeutralButton(R.string.c_remove, new MathEntityRemover<IConstant>(var, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
if (var != null) {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
// EDIT mode
|
||||||
createEditVariableDialog(fragment, var, name, value, description);
|
|
||||||
}
|
builder.setTitle(R.string.c_var_edit_var);
|
||||||
}, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), fragment));
|
builder.setNeutralButton(R.string.c_remove, new MathEntityRemover<IConstant>(var, new DialogInterface.OnClickListener() {
|
||||||
} else {
|
@Override
|
||||||
// CREATE mode
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
createEditVariableDialog(fragment, var, name, value, description);
|
||||||
builder.setTitle(R.string.c_var_create_var);
|
}
|
||||||
}
|
}, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), fragment));
|
||||||
|
} else {
|
||||||
builder.create().show();
|
// CREATE mode
|
||||||
} else {
|
|
||||||
Toast.makeText(activity, fragment.getString(R.string.c_sys_var_cannot_be_changed), Toast.LENGTH_LONG).show();
|
builder.setTitle(R.string.c_var_create_var);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
builder.create().show();
|
||||||
public static boolean isValidValue(@NotNull String value) {
|
} else {
|
||||||
// now every string might be constant
|
Toast.makeText(activity, fragment.getString(R.string.c_sys_var_cannot_be_changed), Toast.LENGTH_LONG).show();
|
||||||
return true;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo serso: menu
|
public static boolean isValidValue(@NotNull String value) {
|
||||||
/* @Override
|
// now every string might be constant
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
return true;
|
||||||
final MenuInflater menuInflater = getMenuInflater();
|
}
|
||||||
menuInflater.inflate(R.menu.var_menu, menu);
|
|
||||||
return true;
|
/*
|
||||||
}
|
**********************************************************************
|
||||||
|
*
|
||||||
@Override
|
* MENU
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
*
|
||||||
boolean result;
|
**********************************************************************
|
||||||
|
*/
|
||||||
switch (item.getItemId()) {
|
|
||||||
case R.id.var_menu_add_var:
|
@Override
|
||||||
createEditVariableDialog(this, null, null, null, null);
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
result = true;
|
inflater.inflate(R.menu.var_menu, menu);
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
result = super.onOptionsItemSelected(item);
|
@Override
|
||||||
}
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
boolean result;
|
||||||
return result;
|
|
||||||
}*/
|
switch (item.getItemId()) {
|
||||||
|
case R.id.var_menu_add_var:
|
||||||
/*
|
createEditVariableDialog(this, null, null, null, null);
|
||||||
**********************************************************************
|
result = true;
|
||||||
*
|
break;
|
||||||
* STATIC
|
default:
|
||||||
*
|
result = super.onOptionsItemSelected(item);
|
||||||
**********************************************************************
|
}
|
||||||
*/
|
|
||||||
|
return result;
|
||||||
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) {
|
* STATIC
|
||||||
((Activity) context).finish();
|
*
|
||||||
}
|
**********************************************************************
|
||||||
}
|
*/
|
||||||
},
|
|
||||||
|
private static enum LongClickMenuItem implements LabeledMenuItem<IConstant>{
|
||||||
edit(R.string.c_edit) {
|
use(R.string.c_use) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull IConstant data, @NotNull Context context) {
|
public void onClick(@NotNull IConstant data, @NotNull Context context) {
|
||||||
/*if (context instanceof AbstractMathEntityListFragment) {
|
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(data.getName());
|
||||||
createEditVariableDialog((AbstractMathEntityListFragment<IConstant>)context, data, data.getName(), StringUtils.getNotEmpty(data.getValue(), ""), data.getDescription());
|
if (context instanceof Activity) {
|
||||||
}*/
|
((Activity) context).finish();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
},
|
||||||
remove(R.string.c_remove) {
|
|
||||||
@Override
|
edit(R.string.c_edit) {
|
||||||
public void onClick(@NotNull IConstant data, @NotNull Context context) {
|
@Override
|
||||||
/*if (context instanceof AbstractMathEntityListFragment) {
|
public void onClick(@NotNull IConstant data, @NotNull Context context) {
|
||||||
new MathEntityRemover<IConstant>(data, null, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), ((AbstractMathEntityListFragment<IConstant>) context)).showConfirmationDialog();
|
/*if (context instanceof AbstractMathEntityListFragment) {
|
||||||
}*/
|
createEditVariableDialog((AbstractMathEntityListFragment<IConstant>)context, data, data.getName(), StringUtils.getNotEmpty(data.getValue(), ""), data.getDescription());
|
||||||
}
|
}*/
|
||||||
},
|
}
|
||||||
|
},
|
||||||
copy_value(R.string.c_copy_value) {
|
|
||||||
@Override
|
remove(R.string.c_remove) {
|
||||||
public void onClick(@NotNull IConstant data, @NotNull Context context) {
|
@Override
|
||||||
final String text = data.getValue();
|
public void onClick(@NotNull IConstant data, @NotNull Context context) {
|
||||||
if (!StringUtils.isEmpty(text)) {
|
/*if (context instanceof AbstractMathEntityListFragment) {
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
new MathEntityRemover<IConstant>(data, null, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), ((AbstractMathEntityListFragment<IConstant>) context)).showConfirmationDialog();
|
||||||
clipboard.setText(text);
|
}*/
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
|
||||||
|
copy_value(R.string.c_copy_value) {
|
||||||
copy_description(R.string.c_copy_description) {
|
@Override
|
||||||
@Override
|
public void onClick(@NotNull IConstant data, @NotNull Context context) {
|
||||||
public void onClick(@NotNull IConstant data, @NotNull Context context) {
|
final String text = data.getValue();
|
||||||
final String text = CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getDescription(data.getName());
|
if (!StringUtils.isEmpty(text)) {
|
||||||
if (!StringUtils.isEmpty(text)) {
|
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
clipboard.setText(text);
|
||||||
clipboard.setText(text);
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
|
||||||
private final int captionId;
|
copy_description(R.string.c_copy_description) {
|
||||||
|
@Override
|
||||||
LongClickMenuItem(int captionId) {
|
public void onClick(@NotNull IConstant data, @NotNull Context context) {
|
||||||
this.captionId = captionId;
|
final String text = CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getDescription(data.getName());
|
||||||
}
|
if (!StringUtils.isEmpty(text)) {
|
||||||
|
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
||||||
@NotNull
|
clipboard.setText(text);
|
||||||
@Override
|
}
|
||||||
public String getCaption(@NotNull Context context) {
|
}
|
||||||
return context.getString(captionId);
|
};
|
||||||
}
|
private final int captionId;
|
||||||
}
|
|
||||||
}
|
LongClickMenuItem(int captionId) {
|
||||||
|
this.captionId = captionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getCaption(@NotNull Context context) {
|
||||||
|
return context.getString(captionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,82 +1,89 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
* or visit http://se.solovyev.org
|
* or visit http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.math.edit;
|
package org.solovyev.android.calculator.math.edit;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
|
import org.solovyev.android.calculator.model.VarCategory;
|
||||||
import org.solovyev.android.calculator.model.VarCategory;
|
|
||||||
|
/**
|
||||||
/**
|
* User: serso
|
||||||
* User: serso
|
* Date: 12/21/11
|
||||||
* Date: 12/21/11
|
* Time: 11:05 PM
|
||||||
* Time: 11:05 PM
|
*/
|
||||||
*/
|
public class CalculatorVarsFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
||||||
public class CalculatorVarsFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
|
||||||
|
@NotNull
|
||||||
@NotNull
|
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
|
||||||
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
|
|
||||||
|
@Override
|
||||||
@Override
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
activityHelper.onCreate(this, savedInstanceState);
|
||||||
activityHelper.onCreate(this, savedInstanceState);
|
|
||||||
|
final Bundle bundle;
|
||||||
final Bundle bundle;
|
|
||||||
|
final Intent intent = getIntent();
|
||||||
final Intent intent = getIntent();
|
if (intent != null) {
|
||||||
if (intent != null) {
|
bundle = intent.getExtras();
|
||||||
bundle = intent.getExtras();
|
} else {
|
||||||
} else {
|
bundle = null;
|
||||||
bundle = null;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (VarCategory category : VarCategory.getCategoriesByTabOrder()) {
|
for (VarCategory category : VarCategory.getCategoriesByTabOrder()) {
|
||||||
if (category == VarCategory.my) {
|
|
||||||
activityHelper.addTab(this, category.name(), CalculatorHistoryFragment.class, bundle, category.getCaptionId(), R.id.main_layout);
|
final Bundle fragmentParameters;
|
||||||
} else {
|
|
||||||
activityHelper.addTab(this, category.name(), CalculatorHistoryFragment.class, null, category.getCaptionId(), R.id.main_layout);
|
if (category == VarCategory.my && bundle != null) {
|
||||||
}
|
AbstractMathEntityListFragment.putCategory(bundle, category.name());
|
||||||
}
|
fragmentParameters = bundle;
|
||||||
|
} else {
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
|
fragmentParameters = AbstractMathEntityListFragment.createBundleFor(category.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
activityHelper.addTab(this, category.name(), CalculatorVarsFragment.class, fragmentParameters, category.getCaptionId(), R.id.main_layout);
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
}
|
||||||
|
|
||||||
activityHelper.onSaveInstanceState(this, outState);
|
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onResume();
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
activityHelper.onResume(this);
|
activityHelper.onSaveInstanceState(this, outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onResume() {
|
||||||
super.onDestroy();
|
super.onResume();
|
||||||
|
|
||||||
this.activityHelper.onDestroy(this);
|
activityHelper.onResume(this);
|
||||||
|
}
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
|
|
||||||
}
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
@Override
|
super.onDestroy();
|
||||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
|
||||||
//To change body of implemented methods use File | Settings | File Templates.
|
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.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user