Search in sources :

Example 16 with FormController

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();
}
Also used : AlertDialog(android.app.AlertDialog) FormController(org.odk.collect.android.logic.FormController) DialogInterface(android.content.DialogInterface) OnClickListener(android.view.View.OnClickListener)

Example 17 with FormController

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()]));
}
Also used : FormController(org.odk.collect.android.logic.FormController) FormEntryCaption(org.javarosa.form.api.FormEntryCaption) ArrayList(java.util.ArrayList) FormIndex(org.javarosa.core.model.FormIndex)

Example 18 with FormController

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);
            }
        });
    }
}
Also used : FormController(org.odk.collect.android.logic.FormController) HierarchyElement(org.odk.collect.android.logic.HierarchyElement) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ODKView(org.odk.collect.android.views.ODKView) ListView(android.widget.ListView) Toolbar(android.support.v7.widget.Toolbar)

Example 19 with FormController

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);
}
Also used : FormController(org.odk.collect.android.logic.FormController) FormIndex(org.javarosa.core.model.FormIndex)

Example 20 with FormController

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);
    }
}
Also used : ContentValues(android.content.ContentValues) FormController(org.odk.collect.android.logic.FormController)

Aggregations

FormController (org.odk.collect.android.logic.FormController)42 FailedConstraint (org.odk.collect.android.logic.FormController.FailedConstraint)10 FormIndex (org.javarosa.core.model.FormIndex)8 JavaRosaException (org.odk.collect.android.exception.JavaRosaException)8 File (java.io.File)7 OnClickListener (android.view.View.OnClickListener)6 ODKView (org.odk.collect.android.views.ODKView)6 DialogInterface (android.content.DialogInterface)5 View (android.view.View)5 AdapterView (android.widget.AdapterView)5 ListView (android.widget.ListView)5 TextView (android.widget.TextView)5 IOException (java.io.IOException)4 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)4 Collect (org.odk.collect.android.application.Collect)4 GDriveConnectionException (org.odk.collect.android.exception.GDriveConnectionException)4 ContentValues (android.content.ContentValues)3 Intent (android.content.Intent)3 Cursor (android.database.Cursor)3 FormEntryCaption (org.javarosa.form.api.FormEntryCaption)3