2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.photos.data;
19 import android.content.Context;
20 import android.content.CursorLoader;
21 import android.database.ContentObserver;
22 import android.database.Cursor;
23 import android.graphics.drawable.Drawable;
24 import android.net.Uri;
25 import android.provider.MediaStore;
26 import android.provider.MediaStore.Files;
27 import android.provider.MediaStore.Files.FileColumns;
29 import com.android.photos.drawables.DataUriThumbnailDrawable;
30 import com.android.photos.shims.LoaderCompatShim;
32 import java.util.ArrayList;
34 public class PhotoSetLoader extends CursorLoader implements LoaderCompatShim<Cursor> {
36 public static final String SUPPORTED_OPERATIONS = "supported_operations";
38 private static final Uri CONTENT_URI = Files.getContentUri("external");
39 public static final String[] PROJECTION = new String[] {
44 FileColumns.DATE_ADDED,
45 FileColumns.MEDIA_TYPE,
49 private static final String SORT_ORDER = FileColumns.DATE_ADDED + " DESC";
50 private static final String SELECTION =
51 FileColumns.MEDIA_TYPE + " == " + FileColumns.MEDIA_TYPE_IMAGE
53 + FileColumns.MEDIA_TYPE + " == " + FileColumns.MEDIA_TYPE_VIDEO;
55 public static final int INDEX_ID = 0;
56 public static final int INDEX_DATA = 1;
57 public static final int INDEX_WIDTH = 2;
58 public static final int INDEX_HEIGHT = 3;
59 public static final int INDEX_DATE_ADDED = 4;
60 public static final int INDEX_MEDIA_TYPE = 5;
61 public static final int INDEX_SUPPORTED_OPERATIONS = 6;
63 private static final Uri GLOBAL_CONTENT_URI = Uri.parse("content://" + MediaStore.AUTHORITY + "/external/");
64 private final ContentObserver mGlobalObserver = new ForceLoadContentObserver();
66 public PhotoSetLoader(Context context) {
67 super(context, CONTENT_URI, PROJECTION, SELECTION, null, SORT_ORDER);
71 protected void onStartLoading() {
72 super.onStartLoading();
73 getContext().getContentResolver().registerContentObserver(GLOBAL_CONTENT_URI,
74 true, mGlobalObserver);
78 protected void onReset() {
80 getContext().getContentResolver().unregisterContentObserver(mGlobalObserver);
84 public Drawable drawableForItem(Cursor item, Drawable recycle) {
85 DataUriThumbnailDrawable drawable = null;
86 if (recycle == null || !(recycle instanceof DataUriThumbnailDrawable)) {
87 drawable = new DataUriThumbnailDrawable();
89 drawable = (DataUriThumbnailDrawable) recycle;
91 drawable.setImage(item.getString(INDEX_DATA),
92 item.getInt(INDEX_WIDTH), item.getInt(INDEX_HEIGHT));
97 public Uri uriForItem(Cursor item) {
102 public ArrayList<Uri> urisForSubItems(Cursor item) {
107 public void deleteItemWithPath(Object path) {
112 public Object getPathForItem(Cursor item) {