use of org.odk.collect.android.logic.FormController in project collect by opendatakit.
the class FormHierarchyActivity method createErrorDialog.
/**
* Creates and displays dialog with the given errorMsg.
*/
protected void createErrorDialog(String errorMsg) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createErrorDialog", "show.");
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setIcon(android.R.drawable.ic_dialog_info);
alertDialog.setTitle(getString(R.string.error_occured));
alertDialog.setMessage(errorMsg);
DialogInterface.OnClickListener errorListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
switch(i) {
case DialogInterface.BUTTON_POSITIVE:
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createErrorDialog", "OK");
FormController formController = Collect.getInstance().getFormController();
formController.jumpToIndex(currentIndex);
break;
}
}
};
alertDialog.setCancelable(false);
alertDialog.setButton(getString(R.string.ok), errorListener);
alertDialog.show();
}
use of org.odk.collect.android.logic.FormController in project collect by opendatakit.
the class FormHierarchyActivity method getCurrentPath.
private String getCurrentPath() {
FormController formController = Collect.getInstance().getFormController();
FormIndex index = formController.getFormIndex();
// move to enclosing group...
index = formController.stepIndexOut(index);
List<FormEntryCaption> groups = new ArrayList<>();
while (index != null) {
groups.add(0, formController.getCaptionPrompt(index));
index = formController.stepIndexOut(index);
}
return ODKView.getGroupsPath(groups.toArray(new FormEntryCaption[groups.size()]));
}
use of org.odk.collect.android.logic.FormController in project collect by opendatakit.
the class FormHierarchyActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hierarchy_layout);
listView = findViewById(android.R.id.list);
listView.setOnItemClickListener(this);
TextView emptyView = findViewById(android.R.id.empty);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FormController formController = Collect.getInstance().getFormController();
// https://github.com/opendatakit/collect/issues/998
if (formController == null) {
finish();
return;
}
// We use a static FormEntryController to make jumping faster.
startIndex = formController.getFormIndex();
setTitle(formController.getFormTitle());
path = findViewById(R.id.pathtext);
jumpPreviousButton = findViewById(R.id.jumpPreviousButton);
jumpPreviousButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "goUpLevelButton", "click");
goUpLevel();
}
});
jumpBeginningButton = findViewById(R.id.jumpBeginningButton);
jumpBeginningButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "jumpToBeginning", "click");
Collect.getInstance().getFormController().jumpToIndex(FormIndex.createBeginningOfFormIndex());
setResult(RESULT_OK);
finish();
}
});
jumpEndButton = findViewById(R.id.jumpEndButton);
jumpEndButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "jumpToEnd", "click");
Collect.getInstance().getFormController().jumpToIndex(FormIndex.createEndOfFormIndex());
setResult(RESULT_OK);
finish();
}
});
refreshView();
// this scrolls to the last question the user was looking at
if (getListAdapter() != null && listView != null) {
emptyView.setVisibility(View.GONE);
listView.post(new Runnable() {
@Override
public void run() {
int position = 0;
for (int i = 0; i < getListAdapter().getCount(); i++) {
HierarchyElement he = (HierarchyElement) getListAdapter().getItem(i);
if (startIndex.equals(he.getFormIndex())) {
position = i;
break;
}
}
listView.setSelection(position);
}
});
}
}
use of org.odk.collect.android.logic.FormController in project collect by opendatakit.
the class ActivityLogger method logInstanceAction.
public void logInstanceAction(Object t, String context, String action) {
FormIndex index = null;
String instancePath = null;
FormController formController = Collect.getInstance().getFormController();
if (formController != null) {
index = formController.getFormIndex();
instancePath = getInstancePath(formController);
}
log(t.getClass().getName(), context, action, instancePath, index, null, null);
}
use of org.odk.collect.android.logic.FormController in project collect by opendatakit.
the class ActivityLogger method logScrollAction.
public void logScrollAction(Object t, int distance) {
if (!isOpen()) {
return;
}
synchronized (scrollActions) {
long timeStamp = Calendar.getInstance().getTimeInMillis();
// Check to see if we can add this scroll action to the previous action.
if (!scrollActions.isEmpty()) {
ContentValues lastCv = scrollActions.get(scrollActions.size() - 1);
long oldTimeStamp = lastCv.getAsLong(TIMESTAMP);
int oldDistance = Integer.parseInt(lastCv.getAsString(PARAM1));
if (Integer.signum(distance) == Integer.signum(oldDistance) && timeStamp - oldTimeStamp < MIN_SCROLL_DELAY) {
lastCv.put(PARAM1, oldDistance + distance);
lastCv.put(TIMESTAMP, timeStamp);
return;
}
}
if (scrollActions.size() >= MAX_SCROLL_ACTION_BUFFER_SIZE) {
// flush scroll list...
insertContentValues(null, null);
}
String idx = "";
String instancePath = null;
FormController formController = Collect.getInstance().getFormController();
if (formController != null) {
idx = getXPath(formController.getFormIndex());
instancePath = getInstancePath(formController);
}
// Add a new scroll action to the buffer.
ContentValues cv = new ContentValues();
cv.put(DEVICEID, deviceId);
cv.put(CLASS, t.getClass().getName());
cv.put(CONTEXT, "scroll");
cv.put(ACTION, "");
cv.put(PARAM1, distance);
cv.put(QUESTION, idx);
cv.put(INSTANCE_PATH, instancePath);
cv.put(TIMESTAMP, timeStamp);
cv.put(PARAM2, timeStamp);
scrollActions.add(cv);
}
}
Aggregations