From 307f9d1871bc1884b6499239f1adc3fd4f363fc0 Mon Sep 17 00:00:00 2001 From: Ron Reiter Date: Mon, 4 Apr 2011 02:57:10 +0300 Subject: [PATCH 1/3] Add maxResolution flag --- framework/assets/js/camera.js | 8 ++++- framework/build.properties | 7 ++++ framework/build.xml | 4 +-- .../src/com/phonegap/CameraLauncher.java | 34 +++++++++++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 framework/build.properties diff --git a/framework/assets/js/camera.js b/framework/assets/js/camera.js index c1ccc6e2..83ca9cb4 100755 --- a/framework/assets/js/camera.js +++ b/framework/assets/js/camera.js @@ -78,6 +78,12 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options) if (options.quality) { quality = this.options.quality; } + + var maxResolution = 0; + if (options.maxResolution) { + maxResolution = this.options.maxResolution; + } + var destinationType = Camera.DestinationType.DATA_URL; if (this.options.destinationType) { destinationType = this.options.destinationType; @@ -86,7 +92,7 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options) if (typeof this.options.sourceType === "number") { sourceType = this.options.sourceType; } - PhoneGap.exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType]); + PhoneGap.exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, maxResolution]); }; PhoneGap.addConstructor(function() { diff --git a/framework/build.properties b/framework/build.properties new file mode 100644 index 00000000..a6f4bf2c --- /dev/null +++ b/framework/build.properties @@ -0,0 +1,7 @@ +source.dir=C:\\Work\\phonegap-android\\framework\\src +gen.dir=C:\\Work\\phonegap-android\\framework\\gen +resource.dir=C:\\Work\\phonegap-android\\framework\\res +asset.dir=C:\\Work\\phonegap-android\\framework\\assets +external.libs.dir=C:\\Work\\phonegap-android\\framework\\lib +native.libs.dir=C:\\Work\\phonegap-android\\framework\\lib +out.dir=C:\\Work\\phonegap-android\\framework\\out diff --git a/framework/build.xml b/framework/build.xml index 1ad9bb75..155e28e0 100755 --- a/framework/build.xml +++ b/framework/build.xml @@ -1,5 +1,5 @@ - + @@ -167,7 +167,7 @@ "build-javascript" => "build-uncompressed-javascript". --> - + diff --git a/framework/src/com/phonegap/CameraLauncher.java b/framework/src/com/phonegap/CameraLauncher.java index 24e72d7c..26a2f8b1 100755 --- a/framework/src/com/phonegap/CameraLauncher.java +++ b/framework/src/com/phonegap/CameraLauncher.java @@ -44,6 +44,7 @@ public class CameraLauncher extends Plugin { private static final int SAVEDPHOTOALBUM = 2; // Choose image from picture library (same as PHOTOLIBRARY for Android) private int mQuality; // Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality) + private int mMaxResolution; // Maximum resolution of picture taken from camera (width or height, depending on the ratio) private Uri imageUri; // Uri of captured image public String callbackId; @@ -65,6 +66,7 @@ public class CameraLauncher extends Plugin { PluginResult.Status status = PluginResult.Status.OK; String result = ""; this.callbackId = callbackId; + this.mMaxResolution = 0; try { if (action.equals("takePicture")) { @@ -76,6 +78,9 @@ public class CameraLauncher extends Plugin { if (args.length() > 2) { srcType = args.getInt(2); } + if (args.length() > 3) { + this.mMaxResolution = args.getInt(3); + } if (srcType == CAMERA) { this.takePicture(args.getInt(0), destType); } @@ -145,6 +150,32 @@ public class CameraLauncher extends Plugin { new String("Get Picture")), (srcType+1)*16 + returnType + 1); } + /** + * Scales the bitmap according to the requested size. + * + * @param bitmap The bitmap to scale. + * @return Bitmap A new Bitmap object of the same bitmap after scaling. + */ + public Bitmap scaleBitmap(Bitmap bitmap) { + int newWidth = 0; + int newHeight = 0; + + if (this.mMaxResolution != 0) { + + // Check if a horizontal or vertical picture was taken + if (bitmap.getWidth() > bitmap.getHeight()) { + newWidth = this.mMaxResolution; + newHeight = (int)(((float)bitmap.getHeight() / (float)bitmap.getWidth()) * newWidth); + } else { + newHeight = this.mMaxResolution; + newWidth = (int)(((float)bitmap.getWidth() / (float)bitmap.getHeight()) * newHeight); + } + // Scale the bitmap before returning a compressed image + return Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true); + } + return bitmap; + } + /** * Called when the camera view exits. * @@ -168,6 +199,8 @@ public class CameraLauncher extends Plugin { // Read in bitmap of captured image Bitmap bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getContentResolver(), imageUri); + bitmap = scaleBitmap(bitmap); + // If sending base64 image back if (destType == DATA_URL) { this.processPicture(bitmap); @@ -230,6 +263,7 @@ public class CameraLauncher extends Plugin { if (destType == DATA_URL) { try { Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); + bitmap = scaleBitmap(bitmap); this.processPicture(bitmap); bitmap.recycle(); bitmap = null; From 8c807315e902995157fe293c52fd9c8155b5204d Mon Sep 17 00:00:00 2001 From: Dave Johnson Date: Thu, 21 Jul 2011 16:42:59 -0700 Subject: [PATCH 2/3] there was a "Location" and a "Geolocation" plugin defined. We use "Geolocation" in the JavaScript --- framework/res/xml/plugins.xml | 1 - 1 file changed, 1 deletion(-) mode change 100755 => 100644 framework/res/xml/plugins.xml diff --git a/framework/res/xml/plugins.xml b/framework/res/xml/plugins.xml old mode 100755 new mode 100644 index e62c959f..3d8d48d8 --- a/framework/res/xml/plugins.xml +++ b/framework/res/xml/plugins.xml @@ -10,7 +10,6 @@ - From 9f673db79fe94906435e4dcc9794faedd8e0c97b Mon Sep 17 00:00:00 2001 From: macdonst Date: Fri, 22 Jul 2011 10:01:44 +0800 Subject: [PATCH 3/3] Issue #176: rc2 for Android does not have updated main.js - demo app code This commit fixes the issue in main.js but it will still need to be packaged up in the rc3 zip. --- example/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/main.js b/example/main.js index 110d3089..1001aabc 100644 --- a/example/main.js +++ b/example/main.js @@ -99,7 +99,7 @@ function get_contacts() { var obj = new ContactFindOptions(); obj.filter = ""; obj.multiple = true; - navigator.service.contacts.find( + navigator.contacts.find( [ "displayName", "name" ], contacts_success, fail, obj); }