This commit is contained in:
serso 2012-10-01 18:30:24 +04:00
parent f8e1d45526
commit fb42a3ebe9
8 changed files with 636 additions and 485 deletions

View File

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

View File

@ -1,22 +1,22 @@
# This file is automatically generated by Android Tools. # This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED! # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
# #
# This file must be checked in Version Control Systems. # This file must be checked in Version Control Systems.
# #
# To customize properties used by the Ant build system use, # To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your # "ant.properties", and override values to adapt the script to your
# project structure. # project structure.
# Project target. # Project target.
target=android-15 target=android-15
android.library.reference.1=gen-external-apklibs/org.solovyev.android_android-common-core_1.0.0 android.library.reference.1=gen-external-apklibs/org.solovyev.android_android-common-core_1.0.0
android.library.reference.2=gen-external-apklibs/org.solovyev.android_android-common-ads_1.0.0 android.library.reference.2=gen-external-apklibs/org.solovyev.android_android-common-ads_1.0.0
android.library.reference.3=gen-external-apklibs/org.solovyev.android_android-common-view_1.0.0 android.library.reference.3=gen-external-apklibs/org.solovyev.android_android-common-view_1.0.0
android.library.reference.4=gen-external-apklibs/org.solovyev.android_android-common-preferences_1.0.0 android.library.reference.4=gen-external-apklibs/org.solovyev.android_android-common-preferences_1.0.0
android.library.reference.5=gen-external-apklibs/org.solovyev.android_android-common-other_1.0.0 android.library.reference.5=gen-external-apklibs/org.solovyev.android_android-common-other_1.0.0
android.library.reference.6=gen-external-apklibs/org.solovyev.android_android-common-menu_1.0.0 android.library.reference.6=gen-external-apklibs/org.solovyev.android_android-common-menu_1.0.0
android.library.reference.7=gen-external-apklibs/org.solovyev.android_android-common-sherlock_1.0.0 android.library.reference.7=gen-external-apklibs/org.solovyev.android_android-common-sherlock_1.0.0
android.library.reference.8=gen-external-apklibs/com.actionbarsherlock_library_4.0.2 android.library.reference.8=gen-external-apklibs/com.actionbarsherlock_library_4.1.0
android.library.reference.9=gen-external-apklibs/org.solovyev.android_android-common-list_1.0.0 android.library.reference.9=gen-external-apklibs/org.solovyev.android_android-common-list_1.0.0

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/main_fragment_layout"
style="?fragmentLayoutStyle"
a:layout_width="match_parent"
a:layout_height="match_parent">
<TextView a:id="@+id/fragmentTitle"
a:layout_height="wrap_content"
a:layout_width="match_parent"
style="?fragmentTitleStyle"/>
<ListView style="?fragmentListViewStyle"/>
</LinearLayout>

View File

@ -1,33 +1,26 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev. ~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com ~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org ~ or visit http://se.solovyev.org
--> -->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical" a:orientation="vertical"
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:layout_height="fill_parent"> a:layout_height="fill_parent">
<LinearLayout <TextView a:id="@+id/math_entity_text"
a:orientation="horizontal" a:layout_width="fill_parent"
a:layout_width="fill_parent" a:layout_height="fill_parent"
a:layout_height="fill_parent"> style="@style/math_entity_text">
</TextView>
<TextView a:id="@+id/math_entity_text"
a:layout_width="fill_parent" <TextView a:id="@+id/math_entity_description"
a:layout_height="fill_parent" a:layout_width="fill_parent"
style="@style/math_entity_text"> a:layout_height="fill_parent"
</TextView> style="@style/math_entity_description">
</TextView>
</LinearLayout>
<TextView a:id="@+id/math_entity_description"
a:layout_width="fill_parent"
a:layout_height="fill_parent"
style="@style/math_entity_description">
</TextView>
</LinearLayout> </LinearLayout>

View File

