use of org.odk.collect.android.logic.FormController in project collect by opendatakit.
the class FormEntryActivity method onPrepareOptionsMenu.
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
boolean useability;
useability = (boolean) AdminSharedPreferences.getInstance().get(AdminKeys.KEY_SAVE_MID);
menu.findItem(R.id.menu_save).setVisible(useability).setEnabled(useability);
useability = (boolean) AdminSharedPreferences.getInstance().get(AdminKeys.KEY_JUMP_TO);
menu.findItem(R.id.menu_goto).setVisible(useability).setEnabled(useability);
FormController formController = getFormController();
useability = (boolean) AdminSharedPreferences.getInstance().get(AdminKeys.KEY_CHANGE_LANGUAGE) && (formController != null) && formController.getLanguages() != null && formController.getLanguages().length > 1;
menu.findItem(R.id.menu_languages).setVisible(useability).setEnabled(useability);
useability = (boolean) AdminSharedPreferences.getInstance().get(AdminKeys.KEY_ACCESS_SETTINGS);
menu.findItem(R.id.menu_preferences).setVisible(useability).setEnabled(useability);
return true;
}
use of org.odk.collect.android.logic.FormController 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.logic.FormController in project collect by opendatakit.
the class FormEntryActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
FormController formController = getFormController();
switch(item.getItemId()) {
case R.id.menu_languages:
Collect.getInstance().getActivityLogger().logInstanceAction(this, "onOptionsItemSelected", "MENU_LANGUAGES");
createLanguageDialog();
return true;
case R.id.menu_save:
Collect.getInstance().getActivityLogger().logInstanceAction(this, "onOptionsItemSelected", "MENU_SAVE");
// don't exit
saveDataToDisk(DO_NOT_EXIT, InstancesDaoHelper.isInstanceComplete(false), null);
return true;
case R.id.menu_goto:
state = null;
Collect.getInstance().getActivityLogger().logInstanceAction(this, "onOptionsItemSelected", "MENU_HIERARCHY_VIEW");
if (formController != null && formController.currentPromptIsQuestion()) {
saveAnswersForCurrentScreen(DO_NOT_EVALUATE_CONSTRAINTS);
}
if (formController != null) {
formController.getTimerLogger().logTimerEvent(TimerLogger.EventTypes.HIERARCHY, 0, null, false, true);
}
Intent i = new Intent(this, EditFormHierarchyActivity.class);
startActivityForResult(i, RequestCodes.HIERARCHY_ACTIVITY);
return true;
case R.id.menu_preferences:
Collect.getInstance().getActivityLogger().logInstanceAction(this, "onOptionsItemSelected", "MENU_PREFERENCES");
Intent pref = new Intent(this, PreferencesActivity.class);
startActivity(pref);
return true;
}
return super.onOptionsItemSelected(item);
}
use of org.odk.collect.android.logic.FormController in project collect by opendatakit.
the class FormEntryActivity method onPause.
@Override
protected void onPause() {
FormController formController = getFormController();
dismissDialogs();
// is getting constantly updated
if (saveToDiskTask == null || saveToDiskTask.getStatus() == AsyncTask.Status.FINISHED) {
if (currentView != null && formController != null && formController.currentPromptIsQuestion()) {
saveAnswersForCurrentScreen(DO_NOT_EVALUATE_CONSTRAINTS);
}
}
if (getCurrentViewIfODKView() != null) {
// stop audio if it's playing
getCurrentViewIfODKView().stopAudio();
}
super.onPause();
}
use of org.odk.collect.android.logic.FormController in project collect by opendatakit.
the class FormEntryActivity method savingComplete.
/**
* Called by SavetoDiskTask if everything saves correctly.
*/
@Override
public void savingComplete(SaveResult saveResult) {
dismissDialog(SAVING_DIALOG);
int saveStatus = saveResult.getSaveResult();
FormController formController = getFormController();
switch(saveStatus) {
case SaveToDiskTask.SAVED:
ToastUtils.showShortToast(R.string.data_saved_ok);
formController.getTimerLogger().logTimerEvent(TimerLogger.EventTypes.FORM_SAVE, 0, null, false, false);
sendSavedBroadcast();
break;
case SaveToDiskTask.SAVED_AND_EXIT:
ToastUtils.showShortToast(R.string.data_saved_ok);
formController.getTimerLogger().logTimerEvent(TimerLogger.EventTypes.FORM_SAVE, 0, null, false, false);
if (saveResult.isComplete()) {
formController.getTimerLogger().logTimerEvent(TimerLogger.EventTypes.FORM_EXIT, 0, null, false, false);
// Force writing of audit since we are exiting
formController.getTimerLogger().logTimerEvent(TimerLogger.EventTypes.FORM_FINALIZE, 0, null, false, true);
} else {
// Force writing of audit since we are exiting
formController.getTimerLogger().logTimerEvent(TimerLogger.EventTypes.FORM_EXIT, 0, null, false, true);
}
sendSavedBroadcast();
finishReturnInstance();
break;
case SaveToDiskTask.SAVE_ERROR:
String message;
formController.getTimerLogger().logTimerEvent(TimerLogger.EventTypes.SAVE_ERROR, 0, null, false, true);
if (saveResult.getSaveErrorMessage() != null) {
message = getString(R.string.data_saved_error) + ": " + saveResult.getSaveErrorMessage();
} else {
message = getString(R.string.data_saved_error);
}
ToastUtils.showLongToast(message);
break;
case SaveToDiskTask.ENCRYPTION_ERROR:
formController.getTimerLogger().logTimerEvent(TimerLogger.EventTypes.FINALIZE_ERROR, 0, null, false, true);
ToastUtils.showLongToast(String.format(getString(R.string.encryption_error_message), saveResult.getSaveErrorMessage()));
finishReturnInstance();
break;
case FormEntryController.ANSWER_CONSTRAINT_VIOLATED:
case FormEntryController.ANSWER_REQUIRED_BUT_EMPTY:
formController.getTimerLogger().logTimerEvent(TimerLogger.EventTypes.CONSTRAINT_ERROR, 0, null, false, true);
refreshCurrentView();
// get constraint behavior preference value with appropriate default
String constraintBehavior = (String) GeneralSharedPreferences.getInstance().get(PreferenceKeys.KEY_CONSTRAINT_BEHAVIOR);
// next question
if (constraintBehavior.equals(PreferenceKeys.CONSTRAINT_BEHAVIOR_ON_SWIPE)) {
next();
} else {
// otherwise, we can get the proper toast(s) by saving with constraint check
saveAnswersForCurrentScreen(EVALUATE_CONSTRAINTS);
}
break;
}
}
Aggregations