List of usage examples for org.apache.cordova PluginResult setKeepCallback
public void setKeepCallback(boolean b)
From source file:com.gotojmp.cordova.NativeAd.NativeAd.java
License:Apache License
/** * Executes the request and returns PluginResult. * * @param action the action to execute./* w w w .ja v a 2 s. c o m*/ * @param args JSONArry of arguments for the plugin. * @param callbackContext the callbackContext used when calling back into JavaScript. * @return A PluginResult object with a status and message. */ public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { if (action.equals("open")) { final String html = args.getString(0); final int adw = this.dpToPixels(args.getInt(1)); final int adh = this.dpToPixels(args.getInt(2)); final String showAt = args.optString(3); final String closeAt = args.optString(4); final int cw = this.dpToPixels(60); final int ch = this.dpToPixels(20); cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { NativeAdView adView = new NativeAdView(cordova.getActivity(), getNativeAd(), adw, adh, cw, ch, closeAt); adView.id = ++_adId; adView.load(html); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); if (showAt.equals("center")) { layoutParams.gravity = Gravity.CENTER; } else if (showAt.equals("top")) { layoutParams.gravity = Gravity.TOP; } else { layoutParams.gravity = Gravity.BOTTOM; } cordova.getActivity().addContentView(adView, layoutParams); ads.put("ad-" + adView.id, adView); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, adView.id); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } }); } else if (action.equals("close")) { final int id = args.getInt(0); if (id > 0) { cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { NativeAdView adView = ads.get("ad-" + id); if (adView != null) { adView.closeAdView(false); } } }); } } else if (action.equals("onClose")) { this.onCloseCallbackContext = callbackContext; PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, 0); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } else if (action.equals("onClick")) { this.onClickCallbackContext = callbackContext; PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, 0); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } else if (action.equals("openUrl")) { this.callbackContext = callbackContext; final String url = args.getString(0); String t = args.optString(1); if (t == null || t.equals("") || t.equals(NULL)) { t = SELF; } final String target = t; final HashMap<String, Boolean> features = parseFeature(args.optString(2)); LOG.d(LOG_TAG, "target = " + target); this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { String result = ""; // SELF if (SELF.equals(target)) { LOG.d(LOG_TAG, "in self"); /* This code exists for compatibility between 3.x and 4.x versions of Cordova. * Previously the Config class had a static method, isUrlWhitelisted(). That * responsibility has been moved to the plugins, with an aggregating method in * PluginManager. */ Boolean shouldAllowNavigation = null; if (url.startsWith("javascript:")) { shouldAllowNavigation = true; } if (shouldAllowNavigation == null) { try { Method iuw = Config.class.getMethod("isUrlWhiteListed", String.class); shouldAllowNavigation = (Boolean) iuw.invoke(null, url); } catch (NoSuchMethodException e) { LOG.d(LOG_TAG, e.getLocalizedMessage()); } catch (IllegalAccessException e) { LOG.d(LOG_TAG, e.getLocalizedMessage()); } catch (InvocationTargetException e) { LOG.d(LOG_TAG, e.getLocalizedMessage()); } } if (shouldAllowNavigation == null) { try { Method gpm = webView.getClass().getMethod("getPluginManager"); PluginManager pm = (PluginManager) gpm.invoke(webView); Method san = pm.getClass().getMethod("shouldAllowNavigation", String.class); shouldAllowNavigation = (Boolean) san.invoke(pm, url); } catch (NoSuchMethodException e) { LOG.d(LOG_TAG, e.getLocalizedMessage()); } catch (IllegalAccessException e) { LOG.d(LOG_TAG, e.getLocalizedMessage()); } catch (InvocationTargetException e) { LOG.d(LOG_TAG, e.getLocalizedMessage()); } } // load in webview if (Boolean.TRUE.equals(shouldAllowNavigation)) { LOG.d(LOG_TAG, "loading in webview"); webView.loadUrl(url); } //Load the dialer else if (url.startsWith(WebView.SCHEME_TEL)) { try { LOG.d(LOG_TAG, "loading in dialer"); Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse(url)); cordova.getActivity().startActivity(intent); } catch (android.content.ActivityNotFoundException e) { LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString()); } } // load in NativeAd else { LOG.d(LOG_TAG, "loading in NativeAd"); result = showWebPage(url, features); } } // SYSTEM else if (SYSTEM.equals(target)) { LOG.d(LOG_TAG, "in system"); result = openExternal(url); } // BLANK - or anything else else { LOG.d(LOG_TAG, "in blank"); result = showWebPage(url, features); } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } }); } else if (action.equals("openDeepLink")) { this.callbackContext = callbackContext; final String deepLink = args.getString(0); final String url = args.getString(1); final HashMap<String, Boolean> features = parseFeature(args.optString(2)); this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { String result = ""; final Intent customSchemeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(deepLink)); final PackageManager packageManager = cordova.getActivity().getApplicationContext() .getPackageManager(); final List<ResolveInfo> resolvedActivities = packageManager .queryIntentActivities(customSchemeIntent, 0); if (resolvedActivities.size() > 0) { cordova.getActivity().startActivity(customSchemeIntent); } else { result = showWebPage(url, features); } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } }); } else { return false; } return true; }
From source file:com.gotojmp.cordova.uid.UID.java
License:MIT 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 True if the action was valid, false if not. *///ww w .j a v a2 s .c o m @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { this.callbackContext = callbackContext; if (action.equals("getUID")) { JSONObject r = new JSONObject(); r.put("UUID", UID.uuid); r.put("IMEI", UID.imei); r.put("IMSI", UID.imsi); r.put("ICCID", UID.iccid); r.put("MAC", UID.mac); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, r); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); return true; } else { return false; } }
From source file:com.grumpysailor.cordova.devicerotationvector.RotationVectorListener.java
License:Apache License
/** * Executes the request./*www . j av a 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 != RotationVectorListener.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 == RotationVectorListener.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:com.grumpysailor.cordova.devicerotationvector.RotationVectorListener.java
License:Apache License
private void win() { // Success return object PluginResult result = new PluginResult(PluginResult.Status.OK, this.getRotationJSON()); result.setKeepCallback(true); callbackContext.sendPluginResult(result); }
From source file:com.grumpysailor.cordova.magnetsensor.MagnetSensor.java
License:Apache License
/** * Executes the request./*from w w w . j a v a 2 s. co 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 != MagnetSensor.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 == MagnetSensor.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:com.grumpysailor.cordova.magnetsensor.MagnetSensor.java
License:Apache License
private void win() { // Success return object PluginResult result = new PluginResult(PluginResult.Status.OK, ""); result.setKeepCallback(true); callbackContext.sendPluginResult(result); }
From source file:com.heyzap.cordova.ads.CDVHeyzapAbstractPlugin.java
License:Open Source License
public void addEventListener(final JSONArray args, final CallbackContext callbackContext) { JSONArray callbackData = new JSONArray(); callbackData.put("OK"); if (listener == null) { listener = new CDVListener(callbackContext); PluginResult result = new PluginResult(PluginResult.Status.OK, callbackData); result.setKeepCallback(true); callbackContext.sendPluginResult(result); setListener(listener);/*from w w w.ja v a 2 s.co m*/ } else { callbackContext.success(callbackData); } }
From source file:com.heyzap.cordova.ads.CDVListener.java
License:Open Source License
private void dispatchCallback(String callbackId, JSONArray data) { if (context != null) { JSONArray callbackData = new JSONArray(); callbackData.put(callbackId);//from w w w . j a va 2 s .co m for (int i = 0; i < data.length(); i++) { try { callbackData.put(data.get(i)); } catch (JSONException e) { Log.e(TAG, "Could not add data to callback."); e.printStackTrace(); } } PluginResult result = new PluginResult(PluginResult.Status.OK, callbackData); result.setKeepCallback(true); context.sendPluginResult(result); } }
From source file:com.ibm.mobilefirstplatform.clientsdk.cordovaplugins.push.CDVBMSPush.java
License:Apache License
private void registerNotificationsCallback(final CallbackContext callbackContext) { notificationCallback = callbackContext; if (!ignoreIncomingNotifications) { cordova.getThreadPool().execute(new Runnable() { public void run() { notificationListener = new MFPPushNotificationListener() { @Override// w ww. ja v a 2 s . c o m public void onReceive(final MFPSimplePushNotification message) { try { JSONObject notification = new JSONObject(); notification.put("message", message.getAlert()); notification.put("payload", message.getPayload()); PluginResult result = new PluginResult(PluginResult.Status.OK, notification); result.setKeepCallback(true); notificationCallback.sendPluginResult(result); } catch (JSONException e) { PluginResult result = new PluginResult(PluginResult.Status.ERROR, e.toString()); result.setKeepCallback(true); notificationCallback.sendPluginResult(result); } } }; MFPPush.getInstance().listen(notificationListener); } }); } else { callbackContext.error( "Error: Called registerNotificationsCallback() after IgnoreIncomingNotifications was set"); } }
From source file:com.ibm.mobilefirstplatform.clientsdk.cordovaplugins.push.CDVMFPPush.java
License:Apache License
private void registerNotificationsCallback(final CallbackContext callbackContext) { pushLogger.debug("In registerNotificationsCallback"); notificationCallback = callbackContext; if (!ignoreIncomingNotifications) { cordova.getThreadPool().execute(new Runnable() { public void run() { notificationListener = new MFPPushNotificationListener() { @Override/*from ww w . j a v a2 s . co m*/ public void onReceive(final MFPSimplePushNotification message) { try { pushLogger.debug("Push notification received: " + message.toString()); JSONObject notification = new JSONObject(); notification.put("message", message.getAlert()); notification.put("payload", message.getPayload()); PluginResult result = new PluginResult(PluginResult.Status.OK, notification); result.setKeepCallback(true); notificationCallback.sendPluginResult(result); } catch (JSONException e) { PluginResult result = new PluginResult(PluginResult.Status.ERROR, e.toString()); result.setKeepCallback(true); notificationCallback.sendPluginResult(result); } } }; MFPPush.getInstance().listen(notificationListener); } }); } else { pushLogger.warn( "Notification handling is currently off. Turn it back on by calling setIgnoreIncomingNotifications(true)"); callbackContext.error( "Error: Called registerNotificationsCallback() after IgnoreIncomingNotifications was set"); } }