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