@ -1,30 +1,22 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev. ~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com ~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org ~ or visit http://se.solovyev.org
--> -->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/main_fragment_layout" a:id="@+id/main_fragment_layout"
style="?fragmentLayoutStyle" style="?fragmentLayoutStyle"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="match_parent"> a:layout_height="match_parent">
<TextView a:id="@+id/fragmentTitle" <TextView a:id="@+id/fragmentTitle"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_width="match_parent" a:layout_width="match_parent"
style="?fragmentTitleStyle"/> style="?fragmentTitleStyle"/>
<ListView style="?fragmentListViewStyle"/> <ListView style="?fragmentListViewStyle"/>
<!--todo serso: uncomment-->
<!--<Button
a:id="@+id/add_var_button"
a:text="@string/c_add"
style="?buttonStyle"
a:onClick="addVarButtonClickHandler"
a:layout_marginBottom="@dimen/pane_padding"/>-->
</LinearLayout> </LinearLayout>

View File

@ -1,324 +1,229 @@
/* /*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev. * Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com * For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org * or visit http://se.solovyev.org
*/ */
package org.solovyev.android.calculator.math.edit; package org.solovyev.android.calculator.math.edit;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.content.Context;
import android.content.Context; import android.os.Bundle;
import android.content.DialogInterface; import android.text.ClipboardManager;
import android.os.Bundle; import android.view.View;
import android.support.v4.app.FragmentActivity; import com.actionbarsherlock.view.Menu;
import android.text.ClipboardManager; import com.actionbarsherlock.view.MenuInflater;
import android.text.Editable; import com.actionbarsherlock.view.MenuItem;
import android.text.TextWatcher; import jscl.math.function.IConstant;
import android.view.LayoutInflater; import org.jetbrains.annotations.NotNull;
import android.view.View; import org.jetbrains.annotations.Nullable;
import android.widget.EditText; import org.solovyev.android.calculator.CalculatorEventType;
import android.widget.Toast; import org.solovyev.android.calculator.CalculatorLocatorImpl;
import com.actionbarsherlock.view.Menu; import org.solovyev.android.calculator.R;
import com.actionbarsherlock.view.MenuInflater; import org.solovyev.android.calculator.math.MathType;
import com.actionbarsherlock.view.MenuItem; import org.solovyev.android.menu.AMenuItem;
import jscl.math.function.IConstant; import org.solovyev.android.menu.LabeledMenuItem;
import org.jetbrains.annotations.NotNull; import org.solovyev.common.JPredicate;
import org.jetbrains.annotations.Nullable; import org.solovyev.common.collections.CollectionsUtils;
import org.solovyev.android.calculator.CalculatorEventType; import org.solovyev.common.text.StringUtils;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.R; import java.util.ArrayList;
import org.solovyev.android.calculator.math.MathType; import java.util.Arrays;
import org.solovyev.android.calculator.model.Var; import java.util.List;
import org.solovyev.android.menu.AMenuItem;
import org.solovyev.android.menu.LabeledMenuItem; /**
import org.solovyev.common.JPredicate; * User: serso
import org.solovyev.common.collections.CollectionsUtils; * Date: 9/28/11
import org.solovyev.common.text.StringUtils; * Time: 10:55 PM
*/
import java.util.ArrayList; public class CalculatorVarsFragment extends AbstractMathEntityListFragment<IConstant> {
import java.util.Arrays;
import java.util.List; public static final String CREATE_VAR_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorVarsTabActivity_create_var";
/** @Override
* User: serso protected int getLayoutId() {
* Date: 9/28/11 return R.layout.vars_fragment;
* Time: 10:55 PM }
*/
public class CalculatorVarsFragment extends AbstractMathEntityListFragment<IConstant> { @Override
public void onCreate(Bundle savedInstanceState) {
public static final String CREATE_VAR_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorVarsTabActivity_create_var"; super.onCreate(savedInstanceState);
@Override final Bundle bundle = getArguments();
protected int getLayoutId() { if (bundle != null) {
return R.layout.vars_fragment; final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING);
} if (!StringUtils.isEmpty(varValue)) {
VarEditDialogFragment.createEditVariableDialog(this, VarEditDialogFragment.Input.newFromValue(varValue));
@Override
public void onCreate(Bundle savedInstanceState) { // in order to stop intent for other tabs
super.onCreate(savedInstanceState); bundle.remove(CREATE_VAR_EXTRA_STRING);
}
final Bundle bundle = getArguments(); }
if (bundle != null) {
final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING); setHasOptionsMenu(true);
if (!StringUtils.isEmpty(varValue)) { }
createEditVariableDialog(this, null, null, varValue, null);
@Override
// in order to stop intent for other tabs protected int getTitleResId() {
bundle.remove(CREATE_VAR_EXTRA_STRING); return R.string.c_vars;
} }
}
@Override
setHasOptionsMenu(true); protected AMenuItem<IConstant> getOnClickAction() {
} return LongClickMenuItem.use;
}
@Override
protected int getTitleResId() { @NotNull
return R.string.c_vars; @Override
} protected List<LabeledMenuItem<IConstant>> getMenuItemsOnLongClick(@NotNull IConstant item) {
final List<LabeledMenuItem<IConstant>> result = new ArrayList<LabeledMenuItem<IConstant>>(Arrays.asList(LongClickMenuItem.values()));
@Override
protected AMenuItem<IConstant> getOnClickAction() { if ( item.isSystem() ) {
return LongClickMenuItem.use; result.remove(LongClickMenuItem.edit);
} result.remove(LongClickMenuItem.remove);
}
@NotNull
@Override if ( StringUtils.isEmpty(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getDescription(item.getName())) ) {
protected List<LabeledMenuItem<IConstant>> getMenuItemsOnLongClick(@NotNull IConstant item) { result.remove(LongClickMenuItem.copy_description);
final List<LabeledMenuItem<IConstant>> result = new ArrayList<LabeledMenuItem<IConstant>>(Arrays.asList(LongClickMenuItem.values())); }
if ( item.isSystem() ) { if ( StringUtils.isEmpty(item.getValue()) ) {
result.remove(LongClickMenuItem.edit); result.remove(LongClickMenuItem.copy_value);
result.remove(LongClickMenuItem.remove); }
}
return result;
if ( StringUtils.isEmpty(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getDescription(item.getName())) ) { }
result.remove(LongClickMenuItem.copy_description);
} @NotNull
@Override
if ( StringUtils.isEmpty(item.getValue()) ) { protected MathEntityDescriptionGetter getDescriptionGetter() {
result.remove(LongClickMenuItem.copy_value); return new MathEntityDescriptionGetterImpl(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry());
} }
return result; @SuppressWarnings({"UnusedDeclaration"})
} public void addVarButtonClickHandler(@NotNull View v) {
VarEditDialogFragment.createEditVariableDialog(this, VarEditDialogFragment.Input.newInstance());
@NotNull }
@Override
protected MathEntityDescriptionGetter getDescriptionGetter() { @NotNull
return new MathEntityDescriptionGetterImpl(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry()); @Override
} protected List<IConstant> getMathEntities() {
final List<IConstant> result = new ArrayList<IConstant>(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getEntities());
@SuppressWarnings({"UnusedDeclaration"})
public void addVarButtonClickHandler(@NotNull View v) { CollectionsUtils.removeAll(result, new JPredicate<IConstant>() {
createEditVariableDialog(this, null, null, null, null); @Override
} public boolean apply(@Nullable IConstant var) {
return var != null && CollectionsUtils.contains(var.getName(), MathType.INFINITY_JSCL, MathType.NAN);
@NotNull }
@Override });
protected List<IConstant> getMathEntities() {
final List<IConstant> result = new ArrayList<IConstant>(CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getEntities()); return result;
}
CollectionsUtils.removeAll(result, new JPredicate<IConstant>() {
@Override @Override
public boolean apply(@Nullable IConstant var) { protected String getMathEntityCategory(@NotNull IConstant var) {
return var != null && CollectionsUtils.contains(var.getName(), MathType.INFINITY_JSCL, MathType.NAN); return CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getCategory(var);
} }
});
public static boolean isValidValue(@NotNull String value) {
return result; // now every string might be constant
} return true;
}
@Override
protected String getMathEntityCategory(@NotNull IConstant var) { /*
return CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getCategory(var); **********************************************************************
} *
* MENU
private static void createEditVariableDialog(@NotNull final AbstractMathEntityListFragment<IConstant> fragment, *
@Nullable final IConstant var, **********************************************************************
@Nullable final String name, */
@Nullable final String value,
@Nullable final String description) { @Override
final FragmentActivity activity = fragment.getActivity(); public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.var_menu, menu);
if (var == null || !var.isSystem()) { }
final LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); @Override
final View editView = layoutInflater.inflate(R.layout.var_edit, null); public boolean onOptionsItemSelected(MenuItem item) {
boolean result;
final String errorMsg = fragment.getString(R.string.c_char_is_not_accepted);
switch (item.getItemId()) {
final EditText editName = (EditText) editView.findViewById(R.id.var_edit_name); case R.id.var_menu_add_var:
editName.setText(name); VarEditDialogFragment.createEditVariableDialog(this, VarEditDialogFragment.Input.newInstance());
editName.addTextChangedListener(new TextWatcher() { result = true;
break;
@Override default:
public void beforeTextChanged(CharSequence s, int start, int count, int after) { result = super.onOptionsItemSelected(item);
} }
@Override return result;
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++) { * STATIC
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();
} private static enum LongClickMenuItem implements LabeledMenuItem<IConstant>{
} use(R.string.c_use) {
} @Override
}); public void onClick(@NotNull IConstant data, @NotNull Context context) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_constant, data);
final EditText editValue = (EditText) editView.findViewById(R.id.var_edit_value); }
if (!StringUtils.isEmpty(value)) { },
editValue.setText(value);
} edit(R.string.c_edit) {
@Override
final EditText editDescription = (EditText) editView.findViewById(R.id.var_edit_description); public void onClick(@NotNull IConstant data, @NotNull Context context) {
editDescription.setText(description); /*if (context instanceof AbstractMathEntityListFragment) {
createEditVariableDialog((AbstractMathEntityListFragment<IConstant>)context, data, data.getName(), StringUtils.getNotEmpty(data.getValue(), ""), data.getDescription());
final Var.Builder varBuilder; }*/
if (var != null) { }
varBuilder = new Var.Builder(var); },
} else {
varBuilder = new Var.Builder(); remove(R.string.c_remove) {
} @Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity) /*if (context instanceof AbstractMathEntityListFragment) {
.setCancelable(true) new MathEntityRemover<IConstant>(data, null, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), ((AbstractMathEntityListFragment<IConstant>) context)).showConfirmationDialog();
.setNegativeButton(R.string.c_cancel, null) }*/
.setPositiveButton(R.string.c_save, new VarEditorSaver<IConstant>(varBuilder, var, editView, fragment, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), new VarEditorSaver.EditorCreator<IConstant>() { }
@Override },
public void showEditor(@NotNull AbstractMathEntityListFragment<IConstant> activity, @Nullable IConstant editedInstance, @Nullable String name, @Nullable String value, @Nullable String description) {
createEditVariableDialog(activity, editedInstance, name, value, description); copy_value(R.string.c_copy_value) {
} @Override
})) public void onClick(@NotNull IConstant data, @NotNull Context context) {
.setView(editView); final String text = data.getValue();
if (!StringUtils.isEmpty(text)) {
if (var != null) { final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
// EDIT mode clipboard.setText(text);
}
builder.setTitle(R.string.c_var_edit_var); }
builder.setNeutralButton(R.string.c_remove, new MathEntityRemover<IConstant>(var, new DialogInterface.OnClickListener() { },
@Override
public void onClick(DialogInterface dialog, int which) { copy_description(R.string.c_copy_description) {
createEditVariableDialog(fragment, var, name, value, description); @Override
} public void onClick(@NotNull IConstant data, @NotNull Context context) {
}, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), fragment)); final String text = CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getDescription(data.getName());
} else { if (!StringUtils.isEmpty(text)) {
// CREATE mode final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
clipboard.setText(text);
builder.setTitle(R.string.c_var_create_var); }
} }
};
builder.create().show(); private final int captionId;
} else {
Toast.makeText(activity, fragment.getString(R.string.c_sys_var_cannot_be_changed), Toast.LENGTH_LONG).show(); LongClickMenuItem(int captionId) {
} this.captionId = captionId;
} }
public static boolean isValidValue(@NotNull String value) { @NotNull
// now every string might be constant @Override
return true; public String getCaption(@NotNull Context context) {
} return context.getString(captionId);
}
/* }
********************************************************************** }
*
* MENU
*
**********************************************************************
*/
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.var_menu, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
boolean result;
switch (item.getItemId()) {
case R.id.var_menu_add_var:
createEditVariableDialog(this, null, null, null, null);
result = true;
break;
default:
result = super.onOptionsItemSelected(item);
}
return result;
}
/*
**********************************************************************
*
* STATIC
*
**********************************************************************
*/
private static enum LongClickMenuItem implements LabeledMenuItem<IConstant>{
use(R.string.c_use) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_constant, data);
}
},
edit(R.string.c_edit) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
/*if (context instanceof AbstractMathEntityListFragment) {
createEditVariableDialog((AbstractMathEntityListFragment<IConstant>)context, data, data.getName(), StringUtils.getNotEmpty(data.getValue(), ""), data.getDescription());
}*/
}
},
remove(R.string.c_remove) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
/*if (context instanceof AbstractMathEntityListFragment) {
new MathEntityRemover<IConstant>(data, null, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), ((AbstractMathEntityListFragment<IConstant>) context)).showConfirmationDialog();
}*/
}
},
copy_value(R.string.c_copy_value) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
final String text = data.getValue();
if (!StringUtils.isEmpty(text)) {
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
clipboard.setText(text);
}
}
},
copy_description(R.string.c_copy_description) {
@Override
public void onClick(@NotNull IConstant data, @NotNull Context context) {
final String text = CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().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);
}
}
}

