Created
May 26, 2014 20:12
-
-
Save CoffeeCode/29ebcaac5ed4f600e5a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GalleryFragmentStatePagerAdapter extends FragmentStatePagerAdapter { | |
private final String TAG = "GalleryFragmentStatePagerAdapter"; | |
private Context context; | |
private Cursor cursor; | |
private LayoutInflater inflater; | |
protected RenderScript renderScript; | |
public GalleryFragmentStatePagerAdapter(Context context, Cursor cursor, FragmentManager fragmentManager) { | |
super(fragmentManager); | |
this.cursor = cursor; | |
Log.d(TAG, "cursor count : " + cursor.getCount()); | |
this.context = context; | |
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
renderScript = RenderScript.create(context); | |
} | |
@Override | |
public void destroyItem(ViewGroup container, int position, Object object) { | |
container.removeView((View) object); | |
} | |
@Override | |
public int getCount() { | |
return cursor.getCount(); | |
} | |
@Override | |
public Fragment getItem(int position) { | |
Log.d(TAG, "get Item from position : " + position); | |
return Viewer.init(getFileFromPosition(position)); | |
} | |
@Override | |
public boolean isViewFromObject(View view, Object object) { | |
return view.equals(object); | |
} | |
public String getFileFromPosition(int position){ | |
cursor.moveToPosition(position); | |
int column_index = cursor.getColumnIndex(MediaStore.MediaColumns.DATA); | |
String path = cursor.getString(column_index); | |
return path; | |
} | |
public void changeCursor(Cursor cursor){ | |
this.cursor = cursor; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment