List of usage examples for org.apache.cordova.api CallbackContext success
public void success(int message)
From source file:br.edu.ufcg.supervisor.SupervisorInterface.java
License:Open Source License
/** * Executes the model with some data and extracts recommendations. * @param args Passed from Javascript interface. * @param callbackContext Used to return the result of processing. * @throws JSONException/*w ww .j ava 2 s . co m*/ */ private void executeModel(JSONArray args, CallbackContext callbackContext) throws JSONException { JSONObject r = new JSONObject(); String name = args.get(0).toString(); Float value = Float.valueOf((String) args.get(1)); map.put(name, value); map2.put(Integer.valueOf((String) args.get(2)), value); String recommendation = ""; String currentState = ""; try { Simulation.executeModel(r, model, map, map2, currentState, recommendation, logString); } catch (Exception e) { recommendation = "Value not monitored."; logString = logString + "(" + recommendation + ")\n"; r.put("error", recommendation); r.put("rec", "Stop and verify your devices. If this appears again, call your healthcare professional."); callbackContext.error(r); } callbackContext.success(r); }
From source file:br.edu.ufcg.supervisor.SupervisorInterface.java
License:Open Source License
/** * Starts the process of executing the chosen model. * @param callbackContext Used to return the result of processing. * @throws JSONException//w w w. j av a2 s .c o m */ private void start(CallbackContext callbackContext) throws JSONException { JSONObject r = new JSONObject(); if (model == null) { r.put("msg", "At first, you have to load a training."); callbackContext.error(r); } else { model.setNome(model.getNome()); LoadedModel.setModel(model); int[] arrayIds = LoadedModel.getIdVariaveisMonitoradas(); ArrayList<String> arrayNames = LoadedModel.getNomesVariaveisMonitoradas(); String ids = ""; String names = ""; map.clear();//zera o map para limpar modelos carregados anteriormente. map2.clear(); logString = ""; for (int i = 0; i < arrayNames.size(); i++) { ids = ids + "," + arrayIds[i]; names = names + "," + arrayNames.get(i); map.put(arrayNames.get(i), 0.f); //map2.put(Integer.valueOf(arrayIds[i]), 0.f); } r.put("ids", ids.replaceFirst(",", "")); r.put("names", names.replaceFirst(",", "")); r.put("msg", model.getNome()); callbackContext.success(r); } }
From source file:br.edu.ufcg.supervisor.SupervisorInterface.java
License:Open Source License
/** * Loads model from a given name of a file. If it does not exist, loads a pre-defined simple one. * @param args Passed from Javascript interface. * @param callbackContext Used to return the result of processing. * @throws JSONException//from w ww . j a v a 2 s . c om */ private void loadModelFromFile(JSONArray args, CallbackContext callbackContext) throws JSONException { JSONObject r = new JSONObject(); String fileName = args.get(0).toString() + ".sup"; pathToFile = Environment.getExternalStorageDirectory().toString() + "/Download/" + fileName; File file = new File(pathToFile); if (!file.exists()) { model = null; //model = TrainingLoader.getDefaultModel(); r.put("msg", "File not found."); callbackContext.error(r); } else { String automatoJson = ""; try { automatoJson = TrainingLoader.readFile(pathToFile); } catch (IOException e) { r.put("msg", "erro ao ler arquivo1."); callbackContext.error(r); } model = new Automaton(automatoJson); r.put("msg", "File found. Model loaded."); callbackContext.success(r); } }
From source file:com.cbtec.eliademy.BillingPlugin.java
License:Open Source License
private void getPurchasedItems(CallbackContext callbackContext) { try {//from w ww . j av a 2 s . c o m JSONArray products = new JSONArray(); Bundle ownedItems = Eliademy.sBillingService.getPurchases(3, Eliademy.sInstance.getPackageName(), "inapp", null); if (ownedItems.getInt("RESPONSE_CODE") == 0) { final ArrayList<String> items = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST"); for (int i = 0; i < items.size(); i++) { products.put(items.get(i)); } } callbackContext.success(products); } catch (RemoteException e) { callbackContext.error(e.getMessage()); } }
From source file:com.google.cordova.ChromeI18n.java
License:Open Source License
private void getAcceptLanguages(final CordovaArgs args, final CallbackContext callbackContext) { try {// ww w. j a v a 2s . c o m JSONArray ret = new JSONArray(); Locale locale = Locale.getDefault(); String localString = locale.toString().replace('_', '-'); ret.put(localString); callbackContext.success(ret); } catch (Exception e) { callbackContext.error("Could not retrieve supported locales"); Log.e(LOG_TAG, "Could not retrieve supported locales", e); } }
From source file:com.google.cordova.ChromeIdentity.java
License:Open Source License
private void getAuthTokenCallback(String token, CallbackContext callbackContext) { if (token.trim().equals("")) { callbackContext.error("Could not get auth token"); } else {/*ww w . j av a 2s . c o m*/ callbackContext.success(token); } }
From source file:com.google.cordova.ChromeStorage.java
License:Open Source License
private void get(final CordovaArgs args, final CallbackContext callbackContext) { executorService.execute(new Runnable() { @Override/*from w ww. j a v a 2 s .c om*/ public void run() { JSONObject storage = getStoredValuesForKeys(args, /*useDefaultValues*/ true); if (storage == null) { callbackContext.error("Could not retrieve storage"); } else { callbackContext.success(storage); } } }); }
From source file:com.google.cordova.ChromeStorage.java
License:Open Source License
private void getBytesInUse(final CordovaArgs args, final CallbackContext callbackContext) { executorService.execute(new Runnable() { @Override//from w ww . jav a 2s . c om public void run() { //Don't use default values as the keys that don't have values in storage don't affect size JSONObject storage = getStoredValuesForKeys(args, /*useDefaultValues*/ false); if (storage == null) { callbackContext.error("Could not retrieve storage"); } else { callbackContext.success(storage.toString().getBytes().length); } } }); }
From source file:com.google.cordova.ChromeStorage.java
License:Open Source License
private void set(final CordovaArgs args, final CallbackContext callbackContext) { executorService.execute(new Runnable() { @Override//from w ww . j a v a 2 s.c o m public void run() { try { boolean sync = args.getBoolean(0); JSONObject jsonObject = (JSONObject) args.getJSONObject(1); JSONArray keyArray = jsonObject.names(); JSONObject oldValues = new JSONObject(); if (keyArray != null) { List<String> keys = JSONUtils.toStringList(keyArray); JSONObject storage = getStorage(sync); for (String key : keys) { Object oldValue = storage.opt(key); if (oldValue != null) { oldValues.put(key, oldValue); } storage.put(key, jsonObject.get(key)); } setStorage(sync, storage); } callbackContext.success(oldValues); } catch (Exception e) { Log.e(LOG_TAG, "Could not update storage", e); callbackContext.error("Could not update storage"); } } }); }
From source file:com.google.cordova.ChromeStorage.java
License:Open Source License
private void remove(final CordovaArgs args, final CallbackContext callbackContext) { executorService.execute(new Runnable() { @Override//from w w w.java2 s.c o m public void run() { try { boolean sync = args.getBoolean(0); JSONObject jsonObject = (JSONObject) args.optJSONObject(1); JSONArray jsonArray = args.optJSONArray(1); boolean isNull = args.isNull(1); List<String> keys = new ArrayList<String>(); JSONObject oldValues = new JSONObject(); if (jsonObject != null) { keys = JSONUtils.toStringList(jsonObject.names()); } else if (jsonArray != null) { keys = JSONUtils.toStringList(jsonArray); } else if (isNull) { keys = null; } if (keys != null && !keys.isEmpty()) { JSONObject storage = getStorage(sync); for (String key : keys) { Object oldValue = storage.opt(key); if (oldValue != null) { oldValues.put(key, oldValue); } storage.remove(key); } setStorage(sync, storage); } callbackContext.success(oldValues); } catch (Exception e) { Log.e(LOG_TAG, "Could not update storage", e); callbackContext.error("Could not update storage"); } } }); }