Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 06656F8C3 for ; Wed, 17 Apr 2013 20:13:50 +0000 (UTC) Received: (qmail 84943 invoked by uid 500); 17 Apr 2013 20:13:49 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 84880 invoked by uid 500); 17 Apr 2013 20:13:49 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 84873 invoked by uid 99); 17 Apr 2013 20:13:49 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Apr 2013 20:13:49 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 8800E36CC4; Wed, 17 Apr 2013 20:13:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agrieve@apache.org To: commits@cordova.apache.org Message-Id: <3e1cbed8c9944bf79be0050b417f20da@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: android commit: [CB-2432] Fix Camera.getPicture() for picasa images Date: Wed, 17 Apr 2013 20:13:49 +0000 (UTC) Updated Branches: refs/heads/master 80fe4458c -> b13166f5d [CB-2432] Fix Camera.getPicture() for picasa images Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/b13166f5 Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/b13166f5 Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/b13166f5 Branch: refs/heads/master Commit: b13166f5d92196ed3e1b2d2dfd4cef7242876d70 Parents: 80fe445 Author: Andrew Grieve Authored: Wed Apr 17 16:12:28 2013 -0400 Committer: Andrew Grieve Committed: Wed Apr 17 16:12:28 2013 -0400 ---------------------------------------------------------------------- .../src/org/apache/cordova/CameraLauncher.java | 28 ++++++++------ 1 files changed, 16 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-android/blob/b13166f5/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 22a9b94..b34f722 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -42,6 +42,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.graphics.Bitmap.CompressFormat; +import android.graphics.Rect; import android.media.MediaScannerConnection; import android.media.MediaScannerConnection.MediaScannerConnectionClient; import android.net.Uri; @@ -396,19 +397,21 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) { this.callbackContext.success(uri.toString()); } else { + String uriString = uri.toString(); // Get the path to the image. Makes loading so much easier. - String imagePath = FileHelper.getRealPath(uri, this.cordova); - String mimeType = FileHelper.getMimeType(imagePath, this.cordova); - // Log.d(LOG_TAG, "Real path = " + imagePath); - // Log.d(LOG_TAG, "mime type = " + mimeType); + String mimeType = FileHelper.getMimeType(uriString, this.cordova); // If we don't have a valid image so quit. - if (imagePath == null || mimeType == null || - !(mimeType.equalsIgnoreCase("image/jpeg") || mimeType.equalsIgnoreCase("image/png"))) { + if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to retrieve path to picture!"); return; } - Bitmap bitmap = getScaledBitmap(imagePath); + Bitmap bitmap = null; + try { + bitmap = getScaledBitmap(uriString); + } catch (IOException e) { + e.printStackTrace(); + } if (bitmap == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to create bitmap!"); @@ -417,7 +420,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect if (this.correctOrientation) { String[] cols = { MediaStore.Images.Media.ORIENTATION }; - Cursor cursor = this.cordova.getActivity().getContentResolver().query(intent.getData(), + Cursor cursor = this.cordova.getActivity().getContentResolver().query(uri, cols, null, null, null); if (cursor != null) { cursor.moveToPosition(0); @@ -563,17 +566,18 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect * * @param imagePath * @return + * @throws IOException */ - private Bitmap getScaledBitmap(String imagePath) { + private Bitmap getScaledBitmap(String imageUrl) throws IOException { // If no new width or height were specified return the original bitmap if (this.targetWidth <= 0 && this.targetHeight <= 0) { - return BitmapFactory.decodeFile(imagePath); + return BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova)); } // figure out the original width and height of the image BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; - BitmapFactory.decodeFile(imagePath, options); + BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova), null, options); //CB-2292: WTF? Why is the width null? if(options.outWidth == 0 || options.outHeight == 0) @@ -587,7 +591,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect // Load in the smallest bitmap possible that is closest to the size we want options.inJustDecodeBounds = false; options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, this.targetWidth, this.targetHeight); - Bitmap unscaledBitmap = BitmapFactory.decodeFile(imagePath, options); + Bitmap unscaledBitmap = BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova), null, options); if (unscaledBitmap == null) { return null; }