Switch getPicture from Gallery to use file instead of content resolver

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/483e5dfb
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/483e5dfb
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/483e5dfb

Branch: refs/heads/master
Commit: 483e5dfbeaa2e13bdd2e7cc79e2f72f9d89eff66
Parents: 8aa9d82
Author: macdonst <[email protected]>
Authored: Tue Jun 26 14:45:51 2012 -0400
Committer: macdonst <[email protected]>
Committed: Thu Jun 28 12:00:18 2012 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/CameraLauncher.java     |   49 +++++++--------
 1 files changed, 23 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/483e5dfb/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 f2ee3e6..2ba5a39 100755
--- a/framework/src/org/apache/cordova/CameraLauncher.java
+++ b/framework/src/org/apache/cordova/CameraLauncher.java
@@ -428,7 +428,6 @@ public class CameraLauncher extends Plugin implements 
MediaScannerConnectionClie
         else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
             if (resultCode == Activity.RESULT_OK) {
                 Uri uri = intent.getData();
-                android.content.ContentResolver resolver = 
this.cordova.getActivity().getContentResolver();
 
                 // 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
@@ -437,32 +436,30 @@ public class CameraLauncher extends Plugin implements 
MediaScannerConnectionClie
                 }
                 else {
                     // If sending base64 image back
+
+                    // Get the path to the image. Makes loading so much easier.
+                    String imagePath = FileUtils.getRealPathFromURI(uri, 
this.cordova);
                     if (destType == DATA_URL) {
-                        try {
-                            Bitmap bitmap = 
android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
-                            String[] cols = { 
MediaStore.Images.Media.ORIENTATION };
-                            Cursor cursor = 
this.cordova.getActivity().getContentResolver().query(intent.getData(),
-                                    cols,
-                                    null, null, null);
-                            if (cursor != null) {
-                                cursor.moveToPosition(0);
-                                rotate = cursor.getInt(0);
-                                cursor.close();
-                            }
-                            if (rotate != 0) {
-                                Matrix matrix = new Matrix();
-                                matrix.setRotate(rotate);
-                                bitmap = Bitmap.createBitmap(bitmap, 0, 0, 
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
-                            }
-                           bitmap = scaleBitmap(bitmap);
-                            this.processPicture(bitmap);
-                            bitmap.recycle();
-                            bitmap = null;
-                            System.gc();
-                        } catch (FileNotFoundException e) {
-                            e.printStackTrace();
-                            this.failPicture("Error retrieving image.");
+                        Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
+                        String[] cols = { MediaStore.Images.Media.ORIENTATION 
};
+                        Cursor cursor = 
this.cordova.getActivity().getContentResolver().query(intent.getData(),
+                                cols,
+                                null, null, null);
+                        if (cursor != null) {
+                            cursor.moveToPosition(0);
+                            rotate = cursor.getInt(0);
+                            cursor.close();
                         }
+                        if (rotate != 0) {
+                            Matrix matrix = new Matrix();
+                            matrix.setRotate(rotate);
+                            bitmap = Bitmap.createBitmap(bitmap, 0, 0, 
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
+                        }
+                        bitmap = scaleBitmap(bitmap);
+                        this.processPicture(bitmap);
+                        bitmap.recycle();
+                        bitmap = null;
+                        System.gc();
                     }
 
                     // If sending filename back
@@ -470,7 +467,7 @@ public class CameraLauncher extends Plugin implements 
MediaScannerConnectionClie
                         // Do we need to scale the returned file
                         if (this.targetHeight > 0 && this.targetWidth > 0) {
                             try {
-                                Bitmap bitmap = 
android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
+                                Bitmap bitmap = 
BitmapFactory.decodeFile(imagePath);
                                 bitmap = scaleBitmap(bitmap);
 
                                 String fileName = 
DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + 
"/resize.jpg";

Reply via email to