[Android] FlingViewGroup: handle all the scroll events in the onScrollChanged function and use the scroller for the scrollTo function

Adrien Maglo git at videolan.org
Tue Jan 14 18:53:49 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Tue Jan 14 18:48:54 2014 +0100| [ec081c3ae5c0e9055aeab7a24897e55186c61bfd] | committer: Adrien Maglo

FlingViewGroup: handle all the scroll events in the onScrollChanged function and use the scroller for the scrollTo function

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=ec081c3ae5c0e9055aeab7a24897e55186c61bfd
---

 .../src/org/videolan/vlc/widget/FlingViewGroup.java     |   15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/widget/FlingViewGroup.java b/vlc-android/src/org/videolan/vlc/widget/FlingViewGroup.java
index cb79f1a..e317c6e 100644
--- a/vlc-android/src/org/videolan/vlc/widget/FlingViewGroup.java
+++ b/vlc-android/src/org/videolan/vlc/widget/FlingViewGroup.java
@@ -212,7 +212,10 @@ public class FlingViewGroup extends ViewGroup {
         super.onScrollChanged(l, t, oldl, oldt);
         if (mViewSwitchListener != null) {
             float progress = (float) l / (float) (getWidth() * (getChildCount() - 1));
-            mViewSwitchListener.onSwitching(progress);
+            if (l != mCurrentView * getWidth())
+                mViewSwitchListener.onSwitching(progress);
+            else
+                mViewSwitchListener.onSwitched(mCurrentView);
         }
     }
 
@@ -227,17 +230,13 @@ public class FlingViewGroup extends ViewGroup {
         final int delta = (position * getWidth()) - getScrollX();
         mScroller.startScroll(getScrollX(), 0, delta, 0, Math.abs(delta));
         invalidate();
-        if (mViewSwitchListener != null) {
-            mViewSwitchListener.onSwitched(position);
-        }
     }
 
     public void scrollTo(int position) {
         mCurrentView = position;
-        scrollTo(position * getWidth(), 0);
-        if (mViewSwitchListener != null) {
-            mViewSwitchListener.onSwitched(position);
-        }
+        final int delta = (position * getWidth()) - getScrollX();
+        mScroller.startScroll(getScrollX(), 0, delta, 0, 0);
+        invalidate();
     }
 
     public void setOnViewSwitchedListener(ViewSwitchListener l) {



More information about the Android mailing list