Fragments

This commit is contained in:
serso 2012-09-25 17:30:44 +04:00
parent c1e6389024
commit 009f536772
7 changed files with 334 additions and 289 deletions

View File

@ -1,72 +1,70 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="81" android:versionName="1.3.2" <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="81" android:versionName="1.3.2"
package="org.solovyev.android.calculator"> package="org.solovyev.android.calculator">
<uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.android.vending.BILLING"/> <uses-permission android:name="com.android.vending.BILLING"/>
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8"/> <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8"/>
<application android:debuggable="true" android:hardwareAccelerated="false" android:icon="@drawable/icon" android:label="@string/c_app_name" android:name=".CalculatorApplication"> <application android:debuggable="true" android:hardwareAccelerated="false" android:icon="@drawable/icon" android:label="@string/c_app_name" android:name=".CalculatorApplication">
<activity android:label="@string/c_app_name" android:name=".CalculatorActivity" android:windowSoftInputMode="adjustPan"> <activity android:label="@string/c_app_name" android:name=".CalculatorActivity" android:windowSoftInputMode="adjustPan">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
<service android:name=".CalculationServiceImpl"/> <!--NOTE: a:configChanges="orientation|keyboardHidden" is needed to correct work of dialog windows (not to close them on orientation change) -->
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_app_settings" android:name=".CalculatorPreferencesActivity"/>
<!--NOTE: a:configChanges="orientation|keyboardHidden" is needed to correct work of dialog windows (not to close them on orientation change) -->
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_app_settings" android:name=".CalculatorPreferencesActivity"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_app_history" android:name=".history.CalculatorHistoryTabActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_app_history" android:name=".history.CalculatorHistoryTabActivity"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_history" android:name=".history.HistoryActivityTab"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_history" android:name=".history.HistoryActivityTab"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_saved_history" android:name=".history.SavedHistoryActivityTab"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_saved_history" android:name=".history.SavedHistoryActivityTab"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorAboutTabActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorAboutTabActivity"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorReleaseNotesActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorReleaseNotesActivity"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.CalculatorHelpTabActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.CalculatorHelpTabActivity"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpFaqActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpFaqActivity"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpHintsActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpHintsActivity"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpScreensActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_help" android:name=".help.HelpScreensActivity"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsTabActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsTabActivity"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsActivity"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_operators" android:name=".math.edit.CalculatorOperatorsActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_operators" android:name=".math.edit.CalculatorOperatorsActivity"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsTabActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsTabActivity"/> <activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsActivity"/>
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsActivity"/> <activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/>
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/> <activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:name="com.google.ads.AdActivity"/>
<activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:name="com.google.ads.AdActivity"/> <service android:name="net.robotmedia.billing.BillingService"/>
<receiver android:name="net.robotmedia.billing.BillingReceiver">
<service android:name="net.robotmedia.billing.BillingService"/> <intent-filter>
<receiver android:name="net.robotmedia.billing.BillingReceiver"> <action android:name="com.android.vending.billing.IN_APP_NOTIFY"/>
<intent-filter> <action android:name="com.android.vending.billing.RESPONSE_CODE"/>
<action android:name="com.android.vending.billing.IN_APP_NOTIFY"/> <action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED"/>
<action android:name="com.android.vending.billing.RESPONSE_CODE"/> </intent-filter>
<action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED"/> </receiver>
</intent-filter>
</receiver> </application>
</application>
</manifest> </manifest>

View File

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

View File

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

View File

@ -13,7 +13,7 @@
a:id="@+id/main_layout" a:id="@+id/main_layout"
a:orientation="vertical" a:orientation="vertical"
a:layout_gravity="center" a:layout_gravity="center"
a:background="#ff000000"> a:background="@color/default_background">
<LinearLayout a:id="@+id/editorContainer" <LinearLayout a:id="@+id/editorContainer"
a:layout_weight="2" a:layout_weight="2"

View File

@ -1,77 +1,77 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android" xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:id="@+id/ad_parent_view" a:id="@+id/ad_parent_view"
a:orientation="vertical" a:orientation="vertical"
a:layout_gravity="center" a:layout_gravity="center"
a:background="#ff000000"> a:background="#ff000000">
<include layout="@layout/calc_editor"/> <include layout="@layout/calc_editor"/>
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp"> <LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
<include layout="@layout/calc_equals_button" <include layout="@layout/calc_equals_button"
a:layout_weight="1" a:layout_weight="1"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_height="fill_parent"/> a:layout_height="fill_parent"/>
<include layout="@layout/calc_display" <include layout="@layout/calc_display"
a:layout_weight="4" a:layout_weight="4"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_height="fill_parent"/> a:layout_height="fill_parent"/>
</LinearLayout> </LinearLayout>
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp"> <LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
<include layout="@layout/calc_one_digit_button"/> <include layout="@layout/calc_one_digit_button"/>
<include layout="@layout/calc_two_digit_button"/> <include layout="@layout/calc_two_digit_button"/>
<include layout="@layout/calc_three_digit_button"/> <include layout="@layout/calc_three_digit_button"/>
<include layout="@layout/calc_multiplication_button"/> <include layout="@layout/calc_multiplication_button"/>
<include layout="@layout/calc_clear_button"/> <include layout="@layout/calc_clear_button"/>
</LinearLayout> </LinearLayout>
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp"> <LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
<include layout="@layout/calc_four_digit_button"/> <include layout="@layout/calc_four_digit_button"/>
<include layout="@layout/calc_five_digit_button"/> <include layout="@layout/calc_five_digit_button"/>
<include layout="@layout/calc_six_digit_button"/> <include layout="@layout/calc_six_digit_button"/>
<include layout="@layout/calc_division_button"/> <include layout="@layout/calc_division_button"/>
<include layout="@layout/calc_erase_button"/> <include layout="@layout/calc_erase_button"/>
</LinearLayout> </LinearLayout>
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp"> <LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
<include layout="@layout/calc_seven_digit_button"/> <include layout="@layout/calc_seven_digit_button"/>
<include layout="@layout/calc_eight_digit_button"/> <include layout="@layout/calc_eight_digit_button"/>
<include layout="@layout/calc_nine_digit_button"/> <include layout="@layout/calc_nine_digit_button"/>
<include layout="@layout/calc_plus_button"/> <include layout="@layout/calc_plus_button"/>
<include layout="@layout/calc_copy_button"/> <include layout="@layout/calc_copy_button"/>
</LinearLayout> </LinearLayout>
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp"> <LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
<include layout="@layout/calc_round_brackets_button"/> <include layout="@layout/calc_round_brackets_button"/>
<include layout="@layout/calc_zero_digit_button"/> <include layout="@layout/calc_zero_digit_button"/>
<include layout="@layout/calc_dot_button"/> <include layout="@layout/calc_dot_button"/>
<include layout="@layout/calc_subtraction_button"/> <include layout="@layout/calc_subtraction_button"/>
<include layout="@layout/calc_paste_button"/> <include layout="@layout/calc_paste_button"/>
</LinearLayout> </LinearLayout>
<LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp"> <LinearLayout a:layout_weight="1" a:layout_width="fill_parent" a:layout_height="0dp">
<include layout="@layout/calc_left_button"/> <include layout="@layout/calc_left_button"/>
<include layout="@layout/calc_right_button"/> <include layout="@layout/calc_right_button"/>
<include layout="@layout/calc_vars_button"/> <include layout="@layout/calc_vars_button"/>
<include layout="@layout/calc_functions_button"/> <include layout="@layout/calc_functions_button"/>
<include layout="@layout/calc_history_button"/> <include layout="@layout/calc_history_button"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -14,6 +14,7 @@ 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.support.v4.app.Fragment;
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;
@ -80,17 +81,17 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
final CalculatorEditorFragment editorFragment = new CalculatorEditorFragment(); final CalculatorEditorFragment editorFragment = new CalculatorEditorFragment();
fragmentTransaction.add(R.id.editorContainer, editorFragment); fragmentTransaction.add(R.id.editorContainer, editorFragment, "editor");
fragmentTransaction.commit(); fragmentTransaction.commit();
fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction = fragmentManager.beginTransaction();
final CalculatorDisplayFragment displayFragment = new CalculatorDisplayFragment(); final CalculatorDisplayFragment displayFragment = new CalculatorDisplayFragment();
fragmentTransaction.add(R.id.displayContainer, displayFragment); fragmentTransaction.add(R.id.displayContainer, displayFragment, "display");
fragmentTransaction.commit(); fragmentTransaction.commit();
fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction = fragmentManager.beginTransaction();
final CalculatorKeyboardFragment keyboardFragment = new CalculatorKeyboardFragment(); final CalculatorKeyboardFragment keyboardFragment = new CalculatorKeyboardFragment();
fragmentTransaction.add(R.id.keyboardContainer, keyboardFragment); fragmentTransaction.add(R.id.keyboardContainer, keyboardFragment, "keyboard");
fragmentTransaction.commit(); fragmentTransaction.commit();
if (customTitleSupported) { if (customTitleSupported) {

View File

@ -90,45 +90,59 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
setOnDragListeners(root, dragPreferences, preferences); setOnDragListeners(root, dragPreferences, preferences);
final OnDragListener historyOnDragListener = new OnDragListenerVibrator(newOnDragListener(new HistoryDragProcessor<CalculatorHistoryState>(getCalculator()), dragPreferences), vibrator, preferences); final OnDragListener historyOnDragListener = new OnDragListenerVibrator(newOnDragListener(new HistoryDragProcessor<CalculatorHistoryState>(getCalculator()), dragPreferences), vibrator, preferences);
((DragButton) root.findViewById(R.id.historyButton)).setOnDragListener(historyOnDragListener); final DragButton historyButton = getButton(root, R.id.historyButton);
if (historyButton != null) {
historyButton.setOnDragListener(historyOnDragListener);
}
((DragButton) root.findViewById(R.id.subtractionButton)).setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new SimpleOnDragListener.DragProcessor() { final DragButton subtractionButton = getButton(root, R.id.subtractionButton);
@Override if (subtractionButton != null) {
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) { subtractionButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new SimpleOnDragListener.DragProcessor() {
if (dragDirection == DragDirection.down) { @Override
CalculatorActivity.operatorsButtonClickHandler(getActivity(), dragButton); public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
return true; if (dragDirection == DragDirection.down) {
CalculatorActivity.operatorsButtonClickHandler(getActivity(), dragButton);
return true;
}
return false;
} }
return false; }, dragPreferences), vibrator, preferences));
} }
}, dragPreferences), vibrator, preferences));
final OnDragListener toPositionOnDragListener = new OnDragListenerVibrator(new SimpleOnDragListener(new CursorDragProcessor(), dragPreferences), vibrator, preferences); final OnDragListener toPositionOnDragListener = new OnDragListenerVibrator(new SimpleOnDragListener(new CursorDragProcessor(), dragPreferences), vibrator, preferences);
((DragButton) root.findViewById(R.id.rightButton)).setOnDragListener(toPositionOnDragListener);
((DragButton) root.findViewById(R.id.leftButton)).setOnDragListener(toPositionOnDragListener);
final DragButton equalsButton = (DragButton) root.findViewById(R.id.equalsButton); final DragButton rightButton = getButton(root, R.id.rightButton);
if (rightButton != null) {
rightButton.setOnDragListener(toPositionOnDragListener);
}
final DragButton leftButton = getButton(root, R.id.leftButton);
if (leftButton != null) {
leftButton.setOnDragListener(toPositionOnDragListener);
}
final DragButton equalsButton = getButton(root, R.id.equalsButton);
if (equalsButton != null) { if (equalsButton != null) {
equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EvalDragProcessor(), dragPreferences), vibrator, preferences)); equalsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new EvalDragProcessor(), dragPreferences), vibrator, preferences));
} }
final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) root.findViewById(R.id.sixDigitButton); final AngleUnitsButton angleUnitsButton = (AngleUnitsButton) getButton(root, R.id.sixDigitButton);
if (angleUnitsButton != null) { if (angleUnitsButton != null) {
angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new AngleUnitsChanger(this.getActivity()), dragPreferences), vibrator, preferences)); angleUnitsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new AngleUnitsChanger(this.getActivity()), dragPreferences), vibrator, preferences));
} }
final NumeralBasesButton clearButton = (NumeralBasesButton) root.findViewById(R.id.clearButton); final NumeralBasesButton clearButton = (NumeralBasesButton) getButton(root, R.id.clearButton);
if (clearButton != null) { if (clearButton != null) {
clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new NumeralBasesChanger(this.getActivity()), dragPreferences), vibrator, preferences)); clearButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new NumeralBasesChanger(this.getActivity()), dragPreferences), vibrator, preferences));
} }
final DragButton varsButton = (DragButton) root.findViewById(R.id.varsButton); final DragButton varsButton = getButton(root, R.id.varsButton);
if (varsButton != null) { if (varsButton != null) {
varsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new VarsDragProcessor(this.getActivity()), dragPreferences), vibrator, preferences)); varsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new VarsDragProcessor(this.getActivity()), dragPreferences), vibrator, preferences));
} }
final DragButton roundBracketsButton = (DragButton) root.findViewById(R.id.roundBracketsButton); final DragButton roundBracketsButton = getButton(root, R.id.roundBracketsButton);
if (roundBracketsButton != null) { if (roundBracketsButton != null) {
roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences)); roundBracketsButton.setOnDragListener(new OnDragListenerVibrator(newOnDragListener(new RoundBracketsDragProcessor(), dragPreferences), vibrator, preferences));
} }
@ -162,6 +176,11 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
initMultiplicationButton(); initMultiplicationButton();
} }
@Nullable
private <T extends DragButton> T getButton(@NotNull View root, int buttonId) {
return (T) root.findViewById(buttonId);
}
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -240,7 +259,10 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
} }
for (Integer dragButtonId : dragButtonIds) { for (Integer dragButtonId : dragButtonIds) {
((DragButton) root.findViewById(dragButtonId)).setOnDragListener(onDragListener); final DragButton button = getButton(root, dragButtonId);
if (button != null) {
button.setOnDragListener(onDragListener);
}
} }
} }
@ -273,7 +295,7 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
} }
private void toggleButtonDirectionText(@NotNull View root, int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) { private void toggleButtonDirectionText(@NotNull View root, int id, boolean showDirectionText, @NotNull DragDirection... dragDirections) {
final View v = root.findViewById(id); final View v = getButton(root, id);
if (v instanceof DirectionDragButton ) { if (v instanceof DirectionDragButton ) {
final DirectionDragButton button = (DirectionDragButton)v; final DirectionDragButton button = (DirectionDragButton)v;
for (DragDirection dragDirection : dragDirections) { for (DragDirection dragDirection : dragDirections) {