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