From 3e642e6921244b0fc541b9f741543ec8ac8e9dc2 Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Thu, 18 Jul 2024 16:03:46 +0200 Subject: [PATCH 1/2] feat(android): add maxImages to openPhotoGallery --- .../src/java/ti/modules/titanium/media/MediaModule.java | 7 +++++++ .../titanium/src/java/org/appcelerator/titanium/TiC.java | 1 + apidoc/Titanium/Media/Media.yml | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java b/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java index 306c99ed35a..32d37e76a69 100644 --- a/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java +++ b/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java @@ -1116,6 +1116,13 @@ public void openPhotoGallery(KrollDict options) TiIntentWrapper galleryIntent = new TiIntentWrapper(new Intent()); galleryIntent.getIntent().setAction(Intent.ACTION_GET_CONTENT); + if (options.containsKeyAndNotNull("maxImages") + && options.containsKey(TiC.PROPERTY_ALLOW_MULTIPLE) + && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + galleryIntent = new TiIntentWrapper(new Intent(MediaStore.ACTION_PICK_IMAGES)); + galleryIntent.getIntent().putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, options.getInt("maxImages")); + } + boolean isSelectingPhoto = false; boolean isSelectingVideo = false; if (options.containsKey(TiC.PROPERTY_MEDIA_TYPES)) { diff --git a/android/titanium/src/java/org/appcelerator/titanium/TiC.java b/android/titanium/src/java/org/appcelerator/titanium/TiC.java index 4f219b4c308..64ce7ea66fc 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/TiC.java +++ b/android/titanium/src/java/org/appcelerator/titanium/TiC.java @@ -560,6 +560,7 @@ public class TiC public static final String PROPERTY_MAX_AGE = "maxAge"; public static final String PROPERTY_MAX_CLASSNAME = "maxClassname"; public static final String PROPERTY_MAX_ELEVATION = "maxElevation"; + public static final String PROPERTY_MAX_IMAGES = "maxImages"; public static final String PROPERTY_MAX_LENGTH = "maxLength"; public static final String PROPERTY_MAX_LINES = "maxLines"; public static final String PROPERTY_MAX_ROW_HEIGHT = "maxRowHeight"; diff --git a/apidoc/Titanium/Media/Media.yml b/apidoc/Titanium/Media/Media.yml index 8f093d29dac..028845aed97 100644 --- a/apidoc/Titanium/Media/Media.yml +++ b/apidoc/Titanium/Media/Media.yml @@ -2235,6 +2235,14 @@ properties: osver: {ios: {min: "14.0"}} since: { android: "6.0.0", iphone: "9.2.0", ipad: "9.2.0" } + - name: maxImages + summary: Specifies the number of images a user can select at maximum. + description: | + Only available on Android API 21 and above and with `allowMultiple:true` + type: Boolean + platforms: [android] + since: { android: "12.5.0" } + - name: selectionLimit summary: Specifies number of media item that can be selected. description: | From 4b45b19957fcb1e898da1d1d4ecc8aa8af4c0945 Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Fri, 19 Jul 2024 09:56:32 +0200 Subject: [PATCH 2/2] pathOnly --- .../modules/titanium/media/MediaModule.java | 20 ++++++++++++++----- .../java/org/appcelerator/titanium/TiC.java | 1 + apidoc/Titanium/Media/Media.yml | 12 +++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java b/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java index 32d37e76a69..87ec0194fcf 100644 --- a/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java +++ b/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java @@ -241,6 +241,7 @@ public class MediaModule extends KrollModule implements Handler.Callback private static String mediaType = MEDIA_TYPE_PHOTO; private static ContentResolver contentResolver; private boolean useCameraX = false; + private static boolean pathOnly = false; public MediaModule() { @@ -1116,11 +1117,13 @@ public void openPhotoGallery(KrollDict options) TiIntentWrapper galleryIntent = new TiIntentWrapper(new Intent()); galleryIntent.getIntent().setAction(Intent.ACTION_GET_CONTENT); - if (options.containsKeyAndNotNull("maxImages") + if (options.containsKeyAndNotNull(TiC.PROPERTY_MAX_IMAGES) && options.containsKey(TiC.PROPERTY_ALLOW_MULTIPLE) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + // set max image count galleryIntent = new TiIntentWrapper(new Intent(MediaStore.ACTION_PICK_IMAGES)); - galleryIntent.getIntent().putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, options.getInt("maxImages")); + galleryIntent.getIntent() + .putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, options.getInt(TiC.PROPERTY_MAX_IMAGES)); } boolean isSelectingPhoto = false; @@ -1170,6 +1173,11 @@ public void openPhotoGallery(KrollDict options) galleryIntent.getIntent().putExtra(Intent.EXTRA_ALLOW_MULTIPLE, allowMultiple); } + pathOnly = false; + if (options.containsKeyAndNotNull(TiC.PROPERTY_PATH_ONLY)) { + pathOnly = options.getBoolean(TiC.PROPERTY_PATH_ONLY); + } + final int code = allowMultiple ? PICK_IMAGE_MULTIPLE : PICK_IMAGE_SINGLE; activitySupport.launchActivityForResult(galleryIntent.getIntent(), code, new TiActivityResultHandler() { @@ -1408,16 +1416,18 @@ protected static KrollDict createDictForImage(TiBlob imageData, String mimeType) d.put("width", width); d.put("height", height); - // Add the image/video's crop dimensiosn to the dictionary. + // Add the image/video's crop dimension to the dictionary. KrollDict cropRect = new KrollDict(); cropRect.put("x", 0); cropRect.put("y", 0); cropRect.put("width", width); cropRect.put("height", height); d.put("cropRect", cropRect); - + d.put("path", imageData.getNativePath()); // Add the blob to the dictionary. - d.put("media", imageData); + if (!pathOnly) { + d.put("media", imageData); + } return d; } diff --git a/android/titanium/src/java/org/appcelerator/titanium/TiC.java b/android/titanium/src/java/org/appcelerator/titanium/TiC.java index 64ce7ea66fc..c7da4f79aa8 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/TiC.java +++ b/android/titanium/src/java/org/appcelerator/titanium/TiC.java @@ -641,6 +641,7 @@ public class TiC public static final String PROPERTY_PASSWORD = "password"; public static final String PROPERTY_PASSWORD_MASK = "passwordMask"; public static final String PROPERTY_PATH = "path"; + public static final String PROPERTY_PATH_ONLY = "pathOnly"; public static final String PROPERTY_PERSISTENT = "persistent"; public static final String PROPERTY_PHONE = "phone"; public static final String PROPERTY_PIN_IMAGE = "pinImage"; diff --git a/apidoc/Titanium/Media/Media.yml b/apidoc/Titanium/Media/Media.yml index 028845aed97..8e6a97e518e 100644 --- a/apidoc/Titanium/Media/Media.yml +++ b/apidoc/Titanium/Media/Media.yml @@ -2243,6 +2243,12 @@ properties: platforms: [android] since: { android: "12.5.0" } + - name: pathOnly + summary: Do not include the blob in the result + type: Boolean + platforms: [android] + since: { android: "12.5.0" } + - name: selectionLimit summary: Specifies number of media item that can be selected. description: | @@ -2292,6 +2298,12 @@ properties: summary: The media object, as a [Blob](Titanium.Blob). type: Titanium.Blob + - name: path + summary: The path of the image when returning data from the gallery. + type: String + platforms: [android] + since: "12.5.0" + - name: mediaType summary: The type of media, either `MEDIA_TYPE_PHOTO`, `MEDIA_TYPE_LIVEPHOTO` or `MEDIA_TYPE_VIDEO` defined in . type: String