use of org.odk.collect.android.logic.FormController in project collect by opendatakit.
the class FormEntryActivity method createDeleteRepeatConfirmDialog.
/**
* Creates a confirm/cancel dialog for deleting repeats.
*/
private void createDeleteRepeatConfirmDialog() {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createDeleteRepeatConfirmDialog", "show");
FormController formController = getFormController();
alertDialog = new AlertDialog.Builder(this).create();
String name = formController.getLastRepeatedGroupName();
int repeatcount = formController.getLastRepeatedGroupRepeatCount();
if (repeatcount != -1) {
name += " (" + (repeatcount + 1) + ")";
}
alertDialog.setTitle(getString(R.string.delete_repeat_ask));
alertDialog.setMessage(getString(R.string.delete_repeat_confirm, name));
DialogInterface.OnClickListener quitListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
FormController formController = getFormController();
switch(i) {
case // yes
BUTTON_POSITIVE:
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createDeleteRepeatConfirmDialog", "OK");
formController.getTimerLogger().logTimerEvent(TimerLogger.EventTypes.DELETE_REPEAT, 0, null, false, true);
formController.deleteRepeat();
showNextView();
break;
case // no
BUTTON_NEGATIVE:
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createDeleteRepeatConfirmDialog", "cancel");
refreshCurrentView();
break;
}
}
};
alertDialog.setCancelable(false);
alertDialog.setButton(BUTTON_POSITIVE, getString(R.string.discard_group), quitListener);
alertDialog.setButton(BUTTON_NEGATIVE, getString(R.string.delete_repeat_no), quitListener);
alertDialog.show();
}
use of org.odk.collect.android.logic.FormController in project collect by opendatakit.
the class FormEntryActivity method showView.
/**
* Displays the View specified by the parameter 'next', animating both the
* current view and next appropriately given the AnimationType. Also updates
* the progress bar.
*/
public void showView(View next, AnimationType from) {
// disable notifications...
if (inAnimation != null) {
inAnimation.setAnimationListener(null);
}
if (outAnimation != null) {
outAnimation.setAnimationListener(null);
}
// by createView()
switch(from) {
case RIGHT:
inAnimation = AnimationUtils.loadAnimation(this, R.anim.push_left_in);
outAnimation = AnimationUtils.loadAnimation(this, R.anim.push_left_out);
// if animation is left or right then it was a swipe, and we want to re-save on
// entry
autoSaved = false;
break;
case LEFT:
inAnimation = AnimationUtils.loadAnimation(this, R.anim.push_right_in);
outAnimation = AnimationUtils.loadAnimation(this, R.anim.push_right_out);
autoSaved = false;
break;
case FADE:
inAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_in);
outAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_out);
break;
}
// complete setup for animations...
inAnimation.setAnimationListener(this);
outAnimation.setAnimationListener(this);
if (shouldOverrideAnimations) {
inAnimation.setDuration(0);
outAnimation.setDuration(0);
}
// drop keyboard before transition...
if (currentView != null) {
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(currentView.getWindowToken(), 0);
}
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
// adjust which view is in the layout container...
staleView = currentView;
currentView = next;
questionHolder.addView(currentView, lp);
animationCompletionSet = 0;
if (staleView != null) {
// start OutAnimation for transition...
staleView.startAnimation(outAnimation);
// and remove the old view (MUST occur after start of animation!!!)
questionHolder.removeView(staleView);
} else {
animationCompletionSet = 2;
}
// start InAnimation for transition...
currentView.startAnimation(inAnimation);
String logString = "";
switch(from) {
case RIGHT:
logString = "next";
break;
case LEFT:
logString = "previous";
break;
case FADE:
logString = "refresh";
break;
}
Collect.getInstance().getActivityLogger().logInstanceAction(this, "showView", logString);
FormController formController = getFormController();
if (formController.getEvent() == FormEntryController.EVENT_QUESTION || formController.getEvent() == FormEntryController.EVENT_GROUP || formController.getEvent() == FormEntryController.EVENT_REPEAT) {
FormEntryPrompt[] prompts = getFormController().getQuestionPrompts();
for (FormEntryPrompt p : prompts) {
List<TreeElement> attrs = p.getBindAttributes();
for (int i = 0; i < attrs.size(); i++) {
if (!autoSaved && "saveIncomplete".equals(attrs.get(i).getName())) {
saveDataToDisk(false, false, null, false);
autoSaved = true;
}
}
}
}
}
use of org.odk.collect.android.logic.FormController in project collect by opendatakit.
the class FormEntryActivity method onResume.
@Override
protected void onResume() {
super.onResume();
String navigation = (String) GeneralSharedPreferences.getInstance().get(PreferenceKeys.KEY_NAVIGATION);
showNavigationButtons = navigation.contains(PreferenceKeys.NAVIGATION_BUTTONS);
backButton.setVisibility(showNavigationButtons ? View.VISIBLE : View.GONE);
nextButton.setVisibility(showNavigationButtons ? View.VISIBLE : View.GONE);
if (errorMessage != null) {
if (alertDialog != null && !alertDialog.isShowing()) {
createErrorDialog(errorMessage, EXIT);
} else {
return;
}
}
FormController formController = getFormController();
Collect.getInstance().getActivityLogger().open();
if (formLoaderTask != null) {
formLoaderTask.setFormLoaderListener(this);
if (formController == null && formLoaderTask.getStatus() == AsyncTask.Status.FINISHED) {
FormController fec = formLoaderTask.getFormController();
if (fec != null) {
loadingComplete(formLoaderTask, formLoaderTask.getFormDef());
} else {
dismissDialog(PROGRESS_DIALOG);
FormLoaderTask t = formLoaderTask;
formLoaderTask = null;
t.cancel(true);
t.destroy();
// there is no formController -- fire MainMenu activity?
startActivity(new Intent(this, MainMenuActivity.class));
}
}
} else {
if (formController == null) {
// there is no formController -- fire MainMenu activity?
startActivity(new Intent(this, MainMenuActivity.class));
return;
} else {
refreshCurrentView();
}
}
if (saveToDiskTask != null) {
saveToDiskTask.setFormSavedListener(this);
}
}
use of org.odk.collect.android.logic.FormController in project collect by opendatakit.
the class FormEntryActivity method createLanguageDialog.
/**
* Creates and displays a dialog allowing the user to set the language for
* the form.
*/
private void createLanguageDialog() {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createLanguageDialog", "show");
FormController formController = getFormController();
final String[] languages = formController.getLanguages();
int selected = -1;
if (languages != null) {
String language = formController.getLanguage();
for (int i = 0; i < languages.length; i++) {
if (language.equals(languages[i])) {
selected = i;
}
}
}
alertDialog = new AlertDialog.Builder(this).setSingleChoiceItems(languages, selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
// Update the language in the content provider
// when selecting a new
// language
ContentValues values = new ContentValues();
values.put(FormsColumns.LANGUAGE, languages[whichButton]);
String selection = FormsColumns.FORM_FILE_PATH + "=?";
String[] selectArgs = { formPath };
int updated = new FormsDao().updateForm(values, selection, selectArgs);
Timber.i("Updated language to: %s in %d rows", languages[whichButton], updated);
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createLanguageDialog", "changeLanguage." + languages[whichButton]);
FormController formController = getFormController();
formController.setLanguage(languages[whichButton]);
dialog.dismiss();
if (formController.currentPromptIsQuestion()) {
saveAnswersForCurrentScreen(DO_NOT_EVALUATE_CONSTRAINTS);
}
refreshCurrentView();
}
}).setTitle(getString(R.string.change_language)).setNegativeButton(getString(R.string.do_not_change), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createLanguageDialog", "cancel");
}
}).create();
alertDialog.show();
}
use of org.odk.collect.android.logic.FormController in project collect by opendatakit.
the class FormEntryActivity method showPreviousView.
/**
* Determines what should be displayed between a question, or the start
* screen and displays the appropriate view. Also saves answers to the data
* model without checking constraints.
*/
private void showPreviousView() {
if (allowMovingBackwards) {
state = null;
try {
FormController formController = getFormController();
if (formController != null) {
// ignored.
if (formController.currentPromptIsQuestion()) {
saveAnswersForCurrentScreen(DO_NOT_EVALUATE_CONSTRAINTS);
}
if (formController.getEvent() != FormEntryController.EVENT_BEGINNING_OF_FORM) {
int event = formController.stepToPreviousScreenEvent();
// this swipe
if (event == FormEntryController.EVENT_BEGINNING_OF_FORM) {
event = formController.stepToNextScreenEvent();
beenSwiped = false;
if (event != FormEntryController.EVENT_PROMPT_NEW_REPEAT) {
// Returning here prevents the same view sliding when user is on the first screen
return;
}
}
if (event == FormEntryController.EVENT_GROUP || event == FormEntryController.EVENT_QUESTION) {
// create savepoint
if ((++viewCount) % SAVEPOINT_INTERVAL == 0) {
nonblockingCreateSavePointData();
}
}
// Close timer events
formController.getTimerLogger().exitView();
View next = createView(event, false);
showView(next, AnimationType.LEFT);
} else {
beenSwiped = false;
}
} else {
Timber.w("FormController has a null value");
}
} catch (JavaRosaException e) {
Timber.d(e);
createErrorDialog(e.getCause().getMessage(), DO_NOT_EXIT);
}
} else {
beenSwiped = false;
}
}
Aggregations