List of usage examples for org.apache.cordova CordovaArgs getString
public String getString(int index) throws JSONException
From source file:br.com.hotforms.usewaze.UseWaze.java
License:Apache 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 otherwise. *///from w w w. j ava 2 s. c o m @Override public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { Log.v(TAG, "Executing action: " + action); if ("search".equals(action)) { callWaze("waze://?q=" + args.getString(0)); return true; } else if ("centerOnMap".equals(action)) { callWaze("waze://?ll=" + args.getString(0) + "," + args.getString(1) + "&z=" + args.getString(2)); return true; } else if ("navigateTo".equals(action)) { callWaze("waze://?ll=" + args.getString(0) + "," + args.getString(1) + "&navigate=yes"); return true; } return false; }
From source file:br.com.infobase.cordova.MintPlugin.java
@Override public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException { if ("initAndStartSession".equals(action)) { try {//from w w w . j a v a2 s.com Mint.initAndStartSession(cordova.getActivity(), args.getString(0)); callbackContext.success(); return true; } catch (Exception e) { callbackContext.success(e.getMessage()); return false; } } return false; }
From source file:com.blackberry.community.SimpleXpBeaconPlugin.java
License:Apache License
@Override public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException { LOG.d(TAG, "requested action = " + action); boolean validAction = false; if (action.equals(ACTION_INITIALISE_BLUETOOTH)) { LOG.d(TAG, "Processing Initialise Bluetooth request"); validAction = true;/*from w ww . j ava 2 s .co m*/ if (!deviceHasBtLeFeature()) { errorResponse(callbackContext, JSON_VALUE_NO_BT_LE_FEATURE); return validAction; } if (isBtInitialised()) { errorResponse(callbackContext, JSON_VALUE_BT_ALREADY_INITIALISED); return validAction; } BluetoothManager bluetoothManager = (BluetoothManager) cordova.getActivity() .getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { errorResponse(callbackContext, JSON_VALUE_NO_BT_ADAPTER); return validAction; } successResponse(callbackContext, JSON_VALUE_BT_INITIALISED); setBtInitialised(true); return validAction; } else if (action.equals(ACTION_TERMINATE_BLUETOOTH)) { LOG.d(TAG, "Processing Terminate Bluetooth request"); validAction = true; if (!isBtInitialised()) { errorResponse(callbackContext, JSON_VALUE_BT_NOT_INITIALISED); return validAction; } mBluetoothAdapter.disable(); mBluetoothAdapter = null; successResponse(callbackContext, JSON_VALUE_BT_TERMINATE); setBtInitialised(false); return validAction; } else if (action.equals(ACTION_PLUGIN_VERSION)) { LOG.d(TAG, "Processing Plugin Version request"); validAction = true; pluginVersionResponse(callbackContext, PLUGIN_VERSION); return validAction; } else if (action.equals(ACTION_START_MONITORING)) { LOG.d(TAG, "Processing Start Monitoring request"); validAction = true; if (!isBtInitialised()) { errorResponse(callbackContext, JSON_VALUE_BT_NOT_INITIALISED); return validAction; } if (isMonitoring()) { errorResponse(callbackContext, JSON_VALUE_ALREADY_MONITORING_FOR_I_BEACONS); return validAction; } if (!enableMonitoring(callbackContext)) { monitorFailResponse(callbackContext); return validAction; } setSupressMonitorCallback(false); monitorSuccessResponse(callbackContext); return validAction; } else if (action.equals(ACTION_STOP_MONITORING)) { LOG.d(TAG, "Processing Stop Monitoring request"); validAction = true; if (!isBtInitialised()) { errorResponse(callbackContext, JSON_VALUE_BT_NOT_INITIALISED); return validAction; } if (!isMonitoring()) { errorResponse(callbackContext, JSON_VALUE_NOT_MONITORING); return validAction; } if (!disableMonitoring(callbackContext)) { errorResponse(callbackContext, JSON_VALUE_FAILED_TO_DISABLE_MONITORING); return validAction; } successResponse(callbackContext, JSON_VALUE_STOPPED_MONITORING); return validAction; } else if (action.equals(ACTION_ADD_BEACON_UUID_TO_MONITOR)) { LOG.d(TAG, "Processing Add Beacon to Monitor request"); validAction = true; UUID beaconRegionUuid; try { beaconRegionUuid = UUID.fromString(args.getString(0)); if (!mBeaconRegionsToMonitor.contains(beaconRegionUuid)) { synchronized (SimpleXpBeaconPlugin.this) { mBeaconRegionsToMonitor.add(beaconRegionUuid); } successResponse(callbackContext, JSON_VALUE_UUID_ADDED); } else { errorResponse(callbackContext, JSON_VALUE_IBEACON_ALREADY_BEING_MONITORED); } } catch (NullPointerException e) { LOG.d(TAG, "" + JSON_VALUE_UUID_WAS_NULL); errorResponse(callbackContext, JSON_VALUE_UUID_WAS_NULL); } catch (IllegalArgumentException e) { LOG.d(TAG, "" + JSON_VALUE_UUID_WAS_IMPROPER_FORMAT); errorResponse(callbackContext, JSON_VALUE_UUID_WAS_IMPROPER_FORMAT); } return validAction; } else if (action.equals(ACTION_REMOVE_BEACON_UUID_TO_MONITOR)) { LOG.d(TAG, "Processing Remove Beacon to Monitor request"); validAction = true; UUID beaconRegionUuid; boolean removed = false; try { beaconRegionUuid = UUID.fromString(args.getString(0)); synchronized (SimpleXpBeaconPlugin.this) { ; removed = mBeaconRegionsToMonitor.remove(beaconRegionUuid); } if (removed) { successResponse(callbackContext, JSON_VALUE_BEACON_REMOVED); } else { errorResponse(callbackContext, JSON_VALUE_NO_MATCH_TO_BEACON_UUID); } } catch (NullPointerException e) { LOG.d(TAG, "" + JSON_VALUE_UUID_WAS_NULL); errorResponse(callbackContext, JSON_VALUE_UUID_WAS_NULL); } catch (IllegalArgumentException e) { LOG.d(TAG, "" + JSON_VALUE_UUID_WAS_IMPROPER_FORMAT); errorResponse(callbackContext, JSON_VALUE_UUID_WAS_IMPROPER_FORMAT); } return validAction; } else { LOG.d(TAG, "Unmatched action" + action); validAction = false; } return validAction; }
From source file:com.dtworkshop.inappcrossbrowser.WebViewBrowser.java
License:Apache License
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @return A PluginResult object with a status and message. *///from ww w.j a v a 2s.c o m 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) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } } 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) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } } // 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); } // perso a3d HORIZONTAL else if (BLANKH.equals(target)) { Log.d(LOG_TAG, "in blank horizontal"); result = showWebPage(url, features); } // 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("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 { return false; } return true; }
From source file:com.dw.bartinter.BarTinter.java
License:Open Source License
@Override public boolean execute(final String action, final CordovaArgs args, final CallbackContext callbackContext) throws JSONException { Log.v(TAG, "Executing action: " + action); final Activity activity = this.cordova.getActivity(); final Window window = activity.getWindow(); if ("_ready".equals(action)) { boolean statusBarVisible = (window.getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0; callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible)); return true; }//from w w w. jav a2 s . c om if ("statusBar".equals(action)) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { statusBar(args.getString(0)); } catch (JSONException ignore) { Log.e(TAG, "Invalid hexString argument."); } } }); return true; } if ("navigationBar".equals(action)) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { navigationBar(args.getString(0)); } catch (JSONException ignore) { Log.e(TAG, "Invalid hexString argument."); } } }); return true; } return false; }
From source file:com.emeth.cordova.ble.central.BLECentralPlugin.java
License:Apache License
@Override public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException { LOG.d(TAG, "action = " + action); if (bluetoothAdapter == null) { Activity activity = cordova.getActivity(); BluetoothManager bluetoothManager = (BluetoothManager) activity .getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); }// ww w. jav a 2s .c om boolean validAction = true; if (action.equals(SCAN)) { UUID[] serviceUUIDs = parseServiceUUIDList(args.getJSONArray(0)); int scanSeconds = args.getInt(1); findLowEnergyDevices(callbackContext, serviceUUIDs, scanSeconds); } else if (action.equals(START_SCAN)) { UUID[] serviceUUIDs = parseServiceUUIDList(args.getJSONArray(0)); findLowEnergyDevices(callbackContext, serviceUUIDs, -1); } else if (action.equals(STOP_SCAN)) { bluetoothAdapter.stopLeScan(this); callbackContext.success(); } else if (action.equals(LIST)) { listKnownDevices(callbackContext); } else if (action.equals(CONNECT)) { String macAddress = args.getString(0); connect(callbackContext, macAddress); } else if (action.equals(DISCONNECT)) { String macAddress = args.getString(0); disconnect(callbackContext, macAddress); } else if (action.equals(READ)) { String macAddress = args.getString(0); UUID serviceUUID = uuidFromString(args.getString(1)); UUID characteristicUUID = uuidFromString(args.getString(2)); read(callbackContext, macAddress, serviceUUID, characteristicUUID); } else if (action.equals(WRITE)) { String macAddress = args.getString(0); UUID serviceUUID = uuidFromString(args.getString(1)); UUID characteristicUUID = uuidFromString(args.getString(2)); byte[] data = args.getArrayBuffer(3); int type = BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT; write(callbackContext, macAddress, serviceUUID, characteristicUUID, data, type); } else if (action.equals(WRITE_WITHOUT_RESPONSE)) { String macAddress = args.getString(0); UUID serviceUUID = uuidFromString(args.getString(1)); UUID characteristicUUID = uuidFromString(args.getString(2)); byte[] data = args.getArrayBuffer(3); int type = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE; write(callbackContext, macAddress, serviceUUID, characteristicUUID, data, type); } else if (action.equals(NOTIFY)) { String macAddress = args.getString(0); UUID serviceUUID = uuidFromString(args.getString(1)); UUID characteristicUUID = uuidFromString(args.getString(2)); registerNotifyCallback(callbackContext, macAddress, serviceUUID, characteristicUUID); } else if (action.equals(IS_ENABLED)) { if (bluetoothAdapter.isEnabled()) { callbackContext.success(); } else { callbackContext.error("Bluetooth is disabled."); } } else if (action.equals(IS_CONNECTED)) { String macAddress = args.getString(0); if (peripherals.containsKey(macAddress) && peripherals.get(macAddress).isConnected()) { callbackContext.success(); } else { callbackContext.error("Not connected."); } } else if (action.equals(SETTINGS)) { Intent intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS); cordova.getActivity().startActivity(intent); callbackContext.success(); } else if (action.equals(ENABLE)) { enableBluetoothCallback = callbackContext; Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); cordova.startActivityForResult(this, intent, REQUEST_ENABLE_BLUETOOTH); } else { validAction = false; } return validAction; }
From source file:com.example.imageZoom.ActivityPlugin.java
License:Apache License
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackId The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. *//*from w w w . j ava2s . c o m*/ public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) { PluginResult result = new PluginResult(PluginResult.Status.OK, ""); try { if (action.equals("start")) { this.startActivity(args.getString(0), args.getString(1)); callbackContext.sendPluginResult(result); callbackContext.success(); return true; } } catch (JSONException e) { result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, "JSON Exception"); callbackContext.sendPluginResult(result); return false; } return false; }
From source file:com.github.michaelins.lightstatusbar.LightStatusBar.java
License:Apache License
/** * Executes the request and returns PluginResult. * * @param action/*from ww w . j a va 2 s. c om*/ * 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 otherwise. */ @Override public boolean execute(final String action, final CordovaArgs args, final CallbackContext callbackContext) throws JSONException { LOG.v(TAG, "Executing action: " + action); final Activity activity = this.cordova.getActivity(); final Window window = activity.getWindow(); if ("isSupported".equals(action)) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M || SystemBarTintManager.IsMiuiV6Plus()) { callbackContext.success("true"); } else { callbackContext.success("false"); } } }); return true; } if ("setStatusBarColor".equals(action)) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { webView.getView().setFitsSystemWindows(true); if (SystemBarTintManager.IsMiuiV6Plus()) { // MIUI6+ light status bar if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(window, true); } SystemBarTintManager tintManager = new SystemBarTintManager(activity); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintColor(Color.parseColor(args.getString(0))); tintManager.setStatusBarDarkMode(true, activity); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // 6.0+ light status bar window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); int uiOptions = window.getDecorView().getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; window.getDecorView().setSystemUiVisibility(uiOptions); setStatusBarBackgroundColor(args.getString(0)); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setStatusBarBackgroundColor(args.getString(0)); } } catch (JSONException ignore) { LOG.e(TAG, "Invalid hexString argument, use f.i. '#777777'"); } } }); return true; } if ("enable".equals(action)) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { } }); return true; } if ("disable".equals(action)) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { } }); return true; } return false; }
From source file:com.glasgowtiger.inappbrowser.InAppBrowser.java
License:Apache License
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackId The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. *///from ww w. j a v a 2 s .co m 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) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } } 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) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } } // 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("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 { return false; } return true; }
From source file:com.google.cordova.ChromeAlarms.java
License:Open Source License
private void create(final CordovaArgs args, final CallbackContext callbackContext) { try {//from w w w. j av a 2 s. co m String name = args.getString(0); Alarm alarm = new Alarm(name, (long) args.getDouble(1), (long) (args.optDouble(2) * 60000)); PendingIntent alarmPendingIntent = makePendingIntentForAlarm(name, PendingIntent.FLAG_CANCEL_CURRENT); alarmManager.cancel(alarmPendingIntent); if (alarm.periodInMillis == 0) { alarmManager.set(AlarmManager.RTC_WAKEUP, alarm.scheduledTime, alarmPendingIntent); } else { alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alarm.scheduledTime, alarm.periodInMillis, alarmPendingIntent); } callbackContext.success(); } catch (Exception e) { Log.e(LOG_TAG, "Could not create alarm", e); callbackContext.error("Could not create alarm"); } }