Search in sources :

Example 1 with ESMFactory

use of com.aware.ui.esms.ESMFactory in project aware-client by denzilferreira.

the class ESM method processFlow.

private static void processFlow(Context context, String current_answer) {
    if (Aware.DEBUG) {
        Log.d(ESM.TAG, "Current answer: " + current_answer);
    }
    try {
        // Check flow
        Cursor last_esm = context.getContentResolver().query(ESM_Data.CONTENT_URI, null, ESM_Data.STATUS + "=" + ESM.STATUS_ANSWERED, null, ESM_Data.TIMESTAMP + " DESC LIMIT 1");
        if (last_esm != null && last_esm.moveToFirst()) {
            JSONObject esm_question = new JSONObject(last_esm.getString(last_esm.getColumnIndex(ESM_Data.JSON)));
            ESM_Question esm = new ESMFactory().getESM(esm_question.getInt(ESM_Question.esm_type), esm_question, last_esm.getInt(last_esm.getColumnIndex(ESM_Data._ID)));
            // Set as branched the flow rules that are not triggered
            JSONArray flows = esm.getFlows();
            for (int i = 0; i < flows.length(); i++) {
                JSONObject flow = flows.getJSONObject(i);
                String flowAnswer = flow.getString(ESM_Question.flow_user_answer);
                JSONObject nextESM = flow.getJSONObject(ESM_Question.flow_next_esm).getJSONObject(EXTRA_ESM);
                if (flowAnswer.equals(current_answer)) {
                    if (Aware.DEBUG)
                        Log.d(ESM.TAG, "Following next question: " + nextESM);
                    // Queued ESM
                    ContentValues rowData = new ContentValues();
                    // fixed issue with synching and support ordering of esms by timestamp
                    rowData.put(ESM_Data.TIMESTAMP, System.currentTimeMillis());
                    rowData.put(ESM_Data.DEVICE_ID, Aware.getSetting(context, Aware_Preferences.DEVICE_ID));
                    rowData.put(ESM_Data.JSON, nextESM.toString());
                    // optional, defaults to 0
                    rowData.put(ESM_Data.EXPIRATION_THRESHOLD, nextESM.optInt(ESM_Data.EXPIRATION_THRESHOLD));
                    // optional, defaults to 0
                    rowData.put(ESM_Data.NOTIFICATION_TIMEOUT, nextESM.optInt(ESM_Data.NOTIFICATION_TIMEOUT));
                    rowData.put(ESM_Data.STATUS, ESM.STATUS_NEW);
                    // optional, defaults to ""
                    rowData.put(ESM_Data.TRIGGER, nextESM.optString(ESM_Data.TRIGGER));
                    context.getContentResolver().insert(ESM_Data.CONTENT_URI, rowData);
                } else {
                    if (Aware.DEBUG)
                        Log.d(ESM.TAG, "Branched split: " + flowAnswer + " Skipping: " + nextESM);
                    // Branched ESM
                    ContentValues rowData = new ContentValues();
                    // fixed issue with synching and support ordering of esms by timestamp
                    rowData.put(ESM_Data.TIMESTAMP, System.currentTimeMillis());
                    rowData.put(ESM_Data.DEVICE_ID, Aware.getSetting(context, Aware_Preferences.DEVICE_ID));
                    rowData.put(ESM_Data.JSON, nextESM.toString());
                    // optional, defaults to 0
                    rowData.put(ESM_Data.EXPIRATION_THRESHOLD, nextESM.optInt(ESM_Data.EXPIRATION_THRESHOLD));
                    // optional, defaults to 0
                    rowData.put(ESM_Data.NOTIFICATION_TIMEOUT, nextESM.optInt(ESM_Data.NOTIFICATION_TIMEOUT));
                    rowData.put(ESM_Data.STATUS, ESM.STATUS_BRANCHED);
                    // optional, defaults to ""
                    rowData.put(ESM_Data.TRIGGER, nextESM.optString(ESM_Data.TRIGGER));
                    context.getContentResolver().insert(ESM_Data.CONTENT_URI, rowData);
                }
            }
        }
        if (last_esm != null && !last_esm.isClosed())
            last_esm.close();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : ESMFactory(com.aware.ui.esms.ESMFactory) JSONObject(org.json.JSONObject) ESM_Question(com.aware.ui.esms.ESM_Question) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Cursor(android.database.Cursor)

Example 2 with ESMFactory

use of com.aware.ui.esms.ESMFactory in project aware-client by denzilferreira.

the class TestESM method testESMS.

private void testESMS(Context context) {
    ESMFactory factory = new ESMFactory();
    try {
        ESM_Freetext esmFreetext = new ESM_Freetext();
        esmFreetext.setTitle("Freetext").setTrigger("test").setReplaceQueue(true).setSubmitButton("OK").setInstructions("Freetext ESM");
        ESM_Checkbox esmCheckbox = new ESM_Checkbox();
        esmCheckbox.addCheck("Check 1").addCheck("Check 2").addCheck("Other").setTitle("Checkbox").setTrigger("test").setSubmitButton("OK").setInstructions("Checkbox ESM");
        ESM_Likert esmLikert = new ESM_Likert();
        esmLikert.setLikertMax(7).setLikertMaxLabel("Great").setLikertMinLabel("Poor").setLikertStep(1).setTitle("Likert 3").setInstructions("Likert ESM").setTrigger("test").setSubmitButton("OK");
        ESM_QuickAnswer esmQuickAnswer = new ESM_QuickAnswer();
        esmQuickAnswer.addQuickAnswer("Yes").addQuickAnswer("No").setTrigger("test").setInstructions("Quick Answers ESM");
        ESM_Radio esmRadio = new ESM_Radio();
        esmRadio.addRadio("Radio 1").addRadio("Radio 2").setTitle("Radios").setInstructions("Radios ESM").setSubmitButton("OK");
        ESM_Scale esmScale = new ESM_Scale();
        esmScale.setScaleMax(100).setScaleMin(0).setScaleStart(50).setScaleMaxLabel("Perfect").setScaleMinLabel("Poor").setScaleStep(10).setTitle("Scale").setInstructions("Scale ESM").setSubmitButton("OK");
        ESM_DateTime esmDate = new ESM_DateTime();
        esmDate.setTitle("Date and Time").setTrigger("AWARE Test").setInstructions("Specify date and time").setSubmitButton("OK");
        ESM_PAM esmPAM = new ESM_PAM();
        esmPAM.setTitle("PAM").setInstructions("Pick the closest to how you feel right now.").setSubmitButton("OK").setTrigger("AWARE Test").setAppIntegration("fourtwentystudy://");
        factory.addESM(esmFreetext);
        factory.addESM(esmCheckbox);
        factory.addESM(esmLikert);
        factory.addESM(esmQuickAnswer);
        factory.addESM(esmRadio);
        factory.addESM(esmScale);
        factory.addESM(esmPAM);
        factory.addESM(esmDate);
        ESM.queueESM(context, factory.build());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : ESMFactory(com.aware.ui.esms.ESMFactory) ESM_Freetext(com.aware.ui.esms.ESM_Freetext) ESM_DateTime(com.aware.ui.esms.ESM_DateTime) ESM_QuickAnswer(com.aware.ui.esms.ESM_QuickAnswer) ESM_Scale(com.aware.ui.esms.ESM_Scale) ESM_PAM(com.aware.ui.esms.ESM_PAM) ESM_Likert(com.aware.ui.esms.ESM_Likert) JSONException(org.json.JSONException) ESM_Checkbox(com.aware.ui.esms.ESM_Checkbox) ESM_Radio(com.aware.ui.esms.ESM_Radio)

Example 3 with ESMFactory

use of com.aware.ui.esms.ESMFactory in project aware-client by denzilferreira.

the class TestESM method testPAM.

private void testPAM(Context context) {
    ESMFactory factory = new ESMFactory();
    try {
        ESM_PAM q1 = new ESM_PAM();
        q1.setTitle("PAM").setInstructions("Pick the closest to how you feel right now.").setSubmitButton("OK").setNotificationTimeout(10).setTrigger("AWARE Test");
        factory.addESM(q1);
        ESM.queueESM(context, factory.build());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : ESMFactory(com.aware.ui.esms.ESMFactory) ESM_PAM(com.aware.ui.esms.ESM_PAM) JSONException(org.json.JSONException)

Example 4 with ESMFactory

use of com.aware.ui.esms.ESMFactory in project aware-client by denzilferreira.

the class TestESM method trialESMS.

private void trialESMS(Context context) {
    ESMFactory factory = new ESMFactory();
    try {
        ESM_Freetext esmFreetext = new ESM_Freetext();
        esmFreetext.setTitle("Freetext").setTrigger("test").setExpirationThreshold(0).setSubmitButton("OK").setInstructions("Freetext ESM");
        ESM_Checkbox esmCheckbox = new ESM_Checkbox();
        esmCheckbox.addCheck("Check 1").addCheck("Check 2").addCheck("Other").setTitle("Checkbox").setTrigger("test").setExpirationThreshold(0).setSubmitButton("OK").setInstructions("Checkbox ESM");
        ESM_Likert esmLikert = new ESM_Likert();
        esmLikert.setLikertMax(5).setLikertMaxLabel("Great").setLikertMinLabel("Poor").setLikertStep(1).setTitle("Likert").setInstructions("Likert ESM").setTrigger("test").setExpirationThreshold(0).setSubmitButton("OK");
        ESM_QuickAnswer esmQuickAnswer = new ESM_QuickAnswer();
        esmQuickAnswer.addQuickAnswer("Yes").addQuickAnswer("No").setTrigger("test").setExpirationThreshold(0).setSubmitButton("OK").setInstructions("Quick Answers ESM");
        ESM_Radio esmRadio = new ESM_Radio();
        esmRadio.addRadio("Radio 1").addRadio("Radio 2").setTitle("Radios").setInstructions("Radios ESM").setExpirationThreshold(0).setSubmitButton("OK");
        ESM_Scale esmScale = new ESM_Scale();
        esmScale.setScaleMax(100).setScaleMin(0).setScaleStart(50).setScaleMaxLabel("Perfect").setScaleMinLabel("Poor").setScaleStep(10).setTitle("Scale").setInstructions("Scale ESM").setExpirationThreshold(0).setSubmitButton("OK");
        factory.addESM(esmFreetext);
        factory.addESM(esmCheckbox);
        factory.addESM(esmLikert);
        factory.addESM(esmQuickAnswer);
        factory.addESM(esmRadio);
        factory.addESM(esmScale);
        ESM.queueESM(context, factory.build(), true);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : ESMFactory(com.aware.ui.esms.ESMFactory) ESM_Freetext(com.aware.ui.esms.ESM_Freetext) ESM_QuickAnswer(com.aware.ui.esms.ESM_QuickAnswer) ESM_Scale(com.aware.ui.esms.ESM_Scale) ESM_Likert(com.aware.ui.esms.ESM_Likert) JSONException(org.json.JSONException) ESM_Checkbox(com.aware.ui.esms.ESM_Checkbox) ESM_Radio(com.aware.ui.esms.ESM_Radio)

Example 5 with ESMFactory

use of com.aware.ui.esms.ESMFactory in project aware-client by denzilferreira.

the class TestESM method testNotificationRetries.

/**
 * This tests the notification re-trigger x times after y seconds have elapsed.
 *
 * @param context
 */
private void testNotificationRetries(Context context) {
    ESMFactory factory = new ESMFactory();
    try {
        ESM_Number number = new ESM_Number();
        // 5 minutes
        number.setNotificationTimeout(5 * 60).setNotificationRetry(// notify the user 3 times, so notification alive for 3 * 5 minutes = 15 minutes
        3).setTitle("Lucky number?").setInstructions("Pick one.");
        factory.addESM(number);
        ESM.queueESM(context, factory.build());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : ESMFactory(com.aware.ui.esms.ESMFactory) JSONException(org.json.JSONException) ESM_Number(com.aware.ui.esms.ESM_Number)

Aggregations

ESMFactory (com.aware.ui.esms.ESMFactory)14 JSONException (org.json.JSONException)14 ESM_Radio (com.aware.ui.esms.ESM_Radio)5 ESM_Checkbox (com.aware.ui.esms.ESM_Checkbox)4 ESM_PAM (com.aware.ui.esms.ESM_PAM)4 ESM_QuickAnswer (com.aware.ui.esms.ESM_QuickAnswer)4 ESM_Freetext (com.aware.ui.esms.ESM_Freetext)3 ESM_Likert (com.aware.ui.esms.ESM_Likert)3 ESM_Scale (com.aware.ui.esms.ESM_Scale)3 Cursor (android.database.Cursor)2 ESM_DateTime (com.aware.ui.esms.ESM_DateTime)2 ESM_Number (com.aware.ui.esms.ESM_Number)2 ESM_Question (com.aware.ui.esms.ESM_Question)2 JSONObject (org.json.JSONObject)2 PendingIntent (android.app.PendingIntent)1 ESM_Date (com.aware.ui.esms.ESM_Date)1 ESM_Web (com.aware.ui.esms.ESM_Web)1 Scheduler (com.aware.utils.Scheduler)1 JSONArray (org.json.JSONArray)1