Support video attachments through GalleryMediaChooser

GalleryMediaChooser supports video types and more image types also. And
video thumbnails are overlaid with the play button image to distinguish
between images and videos.

Note:
 1. EXTRA_ALLOW_MULTIPLE is not specified for ACTION_GET_CONTENT.
 2. Files, methods and variables' name are still including "image".
 3. Content descriptions are not updated.

Test: Manual

Change-Id: I961928f150e4ae8ee80a1fba2f20c37fb5426669
Signed-off-by: Taesu Lee <taesu82.lee@samsung.com>
This commit is contained in:
Taesu Lee
2020-02-19 18:36:32 +09:00
parent a531636ae3
commit 6c77158718
20 changed files with 131 additions and 99 deletions
+4 -3
View File
@@ -44,8 +44,8 @@ public abstract class UIIntents {
// Sending draft data (from share intent / message forwarding) to the ConversationActivity.
public static final String UI_INTENT_EXTRA_DRAFT_DATA = "draft_data";
// The request code for picking image from the Document picker.
public static final int REQUEST_PICK_IMAGE_FROM_DOCUMENT_PICKER = 1400;
// The request code for picking a media from the Document picker.
public static final int REQUEST_PICK_MEDIA_FROM_DOCUMENT_PICKER = 1400;
// Indicates what type of notification this applies to (See BugleNotifications:
// UPDATE_NONE, UPDATE_MESSAGES, UPDATE_ERRORS, UPDATE_ALL)
@@ -166,7 +166,8 @@ public abstract class UIIntents {
public abstract void launchAddContactActivity(final Context context, final String destination);
/**
* Launch an activity to show the document picker to pick an image.
* Launch an activity to show the document picker to pick an image/video.
*
* @param fragment the requesting fragment
*/
public abstract void launchDocumentImagePicker(final Fragment fragment);
@@ -236,11 +236,11 @@ public class UIIntentsImpl extends UIIntents {
@Override
public void launchDocumentImagePicker(final Fragment fragment) {
final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_MIME_TYPES, MessagePartData.ACCEPTABLE_IMAGE_TYPES);
intent.putExtra(Intent.EXTRA_MIME_TYPES, MessagePartData.ACCEPTABLE_GALLERY_MEDIA_TYPES);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType(ContentType.IMAGE_UNSPECIFIED);
intent.setType(ContentType.ANY_TYPE);
fragment.startActivityForResult(intent, REQUEST_PICK_IMAGE_FROM_DOCUMENT_PICKER);
fragment.startActivityForResult(intent, REQUEST_PICK_MEDIA_FROM_DOCUMENT_PICKER);
}
@Override
@@ -30,8 +30,8 @@ import com.android.messaging.util.ImageUtils;
import com.android.messaging.util.SafeAsyncTask;
/**
* Wraps around the functionalities to allow the user to pick images from the document
* picker. Instances of this class must be tied to a Fragment which is able to delegate activity
* Wraps around the functionalities to allow the user to pick an image/video from the document
* picker. Instances of this class must be tied to a Fragment which is able to delegate activity
* result callbacks.
*/
public class DocumentImagePicker {
@@ -79,8 +79,8 @@ public class DocumentImagePicker {
* Must be called from the fragment/activity's onActivityResult().
*/
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if (requestCode == UIIntents.REQUEST_PICK_IMAGE_FROM_DOCUMENT_PICKER &&
resultCode == Activity.RESULT_OK) {
if (requestCode == UIIntents.REQUEST_PICK_MEDIA_FROM_DOCUMENT_PICKER
&& resultCode == Activity.RESULT_OK) {
// Sometimes called after media item has been picked from the document picker.
String url = data.getStringExtra(EXTRA_PHOTO_URL);
if (url == null) {
@@ -24,13 +24,14 @@ import android.view.TouchDelegate;
import android.view.View;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.ImageView.ScaleType;
import android.widget.ImageView;
import com.android.messaging.R;
import com.android.messaging.datamodel.DataModel;
import com.android.messaging.datamodel.data.GalleryGridItemData;
import com.android.messaging.ui.AsyncImageView;
import com.android.messaging.ui.ConversationDrawables;
import com.android.messaging.util.ContentType;
import com.google.common.annotations.VisibleForTesting;
import java.util.concurrent.TimeUnit;
@@ -135,17 +136,24 @@ public class GalleryGridItemView extends FrameLayout {
}
private void updateImageView() {
ImageView playButton = (ImageView) findViewById(R.id.video_thumbnail_play_button);
if (mData.isDocumentPickerItem()) {
mImageView.setScaleType(ScaleType.CENTER);
mImageView.setScaleType(ImageView.ScaleType.CENTER);
setBackgroundColor(ConversationDrawables.get().getConversationThemeColor());
mImageView.setImageResourceId(null);
mImageView.setImageResource(R.drawable.ic_photo_library_light);
playButton.setVisibility(GONE);
mImageView.setContentDescription(getResources().getString(
R.string.pick_image_from_document_library_content_description));
} else {
mImageView.setScaleType(ScaleType.CENTER_CROP);
mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
setBackgroundColor(getResources().getColor(R.color.gallery_image_default_background));
mImageView.setImageResourceId(mData.getImageRequestDescriptor());
if (ContentType.isVideoType(mData.getContentType())) {
playButton.setVisibility(VISIBLE);
} else {
playButton.setVisibility(GONE);
}
final long dateSeconds = mData.getDateSeconds();
final boolean isValidDate = (dateSeconds > 0);
final int templateId = isValidDate ?
@@ -43,16 +43,16 @@ import java.util.Iterator;
import java.util.Map;
/**
* Shows a list of galley images from external storage in a GridView with multi-select
* capabilities, and with the option to intent out to a standalone image picker.
* Shows a list of galley mediae from external storage in a GridView with multi-select capabilities,
* and with the option to intent out to a standalone media picker.
*/
public class GalleryGridView extends MediaPickerGridView implements
GalleryGridItemView.HostInterface,
PersistentInstanceState,
DraftMessageDataListener {
/**
* Implemented by the owner of this GalleryGridView instance to communicate on image
* picking and multi-image selection events.
* Implemented by the owner of this GalleryGridView instance to communicate on media picking and
* multi-media selection events.
*/
public interface GalleryGridViewListener {
void onDocumentPickerItemClicked();
@@ -127,7 +127,7 @@ public class GalleryGridView extends MediaPickerGridView implements
final MessagePartData item = mSelectedImages.remove(data.getImageUri());
mListener.onItemUnselected(item);
if (mSelectedImages.size() == 0) {
// No image is selected any more, turn off multi-select mode.
// No media is selected any more, turn off multi-select mode.
setMultiSelectEnabled(false);
}
} else {
@@ -63,7 +63,7 @@ class GalleryMediaChooser extends MediaChooser implements
mAdapter.setHostInterface(null);
// The loader is started only if startMediaPickerDataLoader() is called
if (OsUtil.hasStoragePermission()) {
mBindingRef.getData().destroyLoader(MediaPickerData.GALLERY_IMAGE_LOADER);
mBindingRef.getData().destroyLoader(MediaPickerData.GALLERY_MEDIA_LOADER);
}
return super.destroyView();
}
@@ -121,7 +121,7 @@ class GalleryMediaChooser extends MediaChooser implements
protected View createView(final ViewGroup container) {
final LayoutInflater inflater = getLayoutInflater();
final View view = inflater.inflate(
R.layout.mediapicker_image_chooser,
R.layout.mediapicker_gallery_chooser,
container /* root */,
false /* attachToRoot */);
@@ -167,7 +167,7 @@ class GalleryMediaChooser extends MediaChooser implements
public void onMediaPickerDataUpdated(final MediaPickerData mediaPickerData, final Object data,
final int loaderId) {
mBindingRef.ensureBound(mediaPickerData);
Assert.equals(MediaPickerData.GALLERY_IMAGE_LOADER, loaderId);
Assert.equals(MediaPickerData.GALLERY_MEDIA_LOADER, loaderId);
Cursor rawCursor = null;
if (data instanceof Cursor) {
rawCursor = (Cursor) data;
@@ -202,8 +202,9 @@ class GalleryMediaChooser extends MediaChooser implements
}
private void startMediaPickerDataLoader() {
mBindingRef.getData().startLoader(MediaPickerData.GALLERY_IMAGE_LOADER, mBindingRef, null,
this);
mBindingRef
.getData()
.startLoader(MediaPickerData.GALLERY_MEDIA_LOADER, mBindingRef, null, this);
}
@Override
@@ -159,7 +159,7 @@ public class MediaPicker extends Fragment implements DraftMessageSubscriptionDat
@VisibleForTesting
final Binding<MediaPickerData> mBinding = BindingBase.createBinding(this);
/** Handles picking image from the document picker */
/** Handles picking a media from the document picker. */
private DocumentImagePicker mDocumentImagePicker;
/** Provides subscription-related data to access per-subscription configurations. */