Skip to content

Instantly share code, notes, and snippets.

@SehoNoh
Last active August 29, 2015 14:05
Show Gist options
  • Save SehoNoh/936fd6a95b85e2f27035 to your computer and use it in GitHub Desktop.
Save SehoNoh/936fd6a95b85e2f27035 to your computer and use it in GitHub Desktop.
items.add(Environment.getExternalStorageDirectory() + "/DCIM/Camera/20140706_170122.jpg");
items.add(Environment.getExternalStorageDirectory() + "/DCIM/Camera/20140822_123456.jpg");
items.add(Environment.getExternalStorageDirectory() + "/DCIM/Camera/20140706_152135.jpg");
for (int count = 0; count < items.size(); count++) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
BitmapFactory.decodeFile(items.get(count), options);
float width;
float height;
if (options.outWidth > getWindowManager().getDefaultDisplay().getWidth()) {
width = pager.getLayoutParams().width;
} else {
width = options.outWidth;
}
if (options.outHeight > getWindowManager().getDefaultDisplay().getHeight()) {
height = getWindowManager().getDefaultDisplay().getHeight();
} else {
height = options.outHeight;
}
Log.i("Display", "Width : " + width + ", Height : " + height);
info.add(new PhotoInfo(height, width));
if ((count + 1) == items.size()) {
pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
private PhotoInfo previousItem = new PhotoInfo();
private PhotoInfo currentItem = new PhotoInfo();
private PhotoInfo nextItem = new PhotoInfo();
private boolean isScrolling = false;
private int previousPosition;
private int currentPosition;
private int nextPosition;
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
ViewGroup.LayoutParams lp = pager.getLayoutParams();
Log.i("OnPageListener", "Position : " + position + ", Position Offset : " + positionOffset + ", Position Offset Pixels : " + positionOffsetPixels);
if (positionOffsetPixels <= 0.1) {
previousPosition = position - 1;
currentPosition = position;
nextPosition = position + 1;
Log.d("IDLE", "Previous Position : " + previousPosition + ", Current Position : " + currentPosition + ", Next Position : " + nextPosition);
}
if (position == 0) {
if (null == info) {
Log.e("OnPageScrolled", "NULL");
}
currentItem = info.get(currentPosition);
nextItem = info.get(nextPosition);
lp.width = (int) nextItem.getWidth();
lp.height = (int) nextItem.getHeight();
} else if (position == items.size()) {
previousItem = info.get(previousPosition);
currentItem = info.get(currentPosition);
lp.width = (int) previousItem.getWidth();
lp.height = (int) previousItem.getHeight();
} else {
previousItem = info.get(previousPosition);
currentItem = info.get(currentPosition);
nextItem = info.get(nextPosition);
if (position == previousPosition) {
lp.width = (int) previousItem.getWidth();
lp.height = (int) previousItem.getHeight();
} else if ((position == currentPosition) && positionOffsetPixels != 0) {
lp.width = (int) nextItem.getWidth();
lp.height = (int) nextItem.getHeight();
} else {
lp.width = (int) currentItem.getWidth();
lp.height = (int) currentItem.getHeight();
}
}
pager.setLayoutParams(lp);
}
@Override
public void onPageSelected(int position) {}
@Override
public void onPageScrollStateChanged(int state) {
switch (state) {
case ViewPager.SCROLL_STATE_DRAGGING:
isScrolling = true;
Log.d("OnPageListener", "Scroll Start");
break;
case ViewPager.SCROLL_STATE_IDLE:
isScrolling = false;
Log.d("OnPageListener", "Scroll Stop");
break;
default:
isScrolling = false;
Log.d("OnPageListener", "Default");
break;
}
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment