List of usage examples for org.apache.cordova PluginResult setKeepCallback
public void setKeepCallback(boolean b)
From source file:net.easysol.dsb.DSBSDKCordovaPlugin.java
public void onBrowsingPharmingEvent(Map<String, String> eventMap) { Log.d(TAG, "report pharming events "); if (this.callbackContextBrowsingPharming != null) { Log.d(TAG, "From pharming events "); try {/* ww w. j a va 2 s .com*/ PluginResult result = new PluginResult(Status.OK, new JSONObject(eventMap)); result.setKeepCallback(true); this.callbackContextBrowsingPharming.sendPluginResult(result); } catch (Exception e) { Log.i(TAG, e.getMessage()); } } }
From source file:net.easysol.dsb.DSBSDKCordovaPlugin.java
public void onMalwareAppScanEvent(Map<String, String> eventMap) { Log.d(TAG, "report malware scaning events"); if (this.callbackContextMalwareAppScan != null) { Log.d(TAG, "From malware scaning events "); try {/*from ww w. j a va 2s . c om*/ PluginResult result = new PluginResult(Status.OK, new JSONObject(eventMap)); result.setKeepCallback(true); this.callbackContextMalwareAppScan.sendPluginResult(result); } catch (Exception e) { Log.i(TAG, e.getMessage()); } } }
From source file:net.easysol.dsb.DSBSDKCordovaPlugin.java
public void onCertificateFailingResponse() { Log.d(TAG, "setCertificateFailingListener response "); if (this.callbackContextCertificateFailing != null) { Log.d(TAG, "From setCertificateFailingListener callback"); PluginResult result = new PluginResult(Status.OK); result.setKeepCallback(true); this.callbackContextCertificateFailing.sendPluginResult(result); }/*from w w w . j a v a 2 s .c o m*/ }
From source file:net.easysol.dsb.DSBSDKCordovaPlugin.java
public void onRiskBlockingConnectionResponse(Map<String, Boolean> response) { Log.d(TAG, "onRiskBlockingConnectionResponse reponse"); if (this.callbackContextRiskBlockingConnection != null) { Log.d(TAG, "From onRiskBlockingConnectionResponse callback"); try {// www . j av a2 s . c om PluginResult result = new PluginResult(Status.OK, new JSONObject(response)); result.setKeepCallback(true); this.callbackContextRiskBlockingConnection.sendPluginResult(result); } catch (Exception e) { Log.i(TAG, e.getMessage()); } } }
From source file:net.easysol.dsb.DSBSDKCordovaPlugin.java
public void onSuspiciousOverlay(OverlapingApp app) { Log.d(TAG, "onSuspiciousOverlay reponse"); if (this.callbackContextOverlayAttack != null) { Log.d(TAG, "From onSuspiciousOverlay callback"); try {//from w w w.ja va2s . c o m JSONObject objReponse = new JSONObject(); objReponse.put("appName", app.appName); objReponse.put("packageName", app.packageName); objReponse.put("versionName", app.versionName); objReponse.put("versionCode", app.versionCode); objReponse.put(App.PATH, app.path); objReponse.put(MalwareApp.SIGNATURE, app.signature); PluginResult result = new PluginResult(Status.OK, objReponse); result.setKeepCallback(true); this.callbackContextOverlayAttack.sendPluginResult(result); } catch (Exception e) { Log.i(TAG, e.getMessage()); } } }
From source file:nib.plugins.deviceorientation.IRRDeviceOrientation.java
License:Apache License
@Override protected void pluginInitialize() { Activity main = cordova.getActivity(); orientationListener = new OrientationEventListener(main, SensorManager.SENSOR_DELAY_NORMAL) { @Override/*from ww w. java 2s.com*/ public void onOrientationChanged(int orientation) { int newRotateTo = lastRotatedTo; if (orientation >= 360 + PORTRAIT - THRESHOLD && orientation < 360 || orientation >= 0 && orientation <= PORTRAIT + THRESHOLD) { newRotateTo = 0; PluginResult result = new PluginResult(PluginResult.Status.OK, PORTRAIT_PRIMARY); result.setKeepCallback(true); } else if (orientation >= LANDSCAPE - THRESHOLD && orientation <= LANDSCAPE + THRESHOLD) { newRotateTo = 90; PluginResult result = new PluginResult(PluginResult.Status.OK, LANDSCAPE_PRIMARY); result.setKeepCallback(true); } else if (orientation >= REVERSE_PORTRAIT - THRESHOLD && orientation <= REVERSE_PORTRAIT + THRESHOLD) { newRotateTo = 180; PluginResult result = new PluginResult(PluginResult.Status.OK, PORTRAIT_SECONDARY); result.setKeepCallback(true); } else if (orientation >= REVERSE_LANDSCAPE - THRESHOLD && orientation <= REVERSE_LANDSCAPE + THRESHOLD) { newRotateTo = -90; PluginResult result = new PluginResult(PluginResult.Status.OK, LANDSCAPE_SECONDARY); result.setKeepCallback(true); } if (newRotateTo != lastRotatedTo) { lastRotatedTo = newRotateTo; } } }; }
From source file:nl.afas.cordova.plugin.secureLocalStorage.SecureLocalStorage.java
License:Open Source License
@Override public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException { final ActionId actionId = getActionId(action); if (actionId == ActionId.ACTION_NONE) { return false; }// ww w. j a va2s . co m PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); // start thread _cordova.getThreadPool().execute(new Runnable() { @Override public void run() { try { handleAction(actionId, args, callbackContext); } catch (SecureLocalStorageException ex) { handleException(ex, callbackContext); } catch (JSONException ex) { handleException(ex, callbackContext); } } }); return true; }
From source file:nl.afas.cordova.plugin.secureLocalStorage.SecureLocalStorage.java
License:Open Source License
private void handleException(Exception ex, CallbackContext callbackContext) { ex.printStackTrace();/*from w w w .j a v a 2 s . c om*/ StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); ex.printStackTrace(pw); pw.close(); PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, pw.toString()); pluginResult.setKeepCallback(false); callbackContext.sendPluginResult(pluginResult); }
From source file:nl.afas.cordova.plugin.secureLocalStorage.SecureLocalStorage.java
License:Open Source License
private void handleAction(ActionId actionId, JSONArray args, CallbackContext callbackContext) throws SecureLocalStorageException, JSONException { if (Build.VERSION.SDK_INT < 18) { throw new SecureLocalStorageException("Invalid API Level (must be >= 18"); }//from w ww . j ava 2 s . c om File file = _cordova.getActivity().getBaseContext().getFileStreamPath(SECURELOCALSTORAGEFILE); HashMap<String, String> hashMap = new HashMap<String, String>(); // lock the access lock.lock(); try { KeyStore keyStore = initKeyStore(); // clear just deletes the storage file if (actionId == ActionId.ACTION_CLEAR) { clear(file, keyStore); try { keyStore = initKeyStore(); generateKey(keyStore); } catch (SecureLocalStorageException ex2) { } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); pluginResult.setKeepCallback(false); callbackContext.sendPluginResult(pluginResult); } else { // clear localStorage if invalid if (actionId == ActionId.ACTION_CLEARIFINVALID) { try { checkValidity(); if (file.exists()) { // save hashmap for re-initializing certificate hashMap = readAndDecryptStorage(keyStore); // only clear file if untouched for 10 days if ((new Date().getTime() - file.lastModified()) > (10 * 24 * 60 * 60 * 1000)) { clear(file, keyStore); keyStore = initKeyStore(); generateKey(keyStore); writeAndEncryptStorage(keyStore, hashMap); } } } catch (SecureLocalStorageException ex) { clear(file, keyStore); try { keyStore = initKeyStore(); generateKey(keyStore); } catch (SecureLocalStorageException ex2) { } } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); pluginResult.setKeepCallback(false); callbackContext.sendPluginResult(pluginResult); } else { // initialize for reading later if (!file.exists()) { // generate key and store in keyStore generateKey(keyStore); writeAndEncryptStorage(keyStore, hashMap); } // read current storage hashmap hashMap = readAndDecryptStorage(keyStore); String key = args.getString(0); if (key == null || key.length() == 0) { throw new SecureLocalStorageException("Key is empty or null"); } // handle the methods. Note: getItem uses callback if (actionId == ActionId.ACTION_GETITEM) { if (hashMap.containsKey(key)) { if (callbackContext != null) { String value = hashMap.get(key); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, value); pluginResult.setKeepCallback(false); callbackContext.sendPluginResult(pluginResult); } } else { // return null when not found PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, (String) null); pluginResult.setKeepCallback(false); callbackContext.sendPluginResult(pluginResult); } } else if (actionId == ActionId.ACTION_SETITEM) { String value = args.getString(1); if (value == null) { throw new SecureLocalStorageException("Value is null"); } hashMap.put(key, value); // store back writeAndEncryptStorage(keyStore, hashMap); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); pluginResult.setKeepCallback(false); callbackContext.sendPluginResult(pluginResult); } else if (actionId == ActionId.ACTION_REMOVEITEM) { hashMap.remove(key); // store back writeAndEncryptStorage(keyStore, hashMap); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); pluginResult.setKeepCallback(false); callbackContext.sendPluginResult(pluginResult); } } } } finally { lock.unlock(); } }
From source file:nl.anewspring.cordova.inappbrowser.InAppBrowser.java
License:Apache License
/** * Executes the request and returns PluginResult. * * @param action the action to execute./*from ww w .ja v a 2 s . co m*/ * @param args JSONArray 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")) { 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 InAppBrowser else { LOG.d(LOG_TAG, "loading in InAppBrowser"); 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("close")) { closeDialog(); } else if (action.equals("injectScriptCode")) { String jsWrapper = null; if (args.getBoolean(1)) { jsWrapper = String.format("(function(){prompt(JSON.stringify([eval(%%s)]), 'gap-iab://%s')})()", callbackContext.getCallbackId()); } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectScriptFile")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('script'); c.src = %%s; c.onload = function() { prompt('', 'gap-iab://%s'); }; d.body.appendChild(c); })(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('script'); c.src = %s; d.body.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectStyleCode")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('style'); c.innerHTML = %%s; d.body.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('style'); c.innerHTML = %s; d.body.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectStyleFile")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%s; d.head.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %s; d.head.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("show")) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { dialog.show(); } }); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); pluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(pluginResult); } else if (action.equals("hide")) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { dialog.hide(); } }); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); pluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(pluginResult); } else { return false; } return true; }