View File

@ -0,0 +1,277 @@
package org.solovyev.android.calculator.math.edit;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.*;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;
import jscl.math.function.IConstant;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.model.Var;
import org.solovyev.common.text.StringUtils;
/**
* User: Solovyev_S
* Date: 01.10.12
* Time: 17:41
*/
public class VarEditDialogFragment extends DialogFragment {
@NotNull
private final Input input;
public VarEditDialogFragment() {
this(Input.newInstance());
}
public VarEditDialogFragment(@NotNull Input input) {
this.input = input;
}
public static void createEditVariableDialog(@NotNull final AbstractMathEntityListFragment<IConstant> fragment,
@NotNull Input input) {
final FragmentManager fm = fragment.getActivity().getSupportFragmentManager();
final FragmentTransaction ft = fm.beginTransaction();
Fragment prev = fm.findFragmentByTag("constant-editor");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
// Create and show the dialog.
final DialogFragment newFragment = new VarEditDialogFragment(input);
newFragment.show(ft, "constant-editor");
}
public static void createEditVariableDialog0(@NotNull final AbstractMathEntityListFragment<IConstant> fragment,
@Nullable final IConstant var,
@Nullable final String name,
@Nullable final String value,
@Nullable final String description) {
final FragmentActivity activity = fragment.getActivity();
if (var == null || !var.isSystem()) {
final LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final View result = layoutInflater.inflate(R.layout.var_edit, null);
final String errorMsg = fragment.getString(R.string.c_char_is_not_accepted);
final EditText editName = (EditText) result.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 (!AbstractMathEntityListFragment.acceptableChars.contains(c)) {
s.delete(i, i + 1);
Toast.makeText(activity, String.format(errorMsg, c), Toast.LENGTH_SHORT).show();
}
}
}
});
final EditText editValue = (EditText) result.findViewById(R.id.var_edit_value);
if (!StringUtils.isEmpty(value)) {
editValue.setText(value);
}
final EditText editDescription = (EditText) result.findViewById(R.id.var_edit_description);
editDescription.setText(description);
final Var.Builder varBuilder;
if (var != null) {
varBuilder = new Var.Builder(var);
} else {
varBuilder = new Var.Builder();
}
final AlertDialog.Builder builder = new AlertDialog.Builder(activity)
.setCancelable(true)
.setNegativeButton(R.string.c_cancel, null)
.setPositiveButton(R.string.c_save, new VarEditorSaver<IConstant>(varBuilder, var, result, fragment, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), new VarEditorSaver.EditorCreator<IConstant>() {
@Override
public void showEditor(@NotNull AbstractMathEntityListFragment<IConstant> activity, @Nullable IConstant editedInstance, @Nullable String name, @Nullable String value, @Nullable String description) {
createEditVariableDialog(activity, Input.newInstance(editedInstance, name, value, description));
}
}))
.setView(result);
if (var != null) {
// EDIT mode
builder.setTitle(R.string.c_var_edit_var);
builder.setNeutralButton(R.string.c_remove, new MathEntityRemover<IConstant>(var, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
createEditVariableDialog(fragment, Input.newInstance(var, name, value, description));
}
}, CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry(), fragment));
} else {
// CREATE mode
builder.setTitle(R.string.c_var_create_var);
}
builder.create().show();
} else {
Toast.makeText(activity, fragment.getString(R.string.c_sys_var_cannot_be_changed), Toast.LENGTH_LONG).show();
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View result = inflater.inflate(R.layout.var_edit, container, false);
return result;
}
@Override
public void onViewCreated(@NotNull View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
final String errorMsg = this.getString(R.string.c_char_is_not_accepted);
final EditText editName = (EditText) root.findViewById(R.id.var_edit_name);
editName.setText(input.getName());
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 (!AbstractMathEntityListFragment.acceptableChars.contains(c)) {
s.delete(i, i + 1);
Toast.makeText(getActivity(), String.format(errorMsg, c), Toast.LENGTH_SHORT).show();
}
}
}
});
final EditText editValue = (EditText) root.findViewById(R.id.var_edit_value);
editValue.setText(input.getValue());
final EditText editDescription = (EditText) root.findViewById(R.id.var_edit_description);
editDescription.setText(input.getDescription());
final Var.Builder varBuilder;
final IConstant constant = input.getConstant();
if (constant != null) {
varBuilder = new Var.Builder(constant);
} else {
varBuilder = new Var.Builder();
}
if ( constant == null ) {
// CREATE MODE
getDialog().setTitle(R.string.c_var_create_var);
} else {
// EDIT MODE
getDialog().setTitle(R.string.c_var_edit_var);
}
}
public static class Input {
@Nullable
private IConstant constant;
@Nullable
private String name;
@Nullable
private String value;
@Nullable
private String description;
private Input() {
}
@NotNull
public static Input newInstance() {
return new Input();
}
@NotNull
public static Input newFromConstant(@NotNull IConstant constant) {
final Input result = new Input();
result.constant = constant;
return result;
}
@NotNull
public static Input newFromValue(@Nullable String value) {
final Input result = new Input();
result.value = value;
return result;
}
@NotNull
public static Input newInstance(@Nullable IConstant constant, @Nullable String name, @Nullable String value, @Nullable String description) {
final Input result = new Input();
result.constant = constant;
result.name = name;
result.value = value;
result.description = description;
return result;
}
@Nullable
public IConstant getConstant() {
return constant;
}
@Nullable
public String getName() {
return name == null ? (constant == null ? null : constant.getName()) : name;
}
@Nullable
public String getValue() {
return value == null ? (constant == null ? null : constant.getValue()) : value;
}
@Nullable
public String getDescription() {
return description == null ? (constant == null ? null : constant.getDescription()) : description;
}
}
}

View File

@ -81,7 +81,7 @@
<dependency> <dependency>
<groupId>com.actionbarsherlock</groupId> <groupId>com.actionbarsherlock</groupId>
<artifactId>library</artifactId> <artifactId>library</artifactId>
<version>4.0.2</version> <version>4.1.0</version>
<type>apklib</type> <type>apklib</type>
</dependency> </dependency>