var activity
This commit is contained in:
parent
f6c20191d7
commit
7fa8eb6f66
@ -19,7 +19,9 @@
|
||||
|
||||
<activity a:name=".CalculatorPreferencesActivity" a:label="@string/c_app_settings"/>
|
||||
<activity a:name=".AboutActivity" a:label="@string/c_about"/>
|
||||
<activity a:name=".CalculatorVarsActivity" a:label="@string/c_vars_and_constants"/>
|
||||
<activity a:name=".CalculatorVarsActivity"
|
||||
a:label="@string/c_vars_and_constants"
|
||||
a:configChanges="orientation|keyboardHidden" />
|
||||
|
||||
</application>
|
||||
</manifest>
|
@ -6,41 +6,52 @@
|
||||
~ or visit http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:id="@+id/var_edit"
|
||||
a:orientation="vertical"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent">
|
||||
<ScrollView xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent">
|
||||
|
||||
<TextView a:layout_height="match_parent"
|
||||
a:layout_width="wrap_content"
|
||||
a:text="Name"/>
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:id="@+id/var_edit"
|
||||
a:orientation="vertical"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:scrollbars="vertical"
|
||||
a:scrollbarAlwaysDrawVerticalTrack="true">
|
||||
|
||||
<EditText a:id="@+id/var_edit_name"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:textSize="20dp">
|
||||
</EditText>
|
||||
<TextView a:layout_height="match_parent"
|
||||
a:layout_width="wrap_content"
|
||||
a:padding="6dp"
|
||||
a:text="@string/c_var_name"/>
|
||||
|
||||
<TextView a:layout_height="match_parent"
|
||||
a:layout_width="wrap_content"
|
||||
a:text="Value"/>
|
||||
<EditText a:id="@+id/var_edit_name"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"
|
||||
a:textSize="20dp">
|
||||
</EditText>
|
||||
|
||||
<EditText a:id="@+id/var_edit_value"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:inputType="number"
|
||||
a:textSize="20dp">
|
||||
</EditText>
|
||||
<TextView a:layout_height="match_parent"
|
||||
a:layout_width="wrap_content"
|
||||
a:padding="6dp"
|
||||
a:text="@string/c_var_value"/>
|
||||
|
||||
<TextView a:layout_height="match_parent"
|
||||
a:layout_width="wrap_content"
|
||||
a:text="Description"/>
|
||||
<EditText a:id="@+id/var_edit_value"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"
|
||||
a:inputType="number"
|
||||
a:textSize="20dp">
|
||||
</EditText>
|
||||
|
||||
<EditText a:id="@+id/var_edit_description"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:textSize="20dp">
|
||||
</EditText>
|
||||
<TextView a:layout_height="match_parent"
|
||||
a:layout_width="wrap_content"
|
||||
a:padding="6dp"
|
||||
a:text="@string/c_var_description"/>
|
||||
|
||||
</LinearLayout>
|
||||
<EditText a:id="@+id/var_edit_description"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"
|
||||
a:textSize="20dp">
|
||||
</EditText>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
@ -37,4 +37,14 @@
|
||||
<string name="c_add">Add</string>
|
||||
<string name="c_cancel">Cancel</string>
|
||||
<string name="c_save">Save</string>
|
||||
<string name="c_remove">Remove</string>
|
||||
<string name="c_yes">Yes</string>
|
||||
<string name="c_no">No</string>
|
||||
<string name="c_var_removal_confirmation">Removal confirmation</string>
|
||||
<string name="c_var_removal_confirmation_question">Do you really want to delete \'%s\' variable?</string>
|
||||
<string name="c_var_name">Name</string>
|
||||
<string name="c_var_value">value</string>
|
||||
<string name="c_var_description">Description</string>
|
||||
<string name="c_var_create_var">Create variable</string>
|
||||
<string name="c_var_edit_var">Edit variable</string>
|
||||
</resources>
|
||||
|
@ -64,7 +64,7 @@ public class CalculatorVarsActivity extends ListActivity {
|
||||
|
||||
}
|
||||
|
||||
private void createEditVariableDialog(@Nullable Var var, @Nullable String name, @Nullable String value, @Nullable String description) {
|
||||
private void createEditVariableDialog(@Nullable final Var var, @Nullable final String name, @Nullable final String value, @Nullable final String description) {
|
||||
if (var == null || !var.isSystem()) {
|
||||
|
||||
final LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||
@ -86,16 +86,29 @@ public class CalculatorVarsActivity extends ListActivity {
|
||||
varBuilder = new Var.Builder();
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
||||
.setCancelable(true)
|
||||
.setNegativeButton(getString(R.string.c_cancel), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// do nothing
|
||||
}
|
||||
})
|
||||
.setPositiveButton(getString(R.string.c_save), new VarEditorSaver(varBuilder, var, editView))
|
||||
.setView(editView).create().show();
|
||||
.setNegativeButton(R.string.c_cancel, null)
|
||||
.setPositiveButton(R.string.c_save, new VarEditorSaver(varBuilder, var, editView))
|
||||
.setView(editView);
|
||||
|
||||
if ( var != null ) {
|
||||
// EDIT mode
|
||||
|
||||
builder.setTitle(R.string.c_var_edit_var);
|
||||
builder.setNeutralButton(R.string.c_remove, new VarEditorRemover(var, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
createEditVariableDialog(var, name, value, description);
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
// CREATE mode
|
||||
|
||||
builder.setTitle(R.string.c_var_create_var);
|
||||
}
|
||||
|
||||
builder.create().show();
|
||||
} else {
|
||||
Toast.makeText(this, "System variable cannot be changed!", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
@ -234,4 +247,48 @@ public class CalculatorVarsActivity extends ListActivity {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private class VarEditorRemover implements DialogInterface.OnClickListener {
|
||||
|
||||
@NotNull
|
||||
private final Var var;
|
||||
|
||||
@Nullable
|
||||
private final DialogInterface.OnClickListener callbackOnCancel;
|
||||
|
||||
private final boolean confirmed;
|
||||
|
||||
public VarEditorRemover(@NotNull Var var, @Nullable DialogInterface.OnClickListener callbackOnCancel) {
|
||||
this(var, callbackOnCancel, false);
|
||||
}
|
||||
|
||||
public VarEditorRemover(@NotNull Var var, @Nullable DialogInterface.OnClickListener callbackOnCancel, boolean confirmed) {
|
||||
this.var = var;
|
||||
this.callbackOnCancel = callbackOnCancel;
|
||||
this.confirmed = confirmed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (!confirmed) {
|
||||
final TextView question = new TextView(CalculatorVarsActivity.this);
|
||||
question.setText(String.format(getString(R.string.c_var_removal_confirmation_question), var.getName()));
|
||||
question.setPadding(6, 6, 6, 6);
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(CalculatorVarsActivity.this)
|
||||
.setCancelable(true)
|
||||
.setView(question)
|
||||
.setTitle(R.string.c_var_removal_confirmation)
|
||||
.setNegativeButton(R.string.c_no, callbackOnCancel)
|
||||
.setPositiveButton(R.string.c_yes, new VarEditorRemover(var, callbackOnCancel, true));
|
||||
|
||||
builder.create().show();
|
||||
} else {
|
||||
adapter.remove(var);
|
||||
final VarsRegister varsRegister = CalculatorModel.getInstance().getVarsRegister();
|
||||
varsRegister.remove(var);
|
||||
varsRegister.save(CalculatorVarsActivity.this);
|
||||
CalculatorVarsActivity.this.adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,6 +56,10 @@ public class VarsRegister {
|
||||
return var;
|
||||
}
|
||||
|
||||
public void remove (@NotNull Var var) {
|
||||
this.vars.remove(var);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Var getVar(@NotNull final String name) {
|
||||
return CollectionsUtils.get(vars, new Finder<Var>() {
|
||||
|
Loading…
Reference in New Issue
Block a user