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.net.Uri;
23 import android.provider.MediaStore;
24 import android.provider.MediaStore.Files;
25 import android.provider.MediaStore.Files.FileColumns;
27 public class PhotoSetLoader extends CursorLoader {
29 private static final Uri CONTENT_URI = Files.getContentUri("external");
30 private static final String[] PROJECTION = new String[] {
35 FileColumns.DATE_ADDED,
36 FileColumns.MEDIA_TYPE,
38 private static final String SORT_ORDER = FileColumns.DATE_ADDED + " DESC";
39 private static final String SELECTION =
40 FileColumns.MEDIA_TYPE + " == " + FileColumns.MEDIA_TYPE_IMAGE
42 + FileColumns.MEDIA_TYPE + " == " + FileColumns.MEDIA_TYPE_VIDEO;
44 public static final int INDEX_ID = 0;
45 public static final int INDEX_DATA = 1;
46 public static final int INDEX_WIDTH = 2;
47 public static final int INDEX_HEIGHT = 3;
48 public static final int INDEX_DATE_ADDED = 4;
49 public static final int INDEX_MEDIA_TYPE = 5;
51 private static final Uri GLOBAL_CONTENT_URI = Uri.parse("content://" + MediaStore.AUTHORITY + "/external/");
52 private final ContentObserver mGlobalObserver = new ForceLoadContentObserver();
54 public PhotoSetLoader(Context context) {
55 super(context, CONTENT_URI, PROJECTION, SELECTION, null, SORT_ORDER);
59 protected void onStartLoading() {
60 super.onStartLoading();
61 getContext().getContentResolver().registerContentObserver(GLOBAL_CONTENT_URI,
62 true, mGlobalObserver);
66 protected void onReset() {
68 getContext().getContentResolver().unregisterContentObserver(mGlobalObserver);