incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tim...@apache.org
Subject webworks commit: [CB-752] Implement saveToPhotoAlbum CameraOption on bb device
Date Fri, 22 Jun 2012 00:11:11 GMT
Updated Branches:
  refs/heads/master 9128f337a -> 9c67191d7


[CB-752] Implement saveToPhotoAlbum CameraOption on bb device


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/commit/9c67191d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/tree/9c67191d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/diff/9c67191d

Branch: refs/heads/master
Commit: 9c67191d730caadccec33fa3e6c060bf428cffda
Parents: 9128f33
Author: Tim Kim <tim.kim@nitobi.com>
Authored: Thu Jun 21 17:10:40 2012 -0700
Committer: Tim Kim <tim.kim@nitobi.com>
Committed: Thu Jun 21 17:10:40 2012 -0700

----------------------------------------------------------------------
 .../ext/src/org/apache/cordova/camera/Camera.java  |   42 ++++++++++++++-
 .../org/apache/cordova/camera/CameraOptions.java   |   32 ++++++++++--
 2 files changed, 69 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/9c67191d/framework/ext/src/org/apache/cordova/camera/Camera.java
----------------------------------------------------------------------
diff --git a/framework/ext/src/org/apache/cordova/camera/Camera.java b/framework/ext/src/org/apache/cordova/camera/Camera.java
index c033abe..e5f95c1 100644
--- a/framework/ext/src/org/apache/cordova/camera/Camera.java
+++ b/framework/ext/src/org/apache/cordova/camera/Camera.java
@@ -175,12 +175,52 @@ public class Camera extends Plugin
             // Reformat the image if the specified options require it,
             // otherwise, get encoded string if base 64 string is output format.
             String imageURIorData = filePath;
+            
+			// save to file:///store/home/user/ as oppsed to photo album
+			// so it doesn't show up in the camera's photo album viewer
+			if(!options.saveToPhotoAlbum){
+				FileConnection fconnIn = null;
+				FileConnection fconnOut = null;
+				InputStream in = null;
+				OutputStream out = null;
+				String newOutName = "";
+				try
+				{
+					fconnIn = (FileConnection)Connector.open(filePath);
+					if (fconnIn.exists())
+					{
+						newOutName = "file:///store/home/user/"+fconnIn.getName();
+						fconnOut = (FileConnection)Connector.open(newOutName);
+            			if (!fconnOut.exists())
+						 {
+							 fconnOut.create();  
+							 in = fconnIn.openInputStream();
+							 out = fconnOut.openOutputStream();
+							 out.write(IOUtilities.streamToBytes(in, 96*1024));
+							 fconnIn.delete();
+							 out.close();
+							 imageURIorData = newOutName;
+							 filePath = newOutName;
+							 waitForImageFile(newOutName);
+						 }
+					}
+				}
+				finally
+				{
+					if (in != null) in.close();
+					if (out != null) out.close();
+					if (fconnIn != null) fconnIn.close();
+					if (fconnOut != null) fconnOut.close();
+				}
+				
+			}
+
             if (options.reformat) {
                 imageURIorData = reformatImage(filePath, options);
             } else if (options.destinationType == CameraOptions.DESTINATION_DATA_URL) {
                 imageURIorData = encodeImage(filePath);
             }
-
+			
             // we have to check the size to avoid memory errors in the browser
             if (imageURIorData.length() > MAX_ENCODING_SIZE)
             {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/9c67191d/framework/ext/src/org/apache/cordova/camera/CameraOptions.java
----------------------------------------------------------------------
diff --git a/framework/ext/src/org/apache/cordova/camera/CameraOptions.java b/framework/ext/src/org/apache/cordova/camera/CameraOptions.java
index 97a4176..8b18f16 100644
--- a/framework/ext/src/org/apache/cordova/camera/CameraOptions.java
+++ b/framework/ext/src/org/apache/cordova/camera/CameraOptions.java
@@ -59,7 +59,8 @@ public class CameraOptions {
     public String fileExtension = ".jpg";
     public int imageFilter = Bitmap.FILTER_LANCZOS;
     public boolean reformat = false;
-
+	public boolean saveToPhotoAlbum = true;
+	
     /**
      * Defines the order of args in the JSONArray
      *
@@ -68,7 +69,12 @@ public class CameraOptions {
      *   Camera.PictureSourceType.PHOTOLIBRARY // sourceType (ignored)
      *   400,                                  // targetWidth
      *   600,                                  // targetHeight
-     *   Camera.EncodingType.JPEG]             // encoding
+     *   Camera.EncodingType.JPEG              // encoding
+     *	 Camera.mediaType
+     *   Camera.allowEdit
+     *   Camera.correctOrientation
+     *	 Camera.saveToPhotoAlbum			   // save to photo album
+     *   Camera.popoverOptions]			   
      */
     private static final int ARG_QUALITY = 0;
     private static final int ARG_DESTINATION_TYPE = 1;
@@ -76,7 +82,7 @@ public class CameraOptions {
     private static final int ARG_TARGET_WIDTH = 3;
     private static final int ARG_TARGET_HEIGHT = 4;
     private static final int ARG_ENCODING = 5;
-
+	private static final int ARG_SAVETOPHOTOALBUM = 9;
 
     /**
      * Parse the JSONArray and populate the class members with the values.
@@ -147,11 +153,28 @@ public class CameraOptions {
                     || options.encoding != ENCODING_JPEG) {
                 options.reformat = true;
             }
+
+            if (!args.isNull(ARG_SAVETOPHOTOALBUM)) {
+                options.saveToPhotoAlbum = parseBoolean(args.getString(ARG_SAVETOPHOTOALBUM));
+            }
+            
         }
 
         return options;
     }
-
+	
+    /**
+     * no parseBoolean in JDK 1.3 :(
+    */
+     
+	public static boolean parseBoolean(String s) {
+		if (s.equals("true")){
+			return true;
+		}else{
+			return false;
+		}
+	}
+	
     /**
      * @see java.lang.Object#toString()
      */
@@ -165,6 +188,7 @@ public class CameraOptions {
         str.append("Encoding:    " + encoding + "\n");
         str.append("Filter: " + imageFilter + "\n");
         str.append("Reformat: " + reformat);
+        str.append("Save To Photo Album: " + saveToPhotoAlbum);
         return str.toString();
     }
 }


Mime
View raw message