mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-cordova-android
This commit is contained in:
commit
c8f0ffb42f
51
bin/create
51
bin/create
@ -48,8 +48,14 @@ fi
|
|||||||
function on_exit {
|
function on_exit {
|
||||||
# [ -f $BUILD_PATH/framework/libs/commons-codec-1.6.jar ] && rm $BUILD_PATH/framework/libs/commons-codec-1.6.jar
|
# [ -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
|
# [ -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
|
if [ -f $BUILD_PATH/framework/assets/www/cordova-$VERSION.js ]
|
||||||
[ -f $BUILD_PATH/framework/cordova-$VERSION.jar ] && rm $BUILD_PATH/framework/cordova-$VERSION.jar
|
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 {
|
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 ' ' )
|
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
|
# 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
|
if [ ! -e $BUILD_PATH/framework/libs/commons-codec-1.6.jar ]; then
|
||||||
# Use curl to get the jar (TODO: Support Apache Mirrors)
|
# 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
|
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
|
unzip commons-codec-1.6-bin.zip &> /dev/null
|
||||||
mkdir -p $BUILD_PATH/framework/libs
|
mkdir -p $BUILD_PATH/framework/libs
|
||||||
cp commons-codec-1.6/commons-codec-1.6.jar $BUILD_PATH/framework/libs
|
cp commons-codec-1.6/commons-codec-1.6.jar $BUILD_PATH/framework/libs
|
||||||
# cleanup yo
|
# cleanup yo
|
||||||
rm commons-codec-1.6-bin.zip && rm -rf commons-codec-1.6
|
rm commons-codec-1.6-bin.zip && rm -rf commons-codec-1.6
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# compile cordova.js and cordova.jar
|
# 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
|
# create new android project
|
||||||
$ANDROID_BIN create project --target $TARGET --path $PROJECT_PATH --package $PACKAGE --activity $ACTIVITY &> /dev/null
|
$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
|
cp -r $BUILD_PATH/bin/templates/project/res $PROJECT_PATH
|
||||||
|
|
||||||
# copy cordova.js, cordova.jar and res/xml
|
# copy cordova.js, cordova.jar and res/xml
|
||||||
cp -r $BUILD_PATH/framework/res/xml $PROJECT_PATH/res
|
if [ -d $BUILD_PATH/framework ]
|
||||||
|
then
|
||||||
cp $BUILD_PATH/framework/assets/www/cordova-$VERSION.js $PROJECT_PATH/assets/www/cordova-$VERSION.js
|
cp -r $BUILD_PATH/framework/res/xml $PROJECT_PATH/res
|
||||||
cp $BUILD_PATH/framework/cordova-$VERSION.jar $PROJECT_PATH/libs/cordova-$VERSION.jar
|
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
|
# interpolate the activity name and package
|
||||||
cp $BUILD_PATH/bin/templates/project/Activity.java $ACTIVITY_PATH
|
cp $BUILD_PATH/bin/templates/project/Activity.java $ACTIVITY_PATH
|
||||||
|
@ -133,13 +133,15 @@ var VERSION=read(ROOT+'\\VERSION').replace(/\r\n/,'').replace(/\n/,'');
|
|||||||
// create the project
|
// create the project
|
||||||
exec('android.bat create project --target '+TARGET+' --path '+PROJECT_PATH+' --package '+PACKAGE+' --activity '+ACTIVITY);
|
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
|
// build from source. distro should have these files
|
||||||
exec('android.bat update project --target '+TARGET+' --path '+ROOT+'\\framework');
|
if (!fso.FileExists(ROOT+'\\cordova-'+VERSION+'.jar') &&
|
||||||
|
!fso.FileExists(ROOT+'\\cordova-'+VERSION+'.js')) {
|
||||||
// pull down commons codec if necessary
|
// update the cordova framework project to a target that exists on this machine
|
||||||
downloadCommonsCodec();
|
exec('android.bat update project --target '+TARGET+' --path '+ROOT+'\\framework');
|
||||||
|
// pull down commons codec if necessary
|
||||||
exec('ant.bat -f '+ ROOT +'\\framework\\build.xml jar');
|
downloadCommonsCodec();
|
||||||
|
exec('ant.bat -f '+ ROOT +'\\framework\\build.xml jar');
|
||||||
|
}
|
||||||
|
|
||||||
// copy in the project template
|
// copy in the project template
|
||||||
exec('%comspec% /c xcopy '+ ROOT + '\\bin\\templates\\project\\res '+PROJECT_PATH+'\\res\\ /E /Y');
|
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\\AndroidManifest.xml ' + PROJECT_PATH + '\\AndroidManifest.xml /Y');
|
||||||
exec('%comspec% /c copy '+ROOT+'\\bin\\templates\\project\\Activity.java '+ ACTIVITY_PATH +' /Y');
|
exec('%comspec% /c copy '+ROOT+'\\bin\\templates\\project\\Activity.java '+ ACTIVITY_PATH +' /Y');
|
||||||
|
|
||||||
// copy in cordova.js
|
// check if we have the source or the distro files
|
||||||
exec('%comspec% /c copy '+ROOT+'\\framework\\assets\\www\\cordova-'+VERSION+'.js '+PROJECT_PATH+'\\assets\\www\\cordova-'+VERSION+'.js /Y');
|
if(fso.FolderExists(ROOT + '\\framework')) {
|
||||||
|
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');
|
||||||
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');
|
||||||
// copy in xml
|
exec('%comspec% /c copy '+ROOT+'\\framework\\res\\xml\\plugins.xml ' + PROJECT_PATH + '\\res\\xml\\plugins.xml /Y');
|
||||||
fso.CreateFolder(PROJECT_PATH + '\\res\\xml');
|
} else {
|
||||||
exec('%comspec% /c copy '+ROOT+'\\framework\\res\\xml\\cordova.xml ' + PROJECT_PATH + '\\res\\xml\\cordova.xml /Y');
|
// copy in cordova.js
|
||||||
exec('%comspec% /c copy '+ROOT+'\\framework\\res\\xml\\plugins.xml ' + PROJECT_PATH + '\\res\\xml\\plugins.xml /Y');
|
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
|
// copy cordova scripts
|
||||||
fso.CreateFolder(PROJECT_PATH + '\\cordova');
|
fso.CreateFolder(PROJECT_PATH + '\\cordova');
|
||||||
|
@ -61,12 +61,15 @@ function log {
|
|||||||
adb logcat
|
adb logcat
|
||||||
}
|
}
|
||||||
|
|
||||||
function debug_install {
|
|
||||||
ant debug install
|
|
||||||
}
|
|
||||||
|
|
||||||
function debug {
|
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 {
|
function launch {
|
||||||
@ -75,16 +78,7 @@ function launch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function BOOM {
|
function BOOM {
|
||||||
clean
|
clean && debug && launch
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO parse arguments
|
# TODO parse arguments
|
||||||
|
28
bin/templates/cordova/cordova.js
vendored
28
bin/templates/cordova/cordova.js
vendored
@ -8,7 +8,7 @@ function exec(command) {
|
|||||||
if(!oExec.StdOut.AtEndOfStream) {
|
if(!oExec.StdOut.AtEndOfStream) {
|
||||||
var line = oExec.StdOut.ReadLine();
|
var line = oExec.StdOut.ReadLine();
|
||||||
// XXX: Change to verbose mode
|
// XXX: Change to verbose mode
|
||||||
//WScript.StdOut.WriteLine(line);
|
// WScript.StdOut.WriteLine(line);
|
||||||
output += line;
|
output += line;
|
||||||
}
|
}
|
||||||
WScript.sleep(100);
|
WScript.sleep(100);
|
||||||
@ -71,15 +71,18 @@ function clean() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function debug() {
|
function debug() {
|
||||||
exec("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1");
|
if(emulator_running()) {
|
||||||
}
|
exec("%comspec% /c ant.bat debug install -f "+ROOT+"\\build.xml 2>&1");
|
||||||
|
} else {
|
||||||
function debug_install() {
|
exec("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1");
|
||||||
exec("%comspec% /c ant.bat debug install -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() {
|
function log() {
|
||||||
WScript.Echo(exec("%comspec% /c adb.bat logcat"));
|
shell.Run("%comspec% /c adb logcat");
|
||||||
}
|
}
|
||||||
|
|
||||||
function launch() {
|
function launch() {
|
||||||
@ -90,15 +93,8 @@ function launch() {
|
|||||||
|
|
||||||
function BOOM() {
|
function BOOM() {
|
||||||
clean();
|
clean();
|
||||||
if(emulator_running()) {
|
debug();
|
||||||
debug_install();
|
launch();
|
||||||
launch();
|
|
||||||
} else {
|
|
||||||
debug();
|
|
||||||
WScript.Echo("##################################################################");
|
|
||||||
WScript.Echo("# Plug in your device or launch an emulator with cordova/emulate #");
|
|
||||||
WScript.Echo("##################################################################");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var args = WScript.Arguments;
|
var args = WScript.Arguments;
|
||||||
if(args.count() != 1) {
|
if(args.count() != 1) {
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
%~dp0\cordova.bat log
|
@ -12,3 +12,4 @@ split.density=false
|
|||||||
# Project target.
|
# Project target.
|
||||||
target=Google Inc.:Google APIs:15
|
target=Google Inc.:Google APIs:15
|
||||||
apk-configurations=
|
apk-configurations=
|
||||||
|
renderscript.opt.level=O0
|
||||||
|
@ -40,6 +40,7 @@ import android.content.ContentValues;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Bitmap.CompressFormat;
|
import android.graphics.Bitmap.CompressFormat;
|
||||||
import android.media.MediaScannerConnection;
|
import android.media.MediaScannerConnection;
|
||||||
@ -82,10 +83,12 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
private int encodingType; // Type of encoding to use
|
private int encodingType; // Type of encoding to use
|
||||||
private int mediaType; // What type of media to retrieve
|
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 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;
|
public String callbackId;
|
||||||
private int numPics;
|
private int numPics;
|
||||||
|
|
||||||
private MediaScannerConnection conn; // Used to update gallery app with newly-written files
|
private MediaScannerConnection conn; // Used to update gallery app with newly-written files
|
||||||
|
|
||||||
//This should never be null!
|
//This should never be null!
|
||||||
@ -136,6 +139,8 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
this.targetHeight = args.getInt(4);
|
this.targetHeight = args.getInt(4);
|
||||||
this.encodingType = args.getInt(5);
|
this.encodingType = args.getInt(5);
|
||||||
this.mediaType = args.getInt(6);
|
this.mediaType = args.getInt(6);
|
||||||
|
this.allowEdit = args.getBoolean(7);
|
||||||
|
this.correctOrientation = args.getBoolean(8);
|
||||||
this.saveToPhotoAlbum = args.getBoolean(9);
|
this.saveToPhotoAlbum = args.getBoolean(9);
|
||||||
|
|
||||||
if (srcType == CAMERA) {
|
if (srcType == CAMERA) {
|
||||||
@ -181,7 +186,6 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
|
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
|
||||||
|
|
||||||
// Specify file so that large image is captured and returned
|
// Specify file so that large image is captured and returned
|
||||||
// TODO: What if there isn't any external storage?
|
|
||||||
File photo = createCaptureFile(encodingType);
|
File photo = createCaptureFile(encodingType);
|
||||||
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
|
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
|
||||||
this.imageUri = Uri.fromFile(photo);
|
this.imageUri = Uri.fromFile(photo);
|
||||||
@ -244,53 +248,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.
|
* Called when the camera view exits.
|
||||||
*
|
*
|
||||||
@ -306,18 +263,19 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
int destType = (requestCode % 16) - 1;
|
int destType = (requestCode % 16) - 1;
|
||||||
int rotate = 0;
|
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();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
// If CAMERA
|
// If CAMERA
|
||||||
if (srcType == 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 image available
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
try {
|
try {
|
||||||
@ -325,7 +283,11 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
|
|
||||||
// If sending base64 image back
|
// If sending base64 image back
|
||||||
if (destType == DATA_URL) {
|
if (destType == DATA_URL) {
|
||||||
bitmap = scaleBitmap(getBitmapFromResult(intent));
|
bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString()));
|
||||||
|
|
||||||
|
if (rotate != 0 && this.correctOrientation) {
|
||||||
|
bitmap = getRotatedBitmap(rotate, bitmap, exif);
|
||||||
|
}
|
||||||
|
|
||||||
this.processPicture(bitmap);
|
this.processPicture(bitmap);
|
||||||
checkForDuplicateImage(DATA_URL);
|
checkForDuplicateImage(DATA_URL);
|
||||||
@ -337,50 +299,32 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
if (!this.saveToPhotoAlbum) {
|
if (!this.saveToPhotoAlbum) {
|
||||||
uri = Uri.fromFile(new File("/data/data/" + this.cordova.getActivity().getPackageName() + "/", (new File(FileUtils.stripFileProtocol(this.imageUri.toString()))).getName()));
|
uri = Uri.fromFile(new File("/data/data/" + this.cordova.getActivity().getPackageName() + "/", (new File(FileUtils.stripFileProtocol(this.imageUri.toString()))).getName()));
|
||||||
} else {
|
} else {
|
||||||
// Create entry in media store for image
|
uri = getUriFromMediaStore();
|
||||||
// (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");
|
|
||||||
|
|
||||||
try {
|
if (uri == null) {
|
||||||
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
this.failPicture("Error capturing image - no media storage found.");
|
||||||
} 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 all this is true we shouldn't compress the image.
|
// 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) {
|
||||||
FileInputStream fis = new FileInputStream(FileUtils.stripFileProtocol(imageUri.toString()));
|
writeUncompressedImage(uri);
|
||||||
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();
|
|
||||||
|
|
||||||
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
||||||
} else {
|
} else {
|
||||||
|
bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString()));
|
||||||
|
|
||||||
|
if (rotate != 0 && this.correctOrientation) {
|
||||||
|
bitmap = getRotatedBitmap(rotate, bitmap, exif);
|
||||||
|
}
|
||||||
|
|
||||||
bitmap = scaleBitmap(getBitmapFromResult(intent));
|
|
||||||
|
|
||||||
// Add compressed version of captured image to returned media store Uri
|
// Add compressed version of captured image to returned media store Uri
|
||||||
OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
|
OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
|
||||||
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
|
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
|
||||||
os.close();
|
os.close();
|
||||||
|
|
||||||
// Restore exif data to file
|
// Restore exif data to file
|
||||||
|
|
||||||
if (this.encodingType == JPEG) {
|
if (this.encodingType == JPEG) {
|
||||||
String exifPath;
|
String exifPath;
|
||||||
if (this.saveToPhotoAlbum) {
|
if (this.saveToPhotoAlbum) {
|
||||||
@ -391,15 +335,21 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
exif.createOutFile(exifPath);
|
exif.createOutFile(exifPath);
|
||||||
exif.writeExifData();
|
exif.writeExifData();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Send Uri back to JavaScript for viewing image
|
// 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);
|
this.cleanup(FILE_URI, this.imageUri, bitmap);
|
||||||
bitmap = null;
|
bitmap = null;
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
this.failPicture("Error capturing image.");
|
this.failPicture("Error capturing image.");
|
||||||
@ -421,7 +371,6 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
|
else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
Uri uri = intent.getData();
|
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
|
// 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
|
// and there will be no attempt to resize any returned data
|
||||||
@ -429,33 +378,28 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
// 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 sending base64 image back
|
||||||
if (destType == DATA_URL) {
|
if (destType == DATA_URL) {
|
||||||
try {
|
String[] cols = { MediaStore.Images.Media.ORIENTATION };
|
||||||
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
Cursor cursor = this.cordova.getActivity().getContentResolver().query(intent.getData(),
|
||||||
String[] cols = { MediaStore.Images.Media.ORIENTATION };
|
cols,
|
||||||
Cursor cursor = this.cordova.getActivity().getContentResolver().query(intent.getData(),
|
null, null, null);
|
||||||
cols,
|
if (cursor != null) {
|
||||||
null, null, null);
|
cursor.moveToPosition(0);
|
||||||
if (cursor != null) {
|
rotate = cursor.getInt(0);
|
||||||
cursor.moveToPosition(0);
|
cursor.close();
|
||||||
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.");
|
|
||||||
}
|
}
|
||||||
|
if (rotate != 0) {
|
||||||
|
Matrix matrix = new Matrix();
|
||||||
|
matrix.setRotate(rotate);
|
||||||
|
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
|
||||||
|
}
|
||||||
|
this.processPicture(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If sending filename back
|
// If sending filename back
|
||||||
@ -463,11 +407,20 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
// Do we need to scale the returned file
|
// Do we need to scale the returned file
|
||||||
if (this.targetHeight > 0 && this.targetWidth > 0) {
|
if (this.targetHeight > 0 && this.targetWidth > 0) {
|
||||||
try {
|
try {
|
||||||
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
// Create an ExifHelper to save the exif data that is lost during compression
|
||||||
bitmap = scaleBitmap(bitmap);
|
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(resizePath);
|
||||||
OutputStream os = new FileOutputStream(fileName);
|
|
||||||
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
|
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
|
||||||
os.close();
|
os.close();
|
||||||
|
|
||||||
@ -477,13 +430,9 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
exif.writeExifData();
|
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
|
// 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.
|
// 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);
|
||||||
System.gc();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
this.failPicture("Error retrieving image.");
|
this.failPicture("Error retrieving image.");
|
||||||
@ -493,6 +442,9 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bitmap.recycle();
|
||||||
|
bitmap = null;
|
||||||
|
System.gc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (resultCode == Activity.RESULT_CANCELED) {
|
else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
@ -504,19 +456,108 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Bitmap getBitmapFromResult(Intent intent)
|
/**
|
||||||
throws IOException, FileNotFoundException {
|
* Figure out if the bitmap should be rotated. For instance if the picture was taken in
|
||||||
Bitmap bitmap = null;
|
* portrait mode
|
||||||
try {
|
*
|
||||||
bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getActivity().getContentResolver(), imageUri);
|
* @param rotate
|
||||||
} catch (FileNotFoundException e) {
|
* @param bitmap
|
||||||
Uri uri = intent.getData();
|
* @return rotated bitmap
|
||||||
android.content.ContentResolver resolver = this.ctx.getActivity().getContentResolver();
|
*/
|
||||||
bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
private Bitmap getRotatedBitmap(int rotate, Bitmap bitmap, ExifHelper exif) {
|
||||||
|
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);
|
||||||
|
exif.resetOrientation();
|
||||||
return bitmap;
|
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.
|
* Creates a cursor that can be used to determine how many images we have.
|
||||||
*
|
*
|
||||||
@ -530,20 +571,22 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
null,
|
null,
|
||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleans up after picture taking. Checking for duplicates and that kind of stuff.
|
* Cleans up after picture taking. Checking for duplicates and that kind of stuff.
|
||||||
*/
|
*/
|
||||||
private void cleanup(int imageType, Uri oldImage, Bitmap bitmap) {
|
private void cleanup(int imageType, Uri oldImage, Bitmap bitmap) {
|
||||||
bitmap.recycle();
|
if (bitmap != null) {
|
||||||
|
bitmap.recycle();
|
||||||
|
}
|
||||||
|
|
||||||
// Clean up initial camera-written image file.
|
// Clean up initial camera-written image file.
|
||||||
(new File(FileUtils.stripFileProtocol(oldImage.toString()))).delete();
|
(new File(FileUtils.stripFileProtocol(oldImage.toString()))).delete();
|
||||||
|
|
||||||
checkForDuplicateImage(imageType);
|
checkForDuplicateImage(imageType);
|
||||||
// Scan for the gallery to update pic refs in gallery
|
// Scan for the gallery to update pic refs in gallery
|
||||||
this.scanForGallery();
|
this.scanForGallery();
|
||||||
|
|
||||||
System.gc();
|
System.gc();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -560,7 +603,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
Cursor cursor = queryImgDB(contentStore);
|
Cursor cursor = queryImgDB(contentStore);
|
||||||
int currentNumOfImages = cursor.getCount();
|
int currentNumOfImages = cursor.getCount();
|
||||||
|
|
||||||
if (type == FILE_URI) {
|
if (type == FILE_URI && this.saveToPhotoAlbum) {
|
||||||
diff = 2;
|
diff = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -616,12 +659,12 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
public void failPicture(String err) {
|
public void failPicture(String err) {
|
||||||
this.error(new PluginResult(PluginResult.Status.ERROR, err), this.callbackId);
|
this.error(new PluginResult(PluginResult.Status.ERROR, err), this.callbackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scanForGallery() {
|
private void scanForGallery() {
|
||||||
if(this.conn!=null) this.conn.disconnect();
|
if(this.conn!=null) this.conn.disconnect();
|
||||||
this.conn = new MediaScannerConnection(this.ctx.getActivity().getApplicationContext(), this);
|
this.conn = new MediaScannerConnection(this.ctx.getActivity().getApplicationContext(), this);
|
||||||
conn.connect();
|
conn.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onMediaScannerConnected() {
|
public void onMediaScannerConnected() {
|
||||||
try{
|
try{
|
||||||
@ -630,10 +673,10 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
LOG.d(LOG_TAG, "Can;t scan file in MediaScanner aftering taking picture");
|
LOG.d(LOG_TAG, "Can;t scan file in MediaScanner aftering taking picture");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onScanCompleted(String path, Uri uri) {
|
public void onScanCompleted(String path, Uri uri) {
|
||||||
this.conn.disconnect();
|
this.conn.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,4 +162,24 @@ public class ExifHelper {
|
|||||||
|
|
||||||
this.outFile.saveAttributes();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetOrientation() {
|
||||||
|
this.orientation = "" + ExifInterface.ORIENTATION_NORMAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ import java.io.InputStream;
|
|||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.URLDecoder;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -73,7 +74,7 @@ public class FileTransfer extends Plugin {
|
|||||||
String source = null;
|
String source = null;
|
||||||
String target = null;
|
String target = null;
|
||||||
try {
|
try {
|
||||||
source = args.getString(0);
|
source = URLDecoder.decode(args.getString(0));
|
||||||
target = args.getString(1);
|
target = args.getString(1);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.d(LOG_TAG, "Missing source or target");
|
Log.d(LOG_TAG, "Missing source or target");
|
||||||
@ -321,7 +322,7 @@ public class FileTransfer extends Plugin {
|
|||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
// Shouldn't happen, but will
|
// Shouldn't happen, but will
|
||||||
JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, conn);
|
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);
|
return new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
|
||||||
} finally {
|
} finally {
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user