android_calculator-46: Add 'Remove' to context menu for constants, functions etc

This commit is contained in:
Sergey Solovyev 2012-01-09 19:11:40 +04:00
parent dfc9292f73
commit 2a4984f0ec
2 changed files with 25 additions and 11 deletions

View File

@ -62,6 +62,15 @@ public class CalculatorVarsActivity extends AbstractMathEntityListActivity<ICons
} }
}, },
remove(R.string.c_remove) {
@Override
public void doAction(@NotNull IConstant data, @NotNull Context context) {
if (context instanceof AbstractMathEntityListActivity) {
new MathEntityRemover<IConstant>(data, null, CalculatorEngine.instance.getVarsRegistry(), ((AbstractMathEntityListActivity<IConstant>) context)).showConfirmationDialog();
}
}
},
copy_value(R.string.c_copy_value) { copy_value(R.string.c_copy_value) {
@Override @Override
public void doAction(@NotNull IConstant data, @NotNull Context context) { public void doAction(@NotNull IConstant data, @NotNull Context context) {
@ -126,6 +135,7 @@ public class CalculatorVarsActivity extends AbstractMathEntityListActivity<ICons
if ( item.isSystem() ) { if ( item.isSystem() ) {
result.remove(LongClickMenuItem.edit); result.remove(LongClickMenuItem.edit);
result.remove(LongClickMenuItem.remove);
} }
if ( StringUtils.isEmpty(CalculatorEngine.instance.getVarsRegistry().getDescription(this, item.getName())) ) { if ( StringUtils.isEmpty(CalculatorEngine.instance.getVarsRegistry().getDescription(this, item.getName())) ) {

View File

@ -58,17 +58,7 @@ class MathEntityRemover<T extends MathEntity> implements DialogInterface.OnClick
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (!confirmed) { if (!confirmed) {
final TextView question = new TextView(activity); showConfirmationDialog();
question.setText(String.format(activity.getString(R.string.c_var_removal_confirmation_question), mathEntity.getName()));
question.setPadding(6, 6, 6, 6);
final AlertDialog.Builder builder = new AlertDialog.Builder(activity)
.setCancelable(true)
.setView(question)
.setTitle(R.string.c_var_removal_confirmation)
.setNegativeButton(R.string.c_no, callbackOnCancel)
.setPositiveButton(R.string.c_yes, new MathEntityRemover<T>(mathEntity, callbackOnCancel, true, varsRegistry, activity));
builder.create().show();
} else { } else {
if (activity.isInCategory(mathEntity)) { if (activity.isInCategory(mathEntity)) {
activity.getAdapter().remove(mathEntity); activity.getAdapter().remove(mathEntity);
@ -81,4 +71,18 @@ class MathEntityRemover<T extends MathEntity> implements DialogInterface.OnClick
} }
} }
} }
public void showConfirmationDialog() {
final TextView question = new TextView(activity);
question.setText(String.format(activity.getString(R.string.c_var_removal_confirmation_question), mathEntity.getName()));
question.setPadding(6, 6, 6, 6);
final AlertDialog.Builder builder = new AlertDialog.Builder(activity)
.setCancelable(true)
.setView(question)
.setTitle(R.string.c_var_removal_confirmation)
.setNegativeButton(R.string.c_no, callbackOnCancel)
.setPositiveButton(R.string.c_yes, new MathEntityRemover<T>(mathEntity, callbackOnCancel, true, varsRegistry, activity));
builder.create().show();
}
} }