/* * This file provided by Facebook is for non-commercial testing and evaluation * purposes only. Facebook reserves all rights not expressly granted. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package com.kiminonawa.mydiary.entries.photo; import android.net.Uri; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.util.SparseArray; import android.view.ViewGroup; import java.util.ArrayList; public class PhotoDetailPagerAdapter extends FragmentPagerAdapter { private SparseArray<Fragment> registeredFragments = new SparseArray<Fragment>(); private ArrayList<Uri> diaryPhotoFileList; public PhotoDetailPagerAdapter(FragmentManager fm, ArrayList<Uri> diaryPhotoFileList) { super(fm); this.diaryPhotoFileList = diaryPhotoFileList; } @Override public PhotoDetailViewerFragment getItem(int position) { PhotoDetailViewerFragment fragment = PhotoDetailViewerFragment.newInstance(diaryPhotoFileList.get(position)); return fragment; } @Override public int getCount() { return diaryPhotoFileList.size(); } @Override public Object instantiateItem(ViewGroup container, int position) { Fragment fragment = (Fragment) super.instantiateItem(container, position); registeredFragments.put(position, fragment); return fragment; } @Override public void destroyItem(ViewGroup container, int position, Object object) { registeredFragments.remove(position); super.destroyItem(container, position, object); } public Fragment getRegisteredFragment(int position) { return registeredFragments.get(position); } }