history changes
This commit is contained in:
parent
c4ecdbf8d3
commit
dc40632cc0
@ -17,7 +17,7 @@
|
||||
|
||||
<activity a:name=".CalculatorActivity"
|
||||
a:label="@string/c_app_name">
|
||||
s
|
||||
|
||||
<intent-filter>
|
||||
<action a:name="android.intent.action.MAIN"/>
|
||||
<category a:name="android.intent.category.LAUNCHER"/>
|
||||
@ -29,10 +29,18 @@
|
||||
a:label="@string/c_app_settings"
|
||||
a:configChanges="orientation|keyboardHidden"/>
|
||||
|
||||
<activity a:name=".CalculatorHistoryActivity"
|
||||
<activity a:name=".history.CalculatorHistoryActivity"
|
||||
a:label="@string/c_app_history"
|
||||
a:configChanges="orientation|keyboardHidden"/>
|
||||
|
||||
<activity a:name=".history.HistoryActivityTab"
|
||||
a:label="@string/c_history"
|
||||
a:configChanges="orientation|keyboardHidden"/>
|
||||
|
||||
<activity a:name=".history.SavedHistoryActivityTab"
|
||||
a:label="@string/c_saved_history"
|
||||
a:configChanges="orientation|keyboardHidden"/>
|
||||
|
||||
<activity a:name=".AboutActivity"
|
||||
a:label="@string/c_about"
|
||||
a:configChanges="orientation|keyboardHidden"/>
|
||||
|
@ -7,7 +7,7 @@
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:orientation="vertical"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="fill_parent"
|
||||
@ -24,11 +24,11 @@
|
||||
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/leftButton"
|
||||
calc:textUp="◀◀"
|
||||
c:textUp="◀◀"
|
||||
a:text="◀"
|
||||
calc:directionTextScale="0.5"
|
||||
c:directionTextScale="0.5"
|
||||
style="?controlButtonStyle"
|
||||
a:onClick="moveLeftButtonClickHandler"
|
||||
a:layout_width="0dp"
|
||||
@ -37,7 +37,7 @@
|
||||
|
||||
|
||||
<org.solovyev.android.view.widgets.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/eraseButton"
|
||||
a:drawableTop="@drawable/sym_keyboard_delete"
|
||||
style="?controlImageButtonStyle"
|
||||
@ -53,11 +53,13 @@
|
||||
a:layout_weight="4"/>
|
||||
|
||||
<org.solovyev.android.view.widgets.NumeralBasesButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/clearButton"
|
||||
calc:textUp="dec"
|
||||
c:textUp="dec"
|
||||
c:textRight="oct"
|
||||
a:text="@string/c_clear"
|
||||
calc:textDown="bin"
|
||||
c:textDown="bin"
|
||||
c:textLeft="hex"
|
||||
a:textStyle="bold"
|
||||
style="?controlImageButtonStyle"
|
||||
a:onClick="clearButtonClickHandler"
|
||||
@ -66,11 +68,11 @@
|
||||
a:layout_weight="1"/>
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/rightButton"
|
||||
calc:textUp="▶▶"
|
||||
c:textUp="▶▶"
|
||||
a:text="▶"
|
||||
calc:directionTextScale="0.5"
|
||||
c:directionTextScale="0.5"
|
||||
style="?controlButtonStyle"
|
||||
a:onClick="moveRightButtonClickHandler"
|
||||
a:layout_width="0dp"
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:orientation="vertical"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="fill_parent"
|
||||
@ -18,11 +18,11 @@
|
||||
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/leftButton"
|
||||
calc:textUp="◀◀"
|
||||
c:textUp="◀◀"
|
||||
a:text="◀"
|
||||
calc:directionTextScale="0.5"
|
||||
c:directionTextScale="0.5"
|
||||
style="?controlButtonStyle"
|
||||
a:onClick="moveLeftButtonClickHandler"
|
||||
a:layout_width="0dp"
|
||||
@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
<org.solovyev.android.view.widgets.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/eraseButton"
|
||||
a:drawableTop="@drawable/sym_keyboard_delete"
|
||||
style="?controlImageButtonStyle"
|
||||
@ -47,11 +47,13 @@
|
||||
a:layout_weight="4"/>
|
||||
|
||||
<org.solovyev.android.view.widgets.NumeralBasesButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/clearButton"
|
||||
calc:textUp="dec"
|
||||
c:textUp="dec"
|
||||
c:textRight="oct"
|
||||
a:text="@string/c_clear"
|
||||
calc:textDown="bin"
|
||||
c:textDown="bin"
|
||||
c:textLeft="hex"
|
||||
a:textStyle="bold"
|
||||
style="?controlImageButtonStyle"
|
||||
a:onClick="clearButtonClickHandler"
|
||||
@ -60,11 +62,11 @@
|
||||
a:layout_weight="1"/>
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/rightButton"
|
||||
calc:textUp="▶▶"
|
||||
c:textUp="▶▶"
|
||||
a:text="▶"
|
||||
calc:directionTextScale="0.5"
|
||||
c:directionTextScale="0.5"
|
||||
style="?controlButtonStyle"
|
||||
a:onClick="moveRightButtonClickHandler"
|
||||
a:layout_width="0dp"
|
||||
|
@ -7,11 +7,13 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.NumeralBasesButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/clearButton"
|
||||
calc:textUp="dec"
|
||||
c:textUp="dec"
|
||||
c:textRight="oct"
|
||||
a:text="@string/c_clear"
|
||||
calc:textDown="bin"
|
||||
c:textDown="bin"
|
||||
c:textLeft="hex"
|
||||
a:textStyle="bold"
|
||||
style="?controlImageButtonStyle"
|
||||
a:onClick="clearButtonClickHandler"/>
|
@ -7,7 +7,7 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/pasteButton"
|
||||
a:drawableTop="@drawable/copy"
|
||||
style="?controlImageButtonStyle"
|
||||
|
@ -7,11 +7,11 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/divisionButton"
|
||||
calc:textUp="%"
|
||||
c:textUp="%"
|
||||
a:text="/"
|
||||
calc:textDown="√"
|
||||
calc:directionTextScale="0.5"
|
||||
c:textDown="√"
|
||||
c:directionTextScale="0.5"
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -7,7 +7,7 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/pasteButton"
|
||||
a:drawableTop="@drawable/heart"
|
||||
style="?controlImageButtonStyle"
|
||||
|
@ -7,10 +7,10 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/squareBracketsButton"
|
||||
a:text="."
|
||||
calc:textUp=","
|
||||
calc:directionTextScale="0.5"
|
||||
c:textUp=","
|
||||
c:directionTextScale="0.5"
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -7,11 +7,11 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/eightDigitButton" a:text="8"
|
||||
calc:textUp="ln"
|
||||
calc:textLeft="0o:"
|
||||
calc:textDown="lg"
|
||||
calc:directionTextScale="0.5;0.5;0.5;0.33"
|
||||
c:textUp="ln"
|
||||
c:textLeft="0o:"
|
||||
c:textDown="lg"
|
||||
c:directionTextScale="0.5;0.5;0.5;0.33"
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -6,5 +6,5 @@
|
||||
~ or visit http://se.solovyev.org
|
||||
-->
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
style="?controlButtonStyle"/>
|
@ -7,11 +7,11 @@
|
||||
-->
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/equalsButton"
|
||||
calc:textUp="≡"
|
||||
c:textUp="≡"
|
||||
a:text="="
|
||||
calc:directionTextScale="0.5"
|
||||
c:directionTextScale="0.5"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="fill_parent"
|
||||
style="?controlButtonStyle"
|
||||
|
@ -7,7 +7,7 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/eraseButton"
|
||||
a:drawableTop="@drawable/sym_keyboard_delete"
|
||||
style="?controlImageButtonStyle"
|
||||
|
@ -6,11 +6,11 @@
|
||||
~ or visit http://se.solovyev.org
|
||||
-->
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/fiveDigitButton"
|
||||
a:text="5"
|
||||
calc:textUp="t"
|
||||
calc:textLeft="E"
|
||||
calc:textDown="j"
|
||||
c:textUp="t"
|
||||
c:textLeft="E"
|
||||
c:textDown="j"
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -6,11 +6,11 @@
|
||||
~ or visit http://se.solovyev.org
|
||||
-->
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/fourDigitButton"
|
||||
a:text="4"
|
||||
calc:textUp="x"
|
||||
calc:textLeft="D"
|
||||
calc:textDown="y"
|
||||
c:textUp="x"
|
||||
c:textLeft="D"
|
||||
c:textDown="y"
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -7,7 +7,7 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/functionsButton"
|
||||
a:text="ƒ(x)"
|
||||
a:textStyle="italic"
|
||||
|
@ -6,11 +6,11 @@
|
||||
~ or visit http://se.solovyev.org
|
||||
-->
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/historyButton"
|
||||
a:text="@string/c_history_button"
|
||||
calc:textUp="@string/c_undo"
|
||||
calc:textDown="@string/c_redo"
|
||||
c:textUp="@string/c_undo"
|
||||
c:textDown="@string/c_redo"
|
||||
style="?controlButtonStyle"
|
||||
a:textStyle="bold"
|
||||
a:onClick="historyButtonClickHandler"/>
|
@ -7,10 +7,10 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/leftButton"
|
||||
calc:textUp="◀◀"
|
||||
c:textUp="◀◀"
|
||||
a:text="◀"
|
||||
calc:directionTextScale="0.5"
|
||||
c:directionTextScale="0.5"
|
||||
style="?controlButtonStyle"
|
||||
a:onClick="moveLeftButtonClickHandler"/>
|
@ -7,12 +7,12 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/multiplicationButton"
|
||||
a:text="×"
|
||||
calc:textUp="^"
|
||||
calc:textDown="^2"
|
||||
c:textUp="^"
|
||||
c:textDown="^2"
|
||||
style="?digitButtonStyle"
|
||||
calc:directionTextScale="0.5"
|
||||
c:directionTextScale="0.5"
|
||||
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -7,11 +7,11 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/nineDigitButton" a:text="9"
|
||||
calc:textDown="e"
|
||||
calc:textLeft="0x:"
|
||||
calc:textUp="π"
|
||||
calc:directionTextScale="0.5;0.5;0.5;0.33"
|
||||
c:textDown="e"
|
||||
c:textLeft="0x:"
|
||||
c:textUp="π"
|
||||
c:directionTextScale="0.5;0.5;0.5;0.33"
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -7,11 +7,11 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/oneDigitButton"
|
||||
a:text="1"
|
||||
calc:textUp="sin"
|
||||
calc:textLeft="A"
|
||||
calc:textDown="asin"
|
||||
c:textUp="sin"
|
||||
c:textLeft="A"
|
||||
c:textDown="asin"
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -7,7 +7,7 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.ColorButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/pasteButton"
|
||||
a:drawableTop="@drawable/paste"
|
||||
style="?controlImageButtonStyle"
|
||||
|
@ -6,11 +6,11 @@
|
||||
~ or visit http://se.solovyev.org
|
||||
-->
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/plusButton"
|
||||
calc:directionTextScale="0.5"
|
||||
calc:textUp="°"
|
||||
calc:textDown="E"
|
||||
c:directionTextScale="0.5"
|
||||
c:textUp="°"
|
||||
c:textDown="E"
|
||||
a:text="+"
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -7,10 +7,10 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/rightButton"
|
||||
calc:textUp="▶▶"
|
||||
c:textUp="▶▶"
|
||||
a:text="▶"
|
||||
calc:directionTextScale="0.5"
|
||||
c:directionTextScale="0.5"
|
||||
style="?controlButtonStyle"
|
||||
a:onClick="moveRightButtonClickHandler"/>
|
@ -7,11 +7,11 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/roundBracketsButton" a:text="()"
|
||||
calc:textUp="("
|
||||
calc:textDown=")"
|
||||
calc:directionTextScale="0.5"
|
||||
c:textUp="("
|
||||
c:textDown=")"
|
||||
c:directionTextScale="0.5"
|
||||
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -7,11 +7,11 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/sevenDigitButton" a:text="7"
|
||||
calc:textUp="i"
|
||||
calc:textLeft="0b:"
|
||||
calc:textDown="!"
|
||||
calc:directionTextScale="0.5;0.5;0.5;0.33"
|
||||
c:textUp="i"
|
||||
c:textLeft="0b:"
|
||||
c:textDown="!"
|
||||
c:directionTextScale="0.5;0.5;0.5;0.33"
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -7,11 +7,12 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.AngleUnitsButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
calc:textUp="deg"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
c:textUp="deg"
|
||||
a:id="@+id/sixDigitButton"
|
||||
a:text="6"
|
||||
calc:textLeft="F"
|
||||
calc:textDown="rad"
|
||||
c:textLeft="F"
|
||||
c:textRight="grad"
|
||||
c:textDown="rad"
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -6,10 +6,10 @@
|
||||
~ or visit http://se.solovyev.org
|
||||
-->
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/subtractionButton"
|
||||
calc:textDown="∂,…"
|
||||
c:textDown="∂,…"
|
||||
a:text="-"
|
||||
calc:directionTextScale="0.5"
|
||||
c:directionTextScale="0.5"
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -7,11 +7,11 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/threeDigitButton"
|
||||
a:text="3"
|
||||
calc:textUp="tan"
|
||||
calc:textLeft="C"
|
||||
calc:textDown="atan"
|
||||
c:textUp="tan"
|
||||
c:textLeft="C"
|
||||
c:textDown="atan"
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -7,11 +7,11 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/twoDigitButton"
|
||||
a:text="2"
|
||||
calc:textUp="cos"
|
||||
calc:textLeft="B"
|
||||
calc:textDown="acos"
|
||||
c:textUp="cos"
|
||||
c:textLeft="B"
|
||||
c:textDown="acos"
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -7,10 +7,10 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/varsButton"
|
||||
calc:directionTextScale="0.5"
|
||||
calc:textUp="+π"
|
||||
c:directionTextScale="0.5"
|
||||
c:textUp="+π"
|
||||
a:text="π,…"
|
||||
a:textStyle="italic"
|
||||
a:onClick="varsButtonClickHandler"
|
||||
|
@ -7,10 +7,10 @@
|
||||
-->
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:id="@+id/zeroDigitButton"
|
||||
a:text="0"
|
||||
calc:textDown="000"
|
||||
calc:directionTextScale="0.5"
|
||||
c:textDown="000"
|
||||
c:directionTextScale="0.5"
|
||||
style="?digitButtonStyle"
|
||||
a:onClick="digitButtonClickHandler"/>
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
xmlns:c="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
|
||||
a:orientation="vertical"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="fill_parent"
|
||||
@ -23,16 +23,16 @@
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton a:id="@+id/calibrationButtonLeft"
|
||||
a:text=""
|
||||
calc:textUp="@string/c_up"
|
||||
calc:textDown="@string/c_down"
|
||||
c:textUp="@string/c_up"
|
||||
c:textDown="@string/c_down"
|
||||
a:layout_width="80dp"
|
||||
a:layout_height="80dp"
|
||||
style="?digitButtonStyle"/>
|
||||
|
||||
<org.solovyev.android.view.widgets.DirectionDragButton a:id="@+id/calibrationButtonRight"
|
||||
a:text=""
|
||||
calc:textUp="@string/c_up"
|
||||
calc:textDown="@string/c_down"
|
||||
c:textUp="@string/c_up"
|
||||
c:textDown="@string/c_down"
|
||||
a:layout_width="80dp"
|
||||
a:layout_height="80dp"
|
||||
style="?digitButtonStyle"/>
|
||||
|
30
res/layout/history_tabs.xml
Normal file
30
res/layout/history_tabs.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?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
|
||||
-->
|
||||
|
||||
<TabHost xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:id="@android:id/tabhost"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="fill_parent">
|
||||
|
||||
<LinearLayout
|
||||
a:orientation="vertical"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="fill_parent">
|
||||
|
||||
<TabWidget
|
||||
a:id="@android:id/tabs"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="wrap_content"/>
|
||||
|
||||
<FrameLayout
|
||||
a:id="@android:id/tabcontent"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="fill_parent"/>
|
||||
|
||||
</LinearLayout>
|
||||
</TabHost>
|
@ -3,6 +3,7 @@
|
||||
<declare-styleable name="DragButton">
|
||||
<attr name="textUp" format="string"/>
|
||||
<attr name="textDown" format="string"/>
|
||||
<attr name="textRight" format="string"/>
|
||||
<attr name="textLeft" format="string"/>
|
||||
<attr name="directionTextScale" format="string"/>
|
||||
<attr name="hTextPosition" format="float"/>
|
||||
|
@ -314,5 +314,6 @@ Check the \'Round result\' preference in application settings - it should be tur
|
||||
<string name="c_save_history">Save history</string>
|
||||
<string name="c_edit_history">Modify history</string>
|
||||
<string name="c_edit">Modify</string>
|
||||
<string name="c_saved_history">Saved history</string>
|
||||
|
||||
</resources>
|
||||
|
@ -162,7 +162,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
boolean result = false;
|
||||
|
||||
if (dragButton instanceof AngleUnitsButton) {
|
||||
if (dragDirection == DragDirection.up || dragDirection == DragDirection.down ) {
|
||||
if (dragDirection != DragDirection.left ) {
|
||||
final String directionText = ((AngleUnitsButton) dragButton).getText(dragDirection);
|
||||
if ( directionText != null ) {
|
||||
try {
|
||||
@ -564,7 +564,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, @Nullable String key) {
|
||||
dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, this));
|
||||
if (key != null && key.startsWith("org.solovyev.android.calculator.DragButtonCalibrationActivity")) {
|
||||
dpclRegister.announce().onDragPreferencesChange(SimpleOnDragListener.getPreferences(preferences, this));
|
||||
}
|
||||
|
||||
if (CalculatorEngine.GROUPING_SEPARATOR_P_KEY.equals(key) ||
|
||||
CalculatorEngine.MULTIPLICATION_SIGN_P_KEY.equals(key) ||
|
||||
|
@ -8,6 +8,7 @@ import jscl.math.function.Constant;
|
||||
import org.achartengine.ChartFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.help.HelpActivity;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
||||
import org.solovyev.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
|
@ -1,242 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.view.widgets.*;
|
||||
import org.solovyev.common.NumberIntervalMapper;
|
||||
import org.solovyev.common.collections.ManyValuedHashMap;
|
||||
import org.solovyev.common.collections.ManyValuedMap;
|
||||
import org.solovyev.common.utils.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 7/16/11
|
||||
* Time: 7:28 PM
|
||||
*/
|
||||
public class DragButtonCalibrationActivity extends Activity {
|
||||
|
||||
@NotNull
|
||||
private final List<DragData> dragHistory = new ArrayList<DragData>();
|
||||
|
||||
private final Map<DragButton, CalibrationArrow> map = new HashMap<DragButton, CalibrationArrow>();
|
||||
|
||||
private static final float DEFAULT_VALUE = -999;
|
||||
private static final int MIN_HISTORY_FOR_CALIBRATION = 10;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.drag_button_calibration);
|
||||
|
||||
createCalibrationButton(R.id.calibrationButtonRight, R.id.calibrationArrowRight);
|
||||
createCalibrationButton(R.id.calibrationButtonLeft, R.id.calibrationArrowLeft);
|
||||
}
|
||||
|
||||
private void createCalibrationButton(int buttonId, int arrowId) {
|
||||
final DragButton calibrationButton = (DragButton) findViewById(buttonId);
|
||||
calibrationButton.setOnDragListener(new CalibrationOnDragListener());
|
||||
|
||||
ImageView imageView = (ImageView) findViewById(arrowId);
|
||||
CalibrationArrow calibrationArrow = new CalibrationArrow(imageView);
|
||||
|
||||
createDragDirection(0, calibrationArrow);
|
||||
|
||||
map.put(calibrationButton, calibrationArrow);
|
||||
}
|
||||
|
||||
private void createDragDirection(long timeout, @NotNull final CalibrationArrow calibrationArrow) {
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
calibrationArrow.dragDirection = Math.random() > 0.5 ? DragDirection.up : DragDirection.down;
|
||||
|
||||
calibrationArrow.calibrationArrow.setImageResource(calibrationArrow.dragDirection == DragDirection.down ? R.drawable.down : R.drawable.up);
|
||||
}
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
public void restartClickHandler(View v) {
|
||||
for (CalibrationArrow calibrationArrow : map.values()) {
|
||||
createDragDirection(0, calibrationArrow);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class CalibrationOnDragListener implements OnDragListener {
|
||||
|
||||
@Override
|
||||
public boolean isSuppressOnClickEvent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDrag(@NotNull DragButton dragButton, @NotNull DragEvent event) {
|
||||
final Point2d startPoint = event.getStartPoint();
|
||||
final MotionEvent motionEvent = event.getMotionEvent();
|
||||
|
||||
// init end point
|
||||
final Point2d endPoint = new Point2d(motionEvent.getX(), motionEvent.getY());
|
||||
|
||||
float distance = MathUtils.getDistance(startPoint, endPoint);
|
||||
|
||||
double angle = Math.toDegrees(MathUtils.getAngle(startPoint, MathUtils.sum(startPoint, SimpleOnDragListener.axis), endPoint));
|
||||
|
||||
final CalibrationArrow calibrationArrow = map.get(dragButton);
|
||||
final DragDirection dragDirection = calibrationArrow.dragDirection;
|
||||
|
||||
assert dragDirection == DragDirection.up || dragDirection == DragDirection.down;
|
||||
|
||||
double deviationAngle = angle;
|
||||
if (dragDirection == DragDirection.up) {
|
||||
deviationAngle = 180 - deviationAngle;
|
||||
}
|
||||
|
||||
if (deviationAngle > 45) {
|
||||
calibrationArrow.calibrationArrow.setImageResource(R.drawable.not_ok);
|
||||
} else {
|
||||
calibrationArrow.calibrationArrow.setImageResource(R.drawable.ok);
|
||||
dragHistory.add(new DragData(dragDirection, distance, angle, (motionEvent.getEventTime() - motionEvent.getDownTime())));
|
||||
}
|
||||
|
||||
createDragDirection(500, calibrationArrow);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
|
||||
if (dragHistory.size() > MIN_HISTORY_FOR_CALIBRATION) {
|
||||
final ManyValuedMap<DragDirection, Double> anglesByDirection = new ManyValuedHashMap<DragDirection, Double>();
|
||||
final ManyValuedMap<DragDirection, Double> distancesByDirection = new ManyValuedHashMap<DragDirection, Double>();
|
||||
final ManyValuedMap<DragDirection, Double> timesByDirection = new ManyValuedHashMap<DragDirection, Double>();
|
||||
for (DragData dragData : dragHistory) {
|
||||
anglesByDirection.put(dragData.getDirection(), dragData.getAngle());
|
||||
distancesByDirection.put(dragData.getDirection(), (double) dragData.getDistance());
|
||||
timesByDirection.put(dragData.getDirection(), dragData.getTime());
|
||||
}
|
||||
|
||||
final Map<DragDirection, MathUtils.StatData> angleStatData = getStatDataByDirection(anglesByDirection);
|
||||
final Map<DragDirection, MathUtils.StatData> distanceStatData = getStatDataByDirection(distancesByDirection);
|
||||
final Map<DragDirection, MathUtils.StatData> timeStatData = getStatDataByDirection(timesByDirection);
|
||||
|
||||
Log.d(this.getClass().getName(), "Angle statistics: ");
|
||||
logStatData(angleStatData);
|
||||
|
||||
Log.d(this.getClass().getName(), "Distance statistics: ");
|
||||
logStatData(distanceStatData);
|
||||
|
||||
Log.d(this.getClass().getName(), "Time statistics: ");
|
||||
logStatData(timeStatData);
|
||||
|
||||
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
final SharedPreferences.Editor editor = settings.edit();
|
||||
|
||||
setPreferences(angleStatData, editor, SimpleOnDragListener.PreferenceType.angle);
|
||||
setPreferences(distanceStatData, editor, SimpleOnDragListener.PreferenceType.distance);
|
||||
setPreferences(timeStatData, editor, SimpleOnDragListener.PreferenceType.duration);
|
||||
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
private void setPreferences(@NotNull Map<DragDirection, MathUtils.StatData> statData, @NotNull SharedPreferences.Editor editor, @NotNull SimpleOnDragListener.PreferenceType preferenceType) {
|
||||
final Mapper<Interval<Float>> mapper = new NumberIntervalMapper<Float>(Float.class);
|
||||
for (Map.Entry<DragDirection, MathUtils.StatData> entry : statData.entrySet()) {
|
||||
final float min = (float) entry.getValue().getMean() - 2 * (float) entry.getValue().getStandardDeviation();
|
||||
final float max = (float) entry.getValue().getMean() + 2 * (float) entry.getValue().getStandardDeviation();
|
||||
editor.putString(SimpleOnDragListener.getPreferenceId(preferenceType, entry.getKey()), mapper.formatValue(SimpleOnDragListener.transformInterval(preferenceType, entry.getKey(), new NumberInterval<Float>(Math.max(0, min), max))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void logStatData(@NotNull Map<DragDirection, MathUtils.StatData> statData) {
|
||||
for (Map.Entry<DragDirection, MathUtils.StatData> entry : statData.entrySet()) {
|
||||
Log.d(this.getClass().getName(), entry.getKey() + "-> m: " + entry.getValue().getMean() + ", d: " + entry.getValue().getStandardDeviation());
|
||||
}
|
||||
}
|
||||
|
||||
private Map<DragDirection, MathUtils.StatData> getStatDataByDirection(@NotNull ManyValuedMap<DragDirection, Double> valuesByDirection) {
|
||||
final Map<DragDirection, MathUtils.StatData> result = new HashMap<DragDirection, MathUtils.StatData>();
|
||||
|
||||
for (Map.Entry<DragDirection, List<Double>> entry : valuesByDirection.entrySet()) {
|
||||
result.put(entry.getKey(), MathUtils.getStatData(entry.getValue()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private class DragData {
|
||||
|
||||
private float distance;
|
||||
|
||||
private double angle;
|
||||
|
||||
private double time;
|
||||
|
||||
@NotNull
|
||||
private DragDirection direction;
|
||||
|
||||
private DragData(@NotNull DragDirection direction, float distance, double angle, double time) {
|
||||
this.distance = distance;
|
||||
this.angle = angle;
|
||||
this.direction = direction;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public float getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public double getAngle() {
|
||||
return angle;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DragDirection getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public double getTime() {
|
||||
return time;
|
||||
}
|
||||
}
|
||||
|
||||
private class CalibrationArrow {
|
||||
@NotNull
|
||||
private ImageView calibrationArrow;
|
||||
|
||||
@NotNull
|
||||
private DragDirection dragDirection = DragDirection.up;
|
||||
|
||||
private CalibrationArrow(@NotNull ImageView calibrationArrow) {
|
||||
this.calibrationArrow = calibrationArrow;
|
||||
}
|
||||
}
|
||||
}
|
@ -35,8 +35,6 @@ public class HelpActivity extends TabActivity {
|
||||
createTab(tabHost, "screens", R.string.c_screens, HelpScreensActivity.class);
|
||||
|
||||
tabHost.setCurrentTab(0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void createTab(@NotNull TabHost tabHost,
|
||||
@ -49,8 +47,7 @@ public class HelpActivity extends TabActivity {
|
||||
final Intent intent = new Intent().setClass(this, activityClass);
|
||||
|
||||
// Initialize a TabSpec for each tab and add it to the TabHost
|
||||
spec = tabHost.newTabSpec(tabId).setIndicator(getString(tabCaptionId))
|
||||
.setContent(intent);
|
||||
spec = tabHost.newTabSpec(tabId).setIndicator(getString(tabCaptionId)).setContent(intent);
|
||||
|
||||
tabHost.addTab(spec);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
* or visit http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
@ -15,16 +15,15 @@ import android.view.*;
|
||||
import android.widget.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.history.*;
|
||||
import org.solovyev.android.calculator.CalculatorModel;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||
import org.solovyev.android.view.AMenu;
|
||||
import org.solovyev.android.view.AMenuItem;
|
||||
import org.solovyev.android.view.MenuImpl;
|
||||
import org.solovyev.android.view.prefs.ResourceCache;
|
||||
import org.solovyev.common.utils.*;
|
||||
import org.solovyev.common.utils.Filter;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -32,9 +31,9 @@ import java.util.*;
|
||||
* Date: 10/15/11
|
||||
* Time: 1:13 PM
|
||||
*/
|
||||
public class CalculatorHistoryActivity extends ListActivity {
|
||||
public abstract class AbstractHistoryActivity extends ListActivity {
|
||||
|
||||
private static final Comparator<CalculatorHistoryState> COMPARATOR = new Comparator<CalculatorHistoryState>() {
|
||||
public static final Comparator<CalculatorHistoryState> COMPARATOR = new Comparator<CalculatorHistoryState>() {
|
||||
@Override
|
||||
public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) {
|
||||
if (state1.isSaved() == state2.isSaved()) {
|
||||
@ -59,13 +58,12 @@ public class CalculatorHistoryActivity extends ListActivity {
|
||||
|
||||
setContentView(R.layout.history_activity);
|
||||
|
||||
final List<CalculatorHistoryState> historyList = getHistoryList();
|
||||
if ( historyList.isEmpty() ) {
|
||||
/* if ( historyList.isEmpty() ) {
|
||||
Toast.makeText(this, R.string.c_history_is_empty, Toast.LENGTH_SHORT).show();
|
||||
this.finish();
|
||||
}
|
||||
}*/
|
||||
|
||||
adapter = new HistoryArrayAdapter(this, R.layout.history, R.id.history_item, historyList);
|
||||
adapter = new HistoryArrayAdapter(this, R.layout.history, R.id.history_item, new ArrayList<CalculatorHistoryState>());
|
||||
setListAdapter(adapter);
|
||||
|
||||
final ListView lv = getListView();
|
||||
@ -77,7 +75,7 @@ public class CalculatorHistoryActivity extends ListActivity {
|
||||
final int position,
|
||||
final long id) {
|
||||
|
||||
useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position), CalculatorHistoryActivity.this);
|
||||
useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position), AbstractHistoryActivity.this);
|
||||
}
|
||||
});
|
||||
|
||||
@ -86,7 +84,7 @@ public class CalculatorHistoryActivity extends ListActivity {
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
|
||||
final CalculatorHistoryState historyState = (CalculatorHistoryState) parent.getItemAtPosition(position);
|
||||
|
||||
final Context context = CalculatorHistoryActivity.this;
|
||||
final Context context = AbstractHistoryActivity.this;
|
||||
|
||||
final HistoryItemMenuData data = new HistoryItemMenuData(historyState, adapter);
|
||||
|
||||
@ -105,10 +103,11 @@ public class CalculatorHistoryActivity extends ListActivity {
|
||||
if (historyState.getDisplayState().isValid() && StringUtils.isEmpty(historyState.getDisplayState().getEditorState().getText())) {
|
||||
menuItems.remove(HistoryItemMenuItem.copy_result);
|
||||
}
|
||||
|
||||
final AMenu<HistoryItemMenuItem> historyItemMenu = new MenuImpl<HistoryItemMenuItem>(menuItems);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setItems(historyItemMenu.getMenuCaptions(), new DialogInterface.OnClickListener() {
|
||||
final AlertDialog.Builder menuDialogBuilder = new AlertDialog.Builder(context);
|
||||
menuDialogBuilder.setItems(historyItemMenu.getMenuCaptions(), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
final AMenuItem<HistoryItemMenuData> historyItemMenuItem = historyItemMenu.itemAt(item);
|
||||
if (historyItemMenuItem != null) {
|
||||
@ -116,12 +115,31 @@ public class CalculatorHistoryActivity extends ListActivity {
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
menuDialogBuilder.create().show();
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
final List<CalculatorHistoryState> historyList = getHistoryList();
|
||||
try {
|
||||
this.adapter.setNotifyOnChange(false);
|
||||
this.adapter.clear();
|
||||
for (CalculatorHistoryState historyState : historyList) {
|
||||
this.adapter.add(historyState);
|
||||
}
|
||||
} finally {
|
||||
this.adapter.setNotifyOnChange(true);
|
||||
}
|
||||
|
||||
this.adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public static boolean isAlreadySaved(@NotNull CalculatorHistoryState historyState) {
|
||||
assert !historyState.isSaved();
|
||||
|
||||
@ -145,7 +163,7 @@ public class CalculatorHistoryActivity extends ListActivity {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState, @NotNull CalculatorHistoryActivity activity) {
|
||||
public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState, @NotNull AbstractHistoryActivity activity) {
|
||||
|
||||
CalculatorModel.instance.doTextOperation(new CalculatorModel.TextOperation() {
|
||||
@Override
|
||||
@ -161,9 +179,9 @@ public class CalculatorHistoryActivity extends ListActivity {
|
||||
activity.finish();
|
||||
}
|
||||
|
||||
private static List<CalculatorHistoryState> getHistoryList() {
|
||||
final List<CalculatorHistoryState> calculatorHistoryStates = new ArrayList<CalculatorHistoryState>(CalculatorHistory.instance.getStates());
|
||||
calculatorHistoryStates.addAll(CalculatorHistory.instance.getSavedHistory());
|
||||
@NotNull
|
||||
private List<CalculatorHistoryState> getHistoryList() {
|
||||
final List<CalculatorHistoryState> calculatorHistoryStates = getHistoryItems();
|
||||
|
||||
Collections.sort(calculatorHistoryStates, COMPARATOR);
|
||||
|
||||
@ -180,54 +198,8 @@ public class CalculatorHistoryActivity extends ListActivity {
|
||||
return calculatorHistoryStates;
|
||||
}
|
||||
|
||||
public class HistoryArrayAdapter extends ArrayAdapter<CalculatorHistoryState> {
|
||||
|
||||
private HistoryArrayAdapter(Context context, int resource, int textViewResourceId, @NotNull List<CalculatorHistoryState> historyList) {
|
||||
super(context, resource, textViewResourceId, historyList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
final ViewGroup result = (ViewGroup) super.getView(position, convertView, parent);
|
||||
|
||||
final CalculatorHistoryState state = getItem(position);
|
||||
|
||||
final TextView time = (TextView) result.findViewById(R.id.history_time);
|
||||
time.setText(new SimpleDateFormat().format(new Date(state.getTime())));
|
||||
|
||||
final TextView editor = (TextView) result.findViewById(R.id.history_item);
|
||||
editor.setText(getHistoryText(state));
|
||||
|
||||
final TextView commentView = (TextView) result.findViewById(R.id.history_item_comment);
|
||||
final String comment = state.getComment();
|
||||
if (!StringUtils.isEmpty(comment)) {
|
||||
commentView.setText(comment);
|
||||
} else {
|
||||
commentView.setText("");
|
||||
}
|
||||
|
||||
final TextView status = (TextView) result.findViewById(R.id.history_item_status);
|
||||
if (state.isSaved()) {
|
||||
status.setText(ResourceCache.instance.getCaption("c_history_item_saved"));
|
||||
} else {
|
||||
if ( isAlreadySaved(state) ) {
|
||||
status.setText(ResourceCache.instance.getCaption("c_history_item_already_saved"));
|
||||
} else {
|
||||
status.setText(ResourceCache.instance.getCaption("c_history_item_not_saved"));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyDataSetChanged() {
|
||||
this.setNotifyOnChange(false);
|
||||
this.sort(COMPARATOR);
|
||||
this.setNotifyOnChange(true);
|
||||
super.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
@NotNull
|
||||
protected abstract List<CalculatorHistoryState> getHistoryItems();
|
||||
|
||||
@NotNull
|
||||
public static String getHistoryText(@NotNull CalculatorHistoryState state) {
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
* or visit http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.TabActivity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TabHost;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 12/18/11
|
||||
* Time: 7:37 PM
|
||||
*/
|
||||
public class CalculatorHistoryActivity extends TabActivity {
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.history_tabs);
|
||||
|
||||
final TabHost tabHost = getTabHost();
|
||||
|
||||
createTab(tabHost, "saved_history", R.string.c_saved_history, SavedHistoryActivityTab.class);
|
||||
createTab(tabHost, "history", R.string.c_history, HistoryActivityTab.class);
|
||||
|
||||
tabHost.setCurrentTab(0);
|
||||
}
|
||||
|
||||
private void createTab(@NotNull TabHost tabHost,
|
||||
@NotNull String tabId,
|
||||
int tabCaptionId,
|
||||
@NotNull Class<? extends Activity> activityClass) {
|
||||
|
||||
TabHost.TabSpec spec;
|
||||
|
||||
final Intent intent = new Intent().setClass(this, activityClass);
|
||||
|
||||
// Initialize a TabSpec for each tab and add it to the TabHost
|
||||
spec = tabHost.newTabSpec(tabId).setIndicator(getString(tabCaptionId)).setContent(intent);
|
||||
|
||||
tabHost.addTab(spec);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
* or visit http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 12/18/11
|
||||
* Time: 7:39 PM
|
||||
*/
|
||||
public class HistoryActivityTab extends AbstractHistoryActivity {
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<CalculatorHistoryState> getHistoryItems() {
|
||||
return new ArrayList<CalculatorHistoryState>(CalculatorHistory.instance.getStates());
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
* or visit http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.view.prefs.ResourceCache;
|
||||
import org.solovyev.common.utils.StringUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 12/18/11
|
||||
* Time: 7:39 PM
|
||||
*/
|
||||
public class HistoryArrayAdapter extends ArrayAdapter<CalculatorHistoryState> {
|
||||
|
||||
HistoryArrayAdapter(Context context, int resource, int textViewResourceId, @NotNull List<CalculatorHistoryState> historyList) {
|
||||
super(context, resource, textViewResourceId, historyList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
final ViewGroup result = (ViewGroup) super.getView(position, convertView, parent);
|
||||
|
||||
final CalculatorHistoryState state = getItem(position);
|
||||
|
||||
final TextView time = (TextView) result.findViewById(R.id.history_time);
|
||||
time.setText(new SimpleDateFormat().format(new Date(state.getTime())));
|
||||
|
||||
final TextView editor = (TextView) result.findViewById(R.id.history_item);
|
||||
editor.setText(AbstractHistoryActivity.getHistoryText(state));
|
||||
|
||||
final TextView commentView = (TextView) result.findViewById(R.id.history_item_comment);
|
||||
final String comment = state.getComment();
|
||||
if (!StringUtils.isEmpty(comment)) {
|
||||
commentView.setText(comment);
|
||||
} else {
|
||||
commentView.setText("");
|
||||
}
|
||||
|
||||
final TextView status = (TextView) result.findViewById(R.id.history_item_status);
|
||||
if (state.isSaved()) {
|
||||
status.setText(ResourceCache.instance.getCaption("c_history_item_saved"));
|
||||
} else {
|
||||
if ( AbstractHistoryActivity.isAlreadySaved(state) ) {
|
||||
status.setText(ResourceCache.instance.getCaption("c_history_item_already_saved"));
|
||||
} else {
|
||||
status.setText(ResourceCache.instance.getCaption("c_history_item_not_saved"));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyDataSetChanged() {
|
||||
this.setNotifyOnChange(false);
|
||||
this.sort(AbstractHistoryActivity.COMPARATOR);
|
||||
this.setNotifyOnChange(true);
|
||||
super.notifyDataSetChanged();
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.CalculatorHistoryActivity;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@ -17,12 +16,12 @@ import org.solovyev.android.calculator.CalculatorHistoryActivity;
|
||||
public class HistoryItemMenuData {
|
||||
|
||||
@NotNull
|
||||
private final CalculatorHistoryActivity.HistoryArrayAdapter adapter;
|
||||
private final HistoryArrayAdapter adapter;
|
||||
|
||||
@NotNull
|
||||
private final CalculatorHistoryState historyState;
|
||||
|
||||
public HistoryItemMenuData(@NotNull CalculatorHistoryState historyState, CalculatorHistoryActivity.HistoryArrayAdapter adapter) {
|
||||
public HistoryItemMenuData(@NotNull CalculatorHistoryState historyState, HistoryArrayAdapter adapter) {
|
||||
this.historyState = historyState;
|
||||
this.adapter = adapter;
|
||||
}
|
||||
@ -33,7 +32,7 @@ public class HistoryItemMenuData {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CalculatorHistoryActivity.HistoryArrayAdapter getAdapter() {
|
||||
public HistoryArrayAdapter getAdapter() {
|
||||
return adapter;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.CalculatorHistoryActivity;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.view.AMenuItem;
|
||||
import org.solovyev.android.view.prefs.ResourceCache;
|
||||
@ -31,16 +30,18 @@ import org.solovyev.common.utils.StringUtils;
|
||||
* Time: 3:09 PM
|
||||
*/
|
||||
public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
|
||||
|
||||
use("c_use_expression") {
|
||||
@Override
|
||||
public void doAction(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
||||
if (context instanceof CalculatorHistoryActivity) {
|
||||
CalculatorHistoryActivity.useHistoryItem(data.getHistoryState(), (CalculatorHistoryActivity) context);
|
||||
if (context instanceof AbstractHistoryActivity) {
|
||||
AbstractHistoryActivity.useHistoryItem(data.getHistoryState(), (AbstractHistoryActivity) context);
|
||||
} else {
|
||||
Log.e(HistoryItemMenuItem.class.getName(), CalculatorHistoryActivity.class + " must be passed as context!");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
copy_expression("c_copy_expression") {
|
||||
@Override
|
||||
public void doAction(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
||||
@ -53,6 +54,7 @@ public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
copy_result("c_copy_result") {
|
||||
@Override
|
||||
public void doAction(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
||||
@ -65,6 +67,7 @@ public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
save("c_save") {
|
||||
@Override
|
||||
public void doAction(@NotNull final HistoryItemMenuData data, @NotNull final Context context) {
|
||||
@ -76,6 +79,7 @@ public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
edit("c_edit") {
|
||||
@Override
|
||||
public void doAction(@NotNull final HistoryItemMenuData data, @NotNull final Context context) {
|
||||
@ -87,6 +91,7 @@ public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
remove("c_remove") {
|
||||
@Override
|
||||
public void doAction(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
||||
@ -106,7 +111,7 @@ public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
|
||||
final LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
final View editView = layoutInflater.inflate(R.layout.history_edit, null);
|
||||
final TextView historyExpression = (TextView)editView.findViewById(R.id.history_edit_expression);
|
||||
historyExpression.setText(CalculatorHistoryActivity.getHistoryText(historyState));
|
||||
historyExpression.setText(AbstractHistoryActivity.getHistoryText(historyState));
|
||||
|
||||
final EditText comment = (EditText)editView.findViewById(R.id.history_edit_comment);
|
||||
comment.setText(historyState.getComment());
|
||||
@ -122,7 +127,8 @@ public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
|
||||
final CalculatorHistoryState savedHistoryItem = CalculatorHistory.instance.addSavedState(historyState);
|
||||
savedHistoryItem.setComment(comment.getText().toString());
|
||||
CalculatorHistory.instance.save(context);
|
||||
data.getAdapter().add(savedHistoryItem);
|
||||
// we don't need to add element to the adapter as adapter of another activity must be updated and not this
|
||||
//data.getAdapter().add(savedHistoryItem);
|
||||
} else {
|
||||
historyState.setComment(comment.getText().toString());
|
||||
CalculatorHistory.instance.save(context);
|
||||
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
* or visit http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 12/18/11
|
||||
* Time: 7:40 PM
|
||||
*/
|
||||
public class SavedHistoryActivityTab extends AbstractHistoryActivity {
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<CalculatorHistoryState> getHistoryItems() {
|
||||
return new ArrayList<CalculatorHistoryState>(CalculatorHistory.instance.getSavedHistory());
|
||||
}
|
||||
}
|
@ -136,26 +136,22 @@ public class DirectionDragButton extends DragButton {
|
||||
@NotNull
|
||||
@Override
|
||||
public Point2d getTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, @NotNull CharSequence text, CharSequence baseText, int w, int h) {
|
||||
final Point2d result = new Point2d();
|
||||
|
||||
float width = paint.measureText(" ");
|
||||
result.setX(width);
|
||||
|
||||
float selfHeight = paint.ascent() + paint.descent();
|
||||
|
||||
basePaint.measureText(StringUtils.getNotEmpty(baseText, "|"));
|
||||
|
||||
result.setY(h / 2 - selfHeight / 2);
|
||||
|
||||
return result;
|
||||
return getLeftRightTextPosition(paint, basePaint, text, baseText, w, h, true);
|
||||
}
|
||||
}/*,
|
||||
},
|
||||
|
||||
right(DragDirection.right, 1) {
|
||||
@Override
|
||||
public int getAttributeId() {
|
||||
return 0;
|
||||
return R.styleable.DragButton_textRight;
|
||||
}
|
||||
}*/;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Point2d getTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, @NotNull CharSequence text, CharSequence baseText, int w, int h) {
|
||||
return getLeftRightTextPosition(paint, basePaint, text, baseText, w, h, false);
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
private final DragDirection dragDirection;
|
||||
@ -176,6 +172,27 @@ public class DirectionDragButton extends DragButton {
|
||||
@NotNull
|
||||
public abstract Point2d getTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, @NotNull CharSequence text, CharSequence baseText, int w, int h);
|
||||
|
||||
@NotNull
|
||||
private static Point2d getLeftRightTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, CharSequence text, @NotNull CharSequence baseText, int w, int h, boolean left) {
|
||||
final Point2d result = new Point2d();
|
||||
|
||||
if (left) {
|
||||
float width = paint.measureText(" ");
|
||||
result.setX(width);
|
||||
} else {
|
||||
float width = paint.measureText(text.toString() + " ");
|
||||
result.setX(w - width);
|
||||
}
|
||||
|
||||
float selfHeight = paint.ascent() + paint.descent();
|
||||
|
||||
basePaint.measureText(StringUtils.getNotEmpty(baseText, "|"));
|
||||
|
||||
result.setY(h / 2 - selfHeight / 2);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Point2d getUpDownTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, @NotNull CharSequence text, CharSequence baseText, float direction, int w, int h) {
|
||||
final Point2d result = new Point2d();
|
||||
|
@ -12,10 +12,7 @@ import android.view.MotionEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.common.NumberIntervalMapper;
|
||||
import org.solovyev.common.utils.Interval;
|
||||
import org.solovyev.common.utils.Mapper;
|
||||
import org.solovyev.common.utils.MathUtils;
|
||||
import org.solovyev.common.utils.Point2d;
|
||||
import org.solovyev.common.utils.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -53,7 +50,12 @@ public class SimpleOnDragListener implements OnDragListener, DragPreferencesChan
|
||||
final Point2d endPoint = new Point2d(motionEvent.getX(), motionEvent.getY());
|
||||
|
||||
final float distance = MathUtils.getDistance(startPoint, endPoint);
|
||||
final double angle = Math.toDegrees(MathUtils.getAngle(startPoint, MathUtils.sum(startPoint, axis), endPoint));
|
||||
|
||||
final MutableObject<Boolean> right = new MutableObject<Boolean>();
|
||||
final double angle = Math.toDegrees(MathUtils.getAngle(startPoint, MathUtils.sum(startPoint, axis), endPoint, right));
|
||||
Log.d(String.valueOf(dragButton.getId()), "Angle: " + angle);
|
||||
Log.d(String.valueOf(dragButton.getId()), "Is right?: " + right.getObject());
|
||||
|
||||
final double duration = motionEvent.getEventTime() - motionEvent.getDownTime();
|
||||
|
||||
final Preference distancePreferences = preferences.getPreferencesMap().get(PreferenceType.distance);
|
||||
@ -66,23 +68,21 @@ public class SimpleOnDragListener implements OnDragListener, DragPreferencesChan
|
||||
Log.d(String.valueOf(dragButton.getId()), "Trying direction interval: " + directionEntry.getValue().getInterval());
|
||||
|
||||
if (isInInterval(directionEntry.getValue().getInterval(), distance)) {
|
||||
for (Map.Entry<DragDirection, DragPreference> angleEntry : anglePreferences.getDirectionPreferences().entrySet()) {
|
||||
final DragPreference anglePreference = anglePreferences.getDirectionPreferences().get(directionEntry.getKey());
|
||||
|
||||
Log.d(String.valueOf(dragButton.getId()), "Trying angle interval: " + angleEntry.getValue().getInterval());
|
||||
Log.d(String.valueOf(dragButton.getId()), "Trying angle interval: " + anglePreference.getInterval());
|
||||
|
||||
if (isInInterval(angleEntry.getValue().getInterval(), (float) angle)) {
|
||||
|
||||
Log.d(String.valueOf(dragButton.getId()), "MATCH! Direction: " + angleEntry.getKey());
|
||||
|
||||
direction = angleEntry.getKey();
|
||||
if (directionEntry.getKey() == DragDirection.left && right.getObject()) {
|
||||
} else if (directionEntry.getKey() == DragDirection.right && !right.getObject()) {
|
||||
} else {
|
||||
if (isInInterval(anglePreference.getInterval(), (float) angle)) {
|
||||
direction = directionEntry.getKey();
|
||||
Log.d(String.valueOf(dragButton.getId()), "MATCH! Direction: " + direction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (direction != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (direction != null) {
|
||||
@ -116,7 +116,9 @@ public class SimpleOnDragListener implements OnDragListener, DragPreferencesChan
|
||||
|
||||
Log.d(String.valueOf(dragButton.getId()), "Start point: " + startPoint + ", End point: " + endPoint);
|
||||
Log.d(String.valueOf(dragButton.getId()), "Distance: " + MathUtils.getDistance(startPoint, endPoint));
|
||||
Log.d(String.valueOf(dragButton.getId()), "Angle: " + Math.toDegrees(MathUtils.getAngle(startPoint, MathUtils.sum(startPoint, axis), endPoint)));
|
||||
final MutableObject<Boolean> right = new MutableObject<Boolean>();
|
||||
Log.d(String.valueOf(dragButton.getId()), "Angle: " + Math.toDegrees(MathUtils.getAngle(startPoint, MathUtils.sum(startPoint, axis), endPoint, right)));
|
||||
Log.d(String.valueOf(dragButton.getId()), "Is right angle? " + right);
|
||||
Log.d(String.valueOf(dragButton.getId()), "Axis: " + axis + " Vector: " + MathUtils.subtract(endPoint, startPoint));
|
||||
Log.d(String.valueOf(dragButton.getId()), "Total time: " + (motionEvent.getEventTime() - motionEvent.getDownTime()) + " ms");
|
||||
}
|
||||
@ -209,11 +211,11 @@ public class SimpleOnDragListener implements OnDragListener, DragPreferencesChan
|
||||
interval.setLeftBorder(180f - rightBorder);
|
||||
interval.setRightBorder(180f - leftBorder);
|
||||
} else if (dragDirection == DragDirection.left ) {
|
||||
interval.setLeftBorder(90f - rightBorder / 2);
|
||||
interval.setRightBorder(90f + rightBorder / 2);
|
||||
interval.setLeftBorder(90f - rightBorder);
|
||||
interval.setRightBorder(90f + rightBorder);
|
||||
} else if ( dragDirection == DragDirection.right ) {
|
||||
interval.setLeftBorder(180f + 90f - rightBorder / 2);
|
||||
interval.setRightBorder(180f + 90f + rightBorder / 2);
|
||||
interval.setLeftBorder(90f - rightBorder);
|
||||
interval.setRightBorder(90f + rightBorder);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user