diff options
author | Andrew Dolgov <[email protected]> | 2012-11-30 13:48:41 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2012-11-30 13:48:41 +0300 |
commit | 88e230ef42ff4c6efb4eab752cc2c44fc0e21d4c (patch) | |
tree | fad91faa8b41f178468364ea7930545c2f4f41aa /src | |
parent | a968341b118f5273ef295cec1258c70c89dc58a1 (diff) |
implement seamless scroll/flick in viewpager
Diffstat (limited to 'src')
-rw-r--r-- | src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java | 6 | ||||
-rw-r--r-- | src/org/fox/ttcomics/ComicFragment.java | 34 | ||||
-rw-r--r-- | src/org/fox/ttcomics/ComicPager.java | 12 | ||||
-rw-r--r-- | src/org/fox/ttcomics/CommonActivity.java | 6 | ||||
-rw-r--r-- | src/org/fox/ttcomics/ViewPager.java | 34 |
5 files changed, 46 insertions, 46 deletions
diff --git a/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java b/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java index de8a7da..73392b1 100644 --- a/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java +++ b/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java @@ -7,7 +7,6 @@ import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; -import android.view.Display; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.MotionEvent; @@ -34,7 +33,7 @@ public class ImageViewTouch extends ImageViewTouchBase { private OnImageViewTouchDoubleTapListener doubleTapListener; public interface OnScaleChangedListener { - public void onScaleChanged(float scale, boolean widthFits); + public void onScaleChanged(float scale); } protected OnScaleChangedListener mScaleChangedListener; @@ -121,8 +120,7 @@ public class ImageViewTouch extends ImageViewTouchBase { if ( !mScaleDetector.isInProgress() ) mCurrentScaleFactor = scale; if (mScaleChangedListener != null) { - RectF bitmapRect = getBitmapRect(); - mScaleChangedListener.onScaleChanged(mCurrentScaleFactor, getWidth() >= (bitmapRect.right - bitmapRect.left) - 3); + mScaleChangedListener.onScaleChanged(mCurrentScaleFactor); } } diff --git a/src/org/fox/ttcomics/ComicFragment.java b/src/org/fox/ttcomics/ComicFragment.java index da34ce4..d55b102 100644 --- a/src/org/fox/ttcomics/ComicFragment.java +++ b/src/org/fox/ttcomics/ComicFragment.java @@ -111,12 +111,12 @@ public class ComicFragment extends Fragment { image.setOnScaleChangedListener(new ImageViewTouch.OnScaleChangedListener() {
@Override
- public void onScaleChanged(float scale, boolean widthFits) {
- ViewPager pager = (ViewPager) getActivity().findViewById(R.id.comics_pager);
+ public void onScaleChanged(float scale) {
+ /* ViewPager pager = (ViewPager) getActivity().findViewById(R.id.comics_pager);
if (pager != null) {
pager.setPagingEnabled(widthFits);
- }
+ } */
}
});
@@ -154,11 +154,33 @@ public class ComicFragment extends Fragment { }
private void onLeftSideTapped() {
- m_activity.selectPreviousComic();
+ ImageViewTouch image = (ImageViewTouch) getView().findViewById(R.id.comic_image);
+
+ if (image != null) {
+ boolean atLeftEdge = !image.canScroll(1);
+
+ if (atLeftEdge) {
+ m_activity.selectPreviousComic();
+ }
+ }
}
-
+
+ public boolean canScroll(int direction) {
+ ImageViewTouch image = (ImageViewTouch) getView().findViewById(R.id.comic_image);
+
+ return image.canScroll(direction);
+ }
+
private void onRightSideTapped() {
- m_activity.selectNextComic();
+ ImageViewTouch image = (ImageViewTouch) getView().findViewById(R.id.comic_image);
+
+ if (image != null) {
+ boolean atRightEdge = !image.canScroll(-1);
+
+ if (atRightEdge) {
+ m_activity.selectNextComic();
+ }
+ }
}
@Override
diff --git a/src/org/fox/ttcomics/ComicPager.java b/src/org/fox/ttcomics/ComicPager.java index ab40936..934aaa7 100644 --- a/src/org/fox/ttcomics/ComicPager.java +++ b/src/org/fox/ttcomics/ComicPager.java @@ -164,17 +164,5 @@ public class ComicPager extends Fragment { out.putString("fileName", m_fileName);
}
-
- public boolean isPagingEnabled() {
-
- ViewPager pager = (ViewPager) getView().findViewById(R.id.comics_pager);
-
- if (pager != null) {
- return pager.isPagingEnabled();
- }
-
- return false;
- }
-
}
diff --git a/src/org/fox/ttcomics/CommonActivity.java b/src/org/fox/ttcomics/CommonActivity.java index 873ccd3..d535fe6 100644 --- a/src/org/fox/ttcomics/CommonActivity.java +++ b/src/org/fox/ttcomics/CommonActivity.java @@ -492,7 +492,7 @@ public class CommonActivity extends FragmentActivity { public void selectPreviousComic() {
ComicPager frag = (ComicPager) getSupportFragmentManager().findFragmentByTag(FRAG_COMICS_PAGER);
- if (frag != null && frag.isAdded() && frag.getPosition() > 0 && frag.isPagingEnabled()) {
+ if (frag != null && frag.isAdded() && frag.getPosition() > 0) {
frag.setCurrentItem(frag.getPosition() - 1);
}
}
@@ -500,11 +500,9 @@ public class CommonActivity extends FragmentActivity { public void selectNextComic() {
ComicPager frag = (ComicPager) getSupportFragmentManager().findFragmentByTag(FRAG_COMICS_PAGER);
- if (frag != null && frag.isAdded() && frag.getPosition() < frag.getCount()-1 && frag.isPagingEnabled()) {
+ if (frag != null && frag.isAdded() && frag.getPosition() < frag.getCount()-1) {
frag.setCurrentItem(frag.getPosition() + 1);
}
-
-
}
public void cleanupSqliteCache(String baseDir) {
diff --git a/src/org/fox/ttcomics/ViewPager.java b/src/org/fox/ttcomics/ViewPager.java index c5d2f13..18bcc49 100644 --- a/src/org/fox/ttcomics/ViewPager.java +++ b/src/org/fox/ttcomics/ViewPager.java @@ -1,43 +1,37 @@ package org.fox.ttcomics;
+import it.sephiroth.android.library.imagezoom.ImageViewTouch;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
+import android.view.View;
public class ViewPager extends android.support.v4.view.ViewPager {
private final String TAG = this.getClass().getSimpleName();
- private boolean enabled;
public ViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
- this.enabled = true;
}
@Override
+ protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
+ if (v instanceof ImageViewTouch) {
+ ImageViewTouch ivt = (ImageViewTouch) v;
+ return ivt.canScroll(dx);
+ } else {
+ return super.canScroll(v, checkV, dx, x, y);
+ }
+ }
+
+ @Override
public boolean onTouchEvent(MotionEvent event) {
- if (this.enabled) {
- return super.onTouchEvent(event);
- }
-
- return false;
+ return super.onTouchEvent(event);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
- if (this.enabled) {
- return super.onInterceptTouchEvent(event);
- }
-
- return false;
- }
-
- public void setPagingEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public boolean isPagingEnabled() {
- return this.enabled;
+ return super.onInterceptTouchEvent(event);
}
}
\ No newline at end of file |