List of usage examples for org.apache.cordova.api PluginResult PluginResult
public PluginResult(Status status, long l)
From source file:com.adobe.plugins.FastCanvas.java
License:Apache License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { //Log.i("CANVAS", "FastCanvas execute: " + action); if (mMessageQueue == null) { Log.i("CANVAS", "FastCanvas messageQueue is NULL in execute."); return true; }/*from w ww. j av a 2 s .c o m*/ try { if (action.equals("setBackgroundColor")) { FastCanvasMessage m = new FastCanvasMessage(FastCanvasMessage.Type.SET_BACKGROUND); m.drawCommands = args.getString(0); Log.i("CANVAS", "FastCanvas queueing set background color " + m.drawCommands); mMessageQueue.add(m); return true; } else if (action.equals("loadTexture")) { FastCanvasMessage m = new FastCanvasMessage(FastCanvasMessage.Type.LOAD); m.url = args.getString(0); m.textureID = args.getInt(1); assert callbackContext != null; m.callbackContext = callbackContext; Log.i("CANVAS", "FastCanvas queueing load texture " + m.textureID + ", " + m.url); mMessageQueue.add(m); return true; } else if (action.equals("unloadTexture")) { FastCanvasMessage m = new FastCanvasMessage(FastCanvasMessage.Type.UNLOAD); m.textureID = args.getInt(0); Log.i("CANVAS", "FastCanvas queueing unload texture " + m.textureID); mMessageQueue.add(m); return true; } else if (action.equals("render")) { FastCanvasMessage m = new FastCanvasMessage(FastCanvasMessage.Type.RENDER); m.drawCommands = args.getString(0); mMessageQueue.add(m); return true; } else if (action.equals("setOrtho")) { FastCanvasMessage m = new FastCanvasMessage(FastCanvasMessage.Type.SET_ORTHO); int width = args.getInt(0); int height = args.getInt(1); m.width = width; m.height = height; Log.i("CANVAS", "FastCanvas queueing setOrtho, width=" + m.width + ", height=" + m.height); mMessageQueue.add(m); return true; } else if (action.equals("capture")) { //set the root path to /mnt/sdcard/ String fileLocation = Environment.getExternalStorageDirectory() + args.getString(4); String justPath = fileLocation.substring(0, fileLocation.lastIndexOf('/')); File directory = new File(justPath); if (!directory.isDirectory()) { //doesn't exist try to make it if (!directory.mkdirs()) { //failed to make directory, callback with error PluginResult result = new PluginResult(PluginResult.Status.ERROR, "Could not create directory"); callbackContext.sendPluginResult(result); return true; } } FastCanvasMessage m = new FastCanvasMessage(FastCanvasMessage.Type.CAPTURE); m.x = args.optInt(0, 0); m.y = args.optInt(1, 0); m.width = args.optInt(2, -1); m.height = args.optInt(3, -1); m.url = fileLocation; Log.i("CANVAS", "FastCanvas queueing capture"); if (callbackContext != null) m.callbackContext = callbackContext; mMessageQueue.add(m); return true; } else if (action.equals("isAvailable")) { // user is checking to see if we exist // simply reply with a successful success callback // if we're not installed, cordova will call // the error callback for us PluginResult result = new PluginResult(PluginResult.Status.OK, true); callbackContext.sendPluginResult(result); // if for some other reason we are installed but // cannot function, the result of OK above can be sent // but with a value of false which indicates unavailability // (may require not disabling the view if that's the case) return true; } else { Log.i("CANVAS", "FastCanvas unknown execute action " + action); } } catch (Exception e) { String argStr = ""; try { argStr = args.join(","); } catch (Exception ignore) { } Log.e("CANVAS", "Unexpected error parsing execute parameters for action " + action + "(" + argStr + ")", e); } return false; }
From source file:com.adobe.plugins.FastCanvas.java
License:Apache License
public static void executeCallback(String callbackID, boolean isError, String result) { if (theCanvas == null) { return;/*from w w w. j a v a 2 s . co m*/ } PluginResult res; if (isError) res = new PluginResult(PluginResult.Status.ERROR, result); else res = new PluginResult(PluginResult.Status.OK, result); theCanvas.mCordovaView.sendPluginResult(res, callbackID); }
From source file:com.android.adcnx.adlib.plugin.AdConnectLibrary.java
License:Open Source License
private PluginResult isCreated(String callbackID) { JSONObject response = new JSONObject(); boolean created = _lib != null; try {/* w ww . j a va 2 s. c o m*/ response.put("isCreated", created); response.put("msg", "The library has already been created"); return new PluginResult(Status.OK, response); } catch (JSONException e) { return new PluginResult(Status.JSON_EXCEPTION, "The library has already been created."); } }
From source file:com.android.adcnx.adlib.plugin.AdConnectLibrary.java
License:Open Source License
private PluginResult createResultWithJSONMessage(Status status, String msg) { JSONObject message = new JSONObject(); try {//from w w w .java2 s . c o m message.put("msg", msg); return new PluginResult(status, message); } catch (JSONException e) { return new PluginResult(status, msg); } }
From source file:com.android.adcnx.adlib.plugin.AdConnectLibrary.java
License:Open Source License
public void OnFailedToReceiveAd(Ad ad, ErrorCode code) { String callbackID = _listeners.get("failedToReceiveAdListener"); if (callbackID != null) { JSONObject message = new JSONObject(); try {//from w ww . j ava 2s . com message.put("msg", "Failed to receive ad: " + ad.toString()); message.put("error", code.name()); this.success(message, callbackID); } catch (JSONException e) { //e.printStackTrace(); PluginResult result = new PluginResult(Status.OK, message); result.setKeepCallback(true); this.success("Failed to receive ad: " + ad.toString() + "\n" + "error: " + code.name(), callbackID); } } }
From source file:com.angrystone.JpegCompressor.java
License:Open Source License
@Override public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; String filename = "/mnt/sdcard/DCIM/Camera/Convert_"; String orifilename = "/mnt/sdcard/DCIM/Camera/"; if (action.equals("compress")) { Integer quality = 100;//from w ww. j av a2s. c o m try { orifilename = orifilename.concat(args.getString(0)); filename = filename.concat(args.getString(0)); quality = args.getInt(1); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } OutputStream outputStream = null; File file = new File(filename); Bitmap bitmap = BitmapFactory.decodeFile(orifilename); try { outputStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream); try { outputStream.flush(); outputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { status = PluginResult.Status.INVALID_ACTION; } return new PluginResult(status, filename); }
From source file:com.angrystone.JpegExifReader.java
License:Open Source License
@Override public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; Integer result = 0;//from ww w . j a va 2 s . c om if (action.equals("getWidth")) { String file = null; try { file = args.getString(0); } catch (JSONException e) { e.printStackTrace(); } try { ExifInterface exif = new ExifInterface(file); result = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (action.equals("getLength")) { String file = null; try { file = args.getString(0); } catch (JSONException e) { e.printStackTrace(); } try { ExifInterface exif = new ExifInterface(file); result = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0); } catch (IOException e) { e.printStackTrace(); } } else { status = PluginResult.Status.INVALID_ACTION; } return new PluginResult(status, result); }
From source file:com.app.plugins.childBrowser.ChildBrowser.java
License:BSD 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. */// w ww . j av a2 s . c o m public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; try { if (action.equals("showWebPage")) { this.browserCallbackId = callbackId; // If the ChildBrowser is already open then throw an error if (dialog != null && dialog.isShowing()) { return new PluginResult(PluginResult.Status.ERROR, "ChildBrowser is already open"); } result = this.showWebPage(args.getString(0), args.optJSONObject(1)); if (result.length() > 0) { status = PluginResult.Status.ERROR; return new PluginResult(status, result); } else { PluginResult pluginResult = new PluginResult(status, result); pluginResult.setKeepCallback(true); return pluginResult; } } else if (action.equals("close")) { closeDialog(); JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); this.onClose(); PluginResult pluginResult = new PluginResult(status, obj); pluginResult.setKeepCallback(false); return pluginResult; } else if (action.equals("openExternal")) { result = this.openExternal(args.getString(0), args.optBoolean(1)); if (result.length() > 0) { status = PluginResult.Status.ERROR; } } else { status = PluginResult.Status.INVALID_ACTION; } return new PluginResult(status, result); } catch (JSONException e) { return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } }
From source file:com.app.plugins.childBrowser.ChildBrowser.java
License:BSD License
/** * Create a new plugin result and send it back to JavaScript * //from ww w . ja va2 s. com * @param obj a JSONObject contain event payload information */ private void sendUpdate(JSONObject obj, boolean keepCallback) { if (this.browserCallbackId != null) { PluginResult result = new PluginResult(PluginResult.Status.OK, obj); result.setKeepCallback(keepCallback); this.success(result, this.browserCallbackId); } }
From source file:com.apptech.first.cordova.plugins.push.pushnotifications.PushNotifications.java
License:Open Source License
private void doOnRegistered(String registrationId) { JSONObject status = new JSONObject(); try {/*from w ww. ja va 2s .co m*/ status.put("deviceToken", registrationId); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } String callbackId = callbackIds.get("registerDevice"); PluginResult result = new PluginResult(Status.OK, status); success(result, callbackId); callbackIds.remove(callbackId); }