List of usage examples for org.apache.cordova PluginResult setKeepCallback
public void setKeepCallback(boolean b)
From source file:com.simplec.phonegap.plugins.videoplayer.VideoPlayer.java
License:BSD License
public boolean resume() { if (this.player != null) { videoView.resume();//from w w w . j ava 2 s .co m this.player.start(); JSONObject event = new JSONObject(); try { event.put("type", "playing"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } PluginResult eventResult = new PluginResult(PluginResult.Status.OK, event); eventResult.setKeepCallback(true); callbackContext.sendPluginResult(eventResult); return true; } return false; }
From source file:com.simplec.phonegap.plugins.videoplayer.VideoPlayer.java
License:BSD License
public boolean stop() { if (player != null) { JSONObject event = new JSONObject(); try {/*from ww w . j av a 2 s . c om*/ event.put("type", "completed"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } PluginResult errorResult = new PluginResult(PluginResult.Status.OK, event); errorResult.setKeepCallback(false); callbackContext.sendPluginResult(errorResult); if (player != null) { player.stop(); player.release(); player = null; } if (dialog != null) { dialog.dismiss(); dialog = null; } prepared = false; videoView = null; detector = null; callbackContext = null; return true; } return false; }
From source file:com.sldev.cordova.locale.LocalizationPlugin.java
License:Apache License
private void initLocaleChangeReceiver() { if (localeChangeReceiver != null) { return;//from w w w. ja v a 2s .com } localeChangeIntent = new IntentFilter(Intent.ACTION_LOCALE_CHANGED); localeChangeReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // update stored strings Iterator<String> jsonKeys = stringMap.keys(); while (jsonKeys.hasNext()) { String key = jsonKeys.next(); try { stringMap.put(key, getFromResource(key)); } catch (JSONException e) { // Log.e(TAG, "Can't update string with key: "+key); } } if (!localeChangeListeners.isEmpty()) { PluginResult result = new PluginResult(PluginResult.Status.OK, getLocale()); result.setKeepCallback(true); for (CallbackContext listener : localeChangeListeners.values()) { listener.sendPluginResult(result); } // localeChangeCallback.success(Locale.getDefault().getDisplayLanguage()); } } }; }
From source file:com.sldev.cordova.locale.LocalizationPlugin.java
License:Apache License
@Override public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException { if (action.equals(ACTION_GET)) { String resourceId = args.getString(0); String resString = get(resourceId); if (resString != null) { callbackContext.success(resString); } else {/*from ww w . jav a 2s. c om*/ callbackContext.error("Resource not found: " + resourceId); } } else if (action.equals(ACTION_GET_ALL)) { LOG.d(TAG, args.toString()); JSONArray resIds = null; try { resIds = args.getJSONArray(0); } catch (JSONException je) { // no res ids callbackContext.error("Resource ID Error: " + je.getLocalizedMessage()); } Log.d(TAG, "getAll: " + resIds); String resString = getAll(resIds); if (resString != null) { callbackContext.success(resString); } else { callbackContext.error("GETALL: Resource not found: " + resIds); } } else if (action.equals(ACTION_REGISTER_CALLBACK)) { localeChangeListeners.put(callbackContext.getCallbackId(), callbackContext); PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, callbackContext.getCallbackId()); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } else if (action.equals(ACTION_UNREGISTER_CALLBACK)) { String callbackId = args.getString(0); if (callbackId != null && localeChangeListeners.containsKey(callbackId)) { localeChangeListeners.remove(callbackId); } else { callbackContext.error("Callback ID invalid."); } } else if (action.equals((ACTION_GET_LOCALE))) { callbackContext.success(getLocale()); } else { callbackContext.error("Invalid action: " + action); } return true; }
From source file:com.tenforwardconsulting.bgloc.cordova.BackgroundGeolocationPlugin.java
License:Apache License
private void sendEvent(String name) { if (callbackContext == null) { return;//from w ww . j a v a 2 s. co m } JSONObject event = new JSONObject(); try { event.put("name", name); PluginResult result = new PluginResult(PluginResult.Status.OK, event); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } catch (JSONException e) { logger.error("Error sending event {}: {}", name, e.getMessage()); } }
From source file:com.tenforwardconsulting.bgloc.cordova.BackgroundGeolocationPlugin.java
License:Apache License
private void sendEvent(String name, JSONObject payload) { if (callbackContext == null) { return;//from w w w . ja va2 s . c om } JSONObject event = new JSONObject(); try { event.put("name", name); event.put("payload", payload); PluginResult result = new PluginResult(PluginResult.Status.OK, event); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } catch (JSONException e) { logger.error("Error sending event {}: {}", name, e.getMessage()); } }
From source file:com.tenforwardconsulting.bgloc.cordova.BackgroundGeolocationPlugin.java
License:Apache License
private void sendEvent(String name, Integer payload) { if (callbackContext == null) { return;// w w w. j a v a 2s. c o m } JSONObject event = new JSONObject(); try { event.put("name", name); event.put("payload", payload); PluginResult result = new PluginResult(PluginResult.Status.OK, event); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } catch (JSONException e) { logger.error("Error sending event {}: {}", name, e.getMessage()); } }
From source file:com.tenforwardconsulting.bgloc.cordova.BackgroundGeolocationPlugin.java
License:Apache License
private void sendError(PluginError error) { if (callbackContext == null) { return;/*from www . java 2s .c o m*/ } try { PluginResult result = new PluginResult(PluginResult.Status.ERROR, error.toJSONObject()); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } catch (JSONException je) { logger.error("Error sending error {}: {}", je.getMessage()); } }
From source file:com.tenforwardconsulting.cordova.bgloc.BackgroundGeolocationPlugin.java
License:Apache License
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException { for (int r : grantResults) { if (r == PackageManager.PERMISSION_DENIED) { Log.d(TAG, "Permission Denied!"); PluginResult result = new PluginResult(PluginResult.Status.ERROR, PERMISSION_DENIED_ERROR); result.setKeepCallback(true); this.callbackContext.sendPluginResult(result); return; }//from w ww . j a v a2 s .c o m } switch (requestCode) { case START_REQ_CODE: startBackgroundService(); break; } }
From source file:com.tmantman.nativecamera.NativeCameraLauncher.java
License:Apache License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult.Status status = PluginResult.Status.OK; String result = ""; this.callbackContext = callbackContext; try {/*from w w w . ja v a 2 s. co m*/ if (action.equals("takePicture")) { this.targetHeight = 0; this.targetWidth = 0; this.mQuality = 80; this.encodingType = args.getInt(5); this.targetHeight = args.getInt(4); this.targetWidth = args.getInt(3); this.mQuality = args.getInt(0); this.srcType = args.getInt(2); this.destType = args.getInt(1); this.takePicture(); PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT); r.setKeepCallback(true); callbackContext.sendPluginResult(r); return true; } return false; } catch (JSONException e) { e.printStackTrace(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); return true; } }