Created
September 25, 2012 12:58
-
-
Save atermenji/3781644 to your computer and use it in GitHub Desktop.
A viewpager which works with ImageViewTouch (https://github.com/sephiroth74/ImageViewZoom)
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
package some.awesome.package; | |
import it.sephiroth.android.library.imagezoom.ImageViewTouch; | |
import android.content.Context; | |
import android.support.v4.view.ViewPager; | |
import android.util.AttributeSet; | |
import android.util.Log; | |
import android.view.View; | |
public class ImageViewTouchViewPager extends ViewPager { | |
private static final String TAG = "ImageViewTouchViewPager"; | |
public static final String VIEW_PAGER_OBJECT_TAG = "image#"; | |
private int previousPosition; | |
private OnPageSelectedListener onPageSelectedListener; | |
public ImageViewTouchViewPager(Context context) { | |
super(context); | |
init(); | |
} | |
public ImageViewTouchViewPager(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
init(); | |
} | |
public void setOnPageSelectedListener(OnPageSelectedListener listener) { | |
onPageSelectedListener = listener; | |
} | |
@Override | |
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) { | |
if (v instanceof ImageViewTouch) { | |
return ((ImageViewTouch) v).canScroll(dx); | |
} else { | |
return super.canScroll(v, checkV, dx, x, y); | |
} | |
} | |
public interface OnPageSelectedListener { | |
public void onPageSelected(int position); | |
} | |
private void init() { | |
previousPosition = getCurrentItem(); | |
setOnPageChangeListener(new SimpleOnPageChangeListener() { | |
@Override | |
public void onPageSelected(int position) { | |
if (onPageSelectedListener != null) { | |
onPageSelectedListener.onPageSelected(position); | |
} | |
} | |
@Override | |
public void onPageScrollStateChanged(int state) { | |
if (state == SCROLL_STATE_SETTLING && previousPosition != getCurrentItem()) { | |
try { | |
ImageViewTouch imageViewTouch = (ImageViewTouch) | |
findViewWithTag(VIEW_PAGER_OBJECT_TAG + getCurrentItem()); | |
if (imageViewTouch != null) { | |
imageViewTouch.zoomTo(1f, 300); | |
} | |
previousPosition = getCurrentItem(); | |
} catch (ClassCastException ex) { | |
Log.e(TAG, "This view pager should have only ImageViewTouch as a children.", ex); | |
} | |
} | |
} | |
}); | |
} | |
} |
Please add ulx's code to the example or (better) to the canScroll() code in ImageViewTouch. It works now.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ulx thanks, your solution is simpler and it hits the problem right into solving it :)
Though the right fix would be in the library itself, it seems to incorrectly calculate bitmap offsets or something like this in
canScroll()