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:
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user