mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-27 04:42:51 +08:00
Refactored cleanup in camera code a bit. Removed overrides for Scanner functionality
This commit is contained in:
parent
5935052ead
commit
5ca4b4a884
@ -335,19 +335,7 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
else if (destType == FILE_URI) {
|
else if (destType == FILE_URI) {
|
||||||
Uri uri;
|
Uri uri;
|
||||||
if (!this.saveToPhotoAlbum) {
|
if (!this.saveToPhotoAlbum) {
|
||||||
File tempFile = new File(this.imageUri.toString());
|
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() + "/", tempFile.getName()));
|
|
||||||
|
|
||||||
// Clean up initial URI before writing out safe URI.
|
|
||||||
// First try File-based approach to delete. Then use the media delete method. Neither seem to work on ICS right now...
|
|
||||||
boolean didWeDeleteIt = tempFile.delete();
|
|
||||||
if (!didWeDeleteIt) {
|
|
||||||
int result = this.cordova.getActivity().getContentResolver().delete(
|
|
||||||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
|
||||||
MediaStore.Images.Media.DATA + " = ?",
|
|
||||||
new String[] { this.imageUri.toString() }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Create entry in media store for image
|
// Create entry in media store for image
|
||||||
// (Don't use insertImage() because it uses default compression setting of 50 - no way to change it)
|
// (Don't use insertImage() because it uses default compression setting of 50 - no way to change it)
|
||||||
@ -381,11 +369,8 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
os.close();
|
os.close();
|
||||||
fis.close();
|
fis.close();
|
||||||
|
|
||||||
checkForDuplicateImage(FILE_URI);
|
|
||||||
|
|
||||||
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
||||||
return;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
bitmap = scaleBitmap(getBitmapFromResult(intent));
|
bitmap = scaleBitmap(getBitmapFromResult(intent));
|
||||||
|
|
||||||
@ -407,18 +392,13 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
exif.writeExifData();
|
exif.writeExifData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
// Scan for the gallery to update pic refs in gallery
|
|
||||||
this.scanForGallery();
|
|
||||||
|
|
||||||
// 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);
|
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
||||||
}
|
}
|
||||||
bitmap.recycle();
|
|
||||||
bitmap = null;
|
|
||||||
System.gc();
|
|
||||||
|
|
||||||
checkForDuplicateImage(FILE_URI);
|
this.cleanup(FILE_URI, this.imageUri, bitmap);
|
||||||
|
bitmap = null;
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -551,6 +531,22 @@ 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();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to find out if we are in a situation where the Camera Intent adds to images
|
* Used to find out if we are in a situation where the Camera Intent adds to images
|
||||||
* to the content store. If we are using a FILE_URI and the number of images in the DB
|
* to the content store. If we are using a FILE_URI and the number of images in the DB
|
||||||
@ -627,7 +623,6 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
conn.connect();
|
conn.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMediaScannerConnected() {
|
public void onMediaScannerConnected() {
|
||||||
try{
|
try{
|
||||||
this.conn.scanFile(this.imageUri.toString(), "image/*");
|
this.conn.scanFile(this.imageUri.toString(), "image/*");
|
||||||
@ -638,7 +633,6 @@ public class CameraLauncher extends Plugin implements MediaScannerConnectionClie
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onScanCompleted(String path, Uri uri) {
|
public void onScanCompleted(String path, Uri uri) {
|
||||||
this.conn.disconnect();
|
this.conn.disconnect();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user