cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject [2/2] cordova-plugin-camera git commit: CB-11447 Respect output format when retrieving images from gallery
Date Thu, 28 Jul 2016 13:57:54 GMT
CB-11447 Respect output format when retrieving images from gallery


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/fed798e6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/fed798e6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/fed798e6

Branch: refs/heads/master
Commit: fed798e6c7f56e23bff994ab2c11d316c8257a78
Parents: 2027d69
Author: Vladimir Kotikov <kotikov.vladimir@gmail.com>
Authored: Tue Jul 26 15:17:44 2016 +0300
Committer: Vladimir Kotikov <kotikov.vladimir@gmail.com>
Committed: Tue Jul 26 15:59:52 2016 +0300

----------------------------------------------------------------------
 src/android/CameraLauncher.java | 39 +++++++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/fed798e6/src/android/CameraLauncher.java
----------------------------------------------------------------------
diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java
index 9db9911..060103b 100644
--- a/src/android/CameraLauncher.java
+++ b/src/android/CameraLauncher.java
@@ -365,7 +365,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
                     intent.putExtra("aspectX", 1);
                     intent.putExtra("aspectY", 1);
                 }
-                File photo = createCaptureFile(encodingType);
+                File photo = createCaptureFile(JPEG);
                 croppedUri = Uri.fromFile(photo);
                 intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, croppedUri);
             } else {
@@ -592,15 +592,29 @@ private void refreshGallery(Uri contentUri)
     this.cordova.getActivity().sendBroadcast(mediaScanIntent);
 }
 
+    /**
+     * Converts output image format int value to string value of mime type.
+     * @param outputFormat int Output format of camera API.
+     *                     Must be value of either JPEG or PNG constant
+     * @return String String value of mime type or empty string if mime type is not supported
+     */
+    private String getMimetypeForFormat(int outputFormat) {
+        if (outputFormat == PNG) return "image/png";
+        if (outputFormat == JPEG) return "image/jpeg";
+        return "";
+    }
 
-private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
+    private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
         // Some content: URIs do not map to file paths (e.g. picasa).
         String realPath = FileHelper.getRealPath(uri, this.cordova);
 
         // Get filename from uri
         String fileName = realPath != null ?
-            realPath.substring(realPath.lastIndexOf('/') + 1) :
-            "modified." + (this.encodingType == JPEG ? "jpg" : "png");
+            realPath.substring(realPath.lastIndexOf('/') + 1, realPath.lastIndexOf(".") +
1) :
+            "modified.";
+
+        // Append filename extension based on output encoding type
+        fileName += (this.encodingType == JPEG ? "jpg" : "png");
 
         String modifiedPath = getTempDirectoryPath() + "/" + fileName;
 
@@ -660,15 +674,18 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException
{
             this.callbackContext.success(fileLocation);
         }
         else {
+            String uriString = uri.toString();
+            // Get the path to the image. Makes loading so much easier.
+            String mimeType = FileHelper.getMimeType(uriString, this.cordova);
+
             // This is a special case to just return the path as no scaling,
             // rotating, nor compressing needs to be done
             if (this.targetHeight == -1 && this.targetWidth == -1 &&
-                    (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation)
{
-                this.callbackContext.success(uri.toString());
+                    (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation
&&
+                    mimeType.equalsIgnoreCase(getMimetypeForFormat(encodingType)))
+            {
+                this.callbackContext.success(uriString);
             } else {
-                String uriString = uri.toString();
-                // Get the path to the image. Makes loading so much easier.
-                String mimeType = FileHelper.getMimeType(uriString, this.cordova);
                 // If we don't have a valid image so quit.
                 if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType)))
{
                     Log.d(LOG_TAG, "I either have a null image path or bitmap");
@@ -710,7 +727,9 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException
{
                 else if (destType == FILE_URI || destType == NATIVE_URI) {
                     // Did we modify the image?
                     if ( (this.targetHeight > 0 && this.targetWidth > 0) ||
-                            (this.correctOrientation && this.orientationCorrected)
) {
+                            (this.correctOrientation && this.orientationCorrected)
||
+                            !mimeType.equalsIgnoreCase(getMimetypeForFormat(encodingType)))
+                    {
                         try {
                             String modifiedPath = this.ouputModifiedBitmap(bitmap, uri);
                             // The modified image is cached by the app in order to get around
this and not have to delete you


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message