1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.messaging.datamodel; 18 19 import android.content.Context; 20 import android.net.Uri; 21 import android.provider.MediaStore.Files; 22 import android.provider.MediaStore.Files.FileColumns; 23 import android.provider.MediaStore.MediaColumns; 24 25 import com.android.messaging.datamodel.data.GalleryGridItemData; 26 import com.android.messaging.datamodel.data.MessagePartData; 27 import com.google.common.base.Joiner; 28 29 /** 30 * A BoundCursorLoader that reads local media on the device. 31 */ 32 public class GalleryBoundCursorLoader extends BoundCursorLoader { 33 public static final String MEDIA_SCANNER_VOLUME_EXTERNAL = "external"; 34 private static final Uri STORAGE_URI = Files.getContentUri(MEDIA_SCANNER_VOLUME_EXTERNAL); 35 private static final String SORT_ORDER = MediaColumns.DATE_MODIFIED + " DESC"; 36 private static final String SELECTION = createSelection( 37 MessagePartData.ACCEPTABLE_GALLERY_MEDIA_TYPES, 38 new Integer[] { 39 FileColumns.MEDIA_TYPE_IMAGE, 40 FileColumns.MEDIA_TYPE_VIDEO, 41 FileColumns.MEDIA_TYPE_AUDIO 42 }); 43 GalleryBoundCursorLoader(final String bindingId, final Context context)44 public GalleryBoundCursorLoader(final String bindingId, final Context context) { 45 super(bindingId, context, STORAGE_URI, GalleryGridItemData.MEDIA_PROJECTION, SELECTION, 46 null, SORT_ORDER); 47 } 48 createSelection(final String[] mimeTypes, Integer[] mediaTypes)49 private static String createSelection(final String[] mimeTypes, Integer[] mediaTypes) { 50 return MediaColumns.MIME_TYPE + " IN ('" + Joiner.on("','").join(mimeTypes) + "') AND " 51 + FileColumns.MEDIA_TYPE + " IN (" + Joiner.on(',').join(mediaTypes) + ")"; 52 } 53 } 54