Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): add maxImages and pathOnly to openPhotoGallery #14086

Merged
merged 5 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -1116,6 +1117,15 @@ public void openPhotoGallery(KrollDict options)
TiIntentWrapper galleryIntent = new TiIntentWrapper(new Intent());
galleryIntent.getIntent().setAction(Intent.ACTION_GET_CONTENT);

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(TiC.PROPERTY_MAX_IMAGES));
}

boolean isSelectingPhoto = false;
boolean isSelectingVideo = false;
if (options.containsKey(TiC.PROPERTY_MEDIA_TYPES)) {
Expand Down Expand Up @@ -1163,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() {
Expand Down Expand Up @@ -1401,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;
}

Expand Down
2 changes: 2 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -640,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";
Expand Down
20 changes: 20 additions & 0 deletions apidoc/Titanium/Media/Media.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,20 @@ 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: 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: |
Expand Down Expand Up @@ -2284,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 <Titanium.Media>.
type: String
Expand Down
Loading