15f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck/* 25f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck * Copyright (C) 2013 The Android Open Source Project 35f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck * 45f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck * Licensed under the Apache License, Version 2.0 (the "License"); 55f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck * you may not use this file except in compliance with the License. 65f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck * You may obtain a copy of the License at 75f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck * 85f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck * http://www.apache.org/licenses/LICENSE-2.0 95f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck * 105f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck * Unless required by applicable law or agreed to in writing, software 115f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck * distributed under the License is distributed on an "AS IS" BASIS, 125f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck * See the License for the specific language governing permissions and 145f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck * limitations under the License. 155f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck */ 165f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck 175f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reckpackage com.android.photos; 185f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck 195f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reckimport android.app.LoaderManager.LoaderCallbacks; 20869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescuimport android.content.Context; 21f6e687bc30887695374580712092aeb917c84253John Reckimport android.content.Intent; 225f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reckimport android.content.Loader; 235f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reckimport android.database.Cursor; 24f6e687bc30887695374580712092aeb917c84253John Reckimport android.net.Uri; 255f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reckimport android.os.Bundle; 265f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reckimport android.view.LayoutInflater; 275f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reckimport android.view.View; 285f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reckimport android.view.ViewGroup; 29d228222e5efca7df8c7f2fe49e5ec76696cbbc05John Reckimport android.widget.GridView; 305f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck 3106c027675948259368a902fd6f8c2ecac5db5167Mangesh Ghiwareimport com.android.gallery3d.app.GalleryActivity; 32fb6132b0b3079153fd1d15acf1dc3c6100aa2e00Bobby Georgescuimport com.android.photos.adapters.PhotoThumbnailAdapter; 335f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reckimport com.android.photos.data.PhotoSetLoader; 34f6e687bc30887695374580712092aeb917c84253John Reckimport com.android.photos.shims.LoaderCompatShim; 35d228222e5efca7df8c7f2fe49e5ec76696cbbc05John Reckimport com.android.photos.shims.MediaItemsLoader; 365f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck 37fb6132b0b3079153fd1d15acf1dc3c6100aa2e00Bobby Georgescuimport java.util.ArrayList; 385f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck 39c1a015f3b9a896179d2b4778e50988460cfd34fbBobby Georgescupublic class PhotoSetFragment extends MultiSelectGridFragment implements LoaderCallbacks<Cursor> { 405f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck 415f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck private static final int LOADER_PHOTOSET = 1; 425f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck 43f6e687bc30887695374580712092aeb917c84253John Reck private LoaderCompatShim<Cursor> mLoaderCompatShim; 44fb6132b0b3079153fd1d15acf1dc3c6100aa2e00Bobby Georgescu private PhotoThumbnailAdapter mAdapter; 455f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck 465f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck @Override 47638d9ec56c26d9f3cff55145ccbd20b35bb964f5John Reck public void onCreate(Bundle savedInstanceState) { 48638d9ec56c26d9f3cff55145ccbd20b35bb964f5John Reck super.onCreate(savedInstanceState); 49869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu Context context = getActivity(); 50869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu mAdapter = new PhotoThumbnailAdapter(context); 51869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu } 52869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu 53869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu @Override 545f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck public View onCreateView(LayoutInflater inflater, ViewGroup container, 555f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck Bundle savedInstanceState) { 56c1a015f3b9a896179d2b4778e50988460cfd34fbBobby Georgescu View root = super.onCreateView(inflater, container, savedInstanceState); 575f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck getLoaderManager().initLoader(LOADER_PHOTOSET, null, this); 585f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck return root; 595f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck } 605f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck 61c1a015f3b9a896179d2b4778e50988460cfd34fbBobby Georgescu @Override 62c1a015f3b9a896179d2b4778e50988460cfd34fbBobby Georgescu public void onViewCreated(View view, Bundle savedInstanceState) { 63c1a015f3b9a896179d2b4778e50988460cfd34fbBobby Georgescu super.onViewCreated(view, savedInstanceState); 64c1a015f3b9a896179d2b4778e50988460cfd34fbBobby Georgescu // TODO: Remove once UI stabilizes 65c1a015f3b9a896179d2b4778e50988460cfd34fbBobby Georgescu getGridView().setColumnWidth(MediaItemsLoader.getThumbnailSize()); 66f6e687bc30887695374580712092aeb917c84253John Reck } 67f6e687bc30887695374580712092aeb917c84253John Reck 68f6e687bc30887695374580712092aeb917c84253John Reck @Override 69c1a015f3b9a896179d2b4778e50988460cfd34fbBobby Georgescu public void onGridItemClick(GridView g, View v, int position, long id) { 70f6e687bc30887695374580712092aeb917c84253John Reck if (mLoaderCompatShim == null) { 71f6e687bc30887695374580712092aeb917c84253John Reck // Not fully initialized yet, discard 72f6e687bc30887695374580712092aeb917c84253John Reck return; 73f6e687bc30887695374580712092aeb917c84253John Reck } 74c1a015f3b9a896179d2b4778e50988460cfd34fbBobby Georgescu Cursor item = (Cursor) getItemAtPosition(position); 75f6e687bc30887695374580712092aeb917c84253John Reck Uri uri = mLoaderCompatShim.uriForItem(item); 76f6e687bc30887695374580712092aeb917c84253John Reck Intent intent = new Intent(Intent.ACTION_VIEW, uri); 7706c027675948259368a902fd6f8c2ecac5db5167Mangesh Ghiware intent.setClass(getActivity(), GalleryActivity.class); 78f6e687bc30887695374580712092aeb917c84253John Reck startActivity(intent); 795f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck } 805f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck 815f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck @Override 825f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck public Loader<Cursor> onCreateLoader(int id, Bundle args) { 83d228222e5efca7df8c7f2fe49e5ec76696cbbc05John Reck // TODO: Switch to PhotoSetLoader 84d228222e5efca7df8c7f2fe49e5ec76696cbbc05John Reck MediaItemsLoader loader = new MediaItemsLoader(getActivity()); 85f6e687bc30887695374580712092aeb917c84253John Reck mLoaderCompatShim = loader; 86fb6132b0b3079153fd1d15acf1dc3c6100aa2e00Bobby Georgescu mAdapter.setDrawableFactory(mLoaderCompatShim); 87d228222e5efca7df8c7f2fe49e5ec76696cbbc05John Reck return loader; 885f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck } 895f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck 905f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck @Override 915f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck public void onLoadFinished(Loader<Cursor> loader, 925f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck Cursor data) { 935f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck mAdapter.swapCursor(data); 94c1a015f3b9a896179d2b4778e50988460cfd34fbBobby Georgescu setAdapter(mAdapter); 955f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck } 965f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck 97fb6132b0b3079153fd1d15acf1dc3c6100aa2e00Bobby Georgescu @Override 98869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu public void onLoaderReset(Loader<Cursor> loader) { 99fb6132b0b3079153fd1d15acf1dc3c6100aa2e00Bobby Georgescu } 100fb6132b0b3079153fd1d15acf1dc3c6100aa2e00Bobby Georgescu 1015f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck @Override 102869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu public int getItemMediaType(Object item) { 103869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu return ((Cursor) item).getInt(PhotoSetLoader.INDEX_MEDIA_TYPE); 1045f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck } 10571bfefaf9029df26ba4c6e4077c4e3e2f259634fJohn Reck 106869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu @Override 107869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu public int getItemSupportedOperations(Object item) { 108869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu return ((Cursor) item).getInt(PhotoSetLoader.INDEX_SUPPORTED_OPERATIONS); 109fb6132b0b3079153fd1d15acf1dc3c6100aa2e00Bobby Georgescu } 11071bfefaf9029df26ba4c6e4077c4e3e2f259634fJohn Reck 111869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu private ArrayList<Uri> mSubItemUriTemp = new ArrayList<Uri>(1); 112fb6132b0b3079153fd1d15acf1dc3c6100aa2e00Bobby Georgescu @Override 113869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu public ArrayList<Uri> getSubItemUrisForItem(Object item) { 114869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu mSubItemUriTemp.clear(); 115869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu mSubItemUriTemp.add(mLoaderCompatShim.uriForItem((Cursor) item)); 116869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu return mSubItemUriTemp; 117fb6132b0b3079153fd1d15acf1dc3c6100aa2e00Bobby Georgescu } 11871bfefaf9029df26ba4c6e4077c4e3e2f259634fJohn Reck 119fb6132b0b3079153fd1d15acf1dc3c6100aa2e00Bobby Georgescu @Override 120869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu public void deleteItemWithPath(Object itemPath) { 121869f4a62594c4508aa57a8622b461b6825b74e7cBobby Georgescu mLoaderCompatShim.deleteItemWithPath(itemPath); 122fb6132b0b3079153fd1d15acf1dc3c6100aa2e00Bobby Georgescu } 123fb6132b0b3079153fd1d15acf1dc3c6100aa2e00Bobby Georgescu 124fb6132b0b3079153fd1d15acf1dc3c6100aa2e00Bobby Georgescu @Override 125c1a015f3b9a896179d2b4778e50988460cfd34fbBobby Georgescu public Uri getItemUri(Object item) { 126c1a015f3b9a896179d2b4778e50988460cfd34fbBobby Georgescu return mLoaderCompatShim.uriForItem((Cursor) item); 12771bfefaf9029df26ba4c6e4077c4e3e2f259634fJohn Reck } 1281a719804ddd5c6fc9a6914ef5a2b6e914834d1f9Bobby Georgescu 1291a719804ddd5c6fc9a6914ef5a2b6e914834d1f9Bobby Georgescu @Override 130c1a015f3b9a896179d2b4778e50988460cfd34fbBobby Georgescu public Object getPathForItem(Object item) { 131c1a015f3b9a896179d2b4778e50988460cfd34fbBobby Georgescu return mLoaderCompatShim.getPathForItem((Cursor) item); 1321a719804ddd5c6fc9a6914ef5a2b6e914834d1f9Bobby Georgescu } 1335f30b98d6ac98c6aa863d48f47e9b8e2b77a1820John Reck} 134