/** * 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. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { this.callbackContext = callbackContext; this.targetHeight = 0; this.targetWidth = 0; this.mQuality = 80; JSONObject options = args.optJSONObject(0); if (options != null) { this.targetHeight = options.getInt("targetHeight"); this.targetWidth = options.getInt("targetWidth"); this.mQuality = options.getInt("quality"); } this.getImage(); PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT); r.setKeepCallback(true); callbackContext.sendPluginResult(r); return true; }
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if ("showEmailComposer".equals(action)) { try { JSONObject parameters = args.getJSONObject(0); if (parameters != null) { sendEmail(parameters); } } catch (Exception e) { } callbackContext.success(); return true; } return false; // Returning false results in a "MethodNotFound" error. }
public boolean execute(String paramString, JSONArray paramJSONArray, CallbackContext paramCallbackContext) { if (paramString.equals("start")) { this.callbackContext = paramCallbackContext; if (this.status != RUNNING) start(); } while (true) { PluginResult localPluginResult = new PluginResult(PluginResult.Status.NO_RESULT, ""); localPluginResult.setKeepCallback(true); paramCallbackContext.sendPluginResult(localPluginResult); return true; if (!paramString.equals("stop")) break; if (this.status != RUNNING) continue; stop(); } return false; }
public boolean execute(String paramString, JSONArray paramJSONArray, CallbackContext paramCallbackContext) throws JSONException { if (paramString.equals("getDeviceInfo")) { JSONObject localJSONObject = new JSONObject(); localJSONObject.put("uuid", uuid); localJSONObject.put("version", getOSVersion()); localJSONObject.put("platform", platform); localJSONObject.put("name", getProductName()); localJSONObject.put("cordova", cordovaVersion); localJSONObject.put("model", getModel()); paramCallbackContext.success(localJSONObject); return true; } return false; }
private void win(Location paramLocation) { Iterator localIterator1 = this.callbacks.iterator(); while (localIterator1.hasNext()) { CallbackContext localCallbackContext = (CallbackContext)localIterator1.next(); this.owner.win(paramLocation, localCallbackContext); } if (this.owner.isGlobalListener(this)) { Log.d(this.TAG, "Stopping global listener"); stop(); } this.callbacks.clear(); Iterator localIterator2 = this.watches.values().iterator(); while (localIterator2.hasNext()) this.owner.win(paramLocation, (CallbackContext)localIterator2.next()); }
protected void fail(int paramInt, String paramString) { Iterator localIterator1 = this.callbacks.iterator(); while (localIterator1.hasNext()) { CallbackContext localCallbackContext = (CallbackContext)localIterator1.next(); this.owner.fail(paramInt, paramString, localCallbackContext); } if (this.owner.isGlobalListener(this)) { Log.d(this.TAG, "Stopping global listener"); stop(); } this.callbacks.clear(); Iterator localIterator2 = this.watches.values().iterator(); while (localIterator2.hasNext()) this.owner.fail(paramInt, paramString, (CallbackContext)localIterator2.next()); }
public boolean execute(String paramString, JSONArray paramJSONArray, CallbackContext paramCallbackContext) throws JSONException { this.ctx = this.cordova.getActivity(); try { this.wifiManager = ((WifiManager)this.ctx.getSystemService("wifi")); Action localAction = Action.valueOf(toAllCaps(paramString)); Log.d("Wifi", "WifiPlugin called with action: " + localAction); switch (2.$SwitchMap$com$worklight$androidgap$plugin$WifiPlugin$Action[localAction.ordinal()]) { case 1: scanWifi(paramCallbackContext); return true; } } catch (Exception localException) { Log.e("Wifi", "Error initializing WIFI scanning, reason: " + localException.getMessage()); return false; } return false; }
public boolean execute(String paramString, JSONArray paramJSONArray, CallbackContext paramCallbackContext) throws JSONException { try { ACTION_LOG localACTION_LOG = ACTION_LOG.fromString(paramString); if (localACTION_LOG == null) { paramCallbackContext.error("Invalid action: " + paramString); return true; } localACTION_LOG.log(this.cordova.getClass().getSimpleName(), paramJSONArray.getString(0)); paramCallbackContext.success("true"); return true; } catch (JSONException localJSONException) { paramCallbackContext.error("Action: " + paramString + " failed. JSON Error is: " + localJSONException.getLocalizedMessage()); } return true; }
public boolean execute(String paramString, JSONArray paramJSONArray, CallbackContext paramCallbackContext) throws JSONException { try { if ("show".equals(paramString)) { show(paramJSONArray.getString(0)); paramCallbackContext.success("true"); return true; } if ("hide".equals(paramString)) { hide(); paramCallbackContext.success("true"); return true; } } catch (JSONException localJSONException) { paramCallbackContext.error("Action: " + paramString + " failed. JSON Error is: " + localJSONException.getLocalizedMessage()); return true; } paramCallbackContext.error("Invalid action: " + paramString); return true; }
private void win(Location paramLocation) { long l = System.currentTimeMillis() - paramLocation.getTime(); if (l > this.maximumAge) Log.d(this.TAG, "Acquired location age: " + l + " milliseconds. More than maximumAge of " + this.maximumAge + " milliseconds. Ignoring."); do { return; Iterator localIterator1 = this.callbacks.values().iterator(); while (localIterator1.hasNext()) this.owner.win(paramLocation, (CallbackContext)localIterator1.next(), false); if ((this.owner.isGlobalListener(this)) && (this.watches.size() == 0)) { Log.d(this.TAG, "Stopping global listener"); stop(); } this.callbacks.clear(); Iterator localIterator2 = this.watches.values().iterator(); while (localIterator2.hasNext()) this.owner.win(paramLocation, (CallbackContext)localIterator2.next(), true); } while (!this.watches.isEmpty()); stop(); }
public boolean execute(String paramString, JSONArray paramJSONArray, CallbackContext paramCallbackContext) throws JSONException { try { if ("show".equals(paramString)) { show(paramJSONArray); paramCallbackContext.success(PluginResult.Status.OK.name()); return true; } paramCallbackContext.error("Invalid action: " + paramString); return true; } catch (Exception localException) { WLUtils.debug("NativePage.show failed. Reason is: " + localException.getMessage(), localException); paramCallbackContext.error("NativePage.show failed. Reason is: " + localException.getMessage()); } return true; }
public boolean execute(String paramString, JSONArray paramJSONArray, CallbackContext paramCallbackContext) throws JSONException { Log.d("WLForegroundBinder", "execute called"); this.ctx = this.cordova.getActivity(); try { Action localAction = Action.valueOf(toAllCaps(paramString)); switch (2.$SwitchMap$com$worklight$androidgap$plugin$ForegroundBinderPlugin$Action[localAction.ordinal()]) { case 1: bindService(paramJSONArray, paramCallbackContext); return true; case 2: unbindService(paramCallbackContext); return false; } } catch (IllegalArgumentException localIllegalArgumentException) { } return false; }
public boolean execute(String paramString, JSONArray paramJSONArray, CallbackContext paramCallbackContext) throws JSONException { boolean bool = paramString.equals("getcheckcode"); int i = 0; if (bool); try { paramCallbackContext.success(CheckCodeUtil.checkcode("", paramJSONArray.getString(0))); i = 1; return i; } catch (JSONException localJSONException) { paramCallbackContext.error("Failed to parse parameters"); } return false; }
/** * Send an error to given CallbackContext containing the error code and message. * * @param ctx Where to send the error. * @param msg What seems to be the problem. * @param code Integer value as a an error "code" */ private void error(CallbackContext ctx, String msg, int code) { try { JSONObject result = new JSONObject(); result.put("message", msg); result.put("code", code); ctx.error(result); } catch(Exception e) { Log.e(LOG_TAG, "Error with... error raising, " + e.getMessage()); } }
/** * Pair the device with the device in the given address. * * @param args Arguments given. First argument should be the address in String format. * @param callbackCtx Where to send results. */ private void pair(JSONArray args, CallbackContext callbackCtx) { // TODO Add a timeout function for pairing if(_pairingCallback != null) { this.error(callbackCtx, "Pairing process is already in progress.", BluetoothError.ERR_PAIRING_IN_PROGRESS); } else { try { String address = args.getString(0); _bluetooth.createBond(address); _pairingCallback = callbackCtx; } catch(Exception e) { _pairingCallback = null; this.error(callbackCtx, e.getMessage(), BluetoothError.ERR_UNKNOWN); } } }
/** * Get the devices paired with this device. * * @param args Arguments given. * @param callbackCtx Where to send results. */ private void getPaired(JSONArray args, CallbackContext callbackCtx) { try { JSONArray devices = new JSONArray(); ArrayList<Pair<String>> bondedDevices = _bluetooth.getBondedDevices(); for(Pair<String> deviceInfo : bondedDevices) { JSONObject device = new JSONObject(); device.put("name", deviceInfo.a); device.put("address", deviceInfo.b); devices.put(device); } callbackCtx.success(devices); } catch(Exception e) { this.error(callbackCtx, e.getMessage(), BluetoothError.ERR_UNKNOWN); } }
/** * Get the UUID(s) of the device at given address. * * @param args Arguments given. First argument should be the address in String format. * @param callbackCtx Where to send results. */ private void getUuids(JSONArray args, CallbackContext callbackCtx) { if(_uuidCallback != null) { this.error(callbackCtx, "Could not start UUID fetching because there is already one in progress.", BluetoothError.ERR_UUID_FETCHING_IN_PROGRESS ); } else { try { String address = args.getString(0); _bluetooth.fetchUuids(address); _uuidCallback = callbackCtx; } catch(Exception e) { _uuidCallback = null; this.error(callbackCtx, e.getMessage(), BluetoothError.ERR_UNKNOWN); } } }
/** * Start a managed connection, allowing read and write operations. * * @param args Arguments given. * @param callbackCtx Where to send results. */ private void startConnectionManager(JSONArray args, CallbackContext callbackCtx) { if(_ioCallback != null) { this.error(callbackCtx, "There is already an active connection.", BluetoothError.ERR_CONNECTION_ALREADY_EXISTS); } else { try { _bluetooth.startConnectionManager(); _ioCallback = callbackCtx; } catch(Exception e) { _ioCallback = null; this.error(callbackCtx, e.getMessage(), BluetoothError.ERR_UNKNOWN); } } }
/** * Stop the managed connection, preventing further read or write operations. * * @param args Arguments given. * @param callbackCtx Where to send results. */ private void stopConnectionManager(JSONArray args, CallbackContext callbackCtx) { try { if(_bluetooth.isConnectionManaged()) { _bluetooth.stopConnectionManager(); callbackCtx.success(); } else { this.error(callbackCtx, "There is no connection being managed.", BluetoothError.ERR_CONNECTION_DOESNT_EXIST ); } } catch(Exception e) { this.error(callbackCtx, e.getMessage(), BluetoothError.ERR_UNKNOWN); } }
/** * Executes the request. * * @param action The action to execute. * @param args The exec() arguments. * @param callbackId The callback id used when calling back into JavaScript. * @return Whether the action was valid. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (action.equals("start")) { this.callbackContext = callbackContext; if (this.status != AccelListener.RUNNING) { // If not running, then this is an async call, so don't worry about waiting // We drop the callback onto our stack, call start, and let start and the sensor callback fire off the callback down the road this.start(); } } else if (action.equals("stop")) { if (this.status == AccelListener.RUNNING) { this.stop(); } } else { // Unsupported action return false; } PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, ""); result.setKeepCallback(true); callbackContext.sendPluginResult(result); return true; }
protected void fail(int code, String message) { this.cancelTimer(); for (CallbackContext callbackContext: this.callbacks) { this.owner.fail(code, message, callbackContext, false); } if(this.owner.isGlobalListener(this) && this.watches.size() == 0) { Log.d(TAG, "Stopping global listener"); this.stop(); } this.callbacks.clear(); Iterator<CallbackContext> it = this.watches.values().iterator(); while (it.hasNext()) { this.owner.fail(code, message, it.next(), true); } }
private void win(Location loc) { this.cancelTimer(); for (CallbackContext callbackContext: this.callbacks) { this.owner.win(loc, callbackContext, false); } if(this.owner.isGlobalListener(this) && this.watches.size() == 0) { Log.d(TAG, "Stopping global listener"); this.stop(); } this.callbacks.clear(); Iterator<CallbackContext> it = this.watches.values().iterator(); while (it.hasNext()) { this.owner.win(loc, it.next(), true); } }
/** * Executes the request and returns PluginResult. * * @param action * The action to execute. * @param args * JSONArry of arguments for the plugin. * @param callbackContext * The callback context used when calling back into JavaScript. * @return True if the action was valid, false otherwise. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("openDatabase")) { this.openDatabase(args.getString(0), args.getString(1), args.getString(2), args.getLong(3)); } else if (action.equals("executeSql")) { String[] s = null; if (args.isNull(1)) { s = new String[0]; } else { JSONArray a = args.getJSONArray(1); int len = a.length(); s = new String[len]; for (int i = 0; i < len; i++) { s[i] = a.getString(i); } } this.executeSql(args.getString(0), s, args.getString(2)); } else { return false; } callbackContext.success(); return true; }
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals("upload") || action.equals("download")) { String source = args.getString(0); String target = args.getString(1); if (action.equals("upload")) { try { source = URLDecoder.decode(source, "UTF-8"); upload(source, target, args, callbackContext); } catch (UnsupportedEncodingException e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.MALFORMED_URL_EXCEPTION, "UTF-8 error.")); } } else { download(source, target, args, callbackContext); } return true; } else if (action.equals("abort")) { String objectId = args.getString(0); abort(objectId); callbackContext.success(); return true; } return false; }
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if ("showEmailComposer".equals(action)) { this._callbackContext = callbackContext; Log.d(LOG_TAG, "Open email composer"); try { JSONObject parameters = args.getJSONObject(0); if (parameters != null) { Log.d(LOG_TAG, "Call sendEmail()"); sendEmail(parameters, callbackContext); } } catch (Exception e) { Log.e(LOG_TAG, "Internal Error"); callbackContext.error("Internal Error"); return false; } } else { Log.e(LOG_TAG, "Invalid Action"); callbackContext.error("Invalid Action"); return false; } return true; }
/** * 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 True if the action was valid, false if not. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("getDeviceInfo")) { JSONObject r = new JSONObject(); r.put("uuid", Device.uuid); r.put("version", this.getOSVersion()); r.put("platform", Device.platform); r.put("cordova", Device.cordovaVersion); r.put("model", this.getModel()); callbackContext.success(r); } else { return false; } return true; }
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals(ACTION_SEND_SMS)) { try { String phoneNumber = args.getString(0); String message = args.getString(1); String method = args.getString(2); if(method.equalsIgnoreCase("INTENT")){ invokeSMSIntent(phoneNumber, message); callbackContext.sendPluginResult(new PluginResult( PluginResult.Status.NO_RESULT)); } else{ sendSMS(phoneNumber, message); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); return true; } catch (JSONException ex) { callbackContext.sendPluginResult(new PluginResult( PluginResult.Status.JSON_EXCEPTION)); } } return false; }