incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From macdo...@apache.org
Subject [6/8] android commit: Decode image from File instead of content resolver
Date Thu, 28 Jun 2012 16:33:45 GMT
Decode image from 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/a74f71c9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/a74f71c9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/a74f71c9

Branch: refs/heads/master
Commit: a74f71c935e4b9c57ab45652664b0c337f257c6b
Parents: 87b81e5
Author: macdonst <simon.macdonald@gmail.com>
Authored: Tue Jun 26 13:41:53 2012 -0400
Committer: macdonst <simon.macdonald@gmail.com>
Committed: Thu Jun 28 12:00:18 2012 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/CameraLauncher.java     |   58 ++++++++-------
 1 files changed, 31 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/a74f71c9/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 3b720b7..496b20e 100755
--- a/framework/src/org/apache/cordova/CameraLauncher.java
+++ b/framework/src/org/apache/cordova/CameraLauncher.java
@@ -40,6 +40,7 @@ import android.content.ContentValues;
 import android.content.Intent;
 import android.database.Cursor;
 import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
 import android.graphics.Matrix;
 import android.graphics.Bitmap.CompressFormat;
 import android.media.MediaScannerConnection;
@@ -85,7 +86,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
 
     public String callbackId;
     private int numPics;
-    
+
     private MediaScannerConnection conn;    // Used to update gallery app with newly-written
files
 
     //This should never be null!
@@ -373,14 +374,14 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
                         } else {
 
                             bitmap = scaleBitmap(getBitmapFromResult(intent));
-    
+
                             // Add compressed version of captured image to returned media
store Uri
                             OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
                             bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
                             os.close();
-    
+
                             // Restore exif data to file
-                            
+
                             if (this.encodingType == JPEG) {
                                 String exifPath;
                                 if (this.saveToPhotoAlbum) {
@@ -391,15 +392,15 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
                                 exif.createOutFile(exifPath);
                                 exif.writeExifData();
                             }
-                            
+
                         }
                         // Send Uri back to JavaScript for viewing image
                         this.success(new PluginResult(PluginResult.Status.OK, uri.toString()),
this.callbackId);
                     }
-                    
+
                     this.cleanup(FILE_URI, this.imageUri, bitmap);
                     bitmap = null;
-                    
+
                 } catch (IOException e) {
                     e.printStackTrace();
                     this.failPicture("Error capturing image.");
@@ -505,15 +506,18 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
     }
 
     private Bitmap getBitmapFromResult(Intent intent)
-            throws IOException, FileNotFoundException {
+            throws IOException {
         Bitmap bitmap = null;
-        try {
-            bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getActivity().getContentResolver(),
imageUri);
-        } catch (FileNotFoundException e) {
-            Uri uri = intent.getData();
-            android.content.ContentResolver resolver = this.ctx.getActivity().getContentResolver();
-            bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
-        }
+        //try {
+            Log.d(LOG_TAG, "Image URI = " + imageUri.toString());
+            String fileName = FileUtils.stripFileProtocol(imageUri.toString());
+            bitmap = BitmapFactory.decodeFile(fileName);
+            //bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getActivity().getContentResolver(),
imageUri);
+        //} catch (FileNotFoundException e) {
+        //    Uri uri = intent.getData();
+        //    android.content.ContentResolver resolver = this.ctx.getActivity().getContentResolver();
+        //    bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
+        //}
         return bitmap;
     }
 
@@ -530,20 +534,20 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
                 null,
                 null);
     }
-    
+
     /**
      * Cleans up after picture taking. Checking for duplicates and that kind of stuff.
      */
     private void cleanup(int imageType, Uri oldImage, Bitmap bitmap) {
         bitmap.recycle();
-        
+
         // Clean up initial camera-written image file.
         (new File(FileUtils.stripFileProtocol(oldImage.toString()))).delete();
-        
+
         checkForDuplicateImage(imageType);
         // Scan for the gallery to update pic refs in gallery
         this.scanForGallery();
-        
+
         System.gc();
     }
 
@@ -616,12 +620,12 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
     public void failPicture(String err) {
         this.error(new PluginResult(PluginResult.Status.ERROR, err), this.callbackId);
     }
-    
-    private void scanForGallery() { 
-        if(this.conn!=null) this.conn.disconnect();  
-        this.conn = new MediaScannerConnection(this.ctx.getActivity().getApplicationContext(),
this); 
-        conn.connect(); 
-    } 
+
+    private void scanForGallery() {
+        if(this.conn!=null) this.conn.disconnect();
+        this.conn = new MediaScannerConnection(this.ctx.getActivity().getApplicationContext(),
this);
+        conn.connect();
+    }
 
     public void onMediaScannerConnected() {
         try{
@@ -630,10 +634,10 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
             e.printStackTrace();
             LOG.d(LOG_TAG, "Can;t scan file in MediaScanner aftering taking picture");
         }
-        
+
     }
 
     public void onScanCompleted(String path, Uri uri) {
-        this.conn.disconnect();   
+        this.conn.disconnect();
     }
 }


Mime
View raw message