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

[TIMOB-24707] Android: Show images and videos in picker #9223

Merged
merged 14 commits into from
May 10, 2018

Conversation

frankieandone
Copy link
Contributor

@frankieandone frankieandone commented Jul 17, 2017

JIRA: https://jira.appcelerator.org/browse/TIMOB-24707

Summary:
Added MEDIA_TYPE_VIDEO support to Ti.Media.openPhotoGallery() on Android. Can now select both images and videos with this API, like iOS.
(Does not support live photos. That is an iOS only feature.)

Test 1:
Re-run test attached to PR #9918.

Test 2:
Re-run test attached to PR #9906.
Verify that selecting an image from Google Drive (via the cloud) does not cause a crash.

Test 3:
Re-run test attached to PR #9771.
Verify that the screenshot taken via toImage() can still be viewed via previewImage().

Test 4:
(You need to take photos and videos using the Android device's camera before starting the below test procedure.)

  1. Build and run the below code on an Android 7.0 or newer device.
  2. An alert is displayed upon app launch. Tap the "Photo" button.
  3. Select a photo from the gallery.
  4. Verify the Titanium app display the selected photo.
  5. Back out of the app and re-launch it.
  6. An alert is displayed upon app launch. Tap the "Video" button.
  7. Select a video from the gallery.
  8. Verify the Titanium app plays the selected video.
  9. Back out of the app and re-launch it.
  10. An alert is displayed upon app launch. Tap the "Both" button.
  11. Select a video from the gallery.
  12. Verify the Titanium app plays the selected video.
  13. Repeat steps 2-12 on an Android 4.1 device.
var window = Ti.UI.createWindow();
window.addEventListener("open", function(e) {
	var dialog = Ti.UI.createAlertDialog(
	{
		message: "Which media type do you want to open?",
		buttonNames: ["Photo", "Video", "Both"],
	});
	dialog.addEventListener("click", function(e) {
		var mediaTypes;
		if (e.index === 0) {
			mediaTypes = [Ti.Media.MEDIA_TYPE_PHOTO];
		} else if (e.index === 1) {
			mediaTypes = [Ti.Media.MEDIA_TYPE_VIDEO];
		} else if (e.index === 2) {
			mediaTypes = [Ti.Media.MEDIA_TYPE_PHOTO, Ti.Media.MEDIA_TYPE_VIDEO];
		} else {
			Ti.API.info("@@@ Alert was canceled.");
			return;
		}
		Ti.Media.openPhotoGallery(
		{
			allowMultiple: false,
			allowEditing: false,
			autohide: true,
			mediaTypes: mediaTypes,
			success: function(e) {
				Ti.API.info("@@@ e: " + JSON.stringify(e));
				Ti.API.info("@@@ e.media.file: " + e.media.file);
				Ti.API.info("@@@ e.media.nativePath: " + e.media.nativePath);
				switch (e.mediaType) {
					case Ti.Media.MEDIA_TYPE_PHOTO:
					case Ti.Media.MEDIA_TYPE_LIVEPHOTO:
						window.add(Ti.UI.createImageView(
						{
							image: e.media,
							width: Ti.UI.FILL,
							height: Ti.UI.FILL,
						}));
						break;
					case Ti.Media.MEDIA_TYPE_VIDEO:
						window.add(Ti.Media.createVideoPlayer(
						{
							url: e.media.nativePath,
							autoplay: true,
							mediaControlStyle: Ti.Media.VIDEO_CONTROL_DEFAULT,
							scalingMode: Ti.Media.VIDEO_SCALING_ASPECT_FIT,
							width: Ti.UI.FILL,
							height: Ti.UI.FILL,
						}));
						break;
					default:
						break;
				}
			},
			cancel: function() {
				Ti.API.info("@@@ Photo gallery selection canceled.");
			},
			error: function() {
				Ti.API.info("@@@ Photo gallery selection error.");
			},
		});
	});
	dialog.show();
});
window.open();

@frankieandone frankieandone added this to the 6.2.0 milestone Jul 17, 2017
@frankieandone frankieandone self-assigned this Jul 17, 2017
Copy link
Contributor

@jquick-axway jquick-axway left a comment

Choose a reason for hiding this comment

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

@fmerzadyan, you need to add support for the "mediaType" array argument here...
http://docs.appcelerator.com/platform/latest/#!/api/PhotoGalleryOptionsType-property-mediaTypes

If this array only contains MEDIA_TYPE_PHOTO or MEDIA_TYPE_LIVE_PHOTO, then the type string should be "image/*".

If this array only contains MEDIA_TYPE_VIDEO, then the type should be "video/*".

If the array contains both photo and video types, then it should be set to "*/*".

@hansemannn hansemannn modified the milestones: 7.0.0, 6.2.0 Aug 15, 2017
@sgtcoolguy sgtcoolguy modified the milestones: 7.0.0, 7.1.0 Nov 30, 2017
@build
Copy link
Contributor

build commented Nov 30, 2017

Messages
📖

🎉 Another contribution from our awesome community member, fmerzadyan! Thanks again for helping us make Titanium SDK better. 👍

📖

💾 Here's the generated SDK zipfile.

Generated by 🚫 dangerJS

…y() video support.

- Modified returned blob's "mimeType" property to no longer return null. Now provides selected file's mime type.
- Added constant Ti.Media.MEDIA_TYPE_LIVEPHOTO, even though it's not supported on Android. (Avoids JavaScript runtime errors.)
- Fixed returned blob to not crash when attempting to access it's "file" property if not accessible on the file system. (Will be null in this case instead.)
- When "allowMultiple" is true, success result's event dictionary now provides a "videos" property. (Pairs with "images" property.)
- Fixed bug with blobs that wrap "content://" URIs to not crash when fetching file size. (Now fetches size from Android ContentProvider.)
- Updated docs to indicate that Android now supports "mediaTypes" property.
@jquick-axway
Copy link
Contributor

Updated PR:

  • Finished code changes to support video selection and playback.
  • Updated API documentation.
  • Added test code to PR which displays selected photos and plays selected videos.

@hansemannn
Copy link
Collaborator

@jquick-axway @garymathews Can you resolve the conflicts?

@hansemannn hansemannn modified the milestones: 7.1.0, 7.2.0 Feb 26, 2018
@lokeshchdhry
Copy link
Contributor

FR Passed.

Images , videos or both are properly shown in the picker according to the mediaTypes property specified.

Studio Ver: 5.1.0.201804230827
SDK Ver: 7.2.0 local build
OS Ver: 10.13.4
Xcode Ver: Xcode 9.3
Appc NPM: 4.2.13
Appc CLI: 7.0.3
Daemon Ver: 1.1.1
Ti CLI Ver: 5.1.0
Alloy Ver: 1.12.0
Node Ver: 8.9.1
NPM Ver: 5.5.1
Java Ver: 10
Devices: ⇨ google Nexus 5 --- Android 6.0.1
⇨ google Nexus 6P --- Android 8.0.0
Emulator: ⇨ Android 4.1.2

@lokeshchdhry
Copy link
Contributor

@jquick-axway , Jenkins is complaining about no tests. Can you please take a look.

@lokeshchdhry lokeshchdhry merged commit 5a30415 into tidev:master May 10, 2018
@sgtcoolguy sgtcoolguy modified the milestones: 7.2.0, 7.3.0 May 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants