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:
@@ -20,25 +20,27 @@ import android.database.Cursor;
|
||||
import android.graphics.Rect;
|
||||
import android.net.Uri;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore.Images.Media;
|
||||
import android.provider.MediaStore.MediaColumns;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.messaging.datamodel.media.FileImageRequestDescriptor;
|
||||
import com.android.messaging.datamodel.media.ImageRequest;
|
||||
import com.android.messaging.datamodel.media.UriImageRequestDescriptor;
|
||||
import com.android.messaging.datamodel.media.VideoThumbnailRequestDescriptor;
|
||||
import com.android.messaging.util.Assert;
|
||||
import com.android.messaging.util.ContentType;
|
||||
|
||||
/**
|
||||
* Provides data for GalleryGridItemView
|
||||
*/
|
||||
public class GalleryGridItemData {
|
||||
public static final String[] IMAGE_PROJECTION = new String[] {
|
||||
Media._ID,
|
||||
Media.DATA,
|
||||
Media.WIDTH,
|
||||
Media.HEIGHT,
|
||||
Media.MIME_TYPE,
|
||||
Media.DATE_MODIFIED};
|
||||
public static final String[] MEDIA_PROJECTION = new String[] {
|
||||
MediaColumns._ID,
|
||||
MediaColumns.DATA,
|
||||
MediaColumns.WIDTH,
|
||||
MediaColumns.HEIGHT,
|
||||
MediaColumns.MIME_TYPE,
|
||||
MediaColumns.DATE_MODIFIED};
|
||||
|
||||
public static final String[] SPECIAL_ITEM_COLUMNS = new String[] {
|
||||
BaseColumns._ID
|
||||
@@ -46,14 +48,14 @@ public class GalleryGridItemData {
|
||||
|
||||
private static final int INDEX_ID = 0;
|
||||
|
||||
// For local image gallery.
|
||||
// For local media gallery.
|
||||
private static final int INDEX_DATA_PATH = 1;
|
||||
private static final int INDEX_WIDTH = 2;
|
||||
private static final int INDEX_HEIGHT = 3;
|
||||
private static final int INDEX_MIME_TYPE = 4;
|
||||
private static final int INDEX_DATE_MODIFIED = 5;
|
||||
|
||||
/** A special item's id for picking images from document picker */
|
||||
/** A special item's id for picking a media from document picker */
|
||||
public static final String ID_DOCUMENT_PICKER_ITEM = "-1";
|
||||
|
||||
private UriImageRequestDescriptor mImageData;
|
||||
@@ -85,15 +87,24 @@ public class GalleryGridItemData {
|
||||
mContentType = cursor.getString(INDEX_MIME_TYPE);
|
||||
final String dateModified = cursor.getString(INDEX_DATE_MODIFIED);
|
||||
mDateSeconds = !TextUtils.isEmpty(dateModified) ? Long.parseLong(dateModified) : -1;
|
||||
mImageData = new FileImageRequestDescriptor(
|
||||
cursor.getString(INDEX_DATA_PATH),
|
||||
desiredWidth,
|
||||
desiredHeight,
|
||||
sourceWidth,
|
||||
sourceHeight,
|
||||
true /* canUseThumbnail */,
|
||||
true /* allowCompression */,
|
||||
true /* isStatic */);
|
||||
if (ContentType.isVideoType(mContentType)) {
|
||||
mImageData = new VideoThumbnailRequestDescriptor(
|
||||
cursor.getLong(INDEX_ID),
|
||||
desiredWidth,
|
||||
desiredHeight,
|
||||
sourceWidth,
|
||||
sourceHeight);
|
||||
} else {
|
||||
mImageData = new FileImageRequestDescriptor(
|
||||
cursor.getString(INDEX_DATA_PATH),
|
||||
desiredWidth,
|
||||
desiredHeight,
|
||||
sourceWidth,
|
||||
sourceHeight,
|
||||
true /* canUseThumbnail */,
|
||||
true /* allowCompression */,
|
||||
true /* isStatic */);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class MediaPickerData extends BindableData {
|
||||
mGalleryLoaderCallbacks = new GalleryLoaderCallbacks();
|
||||
}
|
||||
|
||||
public static final int GALLERY_IMAGE_LOADER = 1;
|
||||
public static final int GALLERY_MEDIA_LOADER = 1;
|
||||
|
||||
/**
|
||||
* A trampoline class so that we can inherit from LoaderManager.LoaderCallbacks multiple times.
|
||||
@@ -63,7 +63,7 @@ public class MediaPickerData extends BindableData {
|
||||
// Check if data still bound to the requesting ui element
|
||||
if (isBound(bindingId)) {
|
||||
switch (id) {
|
||||
case GALLERY_IMAGE_LOADER:
|
||||
case GALLERY_MEDIA_LOADER:
|
||||
return new GalleryBoundCursorLoader(bindingId, mContext);
|
||||
|
||||
default:
|
||||
@@ -84,9 +84,9 @@ public class MediaPickerData extends BindableData {
|
||||
final BoundCursorLoader cursorLoader = (BoundCursorLoader) loader;
|
||||
if (isBound(cursorLoader.getBindingId())) {
|
||||
switch (loader.getId()) {
|
||||
case GALLERY_IMAGE_LOADER:
|
||||
case GALLERY_MEDIA_LOADER:
|
||||
mListener.onMediaPickerDataUpdated(MediaPickerData.this, data,
|
||||
GALLERY_IMAGE_LOADER);
|
||||
GALLERY_MEDIA_LOADER);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -106,9 +106,9 @@ public class MediaPickerData extends BindableData {
|
||||
final BoundCursorLoader cursorLoader = (BoundCursorLoader) loader;
|
||||
if (isBound(cursorLoader.getBindingId())) {
|
||||
switch (loader.getId()) {
|
||||
case GALLERY_IMAGE_LOADER:
|
||||
case GALLERY_MEDIA_LOADER:
|
||||
mListener.onMediaPickerDataUpdated(MediaPickerData.this, null,
|
||||
GALLERY_IMAGE_LOADER);
|
||||
GALLERY_MEDIA_LOADER);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -129,7 +129,7 @@ public class MediaPickerData extends BindableData {
|
||||
args = new Bundle();
|
||||
}
|
||||
args.putString(BINDING_ID, binding.getBindingId());
|
||||
if (loaderId == GALLERY_IMAGE_LOADER) {
|
||||
if (loaderId == GALLERY_MEDIA_LOADER) {
|
||||
mLoaderManager.initLoader(loaderId, args, mGalleryLoaderCallbacks).forceLoad();
|
||||
} else {
|
||||
Assert.fail("Unsupported loader id for media picker!");
|
||||
@@ -149,7 +149,7 @@ public class MediaPickerData extends BindableData {
|
||||
protected void unregisterListeners() {
|
||||
// This could be null if we bind but the caller doesn't init the BindableData
|
||||
if (mLoaderManager != null) {
|
||||
mLoaderManager.destroyLoader(GALLERY_IMAGE_LOADER);
|
||||
mLoaderManager.destroyLoader(GALLERY_MEDIA_LOADER);
|
||||
mLoaderManager = null;
|
||||
}
|
||||
}
|
||||
@@ -172,4 +172,4 @@ public class MediaPickerData extends BindableData {
|
||||
selectedIndex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,9 +52,17 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class MessagePartData implements Parcelable {
|
||||
public static final int UNSPECIFIED_SIZE = MessagingContentProvider.UNSPECIFIED_SIZE;
|
||||
public static final String[] ACCEPTABLE_IMAGE_TYPES =
|
||||
new String[] { ContentType.IMAGE_JPEG, ContentType.IMAGE_JPG, ContentType.IMAGE_PNG,
|
||||
ContentType.IMAGE_GIF };
|
||||
|
||||
public static final String[] ACCEPTABLE_GALLERY_MEDIA_TYPES =
|
||||
new String[] {
|
||||
// Acceptable image types
|
||||
ContentType.IMAGE_JPEG, ContentType.IMAGE_JPG, ContentType.IMAGE_PNG,
|
||||
ContentType.IMAGE_GIF, ContentType.IMAGE_WBMP, ContentType.IMAGE_X_MS_BMP,
|
||||
// Acceptable video types
|
||||
ContentType.VIDEO_3GP, ContentType.VIDEO_3GPP, ContentType.VIDEO_3G2,
|
||||
ContentType.VIDEO_H263, ContentType.VIDEO_M4V, ContentType.VIDEO_MP4,
|
||||
ContentType.VIDEO_MPEG, ContentType.VIDEO_MPEG4, ContentType.VIDEO_WEBM
|
||||
};
|
||||
|
||||
private static final String[] sProjection = {
|
||||
PartColumns._ID,
|
||||
|
||||
Reference in New Issue
Block a user