Changes
This commit is contained in:
parent
c720306891
commit
93412c7344
@ -22,27 +22,17 @@
|
|||||||
|
|
||||||
<activity android:label="@string/c_app_settings" android:name=".CalculatorPreferencesActivity"/>
|
<activity android:label="@string/c_app_settings" android:name=".CalculatorPreferencesActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_history" android:name=".history.CalculatorHistoryFragmentActivity"/>
|
<activity android:label="@string/c_history" android:name=".history.CalculatorHistoryActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_about" android:name=".about.CalculatorAboutTabActivity"/>
|
|
||||||
|
|
||||||
<activity android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/>
|
<activity android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_about" android:name=".about.CalculatorReleaseNotesActivity"/>
|
<activity android:label="@string/c_help" android:name=".help.CalculatorHelpActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_help" android:name=".help.CalculatorHelpTabActivity"/>
|
<activity android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_help" android:name=".help.HelpFaqActivity"/>
|
<activity android:label="@string/c_operators" android:name=".math.edit.CalculatorOperatorsActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_help" android:name=".help.HelpHintsActivity"/>
|
<activity android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsActivity"/>
|
||||||
|
|
||||||
<activity android:label="@string/c_help" android:name=".help.HelpScreensActivity"/>
|
|
||||||
|
|
||||||
<activity android:label="@string/c_functions" android:name=".math.edit.CalculatorFunctionsFragmentActivity"/>
|
|
||||||
|
|
||||||
<activity android:label="@string/c_operators" android:name=".math.edit.CalculatorOperatorsFragmentActivity"/>
|
|
||||||
|
|
||||||
<activity android:label="@string/c_vars_and_constants" android:name=".math.edit.CalculatorVarsFragmentActivity"/>
|
|
||||||
|
|
||||||
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/>
|
<activity android:label="@string/c_plot_graph" android:name=".plot.CalculatorPlotActivity"/>
|
||||||
|
|
||||||
|
@ -1,47 +1,47 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="fill_parent"
|
||||||
a:background="#ff000000">
|
a:background="#ff000000">
|
||||||
|
|
||||||
<ImageView a:layout_width="wrap_content"
|
<ImageView a:layout_width="wrap_content"
|
||||||
a:layout_height="wrap_content"
|
a:layout_height="wrap_content"
|
||||||
a:layout_gravity="center"
|
a:layout_gravity="center"
|
||||||
a:layout_weight="1"
|
a:layout_weight="1"
|
||||||
a:padding="6dp"
|
a:padding="6dp"
|
||||||
a:src="@drawable/logo"/>
|
a:src="@drawable/logo"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
a:id="@+id/aboutTextView"
|
a:id="@+id/aboutTextView"
|
||||||
a:text="@string/c_about_content"
|
a:text="@string/c_about_content"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="fill_parent"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_gravity="top|center_horizontal"
|
a:layout_gravity="top|center_horizontal"
|
||||||
a:layout_weight="1"
|
a:layout_weight="1"
|
||||||
a:scrollbars="vertical"
|
a:scrollbars="vertical"
|
||||||
style="@style/about_style"/>
|
style="@style/about_style"/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
a:scrollbarFadeDuration="0" is not support in android_1.6_compatibility
|
a:scrollbarFadeDuration="0" is not support in android_1.6_compatibility
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
a:id="@+id/aboutTextView"
|
a:id="@+id/aboutTextView"
|
||||||
a:text="@string/c_copyright"
|
a:text="@string/c_copyright"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="fill_parent"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_gravity="top|center_horizontal"
|
a:layout_gravity="top|center_horizontal"
|
||||||
a:layout_weight="1"
|
a:layout_weight="1"
|
||||||
a:scrollbars="vertical"
|
a:scrollbars="vertical"
|
||||||
a:scrollbarFadeDuration="0"
|
a:scrollbarFadeDuration="0"
|
||||||
style="@style/about_style"/>
|
style="@style/about_style"/>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -1,40 +1,40 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent">
|
a:layout_height="fill_parent">
|
||||||
|
|
||||||
<TextView a:id="@+id/history_time"
|
<TextView a:id="@+id/history_time"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="fill_parent"
|
||||||
style="@style/history_time"/>
|
style="@style/history_time"/>
|
||||||
|
|
||||||
<TextView a:id="@+id/history_item"
|
<TextView a:id="@+id/history_item"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="fill_parent"
|
||||||
a:textColor="@color/button_operator_text_color"
|
a:textColor="@color/button_operator_text_color"
|
||||||
style="@style/history_item"/>
|
style="@style/history_item"/>
|
||||||
|
|
||||||
<LinearLayout a:orientation="horizontal"
|
<LinearLayout a:orientation="horizontal"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent">
|
a:layout_height="fill_parent">
|
||||||
|
|
||||||
<TextView a:layout_width="wrap_content"
|
<TextView a:layout_width="wrap_content"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="fill_parent"
|
||||||
a:text="@string/c_history_item_status"
|
a:text="@string/c_history_item_status"
|
||||||
style="@style/history_item_label"/>
|
style="@style/history_item_label"/>
|
||||||
|
|
||||||
<TextView a:id="@+id/history_item_status"
|
<TextView a:id="@+id/history_item_status"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="fill_parent"
|
||||||
style="@style/history_item"/>
|
style="@style/history_item"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -1,28 +1,28 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="fill_parent"
|
||||||
a:background="#ff000000">
|
a:background="#ff000000">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
a:id="@+id/releaseNotesTextView"
|
a:id="@+id/releaseNotesTextView"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="fill_parent"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_weight="1"
|
a:layout_weight="1"
|
||||||
a:gravity="top|left"
|
a:gravity="top|left"
|
||||||
a:scrollbars="vertical"
|
a:scrollbars="vertical"
|
||||||
style="@style/about_style"/>
|
style="@style/about_style"/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
a:scrollbarFadeDuration="0" is not support in android_1.6_compatibility
|
a:scrollbarFadeDuration="0" is not support in android_1.6_compatibility
|
||||||
-->
|
-->
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -1,41 +1,41 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
~ For more information, please, contact se.solovyev@gmail.com
|
~ For more information, please, contact se.solovyev@gmail.com
|
||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent">
|
a:layout_height="fill_parent">
|
||||||
|
|
||||||
<TextView a:id="@+id/history_time"
|
<TextView a:id="@+id/history_time"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="fill_parent"
|
||||||
style="@style/history_time"/>
|
style="@style/history_time"/>
|
||||||
|
|
||||||
<TextView a:id="@+id/history_item"
|
<TextView a:id="@+id/history_item"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="fill_parent"
|
||||||
a:textColor="@color/button_operator_text_color"
|
a:textColor="@color/button_operator_text_color"
|
||||||
style="@style/history_item"/>
|
style="@style/history_item"/>
|
||||||
|
|
||||||
<LinearLayout a:orientation="horizontal"
|
<LinearLayout a:orientation="horizontal"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent">
|
a:layout_height="fill_parent">
|
||||||
|
|
||||||
<TextView a:id="@+id/history_item_comment_label"
|
<TextView a:id="@+id/history_item_comment_label"
|
||||||
a:layout_width="wrap_content"
|
a:layout_width="wrap_content"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="fill_parent"
|
||||||
a:text="@string/c_history_item_comment"
|
a:text="@string/c_history_item_comment"
|
||||||
style="@style/history_item_label"/>
|
style="@style/history_item_label"/>
|
||||||
|
|
||||||
<TextView a:id="@+id/history_item_comment"
|
<TextView a:id="@+id/history_item_comment"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="fill_parent"
|
||||||
a:layout_height="fill_parent"
|
a:layout_height="fill_parent"
|
||||||
style="@style/history_item"/>
|
style="@style/history_item"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -1,6 +1,5 @@
|
|||||||
package org.solovyev.android;
|
package org.solovyev.android;
|
||||||
|
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
@ -33,11 +32,4 @@ public final class AndroidUtils2 {
|
|||||||
dialogFragment.show(ft, fragmentTag);
|
dialogFragment.show(ft, fragmentTag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// copied from API-15
|
|
||||||
public static boolean isLayoutSizeAtLeast(int size, @NotNull Configuration configuration) {
|
|
||||||
int cur = configuration.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
|
|
||||||
if (cur == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) return false;
|
|
||||||
return cur >= size;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.AndroidUtils;
|
import org.solovyev.android.AndroidUtils;
|
||||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
import org.solovyev.android.calculator.about.CalculatorReleaseNotesFragment;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
|
||||||
import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
|
|
||||||
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment;
|
|
||||||
import org.solovyev.android.calculator.math.edit.CalculatorOperatorsFragment;
|
|
||||||
import org.solovyev.android.calculator.math.edit.CalculatorVarsFragment;
|
|
||||||
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
|
|
||||||
import org.solovyev.android.fragments.FragmentUtils;
|
import org.solovyev.android.fragments.FragmentUtils;
|
||||||
import org.solovyev.android.prefs.Preference;
|
import org.solovyev.android.prefs.Preference;
|
||||||
import org.solovyev.android.view.ColorButton;
|
import org.solovyev.android.view.ColorButton;
|
||||||
@ -78,6 +72,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
|
|||||||
activityHelper.addTab(this, CalculatorFragmentType.functions, null, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.functions, null, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, CalculatorFragmentType.operators, null, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.operators, null, R.id.main_second_pane);
|
||||||
activityHelper.addTab(this, CalculatorFragmentType.plotter, null, R.id.main_second_pane);
|
activityHelper.addTab(this, CalculatorFragmentType.plotter, null, R.id.main_second_pane);
|
||||||
|
activityHelper.addTab(this, CalculatorFragmentType.faq, null, R.id.main_second_pane);
|
||||||
} else {
|
} else {
|
||||||
getSupportActionBar().hide();
|
getSupportActionBar().hide();
|
||||||
}
|
}
|
||||||
@ -141,7 +136,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Shar
|
|||||||
if (savedVersion < appVersion) {
|
if (savedVersion < appVersion) {
|
||||||
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
|
final boolean showReleaseNotes = CalculatorPreferences.Gui.showReleaseNotes.getPreference(preferences);
|
||||||
if (showReleaseNotes) {
|
if (showReleaseNotes) {
|
||||||
final String releaseNotes = CalculatorReleaseNotesActivity.getReleaseNotes(context, savedVersion + 1);
|
final String releaseNotes = CalculatorReleaseNotesFragment.getReleaseNotes(context, savedVersion + 1);
|
||||||
if (!StringUtils.isEmpty(releaseNotes)) {
|
if (!StringUtils.isEmpty(releaseNotes)) {
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context).setMessage(Html.fromHtml(releaseNotes));
|
||||||
builder.setPositiveButton(android.R.string.ok, null);
|
builder.setPositiveButton(android.R.string.ok, null);
|
||||||
|
@ -16,9 +16,6 @@ import org.solovyev.android.AndroidUtils;
|
|||||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
|
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 9/25/12
|
* Date: 9/25/12
|
||||||
@ -46,9 +43,6 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
|
|||||||
|
|
||||||
private boolean homeIcon = false;
|
private boolean homeIcon = false;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private final List<String> fragmentTags = new ArrayList<String>();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private CalculatorPreferences.Gui.Theme theme;
|
private CalculatorPreferences.Gui.Theme theme;
|
||||||
|
|
||||||
@ -196,8 +190,6 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
|
|||||||
final ActionBarFragmentTabListener listener = new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId);
|
final ActionBarFragmentTabListener listener = new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId);
|
||||||
tab.setTabListener(listener);
|
tab.setTabListener(listener);
|
||||||
actionBar.addTab(tab);
|
actionBar.addTab(tab);
|
||||||
|
|
||||||
fragmentTags.add(tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,10 +7,9 @@ import jscl.math.Generic;
|
|||||||
import jscl.math.function.Constant;
|
import jscl.math.function.Constant;
|
||||||
import org.achartengine.ChartFactory;
|
import org.achartengine.ChartFactory;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.AndroidUtils2;
|
import org.solovyev.android.calculator.about.CalculatorAboutActivity;
|
||||||
import org.solovyev.android.calculator.about.CalculatorAboutTabActivity;
|
import org.solovyev.android.calculator.help.CalculatorHelpActivity;
|
||||||
import org.solovyev.android.calculator.help.CalculatorHelpTabActivity;
|
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
|
|
||||||
import org.solovyev.android.calculator.math.edit.*;
|
import org.solovyev.android.calculator.math.edit.*;
|
||||||
import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
|
import org.solovyev.android.calculator.plot.CalculatorPlotActivity;
|
||||||
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
|
import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
|
||||||
@ -25,11 +24,11 @@ import org.solovyev.common.text.StringUtils;
|
|||||||
public class CalculatorActivityLauncher {
|
public class CalculatorActivityLauncher {
|
||||||
|
|
||||||
public static void showHistory(@NotNull final Context context) {
|
public static void showHistory(@NotNull final Context context) {
|
||||||
context.startActivity(new Intent(context, CalculatorHistoryFragmentActivity.class));
|
context.startActivity(new Intent(context, CalculatorHistoryActivity.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showHelp(@NotNull final Context context) {
|
public static void showHelp(@NotNull final Context context) {
|
||||||
context.startActivity(new Intent(context, CalculatorHelpTabActivity.class));
|
context.startActivity(new Intent(context, CalculatorHelpActivity.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showSettings(@NotNull final Context context) {
|
public static void showSettings(@NotNull final Context context) {
|
||||||
@ -37,19 +36,19 @@ public class CalculatorActivityLauncher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void showAbout(@NotNull final Context context) {
|
public static void showAbout(@NotNull final Context context) {
|
||||||
context.startActivity(new Intent(context, CalculatorAboutTabActivity.class));
|
context.startActivity(new Intent(context, CalculatorAboutActivity.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showFunctions(@NotNull final Context context) {
|
public static void showFunctions(@NotNull final Context context) {
|
||||||
context.startActivity(new Intent(context, CalculatorFunctionsFragmentActivity.class));
|
context.startActivity(new Intent(context, CalculatorFunctionsActivity.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showOperators(@NotNull final Context context) {
|
public static void showOperators(@NotNull final Context context) {
|
||||||
context.startActivity(new Intent(context, CalculatorOperatorsFragmentActivity.class));
|
context.startActivity(new Intent(context, CalculatorOperatorsActivity.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showVars(@NotNull final Context context) {
|
public static void showVars(@NotNull final Context context) {
|
||||||
context.startActivity(new Intent(context, CalculatorVarsFragmentActivity.class));
|
context.startActivity(new Intent(context, CalculatorVarsActivity.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void plotGraph(@NotNull final Context context, @NotNull Generic generic, @NotNull Constant constant){
|
public static void plotGraph(@NotNull final Context context, @NotNull Generic generic, @NotNull Constant constant){
|
||||||
@ -69,7 +68,7 @@ public class CalculatorActivityLauncher {
|
|||||||
if (context instanceof SherlockFragmentActivity) {
|
if (context instanceof SherlockFragmentActivity) {
|
||||||
VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromValue(varValue), ((SherlockFragmentActivity) context).getSupportFragmentManager());
|
VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromValue(varValue), ((SherlockFragmentActivity) context).getSupportFragmentManager());
|
||||||
} else {
|
} else {
|
||||||
final Intent intent = new Intent(context, CalculatorVarsFragmentActivity.class);
|
final Intent intent = new Intent(context, CalculatorVarsActivity.class);
|
||||||
intent.putExtra(CalculatorVarsFragment.CREATE_VAR_EXTRA_STRING, varValue);
|
intent.putExtra(CalculatorVarsFragment.CREATE_VAR_EXTRA_STRING, varValue);
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ import jscl.NumeralBase;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.AndroidUtils;
|
import org.solovyev.android.AndroidUtils;
|
||||||
import org.solovyev.android.AndroidUtils2;
|
|
||||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||||
import org.solovyev.android.calculator.view.AngleUnitsButton;
|
import org.solovyev.android.calculator.view.AngleUnitsButton;
|
||||||
import org.solovyev.android.calculator.view.NumeralBasesButton;
|
import org.solovyev.android.calculator.view.NumeralBasesButton;
|
||||||
@ -66,7 +65,7 @@ public final class CalculatorButtons {
|
|||||||
@NotNull Activity activity) {
|
@NotNull Activity activity) {
|
||||||
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences;
|
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(activity) : preferences;
|
||||||
|
|
||||||
final boolean large = AndroidUtils2.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, activity.getResources().getConfiguration());
|
final boolean large = AndroidUtils.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, activity.getResources().getConfiguration());
|
||||||
|
|
||||||
if (!large) {
|
if (!large) {
|
||||||
if (AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT
|
if (AndroidUtils.getScreenOrientation(activity) == Configuration.ORIENTATION_PORTRAIT
|
||||||
|
@ -1,98 +1,64 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.View;
|
||||||
import android.view.View;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import android.view.ViewGroup;
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
import com.actionbarsherlock.app.SherlockFragment;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
import com.actionbarsherlock.view.Menu;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import com.actionbarsherlock.view.MenuInflater;
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import com.actionbarsherlock.view.MenuItem;
|
import org.solovyev.android.menu.ActivityMenu;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.solovyev.android.menu.ListActivityMenu;
|
||||||
import org.solovyev.android.menu.ActivityMenu;
|
import org.solovyev.android.sherlock.menu.SherlockMenuHelper;
|
||||||
import org.solovyev.android.menu.ListActivityMenu;
|
|
||||||
import org.solovyev.android.sherlock.menu.SherlockMenuHelper;
|
/**
|
||||||
|
* User: Solovyev_S
|
||||||
/**
|
* Date: 25.09.12
|
||||||
* User: Solovyev_S
|
* Time: 10:49
|
||||||
* Date: 25.09.12
|
*/
|
||||||
* Time: 10:49
|
public class CalculatorEditorFragment extends CalculatorFragment {
|
||||||
*/
|
|
||||||
public class CalculatorEditorFragment extends SherlockFragment {
|
@NotNull
|
||||||
|
private ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromList(CalculatorMenu.class, SherlockMenuHelper.getInstance());
|
||||||
@NotNull
|
|
||||||
private ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromList(CalculatorMenu.class, SherlockMenuHelper.getInstance());
|
public CalculatorEditorFragment() {
|
||||||
|
super(CalculatorFragmentType.editor);
|
||||||
private CalculatorFragmentHelper fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.calc_editor, R.string.editor);
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
fragmentHelper.onCreate(this);
|
setHasOptionsMenu(true);
|
||||||
|
}
|
||||||
setHasOptionsMenu(true);
|
|
||||||
}
|
@Override
|
||||||
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
@Override
|
super.onViewCreated(view, savedInstanceState);
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
||||||
return fragmentHelper.onCreateView(this, inflater, container);
|
((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator()).setEditor(getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
**********************************************************************
|
||||||
super.onViewCreated(view, savedInstanceState);
|
*
|
||||||
|
* MENU
|
||||||
fragmentHelper.onViewCreated(this, view);
|
*
|
||||||
|
**********************************************************************
|
||||||
((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator()).setEditor(getActivity());
|
*/
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
this.menu.onCreateOptionsMenu(this.getActivity(), menu);
|
||||||
super.onActivityCreated(savedInstanceState);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public void onPrepareOptionsMenu(Menu menu) {
|
||||||
public void onDestroy() {
|
this.menu.onPrepareOptionsMenu(this.getActivity(), menu);
|
||||||
fragmentHelper.onDestroy(this);
|
}
|
||||||
super.onDestroy();
|
|
||||||
}
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
@Override
|
return this.menu.onOptionsItemSelected(this.getActivity(), item);
|
||||||
public void onResume() {
|
}
|
||||||
super.onResume();
|
}
|
||||||
|
|
||||||
this.fragmentHelper.onResume(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
this.fragmentHelper.onPause(this);
|
|
||||||
|
|
||||||
super.onPause();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
**********************************************************************
|
|
||||||
*
|
|
||||||
* MENU
|
|
||||||
*
|
|
||||||
**********************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
||||||
this.menu.onCreateOptionsMenu(this.getActivity(), menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPrepareOptionsMenu(Menu menu) {
|
|
||||||
this.menu.onPrepareOptionsMenu(this.getActivity(), menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
return this.menu.onOptionsItemSelected(this.getActivity(), item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import com.actionbarsherlock.app.SherlockFragment;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: Solovyev_S
|
||||||
|
* Date: 03.10.12
|
||||||
|
* Time: 14:18
|
||||||
|
*/
|
||||||
|
public abstract class CalculatorFragment extends SherlockFragment {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final CalculatorFragmentHelper fragmentHelper;
|
||||||
|
|
||||||
|
protected CalculatorFragment(int layoutResId, int titleResId) {
|
||||||
|
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(layoutResId, titleResId);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CalculatorFragment(@NotNull CalculatorFragmentType fragmentType) {
|
||||||
|
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
fragmentHelper.onCreate(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
return fragmentHelper.onCreateView(this, inflater, container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
fragmentHelper.onViewCreated(this, view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
fragmentHelper.onDestroy(this);
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
this.fragmentHelper.onResume(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
this.fragmentHelper.onPause(this);
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: Solovyev_S
|
||||||
|
* Date: 03.10.12
|
||||||
|
* Time: 14:07
|
||||||
|
*/
|
||||||
|
public abstract class CalculatorFragmentActivity extends SherlockFragmentActivity {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final CalculatorActivityHelper activityHelper;
|
||||||
|
|
||||||
|
protected CalculatorFragmentActivity() {
|
||||||
|
this(R.layout.main_empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CalculatorFragmentActivity(int layoutResId) {
|
||||||
|
this.activityHelper = CalculatorApplication.getInstance().createActivityHelper(layoutResId, getClass().getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
protected CalculatorActivityHelper getActivityHelper() {
|
||||||
|
return activityHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
activityHelper.onCreate(this, savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
|
activityHelper.onSaveInstanceState(this, outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
activityHelper.onResume(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
this.activityHelper.onPause(this);
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
|
||||||
|
activityHelper.onDestroy(this);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* 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.about;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import org.solovyev.android.calculator.CalculatorFragment;
|
||||||
|
import org.solovyev.android.calculator.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 12/24/11
|
||||||
|
* Time: 11:55 PM
|
||||||
|
*/
|
||||||
|
public class CalculatorAboutFragment extends CalculatorFragment {
|
||||||
|
|
||||||
|
public CalculatorAboutFragment() {
|
||||||
|
super(CalculatorFragmentType.about);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(root, savedInstanceState);
|
||||||
|
|
||||||
|
final TextView about = (TextView) root.findViewById(R.id.aboutTextView);
|
||||||
|
about.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
}
|
||||||
|
}
|
@ -1,50 +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.about;
|
|
||||||
|
|
||||||
import android.app.TabActivity;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.widget.TabHost;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.solovyev.android.AndroidUtils;
|
|
||||||
import org.solovyev.android.LastTabSaver;
|
|
||||||
import org.solovyev.android.calculator.R;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 9/16/11
|
|
||||||
* Time: 11:52 PM
|
|
||||||
*/
|
|
||||||
public class CalculatorAboutTabActivity extends TabActivity {
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private LastTabSaver lastTabSaver;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
setContentView(R.layout.tabs);
|
|
||||||
|
|
||||||
final TabHost tabHost = getTabHost();
|
|
||||||
|
|
||||||
AndroidUtils.addTab(this, tabHost, "about", R.string.c_about, CalculatorAboutActivity.class);
|
|
||||||
AndroidUtils.addTab(this, tabHost, "release_notes", R.string.c_release_notes, CalculatorReleaseNotesActivity.class);
|
|
||||||
|
|
||||||
lastTabSaver = new LastTabSaver(this, "about");
|
|
||||||
|
|
||||||
AndroidUtils.centerAndWrapTabsFor(tabHost);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
if ( this.lastTabSaver != null ) {
|
|
||||||
this.lastTabSaver.destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,7 +2,11 @@ package org.solovyev.android.calculator.about;
|
|||||||
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.solovyev.android.calculator.CalculatorEditorFragment;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
|
import org.solovyev.android.calculator.help.CalculatorHelpFaqFragment;
|
||||||
|
import org.solovyev.android.calculator.help.CalculatorHelpHintsFragment;
|
||||||
|
import org.solovyev.android.calculator.help.CalculatorHelpScreensFragment;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
||||||
import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
|
import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
|
||||||
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment;
|
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsFragment;
|
||||||
@ -17,30 +21,41 @@ import org.solovyev.android.calculator.plot.CalculatorPlotFragment;
|
|||||||
*/
|
*/
|
||||||
public enum CalculatorFragmentType {
|
public enum CalculatorFragmentType {
|
||||||
|
|
||||||
history(CalculatorHistoryFragment.class, "history", R.string.c_history),
|
editor(CalculatorEditorFragment.class, R.layout.calc_editor, R.string.editor),
|
||||||
saved_history(CalculatorSavedHistoryFragment.class, "saved_history", R.string.c_saved_history),
|
//display(CalculatorHistoryFragment.class, "history", R.layout.history_fragment, R.string.c_history),
|
||||||
variables(CalculatorVarsFragment.class, "vars", R.string.c_vars),
|
//keyboard(CalculatorHistoryFragment.class, "history", R.layout.history_fragment, R.string.c_history),
|
||||||
functions(CalculatorFunctionsFragment.class, "functions", R.string.c_functions),
|
history(CalculatorHistoryFragment.class, R.layout.history_fragment, R.string.c_history),
|
||||||
operators(CalculatorOperatorsFragment.class, "operators", R.string.c_operators),
|
saved_history(CalculatorSavedHistoryFragment.class, R.layout.history_fragment, R.string.c_saved_history),
|
||||||
plotter(CalculatorPlotFragment.class, "plotter", R.string.c_plot);
|
variables(CalculatorVarsFragment.class, R.layout.vars_fragment, R.string.c_vars),
|
||||||
|
functions(CalculatorFunctionsFragment.class, R.layout.math_entities_fragment, R.string.c_functions),
|
||||||
|
operators(CalculatorOperatorsFragment.class, R.layout.math_entities_fragment, R.string.c_operators),
|
||||||
|
plotter(CalculatorPlotFragment.class, R.layout.plot_fragment, R.string.c_plot),
|
||||||
|
about(CalculatorAboutFragment.class, R.layout.about_fragment, R.string.c_about),
|
||||||
|
|
||||||
|
// todo serso: rename and inflate ad
|
||||||
|
faq(CalculatorHelpFaqFragment.class, R.layout.help_faq, R.string.c_faq),
|
||||||
|
hints(CalculatorHelpHintsFragment.class, R.layout.help_hints, R.string.c_hints),
|
||||||
|
screens(CalculatorHelpScreensFragment.class, R.layout.help_screens, R.string.c_screens),
|
||||||
|
release_notes(CalculatorReleaseNotesFragment.class, R.layout.release_notes_fragment, R.string.c_release_notes);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Class<? extends Fragment> fragmentClass;
|
private Class<? extends Fragment> fragmentClass;
|
||||||
|
|
||||||
@NotNull
|
private final int defaultLayoutId;
|
||||||
private final String fragmentTag;
|
|
||||||
|
|
||||||
private int defaultTitleResId;
|
private int defaultTitleResId;
|
||||||
|
|
||||||
private CalculatorFragmentType(@NotNull Class<? extends Fragment> fragmentClass, @NotNull String fragmentTag, int defaultTitleResId) {
|
private CalculatorFragmentType(@NotNull Class<? extends Fragment> fragmentClass,
|
||||||
|
int defaultLayoutId,
|
||||||
|
int defaultTitleResId) {
|
||||||
this.fragmentClass = fragmentClass;
|
this.fragmentClass = fragmentClass;
|
||||||
this.fragmentTag = fragmentTag;
|
this.defaultLayoutId = defaultLayoutId;
|
||||||
this.defaultTitleResId = defaultTitleResId;
|
this.defaultTitleResId = defaultTitleResId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getFragmentTag() {
|
public String getFragmentTag() {
|
||||||
return fragmentTag;
|
return this.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDefaultTitleResId() {
|
public int getDefaultTitleResId() {
|
||||||
@ -52,8 +67,12 @@ public enum CalculatorFragmentType {
|
|||||||
return fragmentClass;
|
return fragmentClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDefaultLayoutId() {
|
||||||
|
return defaultLayoutId;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String createSubFragmentTag(@NotNull String subFragmentTag) {
|
public String createSubFragmentTag(@NotNull String subFragmentTag) {
|
||||||
return this.fragmentTag + "_" + subFragmentTag;
|
return this.getFragmentTag() + "_" + subFragmentTag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,16 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator.about;
|
package org.solovyev.android.calculator.about;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.AndroidUtils;
|
import org.solovyev.android.AndroidUtils;
|
||||||
import org.solovyev.android.calculator.CalculatorActivity;
|
import org.solovyev.android.calculator.CalculatorActivity;
|
||||||
|
import org.solovyev.android.calculator.CalculatorFragment;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.common.text.StringUtils;
|
import org.solovyev.common.text.StringUtils;
|
||||||
|
|
||||||
@ -24,23 +24,23 @@ import org.solovyev.common.text.StringUtils;
|
|||||||
* Date: 12/25/11
|
* Date: 12/25/11
|
||||||
* Time: 12:00 AM
|
* Time: 12:00 AM
|
||||||
*/
|
*/
|
||||||
public class CalculatorReleaseNotesActivity extends Activity {
|
public class CalculatorReleaseNotesFragment extends CalculatorFragment {
|
||||||
|
|
||||||
@Override
|
public CalculatorReleaseNotesFragment() {
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
super(CalculatorFragmentType.release_notes);
|
||||||
super.onCreate(savedInstanceState);
|
}
|
||||||
|
|
||||||
setContentView(R.layout.release_notes);
|
@Override
|
||||||
|
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(root, savedInstanceState);
|
||||||
|
|
||||||
final TextView releaseNotes = (TextView) findViewById(R.id.releaseNotesTextView);
|
final TextView releaseNotes = (TextView) root.findViewById(R.id.releaseNotesTextView);
|
||||||
releaseNotes.setMovementMethod(LinkMovementMethod.getInstance());
|
releaseNotes.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|
||||||
releaseNotes.setText(Html.fromHtml(getReleaseNotes(this)));
|
releaseNotes.setText(Html.fromHtml(getReleaseNotes(this.getActivity())));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
@NotNull
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static String getReleaseNotes(@NotNull Context context) {
|
public static String getReleaseNotes(@NotNull Context context) {
|
||||||
return getReleaseNotes(context, 0);
|
return getReleaseNotes(context, 0);
|
||||||
}
|
}
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009-2012. 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.help;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import com.google.ads.AdView;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.solovyev.android.ads.AdsController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 1/4/12
|
|
||||||
* Time: 12:34 AM
|
|
||||||
*/
|
|
||||||
public class AbstractHelpActivity extends Activity {
|
|
||||||
|
|
||||||
private final int layoutId;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private AdView adView;
|
|
||||||
|
|
||||||
protected AbstractHelpActivity(int layoutId) {
|
|
||||||
this.layoutId = layoutId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
setContentView(layoutId);
|
|
||||||
|
|
||||||
// do not inflate ad in help (as some problems were encountered dut to ScrollView - no space for ad banner)
|
|
||||||
adView = AdsController.getInstance().inflateAd(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
if (this.adView != null) {
|
|
||||||
this.adView.destroy();
|
|
||||||
}
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.help;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.solovyev.android.calculator.CalculatorFragmentActivity;
|
||||||
|
import org.solovyev.android.calculator.R;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 11/19/11
|
||||||
|
* Time: 11:35 AM
|
||||||
|
*/
|
||||||
|
public class CalculatorHelpActivity extends CalculatorFragmentActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
getActivityHelper().addTab(this, CalculatorFragmentType.faq, null, R.id.main_layout);
|
||||||
|
getActivityHelper().addTab(this, CalculatorFragmentType.hints, null, R.id.main_layout);
|
||||||
|
getActivityHelper().addTab(this, CalculatorFragmentType.screens, null, R.id.main_layout);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* 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.help;
|
||||||
|
|
||||||
|
import org.solovyev.android.calculator.CalculatorFragment;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 11/19/11
|
||||||
|
* Time: 11:37 AM
|
||||||
|
*/
|
||||||
|
public class CalculatorHelpFaqFragment extends CalculatorFragment {
|
||||||
|
|
||||||
|
public CalculatorHelpFaqFragment() {
|
||||||
|
super(CalculatorFragmentType.faq);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* 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.help;
|
||||||
|
|
||||||
|
import org.solovyev.android.calculator.CalculatorFragment;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 11/19/11
|
||||||
|
* Time: 11:37 AM
|
||||||
|
*/
|
||||||
|
public class CalculatorHelpHintsFragment extends CalculatorFragment {
|
||||||
|
|
||||||
|
public CalculatorHelpHintsFragment() {
|
||||||
|
super(CalculatorFragmentType.hints);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* 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.help;
|
||||||
|
|
||||||
|
import org.solovyev.android.calculator.CalculatorFragment;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 11/19/11
|
||||||
|
* Time: 11:38 AM
|
||||||
|
*/
|
||||||
|
public class CalculatorHelpScreensFragment extends CalculatorFragment {
|
||||||
|
|
||||||
|
public CalculatorHelpScreensFragment() {
|
||||||
|
super(CalculatorFragmentType.screens);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.help;
|
|
||||||
|
|
||||||
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.AndroidUtils;
|
|
||||||
import org.solovyev.android.LastTabSaver;
|
|
||||||
import org.solovyev.android.calculator.R;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 11/19/11
|
|
||||||
* Time: 11:35 AM
|
|
||||||
*/
|
|
||||||
public class CalculatorHelpTabActivity extends TabActivity {
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private LastTabSaver lastTabSaver;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
setContentView(R.layout.tabs);
|
|
||||||
|
|
||||||
final TabHost tabHost = getTabHost();
|
|
||||||
|
|
||||||
createTab(tabHost, "faq", R.string.c_faq, HelpFaqActivity.class);
|
|
||||||
createTab(tabHost, "hints", R.string.c_hints, HelpHintsActivity.class);
|
|
||||||
createTab(tabHost, "screens", R.string.c_screens, HelpScreensActivity.class);
|
|
||||||
|
|
||||||
this.lastTabSaver = new LastTabSaver(this, "faq");
|
|
||||||
|
|
||||||
AndroidUtils.centerAndWrapTabsFor(tabHost);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
if (this.lastTabSaver != null) {
|
|
||||||
this.lastTabSaver.destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.help;
|
|
||||||
|
|
||||||
import org.solovyev.android.calculator.R;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 11/19/11
|
|
||||||
* Time: 11:37 AM
|
|
||||||
*/
|
|
||||||
public class HelpFaqActivity extends AbstractHelpActivity {
|
|
||||||
|
|
||||||
public HelpFaqActivity() {
|
|
||||||
super(R.layout.help_faq);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.help;
|
|
||||||
|
|
||||||
import org.solovyev.android.calculator.R;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 11/19/11
|
|
||||||
* Time: 11:37 AM
|
|
||||||
*/
|
|
||||||
public class HelpHintsActivity extends AbstractHelpActivity {
|
|
||||||
|
|
||||||
public HelpHintsActivity() {
|
|
||||||
super(R.layout.help_hints);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.help;
|
|
||||||
|
|
||||||
import org.solovyev.android.calculator.R;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 11/19/11
|
|
||||||
* Time: 11:38 AM
|
|
||||||
*/
|
|
||||||
public class HelpScreensActivity extends AbstractHelpActivity{
|
|
||||||
|
|
||||||
public HelpScreensActivity() {
|
|
||||||
super(R.layout.help_screens);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,318 +1,319 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
* or visit http://se.solovyev.org
|
* or visit http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import com.actionbarsherlock.app.SherlockListFragment;
|
import com.actionbarsherlock.app.SherlockListFragment;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.menu.AMenuBuilder;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
import org.solovyev.android.menu.MenuImpl;
|
import org.solovyev.android.menu.AMenuBuilder;
|
||||||
import org.solovyev.common.collections.CollectionsUtils;
|
import org.solovyev.android.menu.MenuImpl;
|
||||||
import org.solovyev.common.equals.Equalizer;
|
import org.solovyev.common.collections.CollectionsUtils;
|
||||||
import org.solovyev.common.filter.Filter;
|
import org.solovyev.common.equals.Equalizer;
|
||||||
import org.solovyev.common.filter.FilterRule;
|
import org.solovyev.common.filter.Filter;
|
||||||
import org.solovyev.common.filter.FilterRulesChain;
|
import org.solovyev.common.filter.FilterRule;
|
||||||
import org.solovyev.common.text.StringUtils;
|
import org.solovyev.common.filter.FilterRulesChain;
|
||||||
|
import org.solovyev.common.text.StringUtils;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
/**
|
|
||||||
* User: serso
|
/**
|
||||||
* Date: 10/15/11
|
* User: serso
|
||||||
* Time: 1:13 PM
|
* Date: 10/15/11
|
||||||
*/
|
* Time: 1:13 PM
|
||||||
public abstract class AbstractCalculatorHistoryFragment extends SherlockListFragment implements CalculatorEventListener {
|
*/
|
||||||
|
public abstract class AbstractCalculatorHistoryFragment extends SherlockListFragment implements CalculatorEventListener {
|
||||||
/*
|
|
||||||
**********************************************************************
|
/*
|
||||||
*
|
**********************************************************************
|
||||||
* CONSTANTS
|
*
|
||||||
*
|
* CONSTANTS
|
||||||
**********************************************************************
|
*
|
||||||
*/
|
**********************************************************************
|
||||||
|
*/
|
||||||
@NotNull
|
|
||||||
private static final String TAG = "CalculatorHistoryFragment";
|
@NotNull
|
||||||
|
private static final String TAG = "CalculatorHistoryFragment";
|
||||||
public static final Comparator<CalculatorHistoryState> COMPARATOR = new Comparator<CalculatorHistoryState>() {
|
|
||||||
@Override
|
public static final Comparator<CalculatorHistoryState> COMPARATOR = new Comparator<CalculatorHistoryState>() {
|
||||||
public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) {
|
@Override
|
||||||
if (state1.isSaved() == state2.isSaved()) {
|
public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) {
|
||||||
long l = state2.getTime() - state1.getTime();
|
if (state1.isSaved() == state2.isSaved()) {
|
||||||
return l > 0l ? 1 : (l < 0l ? -1 : 0);
|
long l = state2.getTime() - state1.getTime();
|
||||||
} else if (state1.isSaved()) {
|
return l > 0l ? 1 : (l < 0l ? -1 : 0);
|
||||||
return -1;
|
} else if (state1.isSaved()) {
|
||||||
} else if (state2.isSaved()) {
|
return -1;
|
||||||
return 1;
|
} else if (state2.isSaved()) {
|
||||||
}
|
return 1;
|
||||||
return 0;
|
}
|
||||||
}
|
return 0;
|
||||||
};
|
}
|
||||||
|
};
|
||||||
/*
|
|
||||||
**********************************************************************
|
/*
|
||||||
*
|
**********************************************************************
|
||||||
* FIELDS
|
*
|
||||||
*
|
* FIELDS
|
||||||
**********************************************************************
|
*
|
||||||
*/
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private ArrayAdapter<CalculatorHistoryState> adapter;
|
@NotNull
|
||||||
|
private ArrayAdapter<CalculatorHistoryState> adapter;
|
||||||
@NotNull
|
|
||||||
private CalculatorFragmentHelper fragmentHelper;
|
@NotNull
|
||||||
|
private CalculatorFragmentHelper fragmentHelper;
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
protected AbstractCalculatorHistoryFragment(@NotNull CalculatorFragmentType fragmentType) {
|
||||||
super.onCreate(savedInstanceState);
|
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId(), false);
|
||||||
|
}
|
||||||
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.history_fragment, getTitleResId(), false);
|
|
||||||
fragmentHelper.onCreate(this);
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
logDebug("onCreate");
|
super.onCreate(savedInstanceState);
|
||||||
}
|
|
||||||
|
fragmentHelper.onCreate(this);
|
||||||
private int logDebug(@NotNull String msg) {
|
|
||||||
return Log.d(TAG + ": " + getTag(), msg);
|
logDebug("onCreate");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private int logDebug(@NotNull String msg) {
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
return Log.d(TAG + ": " + getTag(), msg);
|
||||||
return fragmentHelper.onCreateView(this, inflater, container);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
return fragmentHelper.onCreateView(this, inflater, container);
|
||||||
super.onViewCreated(root, savedInstanceState);
|
}
|
||||||
|
|
||||||
logDebug("onViewCreated");
|
@Override
|
||||||
|
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||||
fragmentHelper.onViewCreated(this, root);
|
super.onViewCreated(root, savedInstanceState);
|
||||||
|
|
||||||
adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), R.id.history_item, new ArrayList<CalculatorHistoryState>());
|
logDebug("onViewCreated");
|
||||||
setListAdapter(adapter);
|
|
||||||
|
fragmentHelper.onViewCreated(this, root);
|
||||||
final ListView lv = getListView();
|
|
||||||
lv.setTextFilterEnabled(true);
|
adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), R.id.history_item, new ArrayList<CalculatorHistoryState>());
|
||||||
|
setListAdapter(adapter);
|
||||||
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
||||||
public void onItemClick(final AdapterView<?> parent,
|
final ListView lv = getListView();
|
||||||
final View view,
|
lv.setTextFilterEnabled(true);
|
||||||
final int position,
|
|
||||||
final long id) {
|
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
|
public void onItemClick(final AdapterView<?> parent,
|
||||||
useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position));
|
final View view,
|
||||||
}
|
final int position,
|
||||||
});
|
final long id) {
|
||||||
|
|
||||||
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position));
|
||||||
@Override
|
}
|
||||||
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
|
});
|
||||||
final CalculatorHistoryState historyState = (CalculatorHistoryState) parent.getItemAtPosition(position);
|
|
||||||
|
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||||
final Context context = getActivity();
|
@Override
|
||||||
|
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
|
||||||
final HistoryItemMenuData data = new HistoryItemMenuData(historyState, adapter);
|
final CalculatorHistoryState historyState = (CalculatorHistoryState) parent.getItemAtPosition(position);
|
||||||
|
|
||||||
final List<HistoryItemMenuItem> menuItems = CollectionsUtils.asList(HistoryItemMenuItem.values());
|
final Context context = getActivity();
|
||||||
|
|
||||||
if (historyState.isSaved()) {
|
final HistoryItemMenuData data = new HistoryItemMenuData(historyState, adapter);
|
||||||
menuItems.remove(HistoryItemMenuItem.save);
|
|
||||||
} else {
|
final List<HistoryItemMenuItem> menuItems = CollectionsUtils.asList(HistoryItemMenuItem.values());
|
||||||
if (isAlreadySaved(historyState)) {
|
|
||||||
menuItems.remove(HistoryItemMenuItem.save);
|
if (historyState.isSaved()) {
|
||||||
}
|
menuItems.remove(HistoryItemMenuItem.save);
|
||||||
menuItems.remove(HistoryItemMenuItem.remove);
|
} else {
|
||||||
menuItems.remove(HistoryItemMenuItem.edit);
|
if (isAlreadySaved(historyState)) {
|
||||||
}
|
menuItems.remove(HistoryItemMenuItem.save);
|
||||||
|
}
|
||||||
if (historyState.getDisplayState().isValid() && StringUtils.isEmpty(historyState.getDisplayState().getEditorState().getText())) {
|
menuItems.remove(HistoryItemMenuItem.remove);
|
||||||
menuItems.remove(HistoryItemMenuItem.copy_result);
|
menuItems.remove(HistoryItemMenuItem.edit);
|
||||||
}
|
}
|
||||||
|
|
||||||
final AMenuBuilder<HistoryItemMenuItem, HistoryItemMenuData> menuBuilder = AMenuBuilder.newInstance(context, MenuImpl.newInstance(menuItems));
|
if (historyState.getDisplayState().isValid() && StringUtils.isEmpty(historyState.getDisplayState().getEditorState().getText())) {
|
||||||
menuBuilder.create(data).show();
|
menuItems.remove(HistoryItemMenuItem.copy_result);
|
||||||
|
}
|
||||||
return true;
|
|
||||||
}
|
final AMenuBuilder<HistoryItemMenuItem, HistoryItemMenuData> menuBuilder = AMenuBuilder.newInstance(context, MenuImpl.newInstance(menuItems));
|
||||||
});
|
menuBuilder.create(data).show();
|
||||||
}
|
|
||||||
|
return true;
|
||||||
protected abstract int getTitleResId();
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void onResume() {
|
@Override
|
||||||
super.onResume();
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
this.fragmentHelper.onResume(this);
|
|
||||||
|
this.fragmentHelper.onResume(this);
|
||||||
updateAdapter();
|
|
||||||
}
|
updateAdapter();
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void onPause() {
|
@Override
|
||||||
this.fragmentHelper.onPause(this);
|
public void onPause() {
|
||||||
|
this.fragmentHelper.onPause(this);
|
||||||
super.onPause();
|
|
||||||
}
|
super.onPause();
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
@Override
|
||||||
logDebug("onDestroy");
|
public void onDestroy() {
|
||||||
|
logDebug("onDestroy");
|
||||||
fragmentHelper.onDestroy(this);
|
|
||||||
|
fragmentHelper.onDestroy(this);
|
||||||
super.onDestroy();
|
|
||||||
}
|
super.onDestroy();
|
||||||
|
}
|
||||||
protected abstract int getItemLayoutId();
|
|
||||||
|
protected abstract int getItemLayoutId();
|
||||||
private void updateAdapter() {
|
|
||||||
final List<CalculatorHistoryState> historyList = getHistoryList();
|
private void updateAdapter() {
|
||||||
|
final List<CalculatorHistoryState> historyList = getHistoryList();
|
||||||
final ArrayAdapter<CalculatorHistoryState> adapter = getAdapter();
|
|
||||||
try {
|
final ArrayAdapter<CalculatorHistoryState> adapter = getAdapter();
|
||||||
adapter.setNotifyOnChange(false);
|
try {
|
||||||
adapter.clear();
|
adapter.setNotifyOnChange(false);
|
||||||
for (CalculatorHistoryState historyState : historyList) {
|
adapter.clear();
|
||||||
adapter.add(historyState);
|
for (CalculatorHistoryState historyState : historyList) {
|
||||||
}
|
adapter.add(historyState);
|
||||||
} finally {
|
}
|
||||||
adapter.setNotifyOnChange(true);
|
} finally {
|
||||||
}
|
adapter.setNotifyOnChange(true);
|
||||||
|
}
|
||||||
adapter.notifyDataSetChanged();
|
|
||||||
}
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
public static boolean isAlreadySaved(@NotNull CalculatorHistoryState historyState) {
|
|
||||||
assert !historyState.isSaved();
|
public static boolean isAlreadySaved(@NotNull CalculatorHistoryState historyState) {
|
||||||
|
assert !historyState.isSaved();
|
||||||
boolean result = false;
|
|
||||||
try {
|
boolean result = false;
|
||||||
historyState.setSaved(true);
|
try {
|
||||||
if ( CollectionsUtils.contains(historyState, CalculatorLocatorImpl.getInstance().getHistory().getSavedHistory(), new Equalizer<CalculatorHistoryState>() {
|
historyState.setSaved(true);
|
||||||
@Override
|
if ( CollectionsUtils.contains(historyState, CalculatorLocatorImpl.getInstance().getHistory().getSavedHistory(), new Equalizer<CalculatorHistoryState>() {
|
||||||
public boolean equals(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
|
@Override
|
||||||
return first != null && second != null &&
|
public boolean equals(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
|
||||||
first.getTime() == second.getTime() &&
|
return first != null && second != null &&
|
||||||
first.getDisplayState().equals(second.getDisplayState()) &&
|
first.getTime() == second.getTime() &&
|
||||||
first.getEditorState().equals(second.getEditorState());
|
first.getDisplayState().equals(second.getDisplayState()) &&
|
||||||
}
|
first.getEditorState().equals(second.getEditorState());
|
||||||
}) ) {
|
}
|
||||||
result = true;
|
}) ) {
|
||||||
}
|
result = true;
|
||||||
} finally {
|
}
|
||||||
historyState.setSaved(false);
|
} finally {
|
||||||
}
|
historyState.setSaved(false);
|
||||||
return result;
|
}
|
||||||
}
|
return result;
|
||||||
|
}
|
||||||
public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState) {
|
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_history_state, historyState);
|
public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState) {
|
||||||
}
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_history_state, historyState);
|
||||||
|
}
|
||||||
@NotNull
|
|
||||||
private List<CalculatorHistoryState> getHistoryList() {
|
@NotNull
|
||||||
final List<CalculatorHistoryState> calculatorHistoryStates = getHistoryItems();
|
private List<CalculatorHistoryState> getHistoryList() {
|
||||||
|
final List<CalculatorHistoryState> calculatorHistoryStates = getHistoryItems();
|
||||||
Collections.sort(calculatorHistoryStates, COMPARATOR);
|
|
||||||
|
Collections.sort(calculatorHistoryStates, COMPARATOR);
|
||||||
final FilterRulesChain<CalculatorHistoryState> filterRulesChain = new FilterRulesChain<CalculatorHistoryState>();
|
|
||||||
filterRulesChain.addFilterRule(new FilterRule<CalculatorHistoryState>() {
|
final FilterRulesChain<CalculatorHistoryState> filterRulesChain = new FilterRulesChain<CalculatorHistoryState>();
|
||||||
@Override
|
filterRulesChain.addFilterRule(new FilterRule<CalculatorHistoryState>() {
|
||||||
public boolean isFiltered(CalculatorHistoryState object) {
|
@Override
|
||||||
return object == null || StringUtils.isEmpty(object.getEditorState().getText());
|
public boolean isFiltered(CalculatorHistoryState object) {
|
||||||
}
|
return object == null || StringUtils.isEmpty(object.getEditorState().getText());
|
||||||
});
|
}
|
||||||
|
});
|
||||||
new Filter<CalculatorHistoryState>(filterRulesChain).filter(calculatorHistoryStates.iterator());
|
|
||||||
|
new Filter<CalculatorHistoryState>(filterRulesChain).filter(calculatorHistoryStates.iterator());
|
||||||
return calculatorHistoryStates;
|
|
||||||
}
|
return calculatorHistoryStates;
|
||||||
|
}
|
||||||
@NotNull
|
|
||||||
protected abstract List<CalculatorHistoryState> getHistoryItems();
|
@NotNull
|
||||||
|
protected abstract List<CalculatorHistoryState> getHistoryItems();
|
||||||
@NotNull
|
|
||||||
public static String getHistoryText(@NotNull CalculatorHistoryState state) {
|
@NotNull
|
||||||
final StringBuilder result = new StringBuilder();
|
public static String getHistoryText(@NotNull CalculatorHistoryState state) {
|
||||||
result.append(state.getEditorState().getText());
|
final StringBuilder result = new StringBuilder();
|
||||||
result.append(getIdentitySign(state.getDisplayState().getJsclOperation()));
|
result.append(state.getEditorState().getText());
|
||||||
final String expressionResult = state.getDisplayState().getEditorState().getText();
|
result.append(getIdentitySign(state.getDisplayState().getJsclOperation()));
|
||||||
if (expressionResult != null) {
|
final String expressionResult = state.getDisplayState().getEditorState().getText();
|
||||||
result.append(expressionResult);
|
if (expressionResult != null) {
|
||||||
}
|
result.append(expressionResult);
|
||||||
return result.toString();
|
}
|
||||||
}
|
return result.toString();
|
||||||
|
}
|
||||||
@NotNull
|
|
||||||
private static String getIdentitySign(@NotNull JsclOperation jsclOperation) {
|
@NotNull
|
||||||
return jsclOperation == JsclOperation.simplify ? "≡" : "=";
|
private static String getIdentitySign(@NotNull JsclOperation jsclOperation) {
|
||||||
}
|
return jsclOperation == JsclOperation.simplify ? "≡" : "=";
|
||||||
|
}
|
||||||
// todo serso: menu
|
|
||||||
/* @Override
|
// todo serso: menu
|
||||||
public boolean onCreateOptionsMenu(android.view.Menu menu) {
|
/* @Override
|
||||||
final MenuInflater menuInflater = getMenuInflater();
|
public boolean onCreateOptionsMenu(android.view.Menu menu) {
|
||||||
menuInflater.inflate(R.menu.history_menu, menu);
|
final MenuInflater menuInflater = getMenuInflater();
|
||||||
return true;
|
menuInflater.inflate(R.menu.history_menu, menu);
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
@Override
|
||||||
boolean result;
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
boolean result;
|
||||||
switch (item.getItemId()) {
|
|
||||||
case R.id.history_menu_clear_history:
|
switch (item.getItemId()) {
|
||||||
clearHistory();
|
case R.id.history_menu_clear_history:
|
||||||
result = true;
|
clearHistory();
|
||||||
break;
|
result = true;
|
||||||
default:
|
break;
|
||||||
result = super.onOptionsItemSelected(item);
|
default:
|
||||||
}
|
result = super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
return result;
|
|
||||||
}*/
|
return result;
|
||||||
|
}*/
|
||||||
protected abstract void clearHistory();
|
|
||||||
|
protected abstract void clearHistory();
|
||||||
@NotNull
|
|
||||||
protected ArrayAdapter<CalculatorHistoryState> getAdapter() {
|
@NotNull
|
||||||
return adapter;
|
protected ArrayAdapter<CalculatorHistoryState> getAdapter() {
|
||||||
}
|
return adapter;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
@Override
|
||||||
if ( calculatorEventType == CalculatorEventType.history_state_added ) {
|
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||||
|
if ( calculatorEventType == CalculatorEventType.history_state_added ) {
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
logDebug("onCalculatorEvent");
|
public void run() {
|
||||||
updateAdapter();
|
logDebug("onCalculatorEvent");
|
||||||
}
|
updateAdapter();
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -18,10 +18,10 @@ import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
|||||||
* Date: 12/18/11
|
* Date: 12/18/11
|
||||||
* Time: 7:37 PM
|
* Time: 7:37 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorHistoryFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
public class CalculatorHistoryActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
|
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
@ -1,44 +1,44 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
* or visit http://se.solovyev.org
|
* or visit http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
/**
|
|
||||||
* User: serso
|
/**
|
||||||
* Date: 12/18/11
|
* User: serso
|
||||||
* Time: 7:39 PM
|
* Date: 12/18/11
|
||||||
*/
|
* Time: 7:39 PM
|
||||||
public class CalculatorHistoryFragment extends AbstractCalculatorHistoryFragment {
|
*/
|
||||||
|
public class CalculatorHistoryFragment extends AbstractCalculatorHistoryFragment {
|
||||||
@Override
|
|
||||||
protected int getTitleResId() {
|
public CalculatorHistoryFragment() {
|
||||||
return R.string.c_history;
|
super(CalculatorFragmentType.history);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getItemLayoutId() {
|
protected int getItemLayoutId() {
|
||||||
return R.layout.history;
|
return R.layout.history_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected List<CalculatorHistoryState> getHistoryItems() {
|
protected List<CalculatorHistoryState> getHistoryItems() {
|
||||||
return new ArrayList<CalculatorHistoryState>(CalculatorLocatorImpl.getInstance().getHistory().getStates());
|
return new ArrayList<CalculatorHistoryState>(CalculatorLocatorImpl.getInstance().getHistory().getStates());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void clearHistory() {
|
protected void clearHistory() {
|
||||||
CalculatorLocatorImpl.getInstance().getHistory().clear();
|
CalculatorLocatorImpl.getInstance().getHistory().clear();
|
||||||
getAdapter().clear();
|
getAdapter().clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,44 +1,44 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
* or visit http://se.solovyev.org
|
* or visit http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
/**
|
|
||||||
* User: serso
|
/**
|
||||||
* Date: 12/18/11
|
* User: serso
|
||||||
* Time: 7:40 PM
|
* Date: 12/18/11
|
||||||
*/
|
* Time: 7:40 PM
|
||||||
public class CalculatorSavedHistoryFragment extends AbstractCalculatorHistoryFragment {
|
*/
|
||||||
|
public class CalculatorSavedHistoryFragment extends AbstractCalculatorHistoryFragment {
|
||||||
@Override
|
|
||||||
protected int getTitleResId() {
|
public CalculatorSavedHistoryFragment() {
|
||||||
return R.string.c_saved_history;
|
super(CalculatorFragmentType.saved_history);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getItemLayoutId() {
|
protected int getItemLayoutId() {
|
||||||
return R.layout.saved_history;
|
return R.layout.saved_history_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected List<CalculatorHistoryState> getHistoryItems() {
|
protected List<CalculatorHistoryState> getHistoryItems() {
|
||||||
return new ArrayList<CalculatorHistoryState>(CalculatorLocatorImpl.getInstance().getHistory().getSavedHistory());
|
return new ArrayList<CalculatorHistoryState>(CalculatorLocatorImpl.getInstance().getHistory().getSavedHistory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void clearHistory() {
|
protected void clearHistory() {
|
||||||
CalculatorLocatorImpl.getInstance().getHistory().clearSavedHistory();
|
CalculatorLocatorImpl.getInstance().getHistory().clearSavedHistory();
|
||||||
getAdapter().clear();
|
getAdapter().clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,351 +1,349 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
* or visit http://se.solovyev.org
|
* or visit http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.math.edit;
|
package org.solovyev.android.calculator.math.edit;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import com.actionbarsherlock.app.SherlockListFragment;
|
import com.actionbarsherlock.app.SherlockListFragment;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.menu.AMenuBuilder;
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.menu.AMenuItem;
|
import org.solovyev.android.menu.AMenuBuilder;
|
||||||
import org.solovyev.android.menu.LabeledMenuItem;
|
import org.solovyev.android.menu.AMenuItem;
|
||||||
import org.solovyev.android.menu.MenuImpl;
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
import org.solovyev.common.equals.EqualsTool;
|
import org.solovyev.android.menu.MenuImpl;
|
||||||
import org.solovyev.common.filter.Filter;
|
import org.solovyev.common.equals.EqualsTool;
|
||||||
import org.solovyev.common.filter.FilterRule;
|
import org.solovyev.common.filter.Filter;
|
||||||
import org.solovyev.common.math.MathEntity;
|
import org.solovyev.common.filter.FilterRule;
|
||||||
import org.solovyev.common.text.StringUtils;
|
import org.solovyev.common.math.MathEntity;
|
||||||
|
import org.solovyev.common.text.StringUtils;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
/**
|
|
||||||
* User: serso
|
/**
|
||||||
* Date: 12/21/11
|
* User: serso
|
||||||
* Time: 9:24 PM
|
* Date: 12/21/11
|
||||||
*/
|
* Time: 9:24 PM
|
||||||
public abstract class AbstractMathEntityListFragment<T extends MathEntity> extends SherlockListFragment implements CalculatorEventListener {
|
*/
|
||||||
|
public abstract class AbstractMathEntityListFragment<T extends MathEntity> extends SherlockListFragment implements CalculatorEventListener {
|
||||||
/*
|
|
||||||
**********************************************************************
|
/*
|
||||||
*
|
**********************************************************************
|
||||||
* CONSTANTS
|
*
|
||||||
*
|
* CONSTANTS
|
||||||
**********************************************************************
|
*
|
||||||
*/
|
**********************************************************************
|
||||||
|
*/
|
||||||
public static final String MATH_ENTITY_CATEGORY_EXTRA_STRING = "org.solovyev.android.calculator.CalculatorVarsActivity_math_entity_category";
|
|
||||||
|
public static final String MATH_ENTITY_CATEGORY_EXTRA_STRING = "org.solovyev.android.calculator.CalculatorVarsActivity_math_entity_category";
|
||||||
protected final static List<Character> acceptableChars = Arrays.asList(StringUtils.toObject("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_".toCharArray()));
|
|
||||||
|
protected final static List<Character> acceptableChars = Arrays.asList(StringUtils.toObject("1234567890abcdefghijklmnopqrstuvwxyzйцукенгшщзхъфывапролджэячсмитьбюё_".toCharArray()));
|
||||||
|
|
||||||
/*
|
|
||||||
**********************************************************************
|
/*
|
||||||
*
|
**********************************************************************
|
||||||
* FIELDS
|
*
|
||||||
*
|
* FIELDS
|
||||||
**********************************************************************
|
*
|
||||||
*/
|
**********************************************************************
|
||||||
|
*/
|
||||||
@Nullable
|
|
||||||
private MathEntityArrayAdapter<T> adapter;
|
@Nullable
|
||||||
|
private MathEntityArrayAdapter<T> adapter;
|
||||||
@Nullable
|
|
||||||
private String category;
|
@Nullable
|
||||||
|
private String category;
|
||||||
@NotNull
|
|
||||||
private CalculatorFragmentHelper fragmentHelper;
|
@NotNull
|
||||||
|
private final CalculatorFragmentHelper fragmentHelper;
|
||||||
@NotNull
|
|
||||||
private final Handler uiHandler = new Handler();
|
@NotNull
|
||||||
|
private final Handler uiHandler = new Handler();
|
||||||
protected int getLayoutId() {
|
|
||||||
return R.layout.math_entities_fragment;
|
protected AbstractMathEntityListFragment(@NotNull CalculatorFragmentType fragmentType) {
|
||||||
}
|
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(),fragmentType.getDefaultTitleResId());
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
@Override
|
||||||
super.onCreate(savedInstanceState);
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
final Bundle bundle = getArguments();
|
|
||||||
if (bundle != null) {
|
final Bundle bundle = getArguments();
|
||||||
category = bundle.getString(MATH_ENTITY_CATEGORY_EXTRA_STRING);
|
if (bundle != null) {
|
||||||
}
|
category = bundle.getString(MATH_ENTITY_CATEGORY_EXTRA_STRING);
|
||||||
|
}
|
||||||
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(getLayoutId(), getTitleResId());
|
|
||||||
fragmentHelper.onCreate(this);
|
fragmentHelper.onCreate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
return fragmentHelper.onCreateView(this, inflater, container);
|
return fragmentHelper.onCreateView(this, inflater, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(root, savedInstanceState);
|
super.onViewCreated(root, savedInstanceState);
|
||||||
|
|
||||||
fragmentHelper.onViewCreated(this, root);
|
fragmentHelper.onViewCreated(this, root);
|
||||||
|
|
||||||
final ListView lv = getListView();
|
final ListView lv = getListView();
|
||||||
lv.setTextFilterEnabled(true);
|
lv.setTextFilterEnabled(true);
|
||||||
|
|
||||||
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
public void onItemClick(final AdapterView<?> parent,
|
public void onItemClick(final AdapterView<?> parent,
|
||||||
final View view,
|
final View view,
|
||||||
final int position,
|
final int position,
|
||||||
final long id) {
|
final long id) {
|
||||||
final AMenuItem<T> onClick = getOnClickAction();
|
final AMenuItem<T> onClick = getOnClickAction();
|
||||||
if (onClick != null) {
|
if (onClick != null) {
|
||||||
onClick.onClick(((T) parent.getItemAtPosition(position)), getActivity());
|
onClick.onClick(((T) parent.getItemAtPosition(position)), getActivity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
final T item = (T) parent.getItemAtPosition(position);
|
final T item = (T) parent.getItemAtPosition(position);
|
||||||
|
|
||||||
final List<LabeledMenuItem<T>> menuItems = getMenuItemsOnLongClick(item);
|
final List<LabeledMenuItem<T>> menuItems = getMenuItemsOnLongClick(item);
|
||||||
|
|
||||||
if (!menuItems.isEmpty()) {
|
if (!menuItems.isEmpty()) {
|
||||||
final AMenuBuilder<LabeledMenuItem<T>, T> menuBuilder = AMenuBuilder.newInstance(AbstractMathEntityListFragment.this.getActivity(), MenuImpl.newInstance(menuItems));
|
final AMenuBuilder<LabeledMenuItem<T>, T> menuBuilder = AMenuBuilder.newInstance(AbstractMathEntityListFragment.this.getActivity(), MenuImpl.newInstance(menuItems));
|
||||||
menuBuilder.create(item).show();
|
menuBuilder.create(item).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
protected abstract AMenuItem<T> getOnClickAction();
|
protected abstract AMenuItem<T> getOnClickAction();
|
||||||
|
|
||||||
protected abstract int getTitleResId();
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
@Override
|
fragmentHelper.onDestroy(this);
|
||||||
public void onDestroy() {
|
|
||||||
fragmentHelper.onDestroy(this);
|
super.onDestroy();
|
||||||
|
}
|
||||||
super.onDestroy();
|
|
||||||
}
|
@NotNull
|
||||||
|
protected abstract List<LabeledMenuItem<T>> getMenuItemsOnLongClick(@NotNull T item);
|
||||||
@NotNull
|
|
||||||
protected abstract List<LabeledMenuItem<T>> getMenuItemsOnLongClick(@NotNull T item);
|
@Override
|
||||||
|
public void onPause() {
|
||||||
@Override
|
this.fragmentHelper.onPause(this);
|
||||||
public void onPause() {
|
|
||||||
this.fragmentHelper.onPause(this);
|
super.onPause();
|
||||||
|
}
|
||||||
super.onPause();
|
|
||||||
}
|
@Override
|
||||||
|
public void onResume() {
|
||||||
@Override
|
super.onResume();
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
this.fragmentHelper.onResume(this);
|
||||||
|
|
||||||
this.fragmentHelper.onResume(this);
|
adapter = new MathEntityArrayAdapter<T>(getDescriptionGetter(), this.getActivity(), R.layout.math_entity, R.id.math_entity_text, getMathEntitiesByCategory());
|
||||||
|
setListAdapter(adapter);
|
||||||
adapter = new MathEntityArrayAdapter<T>(getDescriptionGetter(), this.getActivity(), R.layout.math_entity, R.id.math_entity_text, getMathEntitiesByCategory());
|
|
||||||
setListAdapter(adapter);
|
sort();
|
||||||
|
}
|
||||||
sort();
|
|
||||||
}
|
@NotNull
|
||||||
|
private List<T> getMathEntitiesByCategory() {
|
||||||
@NotNull
|
final List<T> result = getMathEntities();
|
||||||
private List<T> getMathEntitiesByCategory() {
|
|
||||||
final List<T> result = getMathEntities();
|
new Filter<T>(new FilterRule<T>() {
|
||||||
|
@Override
|
||||||
new Filter<T>(new FilterRule<T>() {
|
public boolean isFiltered(T t) {
|
||||||
@Override
|
return !isInCategory(t);
|
||||||
public boolean isFiltered(T t) {
|
}
|
||||||
return !isInCategory(t);
|
}).filter(result.iterator());
|
||||||
}
|
|
||||||
}).filter(result.iterator());
|
return result;
|
||||||
|
}
|
||||||
return result;
|
|
||||||
}
|
protected boolean isInCategory(@Nullable T t) {
|
||||||
|
return t != null && (category == null || EqualsTool.areEqual(getMathEntityCategory(t), category));
|
||||||
protected boolean isInCategory(@Nullable T t) {
|
}
|
||||||
return t != null && (category == null || EqualsTool.areEqual(getMathEntityCategory(t), category));
|
|
||||||
}
|
@NotNull
|
||||||
|
protected abstract MathEntityDescriptionGetter getDescriptionGetter();
|
||||||
@NotNull
|
|
||||||
protected abstract MathEntityDescriptionGetter getDescriptionGetter();
|
@NotNull
|
||||||
|
protected abstract List<T> getMathEntities();
|
||||||
@NotNull
|
|
||||||
protected abstract List<T> getMathEntities();
|
@Nullable
|
||||||
|
abstract String getMathEntityCategory(@NotNull T t);
|
||||||
@Nullable
|
|
||||||
abstract String getMathEntityCategory(@NotNull T t);
|
protected void sort() {
|
||||||
|
final MathEntityArrayAdapter<T> localAdapter = adapter;
|
||||||
protected void sort() {
|
if (localAdapter != null) {
|
||||||
final MathEntityArrayAdapter<T> localAdapter = adapter;
|
localAdapter.sort(new Comparator<T>() {
|
||||||
if (localAdapter != null) {
|
@Override
|
||||||
localAdapter.sort(new Comparator<T>() {
|
public int compare(T function1, T function2) {
|
||||||
@Override
|
return function1.getName().compareTo(function2.getName());
|
||||||
public int compare(T function1, T function2) {
|
}
|
||||||
return function1.getName().compareTo(function2.getName());
|
});
|
||||||
}
|
|
||||||
});
|
localAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
localAdapter.notifyDataSetChanged();
|
}
|
||||||
}
|
|
||||||
}
|
protected static class MathEntityArrayAdapter<T extends MathEntity> extends ArrayAdapter<T> {
|
||||||
|
|
||||||
protected static class MathEntityArrayAdapter<T extends MathEntity> extends ArrayAdapter<T> {
|
@NotNull
|
||||||
|
private final MathEntityDescriptionGetter descriptionGetter;
|
||||||
@NotNull
|
|
||||||
private final MathEntityDescriptionGetter descriptionGetter;
|
private MathEntityArrayAdapter(@NotNull MathEntityDescriptionGetter descriptionGetter,
|
||||||
|
@NotNull Context context,
|
||||||
private MathEntityArrayAdapter(@NotNull MathEntityDescriptionGetter descriptionGetter,
|
int resource,
|
||||||
@NotNull Context context,
|
int textViewResourceId,
|
||||||
int resource,
|
@NotNull List<T> objects) {
|
||||||
int textViewResourceId,
|
|
||||||
@NotNull List<T> objects) {
|
super(context, resource, textViewResourceId, objects);
|
||||||
|
this.descriptionGetter = descriptionGetter;
|
||||||
super(context, resource, textViewResourceId, objects);
|
}
|
||||||
this.descriptionGetter = descriptionGetter;
|
|
||||||
}
|
@Override
|
||||||
|
public View getView(int position, @Nullable View convertView, ViewGroup parent) {
|
||||||
@Override
|
final ViewGroup result;
|
||||||
public View getView(int position, @Nullable View convertView, ViewGroup parent) {
|
|
||||||
final ViewGroup result;
|
if (convertView == null) {
|
||||||
|
result = (ViewGroup) super.getView(position, convertView, parent);
|
||||||
if (convertView == null) {
|
fillView(position, result);
|
||||||
result = (ViewGroup) super.getView(position, convertView, parent);
|
} else {
|
||||||
fillView(position, result);
|
result = (ViewGroup) convertView;
|
||||||
} else {
|
fillView(position, result);
|
||||||
result = (ViewGroup) convertView;
|
}
|
||||||
fillView(position, result);
|
|
||||||
}
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
return result;
|
|
||||||
}
|
private void fillView(int position, @NotNull ViewGroup result) {
|
||||||
|
final T mathEntity = getItem(position);
|
||||||
private void fillView(int position, @NotNull ViewGroup result) {
|
|
||||||
final T mathEntity = getItem(position);
|
final TextView text = (TextView) result.findViewById(R.id.math_entity_text);
|
||||||
|
text.setText(String.valueOf(mathEntity));
|
||||||
final TextView text = (TextView) result.findViewById(R.id.math_entity_text);
|
|
||||||
text.setText(String.valueOf(mathEntity));
|
final String mathEntityDescription = descriptionGetter.getDescription(getContext(), mathEntity.getName());
|
||||||
|
|
||||||
final String mathEntityDescription = descriptionGetter.getDescription(getContext(), mathEntity.getName());
|
final TextView description = (TextView) result.findViewById(R.id.math_entity_description);
|
||||||
|
if (!StringUtils.isEmpty(mathEntityDescription)) {
|
||||||
final TextView description = (TextView) result.findViewById(R.id.math_entity_description);
|
description.setVisibility(View.VISIBLE);
|
||||||
if (!StringUtils.isEmpty(mathEntityDescription)) {
|
description.setText(mathEntityDescription);
|
||||||
description.setVisibility(View.VISIBLE);
|
} else {
|
||||||
description.setText(mathEntityDescription);
|
description.setVisibility(View.GONE);
|
||||||
} else {
|
}
|
||||||
description.setVisibility(View.GONE);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
protected static class MathEntityDescriptionGetterImpl implements MathEntityDescriptionGetter {
|
||||||
|
|
||||||
protected static class MathEntityDescriptionGetterImpl implements MathEntityDescriptionGetter {
|
@NotNull
|
||||||
|
private final CalculatorMathRegistry<?> mathRegistry;
|
||||||
@NotNull
|
|
||||||
private final CalculatorMathRegistry<?> mathRegistry;
|
public MathEntityDescriptionGetterImpl(@NotNull CalculatorMathRegistry<?> mathRegistry) {
|
||||||
|
this.mathRegistry = mathRegistry;
|
||||||
public MathEntityDescriptionGetterImpl(@NotNull CalculatorMathRegistry<?> mathRegistry) {
|
}
|
||||||
this.mathRegistry = mathRegistry;
|
|
||||||
}
|
@Override
|
||||||
|
public String getDescription(@NotNull Context context, @NotNull String mathEntityName) {
|
||||||
@Override
|
return this.mathRegistry.getDescription(mathEntityName);
|
||||||
public String getDescription(@NotNull Context context, @NotNull String mathEntityName) {
|
}
|
||||||
return this.mathRegistry.getDescription(mathEntityName);
|
}
|
||||||
}
|
|
||||||
}
|
protected static interface MathEntityDescriptionGetter {
|
||||||
|
|
||||||
protected static interface MathEntityDescriptionGetter {
|
@Nullable
|
||||||
|
String getDescription(@NotNull Context context, @NotNull String mathEntityName);
|
||||||
@Nullable
|
}
|
||||||
String getDescription(@NotNull Context context, @NotNull String mathEntityName);
|
|
||||||
}
|
public void addToAdapter(@NotNull T mathEntity) {
|
||||||
|
if (this.adapter != null) {
|
||||||
public void addToAdapter(@NotNull T mathEntity) {
|
this.adapter.add(mathEntity);
|
||||||
if (this.adapter != null) {
|
}
|
||||||
this.adapter.add(mathEntity);
|
}
|
||||||
}
|
|
||||||
}
|
public void removeFromAdapter(@NotNull T mathEntity) {
|
||||||
|
if (this.adapter != null) {
|
||||||
public void removeFromAdapter(@NotNull T mathEntity) {
|
this.adapter.remove(mathEntity);
|
||||||
if (this.adapter != null) {
|
}
|
||||||
this.adapter.remove(mathEntity);
|
}
|
||||||
}
|
|
||||||
}
|
public void notifyAdapter() {
|
||||||
|
if (this.adapter != null) {
|
||||||
public void notifyAdapter() {
|
this.adapter.notifyDataSetChanged();
|
||||||
if (this.adapter != null) {
|
}
|
||||||
this.adapter.notifyDataSetChanged();
|
}
|
||||||
}
|
|
||||||
}
|
@NotNull
|
||||||
|
protected Handler getUiHandler() {
|
||||||
@NotNull
|
return uiHandler;
|
||||||
protected Handler getUiHandler() {
|
}
|
||||||
return uiHandler;
|
|
||||||
}
|
/*
|
||||||
|
**********************************************************************
|
||||||
/*
|
*
|
||||||
**********************************************************************
|
* STATIC
|
||||||
*
|
*
|
||||||
* STATIC
|
**********************************************************************
|
||||||
*
|
*/
|
||||||
**********************************************************************
|
|
||||||
*/
|
static void createTab(@NotNull Context context,
|
||||||
|
@NotNull TabHost tabHost,
|
||||||
static void createTab(@NotNull Context context,
|
@NotNull String tabId,
|
||||||
@NotNull TabHost tabHost,
|
@NotNull String categoryId,
|
||||||
@NotNull String tabId,
|
int tabCaptionId,
|
||||||
@NotNull String categoryId,
|
@NotNull Class<? extends Activity> activityClass,
|
||||||
int tabCaptionId,
|
@Nullable Intent parentIntent) {
|
||||||
@NotNull Class<? extends Activity> activityClass,
|
|
||||||
@Nullable Intent parentIntent) {
|
TabHost.TabSpec spec;
|
||||||
|
|
||||||
TabHost.TabSpec spec;
|
final Intent intent;
|
||||||
|
if (parentIntent != null) {
|
||||||
final Intent intent;
|
intent = new Intent(parentIntent);
|
||||||
if (parentIntent != null) {
|
} else {
|
||||||
intent = new Intent(parentIntent);
|
intent = new Intent();
|
||||||
} else {
|
}
|
||||||
intent = new Intent();
|
intent.setClass(context, activityClass);
|
||||||
}
|
intent.putExtra(MATH_ENTITY_CATEGORY_EXTRA_STRING, categoryId);
|
||||||
intent.setClass(context, activityClass);
|
|
||||||
intent.putExtra(MATH_ENTITY_CATEGORY_EXTRA_STRING, categoryId);
|
// Initialize a TabSpec for each tab and add it to the TabHost
|
||||||
|
spec = tabHost.newTabSpec(tabId).setIndicator(context.getString(tabCaptionId)).setContent(intent);
|
||||||
// Initialize a TabSpec for each tab and add it to the TabHost
|
|
||||||
spec = tabHost.newTabSpec(tabId).setIndicator(context.getString(tabCaptionId)).setContent(intent);
|
tabHost.addTab(spec);
|
||||||
|
}
|
||||||
tabHost.addTab(spec);
|
|
||||||
}
|
@NotNull
|
||||||
|
public static Bundle createBundleFor(@NotNull String categoryId) {
|
||||||
@NotNull
|
final Bundle result = new Bundle(1);
|
||||||
public static Bundle createBundleFor(@NotNull String categoryId) {
|
putCategory(result, categoryId);
|
||||||
final Bundle result = new Bundle(1);
|
return result;
|
||||||
putCategory(result, categoryId);
|
}
|
||||||
return result;
|
|
||||||
}
|
static void putCategory(@NotNull Bundle bundle, @NotNull String categoryId) {
|
||||||
|
bundle.putString(MATH_ENTITY_CATEGORY_EXTRA_STRING, categoryId);
|
||||||
static void putCategory(@NotNull Bundle bundle, @NotNull String categoryId) {
|
}
|
||||||
bundle.putString(MATH_ENTITY_CATEGORY_EXTRA_STRING, categoryId);
|
|
||||||
}
|
@Override
|
||||||
|
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||||
@Override
|
}
|
||||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -12,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
|
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
||||||
import org.solovyev.android.calculator.model.AndroidFunctionsMathRegistry;
|
import org.solovyev.android.calculator.model.AndroidFunctionsMathRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,10 +20,10 @@ import org.solovyev.android.calculator.model.AndroidFunctionsMathRegistry;
|
|||||||
* Date: 12/21/11
|
* Date: 12/21/11
|
||||||
* Time: 10:33 PM
|
* Time: 10:33 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorFunctionsFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
public class CalculatorFunctionsActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
|
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
@ -1,238 +1,238 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||||
* For more information, please, contact se.solovyev@gmail.com
|
* For more information, please, contact se.solovyev@gmail.com
|
||||||
* or visit http://se.solovyev.org
|
* or visit http://se.solovyev.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.solovyev.android.calculator.math.edit;
|
package org.solovyev.android.calculator.math.edit;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.ClipboardManager;
|
import android.text.ClipboardManager;
|
||||||
import jscl.math.function.Function;
|
import jscl.math.function.Function;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.CalculatorEventType;
|
import org.solovyev.android.calculator.CalculatorEventType;
|
||||||
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.menu.AMenuItem;
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.menu.LabeledMenuItem;
|
import org.solovyev.android.menu.AMenuItem;
|
||||||
import org.solovyev.common.text.StringUtils;
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
|
import org.solovyev.common.text.StringUtils;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
/**
|
|
||||||
* User: serso
|
/**
|
||||||
* Date: 10/29/11
|
* User: serso
|
||||||
* Time: 4:55 PM
|
* Date: 10/29/11
|
||||||
*/
|
* Time: 4:55 PM
|
||||||
public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<Function> {
|
*/
|
||||||
|
public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<Function> {
|
||||||
public static final String CREATE_FUN_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorFunctionsTabActivity_create_fun";
|
|
||||||
|
public static final String CREATE_FUN_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorFunctionsTabActivity_create_fun";
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public CalculatorFunctionsFragment() {
|
||||||
super.onCreate(savedInstanceState);
|
super(CalculatorFragmentType.functions);
|
||||||
|
}
|
||||||
/*getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
final Function function = (Function) parent.getItemAtPosition(position);
|
super.onCreate(savedInstanceState);
|
||||||
if (function instanceof CustomFunction) {
|
|
||||||
createEditVariableDialog(CalculatorFunctionsTabActivity.this,
|
/*getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||||
((CustomFunction) function),
|
@Override
|
||||||
function.getName(),
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
((CustomFunction) function).getContent(),
|
final Function function = (Function) parent.getItemAtPosition(position);
|
||||||
((CustomFunction) function).getParameterNames(),
|
if (function instanceof CustomFunction) {
|
||||||
null);
|
createEditVariableDialog(CalculatorFunctionsTabActivity.this,
|
||||||
}
|
((CustomFunction) function),
|
||||||
return true;
|
function.getName(),
|
||||||
}
|
((CustomFunction) function).getContent(),
|
||||||
});*/
|
((CustomFunction) function).getParameterNames(),
|
||||||
|
null);
|
||||||
/*final Intent intent = getIntent();
|
}
|
||||||
if (intent != null) {
|
return true;
|
||||||
final String varValue = intent.getStringExtra(CREATE_FUN_EXTRA_STRING);
|
}
|
||||||
if (!StringUtils.isEmpty(varValue)) {
|
});*/
|
||||||
createEditVariableDialog(this, null, null, varValue, null, null);
|
|
||||||
|
/*final Intent intent = getIntent();
|
||||||
// in order to stop intent for other tabs
|
if (intent != null) {
|
||||||
intent.removeExtra(CREATE_FUN_EXTRA_STRING);
|
final String varValue = intent.getStringExtra(CREATE_FUN_EXTRA_STRING);
|
||||||
}
|
if (!StringUtils.isEmpty(varValue)) {
|
||||||
}*/
|
createEditVariableDialog(this, null, null, varValue, null, null);
|
||||||
}
|
|
||||||
|
// in order to stop intent for other tabs
|
||||||
@Override
|
intent.removeExtra(CREATE_FUN_EXTRA_STRING);
|
||||||
protected AMenuItem<Function> getOnClickAction() {
|
}
|
||||||
return LongClickMenuItem.use;
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getTitleResId() {
|
protected AMenuItem<Function> getOnClickAction() {
|
||||||
return R.string.c_functions;
|
return LongClickMenuItem.use;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected List<LabeledMenuItem<Function>> getMenuItemsOnLongClick(@NotNull Function item) {
|
protected List<LabeledMenuItem<Function>> getMenuItemsOnLongClick(@NotNull Function item) {
|
||||||
List<LabeledMenuItem<Function>> result = new ArrayList<LabeledMenuItem<Function>>(Arrays.asList(LongClickMenuItem.values()));
|
List<LabeledMenuItem<Function>> result = new ArrayList<LabeledMenuItem<Function>>(Arrays.asList(LongClickMenuItem.values()));
|
||||||
|
|
||||||
if ( StringUtils.isEmpty(CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().getDescription(item.getName())) ) {
|
if ( StringUtils.isEmpty(CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().getDescription(item.getName())) ) {
|
||||||
result.remove(LongClickMenuItem.copy_description);
|
result.remove(LongClickMenuItem.copy_description);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* private static void createEditVariableDialog(@NotNull final AbstractMathEntityListActivity<Function> activity,
|
/* private static void createEditVariableDialog(@NotNull final AbstractMathEntityListActivity<Function> activity,
|
||||||
@Nullable final CustomFunction function,
|
@Nullable final CustomFunction function,
|
||||||
@Nullable final String name,
|
@Nullable final String name,
|
||||||
@Nullable final String expression,
|
@Nullable final String expression,
|
||||||
@Nullable final String[] parameterNames,
|
@Nullable final String[] parameterNames,
|
||||||
@Nullable final String description) {
|
@Nullable final String description) {
|
||||||
if (function == null || !function.isSystem()) {
|
if (function == null || !function.isSystem()) {
|
||||||
|
|
||||||
final LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(LAYOUT_INFLATER_SERVICE);
|
final LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||||
final View editView = layoutInflater.inflate(R.layout.var_edit, null);
|
final View editView = layoutInflater.inflate(R.layout.var_edit, null);
|
||||||
|
|
||||||
final String errorMsg = activity.getString(R.string.c_char_is_not_accepted);
|
final String errorMsg = activity.getString(R.string.c_char_is_not_accepted);
|
||||||
|
|
||||||
final EditText editName = (EditText) editView.findViewById(R.id.var_edit_name);
|
final EditText editName = (EditText) editView.findViewById(R.id.var_edit_name);
|
||||||
editName.setText(name);
|
editName.setText(name);
|
||||||
editName.addTextChangedListener(new TextWatcher() {
|
editName.addTextChangedListener(new TextWatcher() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
for (int i = 0; i < s.length(); i++) {
|
for (int i = 0; i < s.length(); i++) {
|
||||||
char c = s.charAt(i);
|
char c = s.charAt(i);
|
||||||
if (!acceptableChars.contains(c)) {
|
if (!acceptableChars.contains(c)) {
|
||||||
s.delete(i, i + 1);
|
s.delete(i, i + 1);
|
||||||
Toast.makeText(activity, String.format(errorMsg, c), Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, String.format(errorMsg, c), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final EditText editValue = (EditText) editView.findViewById(R.id.var_edit_value);
|
final EditText editValue = (EditText) editView.findViewById(R.id.var_edit_value);
|
||||||
if (!StringUtils.isEmpty(expression)) {
|
if (!StringUtils.isEmpty(expression)) {
|
||||||
editValue.setText(expression);
|
editValue.setText(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
final EditText editDescription = (EditText) editView.findViewById(R.id.var_edit_description);
|
final EditText editDescription = (EditText) editView.findViewById(R.id.var_edit_description);
|
||||||
editDescription.setText(description);
|
editDescription.setText(description);
|
||||||
|
|
||||||
final CustomFunction.Builder functionBuilder;
|
final CustomFunction.Builder functionBuilder;
|
||||||
if (function != null) {
|
if (function != null) {
|
||||||
functionBuilder = new CustomFunction.Builder(function);
|
functionBuilder = new CustomFunction.Builder(function);
|
||||||
} else {
|
} else {
|
||||||
functionBuilder = new CustomFunction.Builder();
|
functionBuilder = new CustomFunction.Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(activity)
|
final AlertDialog.Builder builder = new AlertDialog.Builder(activity)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setNegativeButton(R.string.c_cancel, null)
|
.setNegativeButton(R.string.c_cancel, null)
|
||||||
.setPositiveButton(R.string.c_save, new FunctionEditorSaver(functionBuilder, function, editView, activity, CalculatorEngine.instance.getFunctionsRegistry(), new FunctionEditorSaver.EditorCreator<Function>() {
|
.setPositiveButton(R.string.c_save, new FunctionEditorSaver(functionBuilder, function, editView, activity, CalculatorEngine.instance.getFunctionsRegistry(), new FunctionEditorSaver.EditorCreator<Function>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showEditor(@NotNull AbstractMathEntityListActivity<Function> activity, @Nullable CustomFunction editedInstance, @Nullable String name, @Nullable String value, @Nullable String[] parameterNames, @Nullable String description) {
|
public void showEditor(@NotNull AbstractMathEntityListActivity<Function> activity, @Nullable CustomFunction editedInstance, @Nullable String name, @Nullable String value, @Nullable String[] parameterNames, @Nullable String description) {
|
||||||
createEditVariableDialog(activity, editedInstance, name, value, parameterNames, description);
|
createEditVariableDialog(activity, editedInstance, name, value, parameterNames, description);
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.setView(editView);
|
.setView(editView);
|
||||||
|
|
||||||
if (function != null) {
|
if (function != null) {
|
||||||
// EDIT mode
|
// EDIT mode
|
||||||
|
|
||||||
builder.setTitle(R.string.c_var_edit_var);
|
builder.setTitle(R.string.c_var_edit_var);
|
||||||
builder.setNeutralButton(R.string.c_remove, new MathEntityRemover<Function>(function, new DialogInterface.OnClickListener() {
|
builder.setNeutralButton(R.string.c_remove, new MathEntityRemover<Function>(function, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
createEditVariableDialog(activity, function, name, expression, parameterNames, description);
|
createEditVariableDialog(activity, function, name, expression, parameterNames, description);
|
||||||
}
|
}
|
||||||
}, CalculatorEngine.instance.getFunctionsRegistry(), activity));
|
}, CalculatorEngine.instance.getFunctionsRegistry(), activity));
|
||||||
} else {
|
} else {
|
||||||
// CREATE mode
|
// CREATE mode
|
||||||
|
|
||||||
builder.setTitle(R.string.c_var_create_var);
|
builder.setTitle(R.string.c_var_create_var);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(activity, activity.getString(R.string.c_sys_var_cannot_be_changed), Toast.LENGTH_LONG).show();
|
Toast.makeText(activity, activity.getString(R.string.c_sys_var_cannot_be_changed), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected MathEntityDescriptionGetter getDescriptionGetter() {
|
protected MathEntityDescriptionGetter getDescriptionGetter() {
|
||||||
return new MathEntityDescriptionGetterImpl(CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry());
|
return new MathEntityDescriptionGetterImpl(CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected List<Function> getMathEntities() {
|
protected List<Function> getMathEntities() {
|
||||||
return new ArrayList<Function>(CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().getEntities());
|
return new ArrayList<Function>(CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().getEntities());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getMathEntityCategory(@NotNull Function function) {
|
protected String getMathEntityCategory(@NotNull Function function) {
|
||||||
return CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().getCategory(function);
|
return CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().getCategory(function);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*
|
*
|
||||||
* STATIC
|
* STATIC
|
||||||
*
|
*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private static enum LongClickMenuItem implements LabeledMenuItem<Function> {
|
private static enum LongClickMenuItem implements LabeledMenuItem<Function> {
|
||||||
use(R.string.c_use) {
|
use(R.string.c_use) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull Function data, @NotNull Context context) {
|
public void onClick(@NotNull Function data, @NotNull Context context) {
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_function, data);
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_function, data);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/*edit(R.string.c_edit) {
|
/*edit(R.string.c_edit) {
|
||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull Function data, @NotNull Context context) {
|
public void doAction(@NotNull Function data, @NotNull Context context) {
|
||||||
if (context instanceof AbstractMathEntityListActivity) {
|
if (context instanceof AbstractMathEntityListActivity) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},*/
|
},*/
|
||||||
|
|
||||||
copy_description(R.string.c_copy_description) {
|
copy_description(R.string.c_copy_description) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull Function data, @NotNull Context context) {
|
public void onClick(@NotNull Function data, @NotNull Context context) {
|
||||||
final String text = CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().getDescription(data.getName());
|
final String text = CalculatorLocatorImpl.getInstance().getEngine().getFunctionsRegistry().getDescription(data.getName());
|
||||||
if (!StringUtils.isEmpty(text)) {
|
if (!StringUtils.isEmpty(text)) {
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
||||||
clipboard.setText(text);
|
clipboard.setText(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private final int captionId;
|
private final int captionId;
|
||||||
|
|
||||||
LongClickMenuItem(int captionId) {
|
LongClickMenuItem(int captionId) {
|
||||||
this.captionId = captionId;
|
this.captionId = captionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getCaption(@NotNull Context context) {
|
public String getCaption(@NotNull Context context) {
|
||||||
return context.getString(captionId);
|
return context.getString(captionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
|
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
||||||
import org.solovyev.android.calculator.model.AndroidFunctionsMathRegistry;
|
|
||||||
import org.solovyev.android.calculator.model.AndroidOperatorsMathRegistry;
|
import org.solovyev.android.calculator.model.AndroidOperatorsMathRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,10 +20,10 @@ import org.solovyev.android.calculator.model.AndroidOperatorsMathRegistry;
|
|||||||
* Date: 12/21/11
|
* Date: 12/21/11
|
||||||
* Time: 10:33 PM
|
* Time: 10:33 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorOperatorsFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
public class CalculatorOperatorsActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
|
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
@ -1,133 +1,133 @@
|
|||||||
package org.solovyev.android.calculator.math.edit;
|
package org.solovyev.android.calculator.math.edit;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.ClipboardManager;
|
import android.text.ClipboardManager;
|
||||||
import jscl.math.operator.Operator;
|
import jscl.math.operator.Operator;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.solovyev.android.calculator.CalculatorEventType;
|
import org.solovyev.android.calculator.CalculatorEventType;
|
||||||
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.menu.AMenuItem;
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.menu.LabeledMenuItem;
|
import org.solovyev.android.menu.AMenuItem;
|
||||||
import org.solovyev.common.text.StringUtils;
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
|
import org.solovyev.common.text.StringUtils;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
/**
|
|
||||||
* User: serso
|
/**
|
||||||
* Date: 11/17/11
|
* User: serso
|
||||||
* Time: 1:53 PM
|
* Date: 11/17/11
|
||||||
*/
|
* Time: 1:53 PM
|
||||||
|
*/
|
||||||
public class CalculatorOperatorsFragment extends AbstractMathEntityListFragment<Operator> {
|
|
||||||
|
public class CalculatorOperatorsFragment extends AbstractMathEntityListFragment<Operator> {
|
||||||
@Override
|
|
||||||
protected AMenuItem<Operator> getOnClickAction() {
|
public CalculatorOperatorsFragment() {
|
||||||
return LongClickMenuItem.use;
|
super(CalculatorFragmentType.operators);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getTitleResId() {
|
protected AMenuItem<Operator> getOnClickAction() {
|
||||||
return R.string.c_operators;
|
return LongClickMenuItem.use;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected List<LabeledMenuItem<Operator>> getMenuItemsOnLongClick(@NotNull Operator item) {
|
protected List<LabeledMenuItem<Operator>> getMenuItemsOnLongClick(@NotNull Operator item) {
|
||||||
final List<LabeledMenuItem<Operator>> result = new ArrayList<LabeledMenuItem<Operator>>(Arrays.asList(LongClickMenuItem.values()));
|
final List<LabeledMenuItem<Operator>> result = new ArrayList<LabeledMenuItem<Operator>>(Arrays.asList(LongClickMenuItem.values()));
|
||||||
|
|
||||||
if ( StringUtils.isEmpty(OperatorDescriptionGetter.instance.getDescription(this.getActivity(), item.getName())) ) {
|
if ( StringUtils.isEmpty(OperatorDescriptionGetter.instance.getDescription(this.getActivity(), item.getName())) ) {
|
||||||
result.remove(LongClickMenuItem.copy_description);
|
result.remove(LongClickMenuItem.copy_description);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected MathEntityDescriptionGetter getDescriptionGetter() {
|
protected MathEntityDescriptionGetter getDescriptionGetter() {
|
||||||
return OperatorDescriptionGetter.instance;
|
return OperatorDescriptionGetter.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected List<Operator> getMathEntities() {
|
protected List<Operator> getMathEntities() {
|
||||||
final List<Operator> result = new ArrayList<Operator>();
|
final List<Operator> result = new ArrayList<Operator>();
|
||||||
|
|
||||||
result.addAll(CalculatorLocatorImpl.getInstance().getEngine().getOperatorsRegistry().getEntities());
|
result.addAll(CalculatorLocatorImpl.getInstance().getEngine().getOperatorsRegistry().getEntities());
|
||||||
result.addAll(CalculatorLocatorImpl.getInstance().getEngine().getPostfixFunctionsRegistry().getEntities());
|
result.addAll(CalculatorLocatorImpl.getInstance().getEngine().getPostfixFunctionsRegistry().getEntities());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getMathEntityCategory(@NotNull Operator operator) {
|
protected String getMathEntityCategory(@NotNull Operator operator) {
|
||||||
String result = CalculatorLocatorImpl.getInstance().getEngine().getOperatorsRegistry().getCategory(operator);
|
String result = CalculatorLocatorImpl.getInstance().getEngine().getOperatorsRegistry().getCategory(operator);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result = CalculatorLocatorImpl.getInstance().getEngine().getPostfixFunctionsRegistry().getCategory(operator);
|
result = CalculatorLocatorImpl.getInstance().getEngine().getPostfixFunctionsRegistry().getCategory(operator);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static enum OperatorDescriptionGetter implements MathEntityDescriptionGetter {
|
private static enum OperatorDescriptionGetter implements MathEntityDescriptionGetter {
|
||||||
|
|
||||||
instance;
|
instance;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription(@NotNull Context context, @NotNull String mathEntityName) {
|
public String getDescription(@NotNull Context context, @NotNull String mathEntityName) {
|
||||||
String result = CalculatorLocatorImpl.getInstance().getEngine().getOperatorsRegistry().getDescription(mathEntityName);
|
String result = CalculatorLocatorImpl.getInstance().getEngine().getOperatorsRegistry().getDescription(mathEntityName);
|
||||||
if (StringUtils.isEmpty(result)) {
|
if (StringUtils.isEmpty(result)) {
|
||||||
result = CalculatorLocatorImpl.getInstance().getEngine().getPostfixFunctionsRegistry().getDescription(mathEntityName);
|
result = CalculatorLocatorImpl.getInstance().getEngine().getPostfixFunctionsRegistry().getDescription(mathEntityName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*
|
*
|
||||||
* STATIC
|
* STATIC
|
||||||
*
|
*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private static enum LongClickMenuItem implements LabeledMenuItem<Operator> {
|
private static enum LongClickMenuItem implements LabeledMenuItem<Operator> {
|
||||||
|
|
||||||
use(R.string.c_use) {
|
use(R.string.c_use) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull Operator data, @NotNull Context context) {
|
public void onClick(@NotNull Operator data, @NotNull Context context) {
|
||||||
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_operator, data);
|
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_operator, data);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
copy_description(R.string.c_copy_description) {
|
copy_description(R.string.c_copy_description) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull Operator data, @NotNull Context context) {
|
public void onClick(@NotNull Operator data, @NotNull Context context) {
|
||||||
final String text = OperatorDescriptionGetter.instance.getDescription(context, data.getName());
|
final String text = OperatorDescriptionGetter.instance.getDescription(context, data.getName());
|
||||||
if (!StringUtils.isEmpty(text)) {
|
if (!StringUtils.isEmpty(text)) {
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
||||||
clipboard.setText(text);
|
clipboard.setText(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private final int captionId;
|
private final int captionId;
|
||||||
|
|
||||||
LongClickMenuItem(int captionId) {
|
LongClickMenuItem(int captionId) {
|
||||||
this.captionId = captionId;
|
this.captionId = captionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getCaption(@NotNull Context context) {
|
public String getCaption(@NotNull Context context) {
|
||||||
return context.getString(captionId);
|
return context.getString(captionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragmentActivity;
|
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
|
||||||
import org.solovyev.android.calculator.model.VarCategory;
|
import org.solovyev.android.calculator.model.VarCategory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,10 +21,10 @@ import org.solovyev.android.calculator.model.VarCategory;
|
|||||||
* Date: 12/21/11
|
* Date: 12/21/11
|
||||||
* Time: 11:05 PM
|
* Time: 11:05 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorVarsFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
public class CalculatorVarsActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
|
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryActivity.class.getSimpleName());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
@ -16,8 +16,8 @@ import com.actionbarsherlock.view.MenuItem;
|
|||||||
import jscl.math.function.IConstant;
|
import jscl.math.function.IConstant;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.AndroidUtils2;
|
|
||||||
import org.solovyev.android.calculator.*;
|
import org.solovyev.android.calculator.*;
|
||||||
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.math.MathType;
|
import org.solovyev.android.calculator.math.MathType;
|
||||||
import org.solovyev.android.menu.AMenuItem;
|
import org.solovyev.android.menu.AMenuItem;
|
||||||
import org.solovyev.android.menu.LabeledMenuItem;
|
import org.solovyev.android.menu.LabeledMenuItem;
|
||||||
@ -38,9 +38,8 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
|
|||||||
|
|
||||||
public static final String CREATE_VAR_EXTRA_STRING = "create_var";
|
public static final String CREATE_VAR_EXTRA_STRING = "create_var";
|
||||||
|
|
||||||
@Override
|
public CalculatorVarsFragment() {
|
||||||
protected int getLayoutId() {
|
super(CalculatorFragmentType.variables);
|
||||||
return R.layout.vars_fragment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,11 +60,6 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
|
|||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getTitleResId() {
|
|
||||||
return R.string.c_vars;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AMenuItem<IConstant> getOnClickAction() {
|
protected AMenuItem<IConstant> getOnClickAction() {
|
||||||
return LongClickMenuItem.use;
|
return LongClickMenuItem.use;
|
||||||
|
@ -2,11 +2,8 @@ package org.solovyev.android.calculator.plot;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.CalculatorActivityHelper;
|
import org.solovyev.android.calculator.CalculatorFragmentActivity;
|
||||||
import org.solovyev.android.calculator.CalculatorApplication;
|
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
||||||
|
|
||||||
@ -15,17 +12,12 @@ import org.solovyev.android.calculator.about.CalculatorFragmentType;
|
|||||||
* Date: 9/30/12
|
* Date: 9/30/12
|
||||||
* Time: 4:56 PM
|
* Time: 4:56 PM
|
||||||
*/
|
*/
|
||||||
public class CalculatorPlotActivity extends SherlockFragmentActivity {
|
public class CalculatorPlotActivity extends CalculatorFragmentActivity {
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorPlotActivity.class.getSimpleName());
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
activityHelper.onCreate(this, savedInstanceState);
|
|
||||||
|
|
||||||
final Intent intent = getIntent();
|
final Intent intent = getIntent();
|
||||||
|
|
||||||
final Bundle arguments;
|
final Bundle arguments;
|
||||||
@ -35,37 +27,6 @@ public class CalculatorPlotActivity extends SherlockFragmentActivity {
|
|||||||
arguments = null;
|
arguments = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
activityHelper.addTab(this, CalculatorFragmentType.plotter, arguments, R.id.main_layout);
|
getActivityHelper().addTab(this, CalculatorFragmentType.plotter, arguments, R.id.main_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
|
|
||||||
activityHelper.onSaveInstanceState(this, outState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
|
|
||||||
activityHelper.onResume(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
this.activityHelper.onPause(this);
|
|
||||||
|
|
||||||
super.onPause();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
|
|
||||||
activityHelper.onDestroy(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user