Skip to content

Commit c208754

Browse files
authored
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
1 parent 0d86764 commit c208754

File tree

1 file changed

+2
-61
lines changed

1 file changed

+2
-61
lines changed

src/android/CameraLauncher.java

+2-61
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
127127
private boolean allowEdit; // Should we allow the user to crop the image.
128128

129129
public CallbackContext callbackContext;
130-
private int numPics;
131130

132131
private MediaScannerConnection conn; // Used to update gallery app with newly-written files
133132
private Uri scanMe; // Uri of image to be added to content store
@@ -307,9 +306,6 @@ public void callTakePicture(int returnType, int encodingType) {
307306

308307
public void takePicture(int returnType, int encodingType)
309308
{
310-
// Save the number of images currently on disk for later
311-
this.numPics = queryImgDB(whichContentStore()).getCount();
312-
313309
// Let's use the intent and see what happens
314310
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
315311

@@ -336,8 +332,6 @@ public void takePicture(int returnType, int encodingType)
336332
LOG.d(LOG_TAG, "Error: You don't have a default camera. Your device may not be CTS complaint.");
337333
}
338334
}
339-
// else
340-
// LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
341335
}
342336

343337
/**
@@ -559,12 +553,7 @@ private void processResultFromCamera(int destType, Intent intent) throws IOExcep
559553
return;
560554
}
561555

562-
563556
this.processPicture(bitmap, this.encodingType);
564-
565-
if (!this.saveToPhotoAlbum) {
566-
checkForDuplicateImage(DATA_URL);
567-
}
568557
}
569558

570559
// If sending filename back
@@ -626,7 +615,7 @@ else if (destType == FILE_URI) {
626615
throw new IllegalStateException();
627616
}
628617

629-
this.cleanup(FILE_URI, this.imageUri, galleryUri, bitmap);
618+
this.cleanup(this.imageUri, galleryUri, bitmap);
630619
bitmap = null;
631620
input.close();
632621
}
@@ -1207,34 +1196,19 @@ public static int calculateSampleSize(int srcWidth, int srcHeight, int dstWidth,
12071196
}
12081197
}
12091198

1210-
/**
1211-
* Creates a cursor that can be used to determine how many images we have.
1212-
*
1213-
* @return a cursor
1214-
*/
1215-
private Cursor queryImgDB(Uri contentStore) {
1216-
return this.cordova.getActivity().getContentResolver().query(
1217-
contentStore,
1218-
new String[]{MediaStore.Images.Media._ID},
1219-
null,
1220-
null,
1221-
null);
1222-
}
1223-
12241199
/**
12251200
* Cleans up after picture taking. Checking for duplicates and that kind of stuff.
12261201
*
12271202
* @param newImage
12281203
*/
1229-
private void cleanup(int imageType, Uri oldImage, Uri newImage, Bitmap bitmap) {
1204+
private void cleanup(Uri oldImage, Uri newImage, Bitmap bitmap) {
12301205
if (bitmap != null) {
12311206
bitmap.recycle();
12321207
}
12331208

12341209
// Clean up initial camera-written image file.
12351210
(new File(FileHelper.stripFileProtocol(oldImage.toString()))).delete();
12361211

1237-
checkForDuplicateImage(imageType);
12381212
// Scan for the gallery to update pic refs in gallery
12391213
if (this.saveToPhotoAlbum && newImage != null) {
12401214
this.scanForGallery(newImage);
@@ -1243,37 +1217,6 @@ private void cleanup(int imageType, Uri oldImage, Uri newImage, Bitmap bitmap) {
12431217
System.gc();
12441218
}
12451219

1246-
/**
1247-
* Used to find out if we are in a situation where the Camera Intent adds to images
1248-
* to the content store. If we are using a FILE_URI and the number of images in the DB
1249-
* increases by 2 we have a duplicate, when using a DATA_URL the number is 1.
1250-
*
1251-
* @param type FILE_URI or DATA_URL
1252-
*/
1253-
private void checkForDuplicateImage(int type) {
1254-
int diff = 1;
1255-
Uri contentStore = whichContentStore();
1256-
Cursor cursor = queryImgDB(contentStore);
1257-
int currentNumOfImages = cursor.getCount();
1258-
1259-
if (type == FILE_URI && this.saveToPhotoAlbum) {
1260-
diff = 2;
1261-
}
1262-
1263-
// delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
1264-
if ((currentNumOfImages - numPics) == diff) {
1265-
cursor.moveToLast();
1266-
@SuppressLint("Range")
1267-
int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
1268-
if (diff == 2) {
1269-
id--;
1270-
}
1271-
Uri uri = Uri.parse(contentStore + "/" + id);
1272-
this.cordova.getActivity().getContentResolver().delete(uri, null, null);
1273-
cursor.close();
1274-
}
1275-
}
1276-
12771220
/**
12781221
* Determine if we are storing the images in internal or external storage
12791222
*
@@ -1377,7 +1320,6 @@ public Bundle onSaveInstanceState() {
13771320
state.putInt("targetHeight", this.targetHeight);
13781321
state.putInt("encodingType", this.encodingType);
13791322
state.putInt("mediaType", this.mediaType);
1380-
state.putInt("numPics", this.numPics);
13811323
state.putBoolean("allowEdit", this.allowEdit);
13821324
state.putBoolean("correctOrientation", this.correctOrientation);
13831325
state.putBoolean("saveToPhotoAlbum", this.saveToPhotoAlbum);
@@ -1401,7 +1343,6 @@ public void onRestoreStateForActivityResult(Bundle state, CallbackContext callba
14011343
this.targetHeight = state.getInt("targetHeight");
14021344
this.encodingType = state.getInt("encodingType");
14031345
this.mediaType = state.getInt("mediaType");
1404-
this.numPics = state.getInt("numPics");
14051346
this.allowEdit = state.getBoolean("allowEdit");
14061347
this.correctOrientation = state.getBoolean("correctOrientation");
14071348
this.saveToPhotoAlbum = state.getBoolean("saveToPhotoAlbum");

0 commit comments

Comments
 (0)