@SimpleFunction(description = "This will clean up the survey database on the smartphone") public void DeleteSurveyDB() { Intent i = new Intent(mainUI, NameValueDatabaseService.class); Log.i(TAG, "archiving data...at: " + System.currentTimeMillis()); i.setAction(DatabaseService.ACTION_ARCHIVE); i.putExtra(DatabaseService.DATABASE_NAME_KEY, SURVEY_DBNAME); mainUI.startService(i); }
/* * Exporting Survey DB to External Storage */ @SimpleFunction( description = "Export Survey results database as CSV files or JSON files." + "Input \"csv\" or \"json\" for exporting format.") public void Export(String format) { if (format == NameValueDatabaseService.EXPORT_JSON) this.exportFormat = NameValueDatabaseService.EXPORT_JSON; else this.exportFormat = NameValueDatabaseService.EXPORT_CSV; // if the user input the wrong format, we will just use csv by default Log.i(TAG, "exporting data...at: " + System.currentTimeMillis()); Bundle b = new Bundle(); b.putString(NameValueDatabaseService.DATABASE_NAME_KEY, SURVEY_DBNAME); b.putString(NameValueDatabaseService.EXPORT_KEY, format); Intent i = new Intent(mainUI, NameValueDatabaseService.class); i.setAction(DatabaseService.ACTION_EXPORT); i.putExtras(b); mainUI.startService(i); }
// in the html files for survey templates private static void close(String result) { Log.i(TAG, "before closing the Activity"); // mainUI.finishActivityWithTextResult(result); mainUI.finish(); }
/** * Creates a new Survey component. * * @param container container the component will be placed in * @throws IOException */ public Survey(ComponentContainer container) throws IOException { super(container); mainUI = container.$form(); exportRoot = new java.io.File(Environment.getExternalStorageDirectory(), mainUI.getPackageName()) + java.io.File.separator + "export"; JsonParser parse = new JsonParser(); webview = new WebView(container.$context()); webview.getSettings().setJavaScriptEnabled(true); webview.setFocusable(true); webview.setVerticalScrollBarEnabled(true); container.$add(this); webview.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } }); // set the initial default properties. Height and Width // will be fill-parent, which will be the default for the web viewer. Width(LENGTH_FILL_PARENT); Height(LENGTH_FILL_PARENT); // set default survey style style = TEXTBOX; // default style // see if the Survey is created by someone tapping on a notification! // create the Survey and load it in the webviewer /* e.g. * value = { * "style": "multipleChoice", * "question": "What is your favorite food" * "options": ["apple", "banana", "strawberry", "orange"], * "surveyGroup": "MIT-food-survey" * } * */ initValues = container.$form().getSurveyStartValues(); Log.i(TAG, "startVal Suvey:" + initValues.toString()); if (initValues != "") { JsonObject values = (JsonObject) parse.parse(initValues); this.style = values.get("style").getAsString(); this.question = values.get("question").getAsString(); this.surveyGroup = values.get("surveyGroup").getAsString(); ArrayList<String> arrOptions = new ArrayList<String>(); JsonArray _options = values.get("options").getAsJsonArray(); for (int i = 0; i < _options.size(); i++) { arrOptions.add(_options.get(i).getAsString()); } this.options = arrOptions; this.styleFromIntent = values.get("style").getAsString(); Log.i(TAG, "Survey component got created"); } }