List of usage examples for org.apache.cordova CordovaArgs getJSONObject
public JSONObject getJSONObject(int index) throws JSONException
From source file:com.google.cordova.ChromeIdentity.java
License:Open Source License
private TokenDetails getTokenDetailsFromArgs(CordovaArgs args) throws JSONException { TokenDetails tokenDetails = new TokenDetails(); JSONObject tokenDetailsObject = args.getJSONObject(0); tokenDetails.interactive = tokenDetailsObject.getBoolean("interactive"); return tokenDetails; }
From source file:com.google.cordova.ChromeSocket.java
License:Open Source License
private void sendTo(CordovaArgs args, final CallbackContext context) throws JSONException { JSONObject opts = args.getJSONObject(0); int socketId = opts.getInt("socketId"); String address = opts.getString("address"); int port = opts.getInt("port"); byte[] data = args.getArrayBuffer(1); SocketData sd = sockets.get(Integer.valueOf(socketId)); if (sd == null) { Log.e(LOG_TAG, "No socket with socketId " + socketId); return;// w ww.ja va2s .c o m } int result = sd.sendTo(data, address, port); if (result <= 0) { context.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, result)); } else { context.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }
From source file:com.google.cordova.ChromeStorage.java
License:Open Source License
private void set(final CordovaArgs args, final CallbackContext callbackContext) { executorService.execute(new Runnable() { @Override//from w w w.j a va2s . co m public void run() { try { boolean sync = args.getBoolean(0); JSONObject jsonObject = (JSONObject) args.getJSONObject(1); JSONArray keyArray = jsonObject.names(); JSONObject oldValues = new JSONObject(); if (keyArray != null) { List<String> keys = JSONUtils.toStringList(keyArray); JSONObject storage = getStorage(sync); for (String key : keys) { Object oldValue = storage.opt(key); if (oldValue != null) { oldValues.put(key, oldValue); } storage.put(key, jsonObject.get(key)); } setStorage(sync, storage); } callbackContext.success(oldValues); } catch (Exception e) { Log.e(LOG_TAG, "Could not update storage", e); callbackContext.error("Could not update storage"); } } }); }
From source file:com.microsoft.c3p.cordova.C3PCordovaPlugin.java
License:Open Source License
@Override public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { try {//from w w w .j a v a2 s . c o m if (JavaScriptBridge.CallType.GET_STATIC_PROPERTY.equals(action)) { String type = args.getString(0); String property = args.getString(1); JavaScriptValue value = this.bridge.getStaticProperty(type, property); C3PCordovaPlugin.returnResult(value, callbackContext); } else if (JavaScriptBridge.CallType.SET_STATIC_PROPERTY.equals(action)) { String type = args.getString(0); String property = args.getString(1); Object value = args.opt(2); this.bridge.setStaticProperty(type, property, JSValue.fromObject(value)); callbackContext.success(); } else if (JavaScriptBridge.CallType.INVOKE_STATIC_METHOD.equals(action)) { String type = args.getString(0); String method = args.getString(1); JSONArray arguments = args.getJSONArray(2); ChainablePromise<JavaScriptValue> returnValue = this.bridge.invokeStaticMethod(type, method, JSValue.fromObject(arguments)); C3PCordovaPlugin.returnFutureResult(returnValue, callbackContext, false); } else if (JavaScriptBridge.CallType.ADD_STATIC_EVENT_LISTENER.equals(action)) { String type = args.getString(0); String event = args.getString(1); Consumer<JavaScriptValue> eventListener = new Consumer<JavaScriptValue>() { @Override public void accept(JavaScriptValue eventObject) { C3PCordovaPlugin.returnResult(eventObject, callbackContext, true); } }; this.bridge.addStaticEventListener(type, event, eventListener); this.eventListenerMap.put(callbackContext.getCallbackId(), eventListener); C3PCordovaPlugin.returnResult(JSValue.fromString(callbackContext.getCallbackId()), callbackContext, true); } else if (JavaScriptBridge.CallType.REMOVE_STATIC_EVENT_LISTENER.equals(action)) { String type = args.getString(0); String event = args.getString(1); String registrationToken = args.getString(2); Consumer<JavaScriptValue> eventListener = this.eventListenerMap.get(registrationToken); if (eventListener != null) { this.bridge.removeStaticEventListener(type, event, eventListener); this.eventListenerMap.remove(registrationToken); } else { Log.w(TAG, "Event registration not found for callbackId: " + registrationToken); } callbackContext.success(); } else if (JavaScriptBridge.CallType.CREATE_INSTANCE.equals(action)) { String type = args.getString(0); JSONArray arguments = args.getJSONArray(1); JavaScriptValue instance = this.bridge.createInstance(type, JSValue.fromObject(arguments)); callbackContext.success((JSONObject) JSValue.toObject(instance)); } else if (JavaScriptBridge.CallType.RELEASE_INSTANCE.equals(action)) { JSONObject instance = args.getJSONObject(0); this.bridge.releaseInstance(JSValue.fromObject(instance)); callbackContext.success(); } else if (JavaScriptBridge.CallType.GET_PROPERTY.equals(action)) { JSONObject instance = args.getJSONObject(0); String property = args.getString(1); JavaScriptValue value = this.bridge.getProperty(JSValue.fromObject(instance), property); C3PCordovaPlugin.returnResult(value, callbackContext); } else if (JavaScriptBridge.CallType.SET_PROPERTY.equals(action)) { JSONObject instance = args.getJSONObject(0); String property = args.getString(1); Object value = args.opt(2); this.bridge.setProperty(JSValue.fromObject(instance), property, JSValue.fromObject(value)); callbackContext.success(); } else if (JavaScriptBridge.CallType.INVOKE_METHOD.equals(action)) { JSONObject instance = args.getJSONObject(0); String method = args.getString(1); JSONArray arguments = args.getJSONArray(2); ChainablePromise<JavaScriptValue> returnValue = this.bridge .invokeMethod(JSValue.fromObject(instance), method, JSValue.fromObject(arguments)); C3PCordovaPlugin.returnFutureResult(returnValue, callbackContext, false); } else if (JavaScriptBridge.CallType.ADD_EVENT_LISTENER.equals(action)) { JSONObject instance = args.getJSONObject(0); String event = args.getString(1); Consumer<JavaScriptValue> eventListener = new Consumer<JavaScriptValue>() { @Override public void accept(JavaScriptValue eventObject) { C3PCordovaPlugin.returnResult(eventObject, callbackContext, true); } }; this.bridge.addEventListener(JSValue.fromObject(instance), event, eventListener); this.eventListenerMap.put(callbackContext.getCallbackId(), eventListener); C3PCordovaPlugin.returnResult(JSValue.fromString(callbackContext.getCallbackId()), callbackContext, true); } else if (JavaScriptBridge.CallType.REMOVE_EVENT_LISTENER.equals(action)) { JSONObject instance = args.getJSONObject(0); String event = args.getString(1); String registrationToken = args.getString(2); Consumer<JavaScriptValue> eventListener = this.eventListenerMap.get(registrationToken); if (eventListener != null) { this.bridge.removeEventListener(JSValue.fromObject(instance), event, eventListener); this.eventListenerMap.remove(registrationToken); } else { Log.w(TAG, "Event registration not found for callbackId: " + registrationToken); } callbackContext.success(); } else { throw new IllegalArgumentException("Invalid action: " + action); } } catch (IllegalArgumentException iaex) { throw new RuntimeException(iaex); } catch (InvocationTargetException itex) { throw new RuntimeException(itex.getTargetException()); } return true; }
From source file:com.simplec.phonegap.plugins.videoplayer.VideoPlayer.java
License:BSD License
public boolean play(CordovaArgs args, final CallbackContext callbackContext) { Log.v(LOG_TAG, "stopping if necessary"); stop();/*from w ww . java 2 s . c o m*/ Log.v(LOG_TAG, "playing"); try { CordovaResourceApi resourceApi = webView.getResourceApi(); String target = args.getString(0); JSONObject optionsTmp = new JSONObject(); try { optionsTmp = args.getJSONObject(1); } catch (Exception e) { // gobble. no options sent } final JSONObject options = optionsTmp; String fileUriStr; try { Uri targetUri = resourceApi.remapUri(Uri.parse(target)); fileUriStr = targetUri.toString(); } catch (IllegalArgumentException e) { fileUriStr = target; } Log.v(LOG_TAG, fileUriStr); Log.v(LOG_TAG, "playing file: " + fileUriStr); if (fileUriStr.startsWith("file:")) { final String path = stripFileProtocol(fileUriStr); File f = new File(path); if (!f.exists()) { Log.v(LOG_TAG, "does not exist: " + fileUriStr); callbackContext.error("video does not exist"); return true; } Log.v(LOG_TAG, "playing path: " + path); // Create dialog in new thread cordova.getActivity().runOnUiThread(new Runnable() { public void run() { Log.v(LOG_TAG, "openVideoDialog"); openVideoDialog(path, options, callbackContext); } }); } else if (fileUriStr.startsWith("http:") || fileUriStr.startsWith("https:")) { final String path = fileUriStr; Log.v(LOG_TAG, "playing URL: " + path); // Create dialog in new thread cordova.getActivity().runOnUiThread(new Runnable() { public void run() { Log.v(LOG_TAG, "openVideoDialog"); openVideoDialog(path, options, callbackContext); } }); } else { Log.v(LOG_TAG, "unknown protocol: " + fileUriStr); callbackContext.error("video unknown protocol"); } return true; } catch (JSONException je) { Log.v(LOG_TAG, "error2: " + je.getMessage()); callbackContext.error(je.getMessage()); je.printStackTrace(); return false; } }
From source file:de.zertapps.dvhma.plugins.storage.DVHMAStorage.java
License:Apache License
private void edit(CordovaArgs args, CallbackContext callbackContext) { int index;//from w ww . ja va 2 s . c o m String newTitle; String newContent; try { index = args.getInt(0); newTitle = args.getJSONObject(1).getString("title"); newContent = args.getJSONObject(1).getString("content"); } catch (JSONException e) { e.printStackTrace(); return; } SQLiteDatabase db = mDbHelper.getWritableDatabase(); Cursor c = db.rawQuery("SELECT * FROM " + DVHMAStorageDbHelper.TABLE_NAME + ";", null); c.moveToPosition(index); db.execSQL("UPDATE " + DVHMAStorageDbHelper.TABLE_NAME + " SET title='" + newTitle + "',content='" + newContent + "' WHERE id=" + c.getInt(c.getColumnIndex("id")) + ";"); db.close(); JSONArray result = queryDatabase(); callbackContext.success(result); }
From source file:de.zertapps.dvhma.plugins.storage.DVHMAStorage.java
License:Apache License
private void create(CordovaArgs args, CallbackContext callbackContext) { String newTitle;/* w w w . j av a 2 s. c o m*/ String newContent; try { newTitle = args.getJSONObject(0).getString("title"); newContent = args.getJSONObject(0).getString("content"); } catch (JSONException e) { e.printStackTrace(); return; } SQLiteDatabase db = mDbHelper.getWritableDatabase(); db.execSQL("INSERT INTO " + DVHMAStorageDbHelper.TABLE_NAME + " (title,content) VALUES('" + newTitle + "','" + newContent + "');"); db.close(); JSONArray result = queryDatabase(); callbackContext.success(result); }
From source file:org.chromium.ChromeBluetoothSocket.java
License:Open Source License
private void create(CordovaArgs args, final CallbackContext callbackContext) throws JSONException { JSONObject properties = args.getJSONObject(0); ChromeBluetoothSocketSocket socket = new ChromeBluetoothSocketSocket(nextSocket++, properties); sockets.put(socket.getSocketId(), socket); JSONObject createInfo = new JSONObject(); createInfo.put("socketId", socket.getSocketId()); callbackContext.success(createInfo); }
From source file:org.chromium.ChromeBluetoothSocket.java
License:Open Source License
private void update(CordovaArgs args, final CallbackContext callbackContext) throws JSONException { int socketId = args.getInt(0); JSONObject properties = args.getJSONObject(1); ChromeBluetoothSocketSocket socket = sockets.get(socketId); if (socket == null) { callbackContext.error("Invalid Argument"); return;/* ww w . j a v a 2 s .c o m*/ } socket.update(properties); callbackContext.success(); }
From source file:org.chromium.ChromeBluetoothSocket.java
License:Open Source License
private void listenUsingRfcomm(CordovaArgs args, final CallbackContext callbackContext) throws JSONException { int socketId = args.getInt(0); String uuid = args.getString(1); JSONObject options = args.getJSONObject(2); ChromeBluetoothSocketSocket socket = sockets.get(socketId); if (socket == null) { callbackContext.error("Invalid Argument"); return;/*from w w w. j a va2 s . com*/ } socket.listenUsingRfcomm(uuid, options, callbackContext); }