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 44C4817E50 for ; Wed, 1 Apr 2015 18:41:57 +0000 (UTC) Received: (qmail 60323 invoked by uid 500); 1 Apr 2015 18:41:57 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 60204 invoked by uid 500); 1 Apr 2015 18:41:57 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 60064 invoked by uid 99); 1 Apr 2015 18:41:57 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Apr 2015 18:41:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D93B7E1832; Wed, 1 Apr 2015 18:41:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: steven@apache.org To: commits@cordova.apache.org Date: Wed, 01 Apr 2015 18:41:59 -0000 Message-Id: <5d4af1aa4274467e83ccd13cedaf603c@git.apache.org> In-Reply-To: <24057c07d9a4435c8bc709cfad0d7b2b@git.apache.org> References: <24057c07d9a4435c8bc709cfad0d7b2b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/8] cordova-plugin-camera git commit: CB-8782: Fixed the flow so that we save the cropped image and use it, not the original non-cropped. Crop only supports G+ Photos Crop, other crops may not work, depending on the OEM CB-8782: Fixed the flow so that we save the cropped image and use it, not the original non-cropped. Crop only supports G+ Photos Crop, other crops may not work, depending on the OEM Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/9fe5b430 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/9fe5b430 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/9fe5b430 Branch: refs/heads/old-ID Commit: 9fe5b430aadb75052d8949567d537199ff3df0fc Parents: 23dbb88 Author: Joe Bowser Authored: Wed Apr 1 11:03:48 2015 -0700 Committer: Joe Bowser Committed: Wed Apr 1 11:04:06 2015 -0700 ---------------------------------------------------------------------- src/android/CameraLauncher.java | 111 ++++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/9fe5b430/src/android/CameraLauncher.java ---------------------------------------------------------------------- diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java index 5035679..f53a348 100644 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -81,6 +81,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect private static final String GET_All = "Get All"; private static final String LOG_TAG = "CameraLauncher"; + + //Where did this come from? private static final int CROP_CAMERA = 100; private int mQuality; // Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality) @@ -312,13 +314,14 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect * * @param picUri */ - private void performCrop(Uri picUri) { + private void performCrop(Uri picUri, int destType, Intent cameraIntent) { try { Intent cropIntent = new Intent("com.android.camera.action.CROP"); // indicate image type and Uri cropIntent.setDataAndType(picUri, "image/*"); // set crop properties cropIntent.putExtra("crop", "true"); + // indicate output X and Y if (targetWidth > 0) { cropIntent.putExtra("outputX", targetWidth); @@ -338,12 +341,18 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect if (this.cordova != null) { this.cordova.startActivityForResult((CordovaPlugin) this, - cropIntent, CROP_CAMERA); + cropIntent, CROP_CAMERA + destType); } } catch (ActivityNotFoundException anfe) { Log.e(LOG_TAG, "Crop operation not supported on this device"); - // Send Uri back to JavaScript for viewing image - this.callbackContext.success(picUri.toString()); + try { + processResultFromCamera(destType, cameraIntent); + } + catch (IOException e) + { + e.printStackTrace(); + Log.e(LOG_TAG, "Unable to write to file"); + } } } @@ -358,16 +367,22 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect // Create an ExifHelper to save the exif data that is lost during compression ExifHelper exif = new ExifHelper(); + String sourcePath; try { - if (this.encodingType == JPEG) { - exif.createInFile(getTempDirectoryPath() + "/.Pic.jpg"); - exif.readExifData(); - rotate = exif.getOrientation(); - } else if (this.encodingType == PNG) { - exif.createInFile(getTempDirectoryPath() + "/.Pic.png"); - exif.readExifData(); - rotate = exif.getOrientation(); + if(allowEdit && croppedUri != null) + { + sourcePath = FileHelper.stripFileProtocol(croppedUri.toString()); + } + else + { + sourcePath = getTempDirectoryPath() + "/.Pic.jpg"; } + + //We don't support PNG, so let's not pretend we do + exif.createInFile(getTempDirectoryPath() + "/.Pic.jpg"); + exif.readExifData(); + rotate = exif.getOrientation(); + } catch (IOException e) { e.printStackTrace(); } @@ -377,7 +392,13 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect // If sending base64 image back if (destType == DATA_URL) { - bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString())); + if(croppedUri != null) { + bitmap = getScaledBitmap(FileHelper.stripFileProtocol(croppedUri.toString())); + } + else + { + bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString())); + } if (bitmap == null) { // Try to get the bitmap from intent. bitmap = (Bitmap)intent.getExtras().get("data"); @@ -445,12 +466,10 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect refreshGallery(uri); } - if (this.allowEdit) { - performCrop(uri); - } else { - // Send Uri back to JavaScript for viewing image - this.callbackContext.success(uri.toString()); - } + + // Send Uri back to JavaScript for viewing image + this.callbackContext.success(uri.toString()); + } } else { throw new IllegalStateException(); @@ -613,34 +632,47 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException { */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { - // Get src and dest types from request code + // Get src and dest types from request code for a Camera Activity int srcType = (requestCode / 16) - 1; int destType = (requestCode % 16) - 1; - // if camera crop - if (requestCode == CROP_CAMERA) { - if (resultCode == Activity.RESULT_OK) { - // // Send Uri back to JavaScript for viewing image - this.callbackContext - .success(croppedUri.toString()); - croppedUri = null; - - }// If cancelled - else if (resultCode == Activity.RESULT_CANCELED) { - this.failPicture("Camera cancelled."); - } - // If something else - else { - this.failPicture("Did not complete!"); - } + // If Camera Crop + if (requestCode >= CROP_CAMERA) { + if (resultCode == Activity.RESULT_OK) { - } + // Because of the inability to pass through multiple intents, this hack will allow us + // to pass arcane codes back. + destType = requestCode - CROP_CAMERA; + try { + processResultFromCamera(destType, intent); + } catch (IOException e) { + e.printStackTrace(); + Log.e(LOG_TAG, "Unable to write to file"); + } + + }// If cancelled + else if (resultCode == Activity.RESULT_CANCELED) { + this.failPicture("Camera cancelled."); + } + + // If something else + else { + this.failPicture("Did not complete!"); + } + } // If CAMERA - if (srcType == CAMERA) { + else if (srcType == CAMERA) { // If image available if (resultCode == Activity.RESULT_OK) { try { - this.processResultFromCamera(destType, intent); + if(this.allowEdit) + { + Uri tmpFile = Uri.fromFile(new File(getTempDirectoryPath(), ".Pic.jpg")); + performCrop(tmpFile, destType, intent); + } + else { + this.processResultFromCamera(destType, intent); + } } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); @@ -657,7 +689,6 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException { this.failPicture("Did not complete!"); } } - // If retrieving photo from library else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { if (resultCode == Activity.RESULT_OK && intent != null) { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org