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

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Jul 18, 2024

  • adding maxImages: max amount of images to select. Use in combination with allowMultiple
  • adding pathOnly: won't include the blob in the returned data
  • add the path to the returned object

Note: EXTRA_PICK_IMAGES_MAX only works with new Intent(MediaStore.ACTION_PICK_IMAGES) so I have to recreate galleryIntent = new TiIntentWrapper(new Intent(MediaStore.ACTION_PICK_IMAGES));

Test:

var win = Ti.UI.createWindow();
var img = Ti.UI.createImageView();
win.add(img);
win.open();

win.addEventListener("click", function() {
	Ti.Media.openPhotoGallery({
		mediaTypes: [Titanium.Media.MEDIA_TYPE_PHOTO],
		allowMultiple: true,    // test it with and without
		maxImages: 3,
		pathOnly: true,
		success: function(e) {
			if (e.images) {
				for (var i = 0; i < e.images.length; ++i) {
					// no blob data
					console.log(e.images[i])
				}
				img.image = e.images[0].path;
			} else {
				// no blob data
				console.log(e)
				img.image = e.path;
			}
		},
		error: function(e) {
			alert('error opening image: ' + e);
		}
	});
})
  • click the window and try to select more than 3 images
  • change allowMultiple to false and test pathOnly values

@m1ga m1ga changed the title feat(android): add maxImages to openPhotoGallery feat(android): add maxImages and pathOnly to openPhotoGallery Jul 19, 2024
@m1ga
Copy link
Contributor Author

m1ga commented Jul 19, 2024

@hansemannn : I'm still testing it a bit but it will just give you:

{
 cropRect: { x: 0, width: 1080, y: 0, height: 2400 },
 path: 'file:///sdcard/.transforms/synthetic/picker_get_content/0/com.android.providers.media.photopicker/media/1000043692.png',
 code: 0,
 success: true,
 x: 0,
 width: 1080,
 y: 0,
 mediaType: 'public.image',
 height: 2400
}

as a result if you set pathOnly: true. Can be used in combination with or without allowMultiple and maxImages. So theoretically you can replace the external image picker module.

Also added the multi image picker to Kitchensink: tidev/kitchensink-v2#69 to test it.

Copy link
Collaborator

@hansemannn hansemannn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! Was it ready to review or were there issues during testing?

@m1ga m1ga marked this pull request as ready for review August 21, 2024 20:37
@m1ga
Copy link
Contributor Author

m1ga commented Aug 21, 2024

Yes, ready for review! I've tested it in an existing app without the new properties and that works as before. So no issues for existing apps and you can enable pathOnly: true to get the new features (no blobs)

@hansemannn hansemannn merged commit 3eda594 into master Aug 21, 2024
6 checks passed
@hansemannn hansemannn deleted the androidMaxImages branch August 21, 2024 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants