Search in sources :

Example 1 with IconMenuItem

use of org.odk.collect.android.adapters.model.IconMenuItem 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();
}
Also used : FormController(org.odk.collect.android.logic.FormController) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ODKView(org.odk.collect.android.views.ODKView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ExternalDataManager(org.odk.collect.android.external.ExternalDataManager) FailedConstraint(org.odk.collect.android.logic.FormController.FailedConstraint) ListView(android.widget.ListView) IconMenuListAdapter(org.odk.collect.android.adapters.IconMenuListAdapter) OnClickListener(android.view.View.OnClickListener) IconMenuItem(org.odk.collect.android.adapters.model.IconMenuItem) AdapterView(android.widget.AdapterView)

Example 2 with IconMenuItem

use of org.odk.collect.android.adapters.model.IconMenuItem 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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) DrawView(org.odk.collect.android.views.DrawView) View(android.view.View) AdapterView(android.widget.AdapterView) CardView(android.support.v7.widget.CardView) ListView(android.widget.ListView) ListView(android.widget.ListView) IconMenuListAdapter(org.odk.collect.android.adapters.IconMenuListAdapter) IconMenuItem(org.odk.collect.android.adapters.model.IconMenuItem) AdapterView(android.widget.AdapterView)

Aggregations

DialogInterface (android.content.DialogInterface)2 AlertDialog (android.support.v7.app.AlertDialog)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 IconMenuListAdapter (org.odk.collect.android.adapters.IconMenuListAdapter)2 IconMenuItem (org.odk.collect.android.adapters.model.IconMenuItem)2 CardView (android.support.v7.widget.CardView)1 OnClickListener (android.view.View.OnClickListener)1 TextView (android.widget.TextView)1 ExternalDataManager (org.odk.collect.android.external.ExternalDataManager)1 FormController (org.odk.collect.android.logic.FormController)1 FailedConstraint (org.odk.collect.android.logic.FormController.FailedConstraint)1 DrawView (org.odk.collect.android.views.DrawView)1 ODKView (org.odk.collect.android.views.ODKView)1