From 99fb3ebe003cb27c03dd80ec377c595540ff17b8 Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Tue, 26 Jun 2012 17:34:19 -0700 Subject: [PATCH 01/16] creating project without source --- bin/create | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/bin/create b/bin/create index a4adc900..688b5fd0 100755 --- a/bin/create +++ b/bin/create @@ -48,8 +48,14 @@ fi function on_exit { # [ -f $BUILD_PATH/framework/libs/commons-codec-1.6.jar ] && rm $BUILD_PATH/framework/libs/commons-codec-1.6.jar # [ -d $BUILD_PATH/framework/libs ] && rmdir $BUILD_PATH/framework/libs - [ -f $BUILD_PATH/framework/assets/www/cordova-$VERSION.js ] && rm $BUILD_PATH/framework/assets/www/cordova-$VERSION.js - [ -f $BUILD_PATH/framework/cordova-$VERSION.jar ] && rm $BUILD_PATH/framework/cordova-$VERSION.jar + if [ -f $BUILD_PATH/framework/assets/www/cordova-$VERSION.js ] + then + rm $BUILD_PATH/framework/assets/www/cordova-$VERSION.js + fi + if [ -f $BUILD_PATH/framework/cordova-$VERSION.jar ] + then + rm $BUILD_PATH/framework/cordova-$VERSION.jar + fi } function on_error { @@ -68,21 +74,26 @@ MANIFEST_PATH=$PROJECT_PATH/AndroidManifest.xml TARGET=$($ANDROID_BIN list targets | grep id: | tail -1 | cut -f 2 -d ' ' ) +# if this a distribution release no need to build a jar +if [ ! -e $BUILD_PATH/cordova-$VERSION.jar ] && [ -d $BUILD_PATH/framework ] +then # update the cordova-android framework for the desired target -$ANDROID_BIN update project --target $TARGET --path $BUILD_PATH/framework &> /dev/null + $ANDROID_BIN update project --target $TARGET --path $BUILD_PATH/framework &> /dev/null -if [ ! -e $BUILD_PATH/framework/libs/commons-codec-1.6.jar ]; then - # Use curl to get the jar (TODO: Support Apache Mirrors) - curl -OL http://mirror.symnds.com/software/Apache//commons/codec/binaries/commons-codec-1.6-bin.zip &> /dev/null - unzip commons-codec-1.6-bin.zip &> /dev/null - mkdir -p $BUILD_PATH/framework/libs - cp commons-codec-1.6/commons-codec-1.6.jar $BUILD_PATH/framework/libs - # cleanup yo - rm commons-codec-1.6-bin.zip && rm -rf commons-codec-1.6 -fi + if [ ! -e $BUILD_PATH/framework/libs/commons-codec-1.6.jar ]; then + # Use curl to get the jar (TODO: Support Apache Mirrors) + curl -OL http://mirror.symnds.com/software/Apache//commons/codec/binaries/commons-codec-1.6-bin.zip &> /dev/null + unzip commons-codec-1.6-bin.zip &> /dev/null + mkdir -p $BUILD_PATH/framework/libs + cp commons-codec-1.6/commons-codec-1.6.jar $BUILD_PATH/framework/libs + # cleanup yo + rm commons-codec-1.6-bin.zip && rm -rf commons-codec-1.6 + fi # compile cordova.js and cordova.jar -(cd $BUILD_PATH/framework && ant jar &> /dev/null ) + (cd $BUILD_PATH/framework && ant jar &> /dev/null ) +fi + # create new android project $ANDROID_BIN create project --target $TARGET --path $PROJECT_PATH --package $PACKAGE --activity $ACTIVITY &> /dev/null @@ -92,10 +103,16 @@ cp -r $BUILD_PATH/bin/templates/project/assets $PROJECT_PATH cp -r $BUILD_PATH/bin/templates/project/res $PROJECT_PATH # copy cordova.js, cordova.jar and res/xml -cp -r $BUILD_PATH/framework/res/xml $PROJECT_PATH/res - -cp $BUILD_PATH/framework/assets/www/cordova-$VERSION.js $PROJECT_PATH/assets/www/cordova-$VERSION.js -cp $BUILD_PATH/framework/cordova-$VERSION.jar $PROJECT_PATH/libs/cordova-$VERSION.jar +if [ -d $BUILD_PATH/framework ] +then + cp -r $BUILD_PATH/framework/res/xml $PROJECT_PATH/res + cp $BUILD_PATH/framework/assets/www/cordova-$VERSION.js $PROJECT_PATH/assets/www/cordova-$VERSION.js + cp $BUILD_PATH/framework/cordova-$VERSION.jar $PROJECT_PATH/libs/cordova-$VERSION.jar +else + cp -r $BUILD_PATH/xml $PROJECT_PATH/res/xml + cp $BUILD_PATH/cordova-$VERSION.js $PROJECT_PATH/assets/www/cordova-$VERSION.js + cp $BUILD_PATH/cordova-$VERSION.jar $PROJECT_PATH/libs/cordova-$VERSION.jar +fi # interpolate the activity name and package cp $BUILD_PATH/bin/templates/project/Activity.java $ACTIVITY_PATH From e639b6303e123d7f52d7d7b900cfabfd5362c2bb Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Wed, 27 Jun 2012 17:54:57 -0700 Subject: [PATCH 02/16] updating create script to work from distro and source --- bin/create.js | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/bin/create.js b/bin/create.js index 35d4fd79..bec182ba 100644 --- a/bin/create.js +++ b/bin/create.js @@ -133,13 +133,15 @@ var VERSION=read(ROOT+'\\VERSION').replace(/\r\n/,'').replace(/\n/,''); // create the project exec('android.bat create project --target '+TARGET+' --path '+PROJECT_PATH+' --package '+PACKAGE+' --activity '+ACTIVITY); -// update the cordova framework project to a target that exists on this machine -exec('android.bat update project --target '+TARGET+' --path '+ROOT+'\\framework'); - -// pull down commons codec if necessary -downloadCommonsCodec(); - -exec('ant.bat -f '+ ROOT +'\\framework\\build.xml jar'); +// build from source. distro should have these files +if (!fso.FileExists(ROOT+'\\cordova-'+VERSION+'.jar') && + !fso.FileExists(ROOT+'\\cordova-'+VERSION+'.js')) { + // update the cordova framework project to a target that exists on this machine + exec('android.bat update project --target '+TARGET+' --path '+ROOT+'\\framework'); + // pull down commons codec if necessary + downloadCommonsCodec(); + exec('ant.bat -f '+ ROOT +'\\framework\\build.xml jar'); +} // copy in the project template exec('%comspec% /c xcopy '+ ROOT + '\\bin\\templates\\project\\res '+PROJECT_PATH+'\\res\\ /E /Y'); @@ -147,16 +149,23 @@ exec('%comspec% /c xcopy '+ ROOT + '\\bin\\templates\\project\\assets '+PROJECT_ exec('%comspec% /c copy '+ROOT+'\\bin\\templates\\project\\AndroidManifest.xml ' + PROJECT_PATH + '\\AndroidManifest.xml /Y'); exec('%comspec% /c copy '+ROOT+'\\bin\\templates\\project\\Activity.java '+ ACTIVITY_PATH +' /Y'); -// copy in cordova.js -exec('%comspec% /c copy '+ROOT+'\\framework\\assets\\www\\cordova-'+VERSION+'.js '+PROJECT_PATH+'\\assets\\www\\cordova-'+VERSION+'.js /Y'); - -// copy in cordova.jar -exec('%comspec% /c copy '+ROOT+'\\framework\\cordova-'+VERSION+'.jar '+PROJECT_PATH+'\\libs\\cordova-'+VERSION+'.jar /Y'); - -// copy in xml -fso.CreateFolder(PROJECT_PATH + '\\res\\xml'); -exec('%comspec% /c copy '+ROOT+'\\framework\\res\\xml\\cordova.xml ' + PROJECT_PATH + '\\res\\xml\\cordova.xml /Y'); -exec('%comspec% /c copy '+ROOT+'\\framework\\res\\xml\\plugins.xml ' + PROJECT_PATH + '\\res\\xml\\plugins.xml /Y'); +// check if we have the source or the distro files +if(fso.FolderExists(ROOT + '\\framework')) { + exec('%comspec% /c copy '+ROOT+'\\framework\\assets\\www\\cordova-'+VERSION+'.js '+PROJECT_PATH+'\\assets\\www\\cordova-'+VERSION+'.js /Y'); + exec('%comspec% /c copy '+ROOT+'\\framework\\cordova-'+VERSION+'.jar '+PROJECT_PATH+'\\libs\\cordova-'+VERSION+'.jar /Y'); + fso.CreateFolder(PROJECT_PATH + '\\res\\xml'); + exec('%comspec% /c copy '+ROOT+'\\framework\\res\\xml\\cordova.xml ' + PROJECT_PATH + '\\res\\xml\\cordova.xml /Y'); + exec('%comspec% /c copy '+ROOT+'\\framework\\res\\xml\\plugins.xml ' + PROJECT_PATH + '\\res\\xml\\plugins.xml /Y'); +} else { + // copy in cordova.js + exec('%comspec% /c copy '+ROOT+'\\cordova-'+VERSION+'.js '+PROJECT_PATH+'\\assets\\www\\cordova-'+VERSION+'.js /Y'); + // copy in cordova.jar + exec('%comspec% /c copy '+ROOT+'\\cordova-'+VERSION+'.jar '+PROJECT_PATH+'\\libs\\cordova-'+VERSION+'.jar /Y'); + // copy in xml + fso.CreateFolder(PROJECT_PATH + '\\res\\xml'); + exec('%comspec% /c copy '+ROOT+'\\xml\\cordova.xml ' + PROJECT_PATH + '\\res\\xml\\cordova.xml /Y'); + exec('%comspec% /c copy '+ROOT+'\\xml\\plugins.xml ' + PROJECT_PATH + '\\res\\xml\\plugins.xml /Y'); +} // copy cordova scripts fso.CreateFolder(PROJECT_PATH + '\\cordova'); From 98138a0a60655e65b2e50436ab869fa0909896b6 Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Wed, 27 Jun 2012 17:55:35 -0700 Subject: [PATCH 03/16] log was actually doing nothing...fixing it --- bin/templates/cordova/cordova.js | 4 ++-- bin/templates/cordova/log.bat | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/templates/cordova/cordova.js b/bin/templates/cordova/cordova.js index 6353b55d..b25ee6b5 100644 --- a/bin/templates/cordova/cordova.js +++ b/bin/templates/cordova/cordova.js @@ -8,7 +8,7 @@ function exec(command) { if(!oExec.StdOut.AtEndOfStream) { var line = oExec.StdOut.ReadLine(); // XXX: Change to verbose mode - //WScript.StdOut.WriteLine(line); + // WScript.StdOut.WriteLine(line); output += line; } WScript.sleep(100); @@ -79,7 +79,7 @@ function debug_install() { } function log() { - WScript.Echo(exec("%comspec% /c adb.bat logcat")); + shell.Run("%comspec% /c adb logcat"); } function launch() { diff --git a/bin/templates/cordova/log.bat b/bin/templates/cordova/log.bat index e69de29b..688d0d02 100644 --- a/bin/templates/cordova/log.bat +++ b/bin/templates/cordova/log.bat @@ -0,0 +1 @@ +%~dp0\cordova.bat log From f78af9f27baa82a351fb4b8a317ad50d54d99e56 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Thu, 28 Jun 2012 08:00:35 -0700 Subject: [PATCH 04/16] Forgot to add it renderscript.opt.level to the project. This will fix ant issues --- framework/project.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/project.properties b/framework/project.properties index 276f1305..1b7604c7 100644 --- a/framework/project.properties +++ b/framework/project.properties @@ -12,3 +12,4 @@ split.density=false # Project target. target=Google Inc.:Google APIs:15 apk-configurations= +renderscript.opt.level=O0 From 87b81e53f00dcd93ebdbdf2f4bdb0c6d950f4f1a Mon Sep 17 00:00:00 2001 From: macdonst Date: Thu, 28 Jun 2012 11:57:06 -0400 Subject: [PATCH 05/16] CB-978: FileTransfer.upload from a directory with a space fails --- framework/src/org/apache/cordova/FileTransfer.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/src/org/apache/cordova/FileTransfer.java b/framework/src/org/apache/cordova/FileTransfer.java index 824ad020..2b2620ba 100644 --- a/framework/src/org/apache/cordova/FileTransfer.java +++ b/framework/src/org/apache/cordova/FileTransfer.java @@ -29,6 +29,7 @@ import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLDecoder; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.Iterator; @@ -73,7 +74,7 @@ public class FileTransfer extends Plugin { String source = null; String target = null; try { - source = args.getString(0); + source = URLDecoder.decode(args.getString(0)); target = args.getString(1); } catch (JSONException e) { Log.d(LOG_TAG, "Missing source or target"); @@ -321,7 +322,7 @@ public class FileTransfer extends Plugin { } catch (Throwable t) { // Shouldn't happen, but will JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, conn); - Log.wtf(LOG_TAG, error.toString(), t); + Log.e(LOG_TAG, error.toString(), t); return new PluginResult(PluginResult.Status.IO_EXCEPTION, error); } finally { if (conn != null) { From a74f71c935e4b9c57ab45652664b0c337f257c6b Mon Sep 17 00:00:00 2001 From: macdonst Date: Tue, 26 Jun 2012 13:41:53 -0400 Subject: [PATCH 06/16] Decode image from File instead of content resolver --- .../org/apache/cordova/CameraLauncher.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index 3b720b71..496b20e8 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(); } } From 8aa9d8213dfc313ceee2d0610cb158fd96bda2e8 Mon Sep 17 00:00:00 2001 From: macdonst Date: Tue, 26 Jun 2012 13:57:52 -0400 Subject: [PATCH 07/16] Cache bust returned Image URI if saveToPhotoAlbum is false --- framework/src/org/apache/cordova/CameraLauncher.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index 496b20e8..f2ee3e67 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -395,7 +395,13 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie } // Send Uri back to JavaScript for viewing image - this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); + if (saveToPhotoAlbum) { + this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); + } else { + // If you don't want to save the file to the photo album you need to append a timestamp + // to the returned URI to do some cache busting. + this.success(new PluginResult(PluginResult.Status.OK, uri.toString() + "?" + System.currentTimeMillis()), this.callbackId); + } } this.cleanup(FILE_URI, this.imageUri, bitmap); From 483e5dfbeaa2e13bdd2e7cc79e2f72f9d89eff66 Mon Sep 17 00:00:00 2001 From: macdonst Date: Tue, 26 Jun 2012 14:45:51 -0400 Subject: [PATCH 08/16] Switch getPicture from Gallery to use file instead of content resolver --- .../org/apache/cordova/CameraLauncher.java | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index f2ee3e67..2ba5a395 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"; From e0eadb6b76adb411e2ca30b37e8d4fde81a78b75 Mon Sep 17 00:00:00 2001 From: macdonst Date: Tue, 26 Jun 2012 22:13:39 -0400 Subject: [PATCH 09/16] Using a better scaling algorithm to resize the image Instead of reading the entire image into a bitmap then scaling we use the inSampleSize option to get a close to the target width and height as possible then we scale that smaller image. --- .../org/apache/cordova/CameraLauncher.java | 200 +++++++++--------- 1 file changed, 96 insertions(+), 104 deletions(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index 2ba5a395..04cd1c02 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -182,7 +182,6 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); // Specify file so that large image is captured and returned - // TODO: What if there isn't any external storage? File photo = createCaptureFile(encodingType); intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); this.imageUri = Uri.fromFile(photo); @@ -245,53 +244,6 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie } } - /** - * 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 = this.targetWidth; - int newHeight = this.targetHeight; - int origWidth = bitmap.getWidth(); - int origHeight = bitmap.getHeight(); - - // If no new width or height were specified return the original bitmap - if (newWidth <= 0 && newHeight <= 0) { - return bitmap; - } - // Only the width was specified - else if (newWidth > 0 && newHeight <= 0) { - newHeight = (newWidth * origHeight) / origWidth; - } - // only the height was specified - else if (newWidth <= 0 && newHeight > 0) { - newWidth = (newHeight * origWidth) / origHeight; - } - // If the user specified both a positive width and height - // (potentially different aspect ratio) then the width or height is - // scaled so that the image fits while maintaining aspect ratio. - // Alternatively, the specified width and height could have been - // kept and Bitmap.SCALE_TO_FIT specified when scaling, but this - // would result in whitespace in the new image. - else { - double newRatio = newWidth / (double) newHeight; - double origRatio = origWidth / (double) origHeight; - - if (origRatio > newRatio) { - newHeight = (newWidth * origHeight) / origWidth; - } else if (origRatio < newRatio) { - newWidth = (newHeight * origWidth) / origHeight; - } - } - - Bitmap retval = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true); - bitmap.recycle(); - System.gc(); - return retval; - } - /** * Called when the camera view exits. * @@ -326,7 +278,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie // If sending base64 image back if (destType == DATA_URL) { - bitmap = scaleBitmap(getBitmapFromResult(intent)); + bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); this.processPicture(bitmap); checkForDuplicateImage(DATA_URL); @@ -338,42 +290,20 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie if (!this.saveToPhotoAlbum) { uri = Uri.fromFile(new File("/data/data/" + this.cordova.getActivity().getPackageName() + "/", (new File(FileUtils.stripFileProtocol(this.imageUri.toString()))).getName())); } else { - // Create entry in media store for image - // (Don't use insertImage() because it uses default compression setting of 50 - no way to change it) - ContentValues values = new ContentValues(); - values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); + uri = getUriFromMediaStore(); + } - try { - uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); - } catch (UnsupportedOperationException e) { - LOG.d(LOG_TAG, "Can't write to external media storage."); - try { - uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); - } catch (UnsupportedOperationException ex) { - LOG.d(LOG_TAG, "Can't write to internal media storage."); - this.failPicture("Error capturing image - no media storage found."); - return; - } - } + if (uri == null) { + this.failPicture("Error capturing image - no media storage found."); } // If all this is true we shouldn't compress the image. if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100) { - FileInputStream fis = new FileInputStream(FileUtils.stripFileProtocol(imageUri.toString())); - OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); - byte[] buffer = new byte[4096]; - int len; - while ((len = fis.read(buffer)) != -1) { - os.write(buffer, 0, len); - } - os.flush(); - os.close(); - fis.close(); + writeUncompressedImage(uri); this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } else { - - bitmap = scaleBitmap(getBitmapFromResult(intent)); + bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); // Add compressed version of captured image to returned media store Uri OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); @@ -435,12 +365,13 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } else { - // If sending base64 image back // Get the path to the image. Makes loading so much easier. String imagePath = FileUtils.getRealPathFromURI(uri, this.cordova); + Bitmap bitmap = getScaledBitmap(imagePath); + + // If sending base64 image back if (destType == DATA_URL) { - Bitmap bitmap = BitmapFactory.decodeFile(imagePath); String[] cols = { MediaStore.Images.Media.ORIENTATION }; Cursor cursor = this.cordova.getActivity().getContentResolver().query(intent.getData(), cols, @@ -455,11 +386,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie 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 @@ -467,8 +394,6 @@ 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 = BitmapFactory.decodeFile(imagePath); - bitmap = scaleBitmap(bitmap); String fileName = DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/resize.jpg"; OutputStream os = new FileOutputStream(fileName); @@ -481,13 +406,9 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie exif.writeExifData(); } - bitmap.recycle(); - bitmap = null; - // The resized image is cached by the app in order to get around this and not have to delete you // application cache I'm adding the current system time to the end of the file url. this.success(new PluginResult(PluginResult.Status.OK, ("file://" + fileName + "?" + System.currentTimeMillis())), this.callbackId); - System.gc(); } catch (Exception e) { e.printStackTrace(); this.failPicture("Error retrieving image."); @@ -497,6 +418,9 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } } + bitmap.recycle(); + bitmap = null; + System.gc(); } } else if (resultCode == Activity.RESULT_CANCELED) { @@ -508,22 +432,88 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie } } - private Bitmap getBitmapFromResult(Intent intent) - throws IOException { - Bitmap bitmap = null; - //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; + /** + * In the special case where the default width, height and quality are unchanged + * we just write the file out to disk saving the expensive Bitmap.compress function. + * + * @param uri + * @throws FileNotFoundException + * @throws IOException + */ + private void writeUncompressedImage(Uri uri) throws FileNotFoundException, + IOException { + FileInputStream fis = new FileInputStream(FileUtils.stripFileProtocol(imageUri.toString())); + OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); + byte[] buffer = new byte[4096]; + int len; + while ((len = fis.read(buffer)) != -1) { + os.write(buffer, 0, len); + } + os.flush(); + os.close(); + fis.close(); } + /** + * Create entry in media store for image + * + * @return uri + */ + private Uri getUriFromMediaStore() { + ContentValues values = new ContentValues(); + values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); + Uri uri; + try { + uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); + } catch (UnsupportedOperationException e) { + LOG.d(LOG_TAG, "Can't write to external media storage."); + try { + uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); + } catch (UnsupportedOperationException ex) { + LOG.d(LOG_TAG, "Can't write to internal media storage."); + return null; + } + } + return uri; + } + + /** + * Return a scaled bitmap based on the target width and height + * + * @param imagePath + * @return + */ + private Bitmap getScaledBitmap(String imagePath) { + // If no new width or height were specified return the original bitmap + if (this.targetWidth <= 0 && this.targetHeight <= 0) { + return BitmapFactory.decodeFile(imagePath); + } + + Bitmap unscaledBitmap = decodeFile(imagePath, + this.targetWidth, this.targetHeight); + return Bitmap.createScaledBitmap(unscaledBitmap, this.targetWidth, this.targetHeight, true); + } + + public static Bitmap decodeFile(String pathName, int dstWidth, int dstHeight) { + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeFile(pathName, options); + options.inJustDecodeBounds = false; + options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, dstWidth, dstHeight); + return BitmapFactory.decodeFile(pathName, options); + } + + public static int calculateSampleSize(int srcWidth, int srcHeight, int dstWidth, int dstHeight) { + final float srcAspect = (float)srcWidth / (float)srcHeight; + final float dstAspect = (float)dstWidth / (float)dstHeight; + + if (srcAspect > dstAspect) { + return srcWidth / dstWidth; + } else { + return srcHeight / dstHeight; + } + } + /** * Creates a cursor that can be used to determine how many images we have. * @@ -542,7 +532,9 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie * Cleans up after picture taking. Checking for duplicates and that kind of stuff. */ private void cleanup(int imageType, Uri oldImage, Bitmap bitmap) { - bitmap.recycle(); + if (bitmap != null) { + bitmap.recycle(); + } // Clean up initial camera-written image file. (new File(FileUtils.stripFileProtocol(oldImage.toString()))).delete(); From e0e4ba2bd7df332f621274728af45b1e64d05564 Mon Sep 17 00:00:00 2001 From: macdonst Date: Tue, 26 Jun 2012 22:24:05 -0400 Subject: [PATCH 10/16] Fix double image problem on Samsung phones On Samsung phones even if you tell the camera not to save to the photo gallery it still does. This small fix deletes the original file as it is not needed. --- framework/src/org/apache/cordova/CameraLauncher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index 04cd1c02..cfe58a61 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -559,7 +559,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie Cursor cursor = queryImgDB(contentStore); int currentNumOfImages = cursor.getCount(); - if (type == FILE_URI) { + if (type == FILE_URI && this.saveToPhotoAlbum) { diff = 2; } From dddce3036827263e6587e94b1e78b85de9de789b Mon Sep 17 00:00:00 2001 From: macdonst Date: Tue, 26 Jun 2012 23:50:52 -0400 Subject: [PATCH 11/16] Rotate image if taken in portrait mode --- .../org/apache/cordova/CameraLauncher.java | 29 +++++++++++++++++++ .../src/org/apache/cordova/ExifHelper.java | 16 ++++++++++ 2 files changed, 45 insertions(+) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index cfe58a61..5d1d2b6e 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -280,6 +280,11 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie if (destType == DATA_URL) { bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); + rotate = exif.getOrientation(); + if (rotate != 0) { + bitmap = getRotatedBitmap(rotate, bitmap); + } + this.processPicture(bitmap); checkForDuplicateImage(DATA_URL); } @@ -305,6 +310,11 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie } else { bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); + rotate = exif.getOrientation(); + if (rotate != 0) { + bitmap = getRotatedBitmap(rotate, bitmap); + } + // 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); @@ -432,6 +442,25 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie } } + /** + * Figure out if the bitmap should be rotated. For instance if the picture was taken in + * portrait mode + * + * @param rotate + * @param bitmap + * @return rotated bitmap + */ + private Bitmap getRotatedBitmap(int rotate, Bitmap bitmap) { + Matrix matrix = new Matrix(); + if (rotate == 180) { + matrix.setRotate(rotate); + } else { + matrix.setRotate(rotate, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2); + } + bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); + return bitmap; + } + /** * In the special case where the default width, height and quality are unchanged * we just write the file out to disk saving the expensive Bitmap.compress function. diff --git a/framework/src/org/apache/cordova/ExifHelper.java b/framework/src/org/apache/cordova/ExifHelper.java index 8b4d179d..c4f7d91e 100644 --- a/framework/src/org/apache/cordova/ExifHelper.java +++ b/framework/src/org/apache/cordova/ExifHelper.java @@ -162,4 +162,20 @@ public class ExifHelper { this.outFile.saveAttributes(); } + + public int getOrientation() { + int o = Integer.parseInt(this.orientation); + + if (o == ExifInterface.ORIENTATION_NORMAL) { + return 0; + } else if (o == ExifInterface.ORIENTATION_ROTATE_90) { + return 90; + } else if (o == ExifInterface.ORIENTATION_ROTATE_180) { + return 180; + } else if (o == ExifInterface.ORIENTATION_ROTATE_270) { + return 270; + } else { + return 0; + } + } } From 231b39d2dc0b953472a17646a591cce1edf9d7af Mon Sep 17 00:00:00 2001 From: macdonst Date: Wed, 27 Jun 2012 14:06:52 -0400 Subject: [PATCH 12/16] Reset orientation exif information when photo is rotated When a photo is taken in portrait mode we rotate it so it shows up properly in the webview. The Exif orientation must be reset to normal orientation (0) or the image will not display properly on desktops. --- framework/src/org/apache/cordova/CameraLauncher.java | 12 ++++++------ framework/src/org/apache/cordova/ExifHelper.java | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index 5d1d2b6e..4d21a9b5 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -265,6 +265,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie if (this.encodingType == JPEG) { exif.createInFile(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/.Pic.jpg"); exif.readExifData(); + rotate = exif.getOrientation(); } } catch (IOException e) { e.printStackTrace(); @@ -280,9 +281,8 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie if (destType == DATA_URL) { bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); - rotate = exif.getOrientation(); if (rotate != 0) { - bitmap = getRotatedBitmap(rotate, bitmap); + bitmap = getRotatedBitmap(rotate, bitmap, exif); } this.processPicture(bitmap); @@ -303,16 +303,15 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie } // If all this is true we shouldn't compress the image. - if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100) { + if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && rotate == 0) { writeUncompressedImage(uri); this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } else { bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); - rotate = exif.getOrientation(); if (rotate != 0) { - bitmap = getRotatedBitmap(rotate, bitmap); + bitmap = getRotatedBitmap(rotate, bitmap, exif); } // Add compressed version of captured image to returned media store Uri @@ -450,7 +449,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie * @param bitmap * @return rotated bitmap */ - private Bitmap getRotatedBitmap(int rotate, Bitmap bitmap) { + private Bitmap getRotatedBitmap(int rotate, Bitmap bitmap, ExifHelper exif) { Matrix matrix = new Matrix(); if (rotate == 180) { matrix.setRotate(rotate); @@ -458,6 +457,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie matrix.setRotate(rotate, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2); } bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); + exif.resetOrientation(); return bitmap; } diff --git a/framework/src/org/apache/cordova/ExifHelper.java b/framework/src/org/apache/cordova/ExifHelper.java index c4f7d91e..4be79f1f 100644 --- a/framework/src/org/apache/cordova/ExifHelper.java +++ b/framework/src/org/apache/cordova/ExifHelper.java @@ -178,4 +178,8 @@ public class ExifHelper { return 0; } } + + public void resetOrientation() { + this.orientation = "" + ExifInterface.ORIENTATION_NORMAL; + } } From e2047afa426066b2764cfb3b1b0fa809abdc6f55 Mon Sep 17 00:00:00 2001 From: macdonst Date: Wed, 27 Jun 2012 15:32:26 -0400 Subject: [PATCH 13/16] Wire rotation fix to correctOrientation parameter --- framework/src/org/apache/cordova/CameraLauncher.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index 4d21a9b5..8b0c7b4d 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -83,6 +83,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie private int encodingType; // Type of encoding to use private int mediaType; // What type of media to retrieve private boolean saveToPhotoAlbum; // Should the picture be saved to the device's photo album + private boolean correctOrientation; // Should the pictures orientation be corrected public String callbackId; private int numPics; @@ -137,6 +138,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie this.targetHeight = args.getInt(4); this.encodingType = args.getInt(5); this.mediaType = args.getInt(6); + this.correctOrientation = args.getBoolean(8); this.saveToPhotoAlbum = args.getBoolean(9); if (srcType == CAMERA) { @@ -281,7 +283,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie if (destType == DATA_URL) { bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); - if (rotate != 0) { + if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } @@ -310,7 +312,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie } else { bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); - if (rotate != 0) { + if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } From 17ff6be6a90b106cf383a80063ea25e8f28d8062 Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Thu, 28 Jun 2012 17:08:32 -0700 Subject: [PATCH 14/16] CB-937 fixing debug --- bin/templates/cordova/cordova | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/bin/templates/cordova/cordova b/bin/templates/cordova/cordova index 0f3e452c..0bca03f7 100755 --- a/bin/templates/cordova/cordova +++ b/bin/templates/cordova/cordova @@ -61,12 +61,15 @@ function log { adb logcat } -function debug_install { - ant debug install -} - function debug { - ant debug + if [ $(check_devices) == 0 ] ; then + ant debug install + else + ant debug + echo "##################################################################" + echo "# Plug in your device or launch an emulator with cordova/emulate #" + echo "##################################################################" + fi } function launch { @@ -75,16 +78,7 @@ function launch { } function BOOM { - clean - if [ $(check_devices) == 0 ] ; then - debug_install && launch - return - else - debug - echo "##################################################################" - echo "# Plug in your device or launch an emulator with cordova/emulate #" - echo "##################################################################" - fi + clean && debug && launch } # TODO parse arguments From e069bbb800436e8748de29008c7632f901b52c95 Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Thu, 28 Jun 2012 17:11:21 -0700 Subject: [PATCH 15/16] CB-937 fixing debug for windows --- bin/templates/cordova/cordova.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/bin/templates/cordova/cordova.js b/bin/templates/cordova/cordova.js index b25ee6b5..e0e9762e 100644 --- a/bin/templates/cordova/cordova.js +++ b/bin/templates/cordova/cordova.js @@ -71,11 +71,14 @@ function clean() { } function debug() { - exec("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1"); -} - -function debug_install() { - exec("%comspec% /c ant.bat debug install -f "+ROOT+"\\build.xml 2>&1"); + if(emulator_running()) { + exec("%comspec% /c ant.bat debug install -f "+ROOT+"\\build.xml 2>&1"); + } else { + exec("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1"); + WScript.Echo("##################################################################"); + WScript.Echo("# Plug in your device or launch an emulator with cordova/emulate #"); + WScript.Echo("##################################################################"); + } } function log() { @@ -90,15 +93,8 @@ function launch() { function BOOM() { clean(); - if(emulator_running()) { - debug_install(); - launch(); - } else { - debug(); - WScript.Echo("##################################################################"); - WScript.Echo("# Plug in your device or launch an emulator with cordova/emulate #"); - WScript.Echo("##################################################################"); - } + debug(); + launch(); } var args = WScript.Arguments; if(args.count() != 1) { From ae7a550a093573e02cc6280a35541b71e822db41 Mon Sep 17 00:00:00 2001 From: macdonst Date: Fri, 29 Jun 2012 11:31:33 -0400 Subject: [PATCH 16/16] Only load Exif information if necessary --- .../org/apache/cordova/CameraLauncher.java | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index 8b0c7b4d..092f2543 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -84,6 +84,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie private int mediaType; // What type of media to retrieve private boolean saveToPhotoAlbum; // Should the picture be saved to the device's photo album private boolean correctOrientation; // Should the pictures orientation be corrected + private boolean allowEdit; // Should we allow the user to crop the image public String callbackId; private int numPics; @@ -138,6 +139,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie this.targetHeight = args.getInt(4); this.encodingType = args.getInt(5); this.mediaType = args.getInt(6); + this.allowEdit = args.getBoolean(7); this.correctOrientation = args.getBoolean(8); this.saveToPhotoAlbum = args.getBoolean(9); @@ -261,19 +263,19 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie int destType = (requestCode % 16) - 1; int rotate = 0; - // Create an ExifHelper to save the exif data that is lost during compression - ExifHelper exif = new ExifHelper(); - try { - if (this.encodingType == JPEG) { - exif.createInFile(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/.Pic.jpg"); - exif.readExifData(); - rotate = exif.getOrientation(); - } - } catch (IOException e) { - e.printStackTrace(); - } // If CAMERA if (srcType == CAMERA) { + // Create an ExifHelper to save the exif data that is lost during compression + ExifHelper exif = new ExifHelper(); + try { + if (this.encodingType == JPEG) { + exif.createInFile(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/.Pic.jpg"); + exif.readExifData(); + rotate = exif.getOrientation(); + } + } catch (IOException e) { + e.printStackTrace(); + } // If image available if (resultCode == Activity.RESULT_OK) { try { @@ -405,9 +407,20 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie // Do we need to scale the returned file if (this.targetHeight > 0 && this.targetWidth > 0) { try { + // Create an ExifHelper to save the exif data that is lost during compression + String resizePath = DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/resize.jpg"; + ExifHelper exif = new ExifHelper(); + try { + if (this.encodingType == JPEG) { + exif.createInFile(resizePath); + exif.readExifData(); + rotate = exif.getOrientation(); + } + } catch (IOException e) { + e.printStackTrace(); + } - String fileName = DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/resize.jpg"; - OutputStream os = new FileOutputStream(fileName); + OutputStream os = new FileOutputStream(resizePath); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); @@ -419,7 +432,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie // The resized image is cached by the app in order to get around this and not have to delete you // application cache I'm adding the current system time to the end of the file url. - this.success(new PluginResult(PluginResult.Status.OK, ("file://" + fileName + "?" + System.currentTimeMillis())), this.callbackId); + this.success(new PluginResult(PluginResult.Status.OK, ("file://" + resizePath + "?" + System.currentTimeMillis())), this.callbackId); } catch (Exception e) { e.printStackTrace(); this.failPicture("Error retrieving image.");