List of usage examples for org.apache.cordova PluginResult setKeepCallback
public void setKeepCallback(boolean b)
From source file:org.chromium.ChromeBluetoothSocket.java
License:Open Source License
private static PluginResult getMultipartEventsResult(String eventType, Status status, JSONObject info) { List<PluginResult> multipartMessage = new ArrayList<PluginResult>(); multipartMessage.add(new PluginResult(Status.OK, eventType)); multipartMessage.add(new PluginResult(Status.OK, info)); PluginResult result = new PluginResult(status, multipartMessage); result.setKeepCallback(true); return result; }
From source file:org.dartlang.phonegap.barometer.BarometerListener.java
License:Open Source License
/** * Executes the request.// w w w .j a va2 s. c o m * * @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 != BarometerListener.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 == BarometerListener.RUNNING) { this.stop(); } } else { // Unsupported action return false; } PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, ""); result.setKeepCallback(true); callbackContext.sendPluginResult(result); return true; }
From source file:org.dartlang.phonegap.barometer.BarometerListener.java
License:Open Source License
private void win() { // Success return object PluginResult result = new PluginResult(PluginResult.Status.OK, this.getPressureJSON()); result.setKeepCallback(true); callbackContext.sendPluginResult(result); }
From source file:org.dartlang.phonegap.gyroscope.GyroscopeListener.java
License:Open Source License
private void win() { // Success return object PluginResult result = new PluginResult(PluginResult.Status.OK, this.getAngularSpeedJSON()); result.setKeepCallback(true); callbackContext.sendPluginResult(result); }
From source file:org.dartlang.phonegap.thermometer.ThermometerListener.java
License:Open Source License
/** * Executes the request.// ww w . j a va 2 s .c o m * * @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 != ThermometerListener.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 == ThermometerListener.RUNNING) { this.stop(); } } else { // Unsupported action return false; } PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, ""); result.setKeepCallback(true); callbackContext.sendPluginResult(result); return true; }
From source file:org.dartlang.phonegap.thermometer.ThermometerListener.java
License:Open Source License
private void win() { // Success return object PluginResult result = new PluginResult(PluginResult.Status.OK, this.getTemperatureJSON()); result.setKeepCallback(true); callbackContext.sendPluginResult(result); }
From source file:org.flexites.plugin.GoogleGPSLocation.java
License:Apache License
public void win(Location loc, CallbackContext callbackContext, boolean keepCallback) { mLastLocation = loc;/*from w w w.ja va 2 s . c o m*/ PluginResult result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(loc)); result.setKeepCallback(keepCallback); callbackContext.sendPluginResult(result); }
From source file:org.jboss.aerogear.cordova.geo.GeofencingPlugin.java
License:Open Source License
private boolean invokeService(final PluginCommand pluginCommand) throws JSONException { if (service != null) { if ("register".equals(pluginCommand.getAction())) { callbackContext = pluginCommand.getCallbackContext(); PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); result.setKeepCallback(true); callbackContext.sendPluginResult(result); if (cachedRegionEvent != null) { sendNotification(cachedRegionEvent); }/*from w w w. j a v a2 s. co m*/ return true; } if ("addRegion".equals(pluginCommand.getAction())) { JSONObject params = parseParameters(pluginCommand.getData()); String id = params.getString("fid"); Log.d(TAG, "adding region " + id); service.addRegion(id, params.getDouble("latitude"), params.getDouble("longitude"), (float) params.getInt("radius")); pluginCommand.getCallbackContext().success(); return true; } if ("removeRegion".equals(pluginCommand.getAction())) { JSONObject params = parseParameters(pluginCommand.getData()); String id = params.getString("fid"); service.removeRegion(id); return true; } if ("getWatchedRegionIds".equals(pluginCommand.getAction())) { pluginCommand.getCallbackContext().success(new JSONArray(service.getWatchedRegionIds())); return true; } return false; } else { pendingActions.add(pluginCommand); timer.schedule(new TimerTask() { @Override public void run() { if (service != null) { for (PluginCommand args : pendingActions) { try { invokeService(args); } catch (JSONException e) { pluginCommand.callbackContext.error(e.getMessage()); } } pendingActions.clear(); cancel(); } } }, 2000); return true; } }
From source file:org.jboss.aerogear.cordova.geo.GeofencingPlugin.java
License:Open Source License
private static void sendNotification(JSONObject regionEvent) { if (callbackContext != null) { PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, regionEvent); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } else {// w w w .j a v a2 s .co m cachedRegionEvent = regionEvent; } }
From source file:org.jboss.aerogear.cordova.push.PushPlugin.java
License:Open Source License
@Override public boolean execute(String action, JSONArray data, final CallbackContext callbackContext) { Log.v(TAG, "execute: action=" + action); foreground = true;//from ww w . j ava 2 s .c o m if (REGISTER.equals(action)) { Log.v(TAG, "execute: data=" + data.toString()); try { context = callbackContext; JSONObject pushConfig = parseConfig(data); saveConfig(pushConfig); sendMetrics = Boolean.parseBoolean(preferences.getString(SEND_METRICS, "false")); cordova.getThreadPool().execute(new Runnable() { @Override public void run() { register(callbackContext); } }); } catch (JSONException e) { callbackContext.error(e.getMessage()); return false; } if (cachedMessage != null) { Log.v(TAG, "sending cached extras"); sendMessage(cachedMessage); cachedMessage = null; } return true; } else if (UNREGISTER.equals(action)) { unRegister(callbackContext); return true; } else if (MESSAGE_CHANNEL.equals(action)) { channel = callbackContext; PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); result.setKeepCallback(true); callbackContext.sendPluginResult(result); return true; } else { callbackContext.error("Invalid action : " + action); } return false; }