List of usage examples for org.apache.cordova PluginResult PluginResult
public PluginResult(Status status)
From source file:com.physicaroid.pocketduino.cordova.PocketDuino.java
License:Apache License
/** * PocketDuino??// w w w.j a v a 2s . c o m */ private void openDevice(CallbackContext callbackContext) { try { if (this.mPhysicaloid.open()) { // ??????upload???????? PluginResult dataResult = new PluginResult(PluginResult.Status.OK); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); } else { PluginResult dataResult = new PluginResult(PluginResult.Status.ERROR); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); } } catch (RuntimeException e) { PluginResult dataResult = new PluginResult(PluginResult.Status.ERROR); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); } }
From source file:com.physicaroid.pocketduino.cordova.PocketDuino.java
License:Apache License
/** * PocketDuino??/*from w w w .j a v a2s. c o m*/ */ private void closeDevice(CallbackContext callbackContext) { try { if (this.mPhysicaloid.close()) { PluginResult dataResult = new PluginResult(PluginResult.Status.OK); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); } else { PluginResult dataResult = new PluginResult(PluginResult.Status.ERROR); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); } } catch (RuntimeException e) { PluginResult dataResult = new PluginResult(PluginResult.Status.ERROR); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); } }
From source file:com.physicaroid.pocketduino.cordova.PocketDuino.java
License:Apache License
/** * *//*from w w w . jav a 2 s . co m*/ private void writeSerial(CallbackContext callbackContext, JSONArray args) { try { String command = args.getString(0); byte[] buf = command.getBytes(); Log.d(POCKETDUINO, command); this.mPhysicaloid.write(buf, buf.length); PluginResult dataResult = new PluginResult(PluginResult.Status.OK); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); } catch (Exception e) { try { String json = "{\"message\":" + e.toString() + " }"; JSONObject parameter = new JSONObject(json); PluginResult dataResult = new PluginResult(PluginResult.Status.ERROR, parameter); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); String hoge; } catch (Exception ex) { Log.e(POCKETDUINO, ex.toString()); } } }
From source file:com.physicaroid.pocketduino.cordova.PocketDuino.java
License:Apache License
/** * hex?/*ww w . j a va 2s .c o m*/ */ private void uploadHexFile(CallbackContext callbackContext, JSONArray args) { try { String fileName = args.getString(0); Log.d(POCKETDUINO, "!!!--- " + fileName + " ---!!!"); // upload()?3? callback ????????? // ??????????????? mPhysicaloid.upload(Boards.POCKETDUINO, cordova.getActivity().getResources().getAssets().open(fileName), null); PluginResult dataResult = new PluginResult(PluginResult.Status.OK); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); } catch (RuntimeException e) { try { String json = "{\"message\":" + e.toString() + " }"; JSONObject parameter = new JSONObject(json); PluginResult dataResult = new PluginResult(PluginResult.Status.ERROR, parameter); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); } catch (JSONException exc) { Log.e(POCKETDUINO, exc.toString()); } } catch (IOException e) { try { String json = "{\"message\":" + e.toString() + " }"; JSONObject parameter = new JSONObject(json); PluginResult dataResult = new PluginResult(PluginResult.Status.ERROR, parameter); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); } catch (JSONException exc) { Log.e(POCKETDUINO, exc.toString()); } } catch (JSONException e) { try { String json = "{\"message\":" + e.toString() + " }"; JSONObject parameter = new JSONObject(json); PluginResult dataResult = new PluginResult(PluginResult.Status.ERROR, parameter); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); } catch (JSONException exc) { Log.e(POCKETDUINO, exc.toString()); } } }
From source file:com.plugin.camera.ForegroundCameraLauncher.java
License:Apache License
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. *///from w w w . j a v a2 s . c o m public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { this.callbackContext = callbackContext; if (action.equals("takePicture")) { this.targetHeight = 0; this.targetWidth = 0; this.mQuality = 50; try { this.mQuality = args.getInt(1); this.targetWidth = args.getInt(3); this.targetHeight = args.getInt(4); } catch (Exception e) { e.printStackTrace(); } // If the user specifies a 0 or smaller width/height // make it -1 so later comparisons succeed if (this.targetWidth < 1) { this.targetWidth = -1; } if (this.targetHeight < 1) { this.targetHeight = -1; } this.takePicture(); PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT); r.setKeepCallback(true); callbackContext.sendPluginResult(r); return true; } return false; }
From source file:com.plugin.gallery.ForegroundGalleryLauncher.java
License:Apache License
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. *//*from w ww . j a va 2s . co m*/ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { this.callbackContext = callbackContext; this.targetHeight = 0; this.targetWidth = 0; this.mQuality = 80; System.out.println("IN"); JSONObject options = args.optJSONObject(0); try { if (options != null) { this.targetHeight = options.getInt("targetHeight"); this.targetWidth = options.getInt("targetWidth"); this.mQuality = options.getInt("quality"); } } catch (Exception e) { System.out.println("Exception"); e.printStackTrace(); } this.getImage(); PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT); r.setKeepCallback(true); callbackContext.sendPluginResult(r); return true; }
From source file:com.polyvi.xface.extension.advancedfiletransfer.AdvancedFileTransfer.java
License:Open Source License
/** * ?/* w w w. j a v a2s.com*/ * * @param transferOp * @param callbackContext * @param action */ private void threadhelper(final AdvancedFileTransferOp transferOp, final CallbackContext callbackContext, final String source, final String target) { cordova.getThreadPool().execute(new Runnable() { public void run() { try { transferOp.run(); } catch (Exception e) { XLog.e(CLASS_NAME, e.getMessage()); e.printStackTrace(); if (e instanceof FileNotFoundException) { JSONObject error = createFileTransferError(FILE_NOT_FOUND_ERR, source, target); callbackContext.error(error); } else if (e instanceof IllegalArgumentException) { JSONObject error = createFileTransferError(INVALID_URL_ERR, source, target); callbackContext.error(error); } else if (e instanceof JSONException) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); } else if (e instanceof IOException) { JSONObject error = createFileTransferError(CONNECTION_ERR, source, target); callbackContext.error(error); } else { callbackContext.error("Unknown Error"); } } } }); }
From source file:com.polyvi.xface.extension.bluetooth.XBluetoothExt.java
License:Open Source License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { mJsCallback = callbackContext;//from www . j av a 2 s.c o m PluginResult result = null; if (COMMAND_DISCOVER_DEVICES.equals(action)) { result = discoverDevice(); } else if (COMMAND_IS_BT_ENABLED.equals(action)) { result = isBluetoothEnabled(); } else if (COMMAND_ENABLE_BT.equals(action)) { result = enableBluetooth(); } else if (COMMAND_DISABLE_BT.equals(action)) { result = disableBluetooth(); } else if (COMMAND_PAIR_BT.equals(action)) { result = pairBluetooth(args); } else if (COMMAND_UNPAIR_BT.equals(action)) { result = unpairBluetooth(args); } else if (COMMAND_LIST_BOUND_DEVICES.equals(action)) { result = listBoundBluetooth(); } else if (COMMAND_STOP_DISCOVERING_BT.equals(action)) { result = stopDiscovering(); } else if (COMMAND_IS_BOUND_BT.equals(action)) { result = isBoundBluetooth(args); } else { result = new PluginResult(PluginResult.Status.INVALID_ACTION); } mJsCallback.sendPluginResult(result); return true; }
From source file:com.polyvi.xface.extension.bluetooth.XBluetoothExt.java
License:Open Source License
/** * ??/*from w w w.ja v a 2 s. co m*/ * * @return */ private PluginResult discoverDevice() { if (mIsDiscovering == true) { return new PluginResult(PluginResult.Status.NO_RESULT); } mFoundDevices.clear(); mIsDiscovering = true; if (mBtadapter.isDiscovering()) { mBtadapter.cancelDiscovery(); } mBtadapter.startDiscovery(); PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); result.setKeepCallback(true); return result; }
From source file:com.polyvi.xface.extension.calendar.XCalendarExt.java
License:Open Source License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { Calendar calendar = Calendar.getInstance(); mCallbackContext = callbackContext;/* w w w. j ava 2 s . c om*/ if (COMMAND_GET_TIME.equals(action)) { // ??? int hours = calendar.get(Calendar.HOUR_OF_DAY); int minutes = calendar.get(Calendar.MINUTE); if (2 == args.length()) { hours = args.getInt(0); minutes = args.getInt(1); } getTime(hours, minutes); } else if (COMMAND_GET_DATE.equals(action)) { // ??? int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); if (3 == args.length()) { year = args.getInt(0); month = args.getInt(1); day = args.getInt(2); } getDate(year, month, day); } PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); result.setKeepCallback(true); callbackContext.sendPluginResult(result); return true; }