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