OSDN Git Service

merge in jb-mr2-release history after reset to master
[android-x86/packages-apps-Gallery2.git] / src / com / android / photos / data / PhotoSetLoader.java
1 /*
2  * Copyright (C) 2013 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.photos.data;
18
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;
26
27 public class PhotoSetLoader extends CursorLoader {
28
29     private static final Uri CONTENT_URI = Files.getContentUri("external");
30     private static final String[] PROJECTION = new String[] {
31         FileColumns._ID,
32         FileColumns.DATA,
33         FileColumns.WIDTH,
34         FileColumns.HEIGHT,
35         FileColumns.DATE_ADDED,
36         FileColumns.MEDIA_TYPE,
37     };
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
41             + " OR "
42             + FileColumns.MEDIA_TYPE + " == " + FileColumns.MEDIA_TYPE_VIDEO;
43
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;
50
51     private static final Uri GLOBAL_CONTENT_URI = Uri.parse("content://" + MediaStore.AUTHORITY + "/external/");
52     private final ContentObserver mGlobalObserver = new ForceLoadContentObserver();
53
54     public PhotoSetLoader(Context context) {
55         super(context, CONTENT_URI, PROJECTION, SELECTION, null, SORT_ORDER);
56     }
57
58     @Override
59     protected void onStartLoading() {
60         super.onStartLoading();
61         getContext().getContentResolver().registerContentObserver(GLOBAL_CONTENT_URI,
62                 true, mGlobalObserver);
63     }
64
65     @Override
66     protected void onReset() {
67         super.onReset();
68         getContext().getContentResolver().unregisterContentObserver(mGlobalObserver);
69     }
70 }