Return-Path: X-Original-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 755EF95A6 for ; Fri, 12 Oct 2012 21:06:19 +0000 (UTC) Received: (qmail 90733 invoked by uid 500); 12 Oct 2012 21:06:19 -0000 Delivered-To: apmail-incubator-callback-commits-archive@incubator.apache.org Received: (qmail 90645 invoked by uid 500); 12 Oct 2012 21:06:19 -0000 Mailing-List: contact callback-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-commits@incubator.apache.org Received: (qmail 90464 invoked by uid 99); 12 Oct 2012 21:06:18 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Oct 2012 21:06:18 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 8C0C744122; Fri, 12 Oct 2012 21:06:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: braden@apache.org To: callback-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [14/18] android commit: Port CameraLauncher to CordovaPlugin. Message-Id: <20121012210618.8C0C744122@tyr.zones.apache.org> Date: Fri, 12 Oct 2012 21:06:18 +0000 (UTC) Port CameraLauncher to CordovaPlugin. Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/205215d4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/205215d4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/205215d4 Branch: refs/heads/master Commit: 205215d409c4f75e958a9c09c0b4a38bd9a859ac Parents: 076bfcd Author: Braden Shepherdson Authored: Thu Oct 11 11:34:46 2012 -0400 Committer: Braden Shepherdson Committed: Thu Oct 11 11:34:46 2012 -0400 ---------------------------------------------------------------------- .../src/org/apache/cordova/CameraLauncher.java | 55 ++++++++------- 1 files changed, 28 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/205215d4/framework/src/org/apache/cordova/CameraLauncher.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index efb14fc..59e9f21 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -27,8 +27,9 @@ import java.io.IOException; import java.io.OutputStream; import org.apache.commons.codec.binary.Base64; +import org.apache.cordova.api.CallbackContext; +import org.apache.cordova.api.CordovaPlugin; import org.apache.cordova.api.LOG; -import org.apache.cordova.api.Plugin; import org.apache.cordova.api.PluginResult; import org.json.JSONArray; import org.json.JSONException; @@ -53,7 +54,7 @@ import android.util.Log; * and returns the captured image. When the camera view is closed, the screen displayed before * the camera view was shown is redisplayed. */ -public class CameraLauncher extends Plugin implements MediaScannerConnectionClient { +public class CameraLauncher extends CordovaPlugin implements MediaScannerConnectionClient { private static final int DATA_URL = 0; // Return base64 encoded string private static final int FILE_URI = 1; // Return file uri (content://media/external/images/media/2 for Android) @@ -82,9 +83,9 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie private int mediaType; // What type of media to retrieve private boolean saveToPhotoAlbum; // Should the picture be saved to the device's photo album private boolean correctOrientation; // Should the pictures orientation be corrected - private boolean allowEdit; // Should we allow the user to crop the image + //private boolean allowEdit; // Should we allow the user to crop the image. UNUSED. - public String callbackId; + public CallbackContext callbackContext; private int numPics; private MediaScannerConnection conn; // Used to update gallery app with newly-written files @@ -110,15 +111,13 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie /** * 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. + * @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 A PluginResult object with a status and message. */ - public PluginResult execute(String action, JSONArray args, String callbackId) { - PluginResult.Status status = PluginResult.Status.OK; - String result = ""; - this.callbackId = callbackId; + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { + this.callbackContext = callbackContext; try { if (action.equals("takePicture")) { @@ -138,7 +137,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie this.targetHeight = args.getInt(4); this.encodingType = args.getInt(5); this.mediaType = args.getInt(6); - this.allowEdit = args.getBoolean(7); + //this.allowEdit = args.getBoolean(7); // This field is unused. this.correctOrientation = args.getBoolean(8); this.saveToPhotoAlbum = args.getBoolean(9); @@ -159,12 +158,14 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie } PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT); r.setKeepCallback(true); - return r; + callbackContext.sendPluginResult(r); + return true; } - return new PluginResult(status, result); + return false; } catch (JSONException e) { e.printStackTrace(); - return new PluginResult(PluginResult.Status.JSON_EXCEPTION); + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); + return true; } } @@ -199,7 +200,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie this.imageUri = Uri.fromFile(photo); if (this.cordova != null) { - this.cordova.startActivityForResult((Plugin) this, intent, (CAMERA + 1) * 16 + returnType + 1); + this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1); } // else // LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity"); @@ -251,7 +252,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); if (this.cordova != null) { - this.cordova.startActivityForResult((Plugin) this, Intent.createChooser(intent, + this.cordova.startActivityForResult((CordovaPlugin) this, Intent.createChooser(intent, new String(title)), (srcType + 1) * 16 + returnType + 1); } } @@ -319,7 +320,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && rotate == 0) { writeUncompressedImage(uri); - this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); + this.callbackContext.success(uri.toString()); } else { bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); @@ -346,7 +347,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie } // Send Uri back to JavaScript for viewing image - this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); + this.callbackContext.success(uri.toString()); } this.cleanup(FILE_URI, this.imageUri, uri, bitmap); @@ -377,14 +378,14 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie // If you ask for video or all media type you will automatically get back a file URI // and there will be no attempt to resize any returned data if (this.mediaType != PICTURE) { - this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); + this.callbackContext.success(uri.toString()); } else { // This is a special case to just return the path as no scaling, // rotating or compression needs to be done if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && destType == FILE_URI && !this.correctOrientation) { - this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); + this.callbackContext.success(uri.toString()); } else { // Get the path to the image. Makes loading so much easier. String imagePath = FileUtils.getRealPathFromURI(uri, this.cordova); @@ -456,14 +457,14 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie // The resized image is cached by the app in order to get around this and not have to delete you // application cache I'm adding the current system time to the end of the file url. - this.success(new PluginResult(PluginResult.Status.OK, ("file://" + resizePath + "?" + System.currentTimeMillis())), this.callbackId); + this.callbackContext.success("file://" + resizePath + "?" + System.currentTimeMillis()); } catch (Exception e) { e.printStackTrace(); this.failPicture("Error retrieving image."); } } else { - this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); + this.callbackContext.success(uri.toString()); } } if (bitmap != null) { @@ -732,7 +733,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie byte[] code = jpeg_data.toByteArray(); byte[] output = Base64.encodeBase64(code); String js_out = new String(output); - this.success(new PluginResult(PluginResult.Status.OK, js_out), this.callbackId); + this.callbackContext.success(js_out); js_out = null; output = null; code = null; @@ -749,7 +750,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie * @param err */ public void failPicture(String err) { - this.error(new PluginResult(PluginResult.Status.ERROR, err), this.callbackId); + this.callbackContext.error(err); } private void scanForGallery(Uri newImage) { @@ -757,7 +758,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie if(this.conn != null) { this.conn.disconnect(); } - this.conn = new MediaScannerConnection(this.ctx.getActivity().getApplicationContext(), this); + this.conn = new MediaScannerConnection(this.cordova.getActivity().getApplicationContext(), this); conn.connect(); }