use of org.odk.collect.android.adapters.IconMenuListAdapter in project collect by opendatakit.
the class FormEntryActivity method createQuitDialog.
/**
* Create a dialog with options to save and exit or quit without
* saving
*/
private void createQuitDialog() {
String title;
{
FormController formController = getFormController();
title = (formController == null) ? null : formController.getFormTitle();
if (title == null) {
title = getString(R.string.no_form_loaded);
}
}
List<IconMenuItem> items;
if ((boolean) AdminSharedPreferences.getInstance().get(AdminKeys.KEY_SAVE_MID)) {
items = ImmutableList.of(new IconMenuItem(R.drawable.ic_save_grey_32dp_wrapped, R.string.keep_changes), new IconMenuItem(R.drawable.ic_delete_grey_32dp_wrapped, R.string.do_not_save));
} else {
items = ImmutableList.of(new IconMenuItem(R.drawable.ic_delete_grey_32dp_wrapped, R.string.do_not_save));
}
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createQuitDialog", "show");
ListView listView = DialogUtils.createActionListView(this);
final IconMenuListAdapter adapter = new IconMenuListAdapter(this, items);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
IconMenuItem item = (IconMenuItem) adapter.getItem(position);
if (item.getTextResId() == R.string.keep_changes) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createQuitDialog", "saveAndExit");
saveDataToDisk(EXIT, InstancesDaoHelper.isInstanceComplete(false), null);
} else {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createQuitDialog", "discardAndExit");
// close all open databases of external data.
ExternalDataManager manager = Collect.getInstance().getExternalDataManager();
if (manager != null) {
manager.close();
}
FormController formController = getFormController();
if (formController != null) {
formController.getTimerLogger().logTimerEvent(TimerLogger.EventTypes.FORM_EXIT, 0, null, false, true);
}
removeTempInstance();
finishReturnInstance();
}
alertDialog.dismiss();
}
});
alertDialog = new AlertDialog.Builder(this).setTitle(getString(R.string.quit_application, title)).setPositiveButton(getString(R.string.do_not_exit), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createQuitDialog", "cancel");
dialog.cancel();
}
}).setView(listView).create();
alertDialog.show();
}
use of org.odk.collect.android.adapters.IconMenuListAdapter in project collect by opendatakit.
the class DrawActivity method createQuitDrawDialog.
/**
* Create a dialog with options to save and exit, save, or quit without
* saving
*/
private void createQuitDrawDialog() {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createQuitDrawDialog", "show");
ListView listView = DialogUtils.createActionListView(this);
List<IconMenuItem> items;
items = ImmutableList.of(new IconMenuItem(R.drawable.ic_save_grey_32dp_wrapped, R.string.keep_changes), new IconMenuItem(R.drawable.ic_delete_grey_32dp_wrapped, R.string.do_not_save));
final IconMenuListAdapter adapter = new IconMenuListAdapter(this, items);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
IconMenuItem item = (IconMenuItem) adapter.getItem(position);
if (item.getTextResId() == R.string.keep_changes) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createQuitDrawDialog", "saveAndExit");
saveAndClose();
} else {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createQuitDrawDialog", "discardAndExit");
cancelAndClose();
}
alertDialog.dismiss();
}
});
alertDialog = new AlertDialog.Builder(this).setTitle(alertTitleString).setPositiveButton(getString(R.string.do_not_exit), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createQuitDrawDialog", "cancel");
}
}).setView(listView).create();
alertDialog.show();
}
Aggregations