1 /* 2 * Copyright (C) 2016 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.dialer.callcomposer; 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.Images.Media; 24 import android.support.v4.content.CursorLoader; 25 26 /** A BoundCursorLoader that reads local media on the device. */ 27 public class GalleryCursorLoader extends CursorLoader { 28 public static final String MEDIA_SCANNER_VOLUME_EXTERNAL = "external"; 29 public static final String[] ACCEPTABLE_IMAGE_TYPES = 30 new String[] {"image/jpeg", "image/jpg", "image/png", "image/webp"}; 31 32 private static final Uri STORAGE_URI = Files.getContentUri(MEDIA_SCANNER_VOLUME_EXTERNAL); 33 private static final String SORT_ORDER = Media.DATE_MODIFIED + " DESC"; 34 private static final String IMAGE_SELECTION = createSelection(); 35 GalleryCursorLoader(Context context)36 public GalleryCursorLoader(Context context) { 37 super( 38 context, 39 STORAGE_URI, 40 GalleryGridItemData.IMAGE_PROJECTION, 41 IMAGE_SELECTION, 42 null, 43 SORT_ORDER); 44 } 45 createSelection()46 private static String createSelection() { 47 return "mime_type IN ('image/jpeg', 'image/jpg', 'image/png', 'image/webp')" 48 + " AND media_type in (" 49 + FileColumns.MEDIA_TYPE_IMAGE 50 + ")"; 51 } 52 } 53