11cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein/*
21cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein * Copyright (C) 2011 Google Inc.
31cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein * Licensed to The Android Open Source Project.
41cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein *
51cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein * Licensed under the Apache License, Version 2.0 (the "License");
61cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein * you may not use this file except in compliance with the License.
71cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein * You may obtain a copy of the License at
81cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein *
91cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein *      http://www.apache.org/licenses/LICENSE-2.0
101cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein *
111cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein * Unless required by applicable law or agreed to in writing, software
121cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein * distributed under the License is distributed on an "AS IS" BASIS,
131cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein * See the License for the specific language governing permissions and
151cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein * limitations under the License.
161cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein */
171cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein
181cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sappersteinpackage com.android.ex.photo.loaders;
191cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein
201cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sappersteinimport android.content.Context;
211cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sappersteinimport android.content.CursorLoader;
221cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sappersteinimport android.database.Cursor;
231cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sappersteinimport android.net.Uri;
241cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein
251cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sappersteinimport com.android.ex.photo.provider.PhotoContract;
261cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein
271cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein/**
281cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein * Loader for a set of photo IDs.
291cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein */
301cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sappersteinpublic class PhotoPagerLoader extends CursorLoader {
311cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein    private final Uri mPhotosUri;
321cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein    private final String[] mProjection;
331cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein
341cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein    public PhotoPagerLoader(
351cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein            Context context, Uri photosUri, String[] projection) {
361cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein        super(context);
371cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein        mPhotosUri = photosUri;
381cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein        mProjection = projection != null ? projection : PhotoContract.PhotoQuery.PROJECTION;
391cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein    }
401cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein
411cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein    @Override
421cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein    public Cursor loadInBackground() {
431cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein        Cursor returnCursor = null;
441cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein
451cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein        final Uri loaderUri = mPhotosUri.buildUpon().appendQueryParameter(
461cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein                PhotoContract.ContentTypeParameters.CONTENT_TYPE, "image/").build();
471cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein        setUri(loaderUri);
481cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein        setProjection(mProjection);
491cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein        returnCursor = super.loadInBackground();
501cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein
511cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein        return returnCursor;
521cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein    }
531cc4b2144a45abb495c8b14f6cfc5a10fb5e8ba8Andrew Sapperstein}
54