var activity
This commit is contained in:
parent
33fb471b5e
commit
f2d260706e
@ -19,7 +19,9 @@
|
|||||||
|
|
||||||
<activity a:name=".CalculatorPreferencesActivity" a:label="@string/c_app_settings"/>
|
<activity a:name=".CalculatorPreferencesActivity" a:label="@string/c_app_settings"/>
|
||||||
<activity a:name=".AboutActivity" a:label="@string/c_about"/>
|
<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>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
@ -6,41 +6,52 @@
|
|||||||
~ or visit http://se.solovyev.org
|
~ or visit http://se.solovyev.org
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
<ScrollView xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:id="@+id/var_edit"
|
|
||||||
a:orientation="vertical"
|
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="match_parent">
|
a:layout_height="match_parent">
|
||||||
|
|
||||||
|
<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">
|
||||||
|
|
||||||
<TextView a:layout_height="match_parent"
|
<TextView a:layout_height="match_parent"
|
||||||
a:layout_width="wrap_content"
|
a:layout_width="wrap_content"
|
||||||
a:text="Name"/>
|
a:padding="6dp"
|
||||||
|
a:text="@string/c_var_name"/>
|
||||||
|
|
||||||
<EditText a:id="@+id/var_edit_name"
|
<EditText a:id="@+id/var_edit_name"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="match_parent"
|
a:layout_height="wrap_content"
|
||||||
a:textSize="20dp">
|
a:textSize="20dp">
|
||||||
</EditText>
|
</EditText>
|
||||||
|
|
||||||
<TextView a:layout_height="match_parent"
|
<TextView a:layout_height="match_parent"
|
||||||
a:layout_width="wrap_content"
|
a:layout_width="wrap_content"
|
||||||
a:text="Value"/>
|
a:padding="6dp"
|
||||||
|
a:text="@string/c_var_value"/>
|
||||||
|
|
||||||
<EditText a:id="@+id/var_edit_value"
|
<EditText a:id="@+id/var_edit_value"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="match_parent"
|
a:layout_height="wrap_content"
|
||||||
a:inputType="number"
|
a:inputType="number"
|
||||||
a:textSize="20dp">
|
a:textSize="20dp">
|
||||||
</EditText>
|
</EditText>
|
||||||
|
|
||||||
<TextView a:layout_height="match_parent"
|
<TextView a:layout_height="match_parent"
|
||||||
a:layout_width="wrap_content"
|
a:layout_width="wrap_content"
|
||||||
a:text="Description"/>
|
a:padding="6dp"
|
||||||
|
a:text="@string/c_var_description"/>
|
||||||
|
|
||||||
<EditText a:id="@+id/var_edit_description"
|
<EditText a:id="@+id/var_edit_description"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="match_parent"
|
a:layout_height="wrap_content"
|
||||||
a:textSize="20dp">
|
a:textSize="20dp">
|
||||||
</EditText>
|
</EditText>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
@ -37,4 +37,14 @@
|
|||||||
<string name="c_add">Add</string>
|
<string name="c_add">Add</string>
|
||||||
<string name="c_cancel">Cancel</string>
|
<string name="c_cancel">Cancel</string>
|
||||||
<string name="c_save">Save</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>
|
</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()) {
|
if (var == null || !var.isSystem()) {
|
||||||
|
|
||||||
final LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
|
final LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||||
@ -86,16 +86,29 @@ public class CalculatorVarsActivity extends ListActivity {
|
|||||||
varBuilder = new Var.Builder();
|
varBuilder = new Var.Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
new AlertDialog.Builder(this)
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setNegativeButton(getString(R.string.c_cancel), new DialogInterface.OnClickListener() {
|
.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
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
// do nothing
|
createEditVariableDialog(var, name, value, description);
|
||||||
}
|
}
|
||||||
})
|
}));
|
||||||
.setPositiveButton(getString(R.string.c_save), new VarEditorSaver(varBuilder, var, editView))
|
} else {
|
||||||
.setView(editView).create().show();
|
// CREATE mode
|
||||||
|
|
||||||
|
builder.setTitle(R.string.c_var_create_var);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.create().show();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, "System variable cannot be changed!", Toast.LENGTH_LONG).show();
|
Toast.makeText(this, "System variable cannot be changed!", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
@ -234,4 +247,48 @@ public class CalculatorVarsActivity extends ListActivity {
|
|||||||
|
|
||||||
return result;
|
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;
|
return var;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void remove (@NotNull Var var) {
|
||||||
|
this.vars.remove(var);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Var getVar(@NotNull final String name) {
|
public Var getVar(@NotNull final String name) {
|
||||||
return CollectionsUtils.get(vars, new Finder<Var>() {
|
return CollectionsUtils.get(vars, new Finder<Var>() {
|
||||||
|
Loading…
Reference in New Issue
Block a user