You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by no...@apache.org on 2024/10/28 16:32:41 UTC
(cordova-plugin-camera) branch master updated: refactor(android): remove query img usage (#907)
This is an automated email from the ASF dual-hosted git repository.
normanbreau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-camera.git
The following commit(s) were added to refs/heads/master by this push:
new c208754 refactor(android): remove query img usage (#907)
c208754 is described below
commit c208754c089af1306300d4cc91820c03b0d1097a
Author: Norman Breau <no...@breautek.com>
AuthorDate: Mon Oct 28 13:32:35 2024 -0300
refactor(android): remove query img usage (#907)
* refactor: remove unnecessary duplicate image checks and queryImgDb usage
* remove unused imageType parameter, because it's a private API anyway
---
src/android/CameraLauncher.java | 63 ++---------------------------------------
1 file changed, 2 insertions(+), 61 deletions(-)
diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java
index 1391886..8817301 100644
--- a/src/android/CameraLauncher.java
+++ b/src/android/CameraLauncher.java
@@ -127,7 +127,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
private boolean allowEdit; // Should we allow the user to crop the image.
public CallbackContext callbackContext;
- private int numPics;
private MediaScannerConnection conn; // Used to update gallery app with newly-written files
private Uri scanMe; // Uri of image to be added to content store
@@ -307,9 +306,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
public void takePicture(int returnType, int encodingType)
{
- // Save the number of images currently on disk for later
- this.numPics = queryImgDB(whichContentStore()).getCount();
-
// Let's use the intent and see what happens
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
@@ -336,8 +332,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
LOG.d(LOG_TAG, "Error: You don't have a default camera. Your device may not be CTS complaint.");
}
}
-// else
-// LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
}
/**
@@ -559,12 +553,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
return;
}
-
this.processPicture(bitmap, this.encodingType);
-
- if (!this.saveToPhotoAlbum) {
- checkForDuplicateImage(DATA_URL);
- }
}
// If sending filename back
@@ -626,7 +615,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
throw new IllegalStateException();
}
- this.cleanup(FILE_URI, this.imageUri, galleryUri, bitmap);
+ this.cleanup(this.imageUri, galleryUri, bitmap);
bitmap = null;
input.close();
}
@@ -1207,26 +1196,12 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
}
}
- /**
- * Creates a cursor that can be used to determine how many images we have.
- *
- * @return a cursor
- */
- private Cursor queryImgDB(Uri contentStore) {
- return this.cordova.getActivity().getContentResolver().query(
- contentStore,
- new String[]{MediaStore.Images.Media._ID},
- null,
- null,
- null);
- }
-
/**
* Cleans up after picture taking. Checking for duplicates and that kind of stuff.
*
* @param newImage
*/
- private void cleanup(int imageType, Uri oldImage, Uri newImage, Bitmap bitmap) {
+ private void cleanup(Uri oldImage, Uri newImage, Bitmap bitmap) {
if (bitmap != null) {
bitmap.recycle();
}
@@ -1234,7 +1209,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
// Clean up initial camera-written image file.
(new File(FileHelper.stripFileProtocol(oldImage.toString()))).delete();
- checkForDuplicateImage(imageType);
// Scan for the gallery to update pic refs in gallery
if (this.saveToPhotoAlbum && newImage != null) {
this.scanForGallery(newImage);
@@ -1243,37 +1217,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
System.gc();
}
- /**
- * 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
- * increases by 2 we have a duplicate, when using a DATA_URL the number is 1.
- *
- * @param type FILE_URI or DATA_URL
- */
- private void checkForDuplicateImage(int type) {
- int diff = 1;
- Uri contentStore = whichContentStore();
- Cursor cursor = queryImgDB(contentStore);
- int currentNumOfImages = cursor.getCount();
-
- if (type == FILE_URI && this.saveToPhotoAlbum) {
- diff = 2;
- }
-
- // delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
- if ((currentNumOfImages - numPics) == diff) {
- cursor.moveToLast();
- @SuppressLint("Range")
- int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
- if (diff == 2) {
- id--;
- }
- Uri uri = Uri.parse(contentStore + "/" + id);
- this.cordova.getActivity().getContentResolver().delete(uri, null, null);
- cursor.close();
- }
- }
-
/**
* Determine if we are storing the images in internal or external storage
*
@@ -1377,7 +1320,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
state.putInt("targetHeight", this.targetHeight);
state.putInt("encodingType", this.encodingType);
state.putInt("mediaType", this.mediaType);
- state.putInt("numPics", this.numPics);
state.putBoolean("allowEdit", this.allowEdit);
state.putBoolean("correctOrientation", this.correctOrientation);
state.putBoolean("saveToPhotoAlbum", this.saveToPhotoAlbum);
@@ -1401,7 +1343,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
this.targetHeight = state.getInt("targetHeight");
this.encodingType = state.getInt("encodingType");
this.mediaType = state.getInt("mediaType");
- this.numPics = state.getInt("numPics");
this.allowEdit = state.getBoolean("allowEdit");
this.correctOrientation = state.getBoolean("correctOrientation");
this.saveToPhotoAlbum = state.getBoolean("saveToPhotoAlbum");
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org