Support audio attachments through GalleryMediaChooser
GalleryMediaChooser supports audio types also. It displays simple audio icon and file info for audio files on grid views. Test: Manual Change-Id: I98b605156af3c1909c0141a2b99380b5da11c1e2 Signed-off-by: Taesu Lee <taesu82.lee@samsung.com>
This commit is contained in:
@@ -35,7 +35,11 @@ public class GalleryBoundCursorLoader extends BoundCursorLoader {
|
||||
private static final String SORT_ORDER = MediaColumns.DATE_MODIFIED + " DESC";
|
||||
private static final String SELECTION = createSelection(
|
||||
MessagePartData.ACCEPTABLE_GALLERY_MEDIA_TYPES,
|
||||
new Integer[] {FileColumns.MEDIA_TYPE_IMAGE, FileColumns.MEDIA_TYPE_VIDEO});
|
||||
new Integer[] {
|
||||
FileColumns.MEDIA_TYPE_IMAGE,
|
||||
FileColumns.MEDIA_TYPE_VIDEO,
|
||||
FileColumns.MEDIA_TYPE_AUDIO
|
||||
});
|
||||
|
||||
public GalleryBoundCursorLoader(final String bindingId, final Context context) {
|
||||
super(bindingId, context, STORAGE_URI, GalleryGridItemData.MEDIA_PROJECTION, SELECTION,
|
||||
|
||||
@@ -29,6 +29,7 @@ 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;
|
||||
import com.android.messaging.util.UriUtil;
|
||||
|
||||
/**
|
||||
* Provides data for GalleryGridItemView
|
||||
@@ -40,7 +41,8 @@ public class GalleryGridItemData {
|
||||
MediaColumns.WIDTH,
|
||||
MediaColumns.HEIGHT,
|
||||
MediaColumns.MIME_TYPE,
|
||||
MediaColumns.DATE_MODIFIED};
|
||||
MediaColumns.DATE_MODIFIED,
|
||||
MediaColumns.DISPLAY_NAME};
|
||||
|
||||
public static final String[] SPECIAL_ITEM_COLUMNS = new String[] {
|
||||
BaseColumns._ID
|
||||
@@ -54,6 +56,7 @@ public class GalleryGridItemData {
|
||||
private static final int INDEX_HEIGHT = 3;
|
||||
private static final int INDEX_MIME_TYPE = 4;
|
||||
private static final int INDEX_DATE_MODIFIED = 5;
|
||||
private static final int INDEX_DISPLAY_NAME = 6;
|
||||
|
||||
/** A special item's id for picking a media from document picker */
|
||||
public static final String ID_DOCUMENT_PICKER_ITEM = "-1";
|
||||
@@ -62,6 +65,8 @@ public class GalleryGridItemData {
|
||||
private String mContentType;
|
||||
private boolean mIsDocumentPickerItem;
|
||||
private long mDateSeconds;
|
||||
private String mFileName;
|
||||
private Uri mAudioUri;
|
||||
|
||||
public GalleryGridItemData() {
|
||||
}
|
||||
@@ -73,37 +78,44 @@ public class GalleryGridItemData {
|
||||
mImageData = null;
|
||||
mContentType = null;
|
||||
} else {
|
||||
int sourceWidth = cursor.getInt(INDEX_WIDTH);
|
||||
int sourceHeight = cursor.getInt(INDEX_HEIGHT);
|
||||
|
||||
// Guard against bad data
|
||||
if (sourceWidth <= 0) {
|
||||
sourceWidth = ImageRequest.UNSPECIFIED_SIZE;
|
||||
}
|
||||
if (sourceHeight <= 0) {
|
||||
sourceHeight = ImageRequest.UNSPECIFIED_SIZE;
|
||||
}
|
||||
|
||||
mContentType = cursor.getString(INDEX_MIME_TYPE);
|
||||
final String filePath = cursor.getString(INDEX_DATA_PATH);
|
||||
final String dateModified = cursor.getString(INDEX_DATE_MODIFIED);
|
||||
mDateSeconds = !TextUtils.isEmpty(dateModified) ? Long.parseLong(dateModified) : -1;
|
||||
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 */);
|
||||
if (ContentType.isAudioType(mContentType)) {
|
||||
mImageData = null;
|
||||
mAudioUri = UriUtil.getUriForResourceFile(filePath);
|
||||
mFileName = cursor.getString(INDEX_DISPLAY_NAME);
|
||||
} else { // For image and video types
|
||||
int sourceWidth = cursor.getInt(INDEX_WIDTH);
|
||||
int sourceHeight = cursor.getInt(INDEX_HEIGHT);
|
||||
|
||||
// Guard against bad data
|
||||
if (sourceWidth <= 0) {
|
||||
sourceWidth = ImageRequest.UNSPECIFIED_SIZE;
|
||||
}
|
||||
if (sourceHeight <= 0) {
|
||||
sourceHeight = ImageRequest.UNSPECIFIED_SIZE;
|
||||
}
|
||||
|
||||
if (ContentType.isVideoType(mContentType)) {
|
||||
mImageData = new VideoThumbnailRequestDescriptor(
|
||||
cursor.getLong(INDEX_ID),
|
||||
desiredWidth,
|
||||
desiredHeight,
|
||||
sourceWidth,
|
||||
sourceHeight);
|
||||
} else {
|
||||
mImageData = new FileImageRequestDescriptor(
|
||||
filePath,
|
||||
desiredWidth,
|
||||
desiredHeight,
|
||||
sourceWidth,
|
||||
sourceHeight,
|
||||
true /* canUseThumbnail */,
|
||||
true /* allowCompression */,
|
||||
true /* isStatic */);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,7 +125,7 @@ public class GalleryGridItemData {
|
||||
}
|
||||
|
||||
public Uri getImageUri() {
|
||||
return mImageData.uri;
|
||||
return ContentType.isAudioType(mContentType) ? mAudioUri : mImageData.uri;
|
||||
}
|
||||
|
||||
public UriImageRequestDescriptor getImageRequestDescriptor() {
|
||||
@@ -122,8 +134,10 @@ public class GalleryGridItemData {
|
||||
|
||||
public MessagePartData constructMessagePartData(final Rect startRect) {
|
||||
Assert.isTrue(!mIsDocumentPickerItem);
|
||||
return new MediaPickerMessagePartData(startRect, mContentType,
|
||||
mImageData.uri, mImageData.sourceWidth, mImageData.sourceHeight);
|
||||
return ContentType.isAudioType(mContentType)
|
||||
? new MediaPickerMessagePartData(startRect, mContentType, mAudioUri, 0, 0)
|
||||
: new MediaPickerMessagePartData(startRect, mContentType, mImageData.uri,
|
||||
mImageData.sourceWidth, mImageData.sourceHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,4 +150,8 @@ public class GalleryGridItemData {
|
||||
public String getContentType() {
|
||||
return mContentType;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return mFileName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,12 @@ public class MessagePartData implements Parcelable {
|
||||
// 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
|
||||
ContentType.VIDEO_MPEG, ContentType.VIDEO_MPEG4, ContentType.VIDEO_WEBM,
|
||||
// Acceptable audio types
|
||||
ContentType.AUDIO_MP3, ContentType.AUDIO_MP4, ContentType.AUDIO_MIDI,
|
||||
ContentType.AUDIO_MID, ContentType.AUDIO_AMR, ContentType.AUDIO_X_WAV,
|
||||
ContentType.AUDIO_AAC, ContentType.AUDIO_X_MIDI, ContentType.AUDIO_X_MID,
|
||||
ContentType.AUDIO_X_MP3
|
||||
};
|
||||
|
||||
private static final String[] sProjection = {
|
||||
|
||||
Reference in New Issue
Block a user