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

@ -43,7 +43,7 @@
<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"/>

View File

@ -16,7 +16,7 @@ android.library.reference.4=gen-external-apklibs/org.solovyev.android_android-co
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

@ -11,19 +11,12 @@
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:layout_height="fill_parent"> a:layout_height="fill_parent">
<LinearLayout
a:orientation="horizontal"
a:layout_width="fill_parent"
a:layout_height="fill_parent">
<TextView a:id="@+id/math_entity_text" <TextView a:id="@+id/math_entity_text"
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"> style="@style/math_entity_text">
</TextView> </TextView>
</LinearLayout>
<TextView a:id="@+id/math_entity_description" <TextView a:id="@+id/math_entity_description"
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:layout_height="fill_parent" a:layout_height="fill_parent"

View File

@ -19,12 +19,4 @@
<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

@ -7,18 +7,10 @@
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.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.text.ClipboardManager; import android.text.ClipboardManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
@ -29,7 +21,6 @@ import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorLocatorImpl; import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.calculator.math.MathType;
import org.solovyev.android.calculator.model.Var;
import org.solovyev.android.menu.AMenuItem; import org.solovyev.android.menu.AMenuItem;
import org.solovyev.android.menu.LabeledMenuItem; import org.solovyev.android.menu.LabeledMenuItem;
import org.solovyev.common.JPredicate; import org.solovyev.common.JPredicate;
@ -62,7 +53,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
if (bundle != null) { if (bundle != null) {
final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING); final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING);
if (!StringUtils.isEmpty(varValue)) { if (!StringUtils.isEmpty(varValue)) {
createEditVariableDialog(this, null, null, varValue, null); VarEditDialogFragment.createEditVariableDialog(this, VarEditDialogFragment.Input.newFromValue(varValue));
// in order to stop intent for other tabs // in order to stop intent for other tabs
bundle.remove(CREATE_VAR_EXTRA_STRING); bundle.remove(CREATE_VAR_EXTRA_STRING);
@ -111,7 +102,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
public void addVarButtonClickHandler(@NotNull View v) { public void addVarButtonClickHandler(@NotNull View v) {
createEditVariableDialog(this, null, null, null, null); VarEditDialogFragment.createEditVariableDialog(this, VarEditDialogFragment.Input.newInstance());
} }
@NotNull @NotNull
@ -134,92 +125,6 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
return CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getCategory(var); return CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().getCategory(var);
} }
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) {
final FragmentActivity activity = fragment.getActivity();
if (var == null || !var.isSystem()) {
final LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final View editView = layoutInflater.inflate(R.layout.var_edit, null);
final String errorMsg = fragment.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(value)) {
editValue.setText(value);
}
final EditText editDescription = (EditText) editView.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, 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);
}
}))
.setView(editView);
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, 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();
}
}
public static boolean isValidValue(@NotNull String value) { public static boolean isValidValue(@NotNull String value) {
// now every string might be constant // now every string might be constant
return true; return true;
@ -244,7 +149,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.var_menu_add_var: case R.id.var_menu_add_var:
createEditVariableDialog(this, null, null, null, null); VarEditDialogFragment.createEditVariableDialog(this, VarEditDialogFragment.Input.newInstance());
result = true; result = true;
break; break;
default: default:

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>