1f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein/*
2f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Copyright (C) 2011 Google Inc.
3f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Licensed to The Android Open Source Project.
4f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein *
5f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Licensed under the Apache License, Version 2.0 (the "License");
6f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * you may not use this file except in compliance with the License.
7f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * You may obtain a copy of the License at
8f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein *
9f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein *      http://www.apache.org/licenses/LICENSE-2.0
10f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein *
11f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Unless required by applicable law or agreed to in writing, software
12f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * distributed under the License is distributed on an "AS IS" BASIS,
13f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * See the License for the specific language governing permissions and
15f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * limitations under the License.
16f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein */
17f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
18f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinpackage com.android.ex.photo.loaders;
19f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
20f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinimport android.content.Context;
21f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinimport android.database.Cursor;
22f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinimport android.net.Uri;
238746927a945358bb9e515985a37cac7807261026Martin Hibdonimport android.support.v4.content.CursorLoader;
24f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
25f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinimport com.android.ex.photo.provider.PhotoContract;
26f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
27f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein/**
28f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Loader for a set of photo IDs.
29f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein */
30f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinpublic class PhotoPagerLoader extends CursorLoader {
31f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    private final Uri mPhotosUri;
32f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    private final String[] mProjection;
33f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
34f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    public PhotoPagerLoader(
35f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            Context context, Uri photosUri, String[] projection) {
36f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        super(context);
37f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        mPhotosUri = photosUri;
38f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        mProjection = projection != null ? projection : PhotoContract.PhotoQuery.PROJECTION;
39f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    }
40f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
41f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    @Override
42f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    public Cursor loadInBackground() {
43f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        Cursor returnCursor = null;
44f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
45f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        final Uri loaderUri = mPhotosUri.buildUpon().appendQueryParameter(
46f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein                PhotoContract.ContentTypeParameters.CONTENT_TYPE, "image/").build();
47f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        setUri(loaderUri);
48f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        setProjection(mProjection);
49f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        returnCursor = super.loadInBackground();
50f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
51f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        return returnCursor;
52f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    }
53f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein}
54