Created
May 26, 2014 10:15
-
-
Save CoffeeCode/2d1aaa8bc0e3a9157e81 to your computer and use it in GitHub Desktop.
Adapter
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; | |
private int count; | |
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); | |
} | |
@Override | |
public void restoreState(Parcelable state, ClassLoader loader) { | |
} | |
@Override | |
public Parcelable saveState() { | |
return null; | |
} | |
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