[Android] FlingViewGroup: add a new onTouchClick event to the listener interface

Adrien Maglo git at videolan.org
Mon Feb 3 21:57:19 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Mon Feb  3 21:55:30 2014 +0100| [70a60f36190a304b0792c49f22215c3d63e10390] | committer: Adrien Maglo

FlingViewGroup: add a new onTouchClick event to the listener interface

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

 .../src/org/videolan/vlc/gui/AboutFragment.java       |    2 ++
 .../vlc/gui/audio/AudioAlbumsSongsFragment.java       |    2 ++
 .../videolan/vlc/gui/audio/AudioBrowserFragment.java  |    2 ++
 .../org/videolan/vlc/widget/AudioMediaSwitcher.java   |    4 ++++
 .../vlc/widget/AudioPlaylistItemViewGroup.java        |    3 +++
 .../src/org/videolan/vlc/widget/FlingViewGroup.java   |   17 ++++++++++++++++-
 6 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java b/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
index 1124dbd..19e9e6a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
@@ -116,6 +116,8 @@ public class AboutFragment extends SherlockFragment {
             public void onTouchDown() {}
             @Override
             public void onTouchUp() {}
+            @Override
+            public void onTouchClick() {}
         });
 
         return v;
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index 55f2155..df5f198 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -153,6 +153,8 @@ public class AudioAlbumsSongsFragment extends SherlockFragment {
             public void onTouchDown() {}
             @Override
             public void onTouchUp() {}
+            @Override
+            public void onTouchClick() {}
         });
 
         return v;
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index 15f8ae6..43eac03 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -328,6 +328,8 @@ public class AudioBrowserFragment extends SherlockFragment {
         @Override
         public void onTouchUp() {}
 
+        @Override
+        public void onTouchClick() {}
     };
 
     /**
diff --git a/vlc-android/src/org/videolan/vlc/widget/AudioMediaSwitcher.java b/vlc-android/src/org/videolan/vlc/widget/AudioMediaSwitcher.java
index b229292..5e588c8 100644
--- a/vlc-android/src/org/videolan/vlc/widget/AudioMediaSwitcher.java
+++ b/vlc-android/src/org/videolan/vlc/widget/AudioMediaSwitcher.java
@@ -117,6 +117,10 @@ public abstract class AudioMediaSwitcher extends FlingViewGroup {
             if (mAudioMediaSwitcherListener != null)
                 mAudioMediaSwitcherListener.onTouchUp();
         }
+
+        @Override
+        public void onTouchClick() {
+        }
     };
 
     public void setAudioMediaSwitcherListener(AudioMediaSwitcherListener l) {
diff --git a/vlc-android/src/org/videolan/vlc/widget/AudioPlaylistItemViewGroup.java b/vlc-android/src/org/videolan/vlc/widget/AudioPlaylistItemViewGroup.java
index 9dc8619..49988eb 100644
--- a/vlc-android/src/org/videolan/vlc/widget/AudioPlaylistItemViewGroup.java
+++ b/vlc-android/src/org/videolan/vlc/widget/AudioPlaylistItemViewGroup.java
@@ -51,6 +51,9 @@ public class AudioPlaylistItemViewGroup extends FlingViewGroup {
 
         @Override
         public void onTouchUp() { }
+
+        @Override
+        public void onTouchClick() { }
     };
 
     public void setOnItemSlidedListener(OnItemSlidedListener l) {
diff --git a/vlc-android/src/org/videolan/vlc/widget/FlingViewGroup.java b/vlc-android/src/org/videolan/vlc/widget/FlingViewGroup.java
index c846b22..470144f 100644
--- a/vlc-android/src/org/videolan/vlc/widget/FlingViewGroup.java
+++ b/vlc-android/src/org/videolan/vlc/widget/FlingViewGroup.java
@@ -45,6 +45,9 @@ public class FlingViewGroup extends ViewGroup {
 
     private float mLastX;
     private float mLastInterceptDownY;
+    private float mInitialMotionX;
+    private float mInitialMotionY;
+
     private ViewSwitchListener mViewSwitchListener;
 
     public FlingViewGroup(Context context, AttributeSet attrs) {
@@ -165,9 +168,12 @@ public class FlingViewGroup extends ViewGroup {
 
         final int action = event.getAction();
         final float x = event.getX();
+        final float y = event.getY();
 
         switch (action) {
             case MotionEvent.ACTION_DOWN:
+                mInitialMotionX = x;
+                mInitialMotionY = y;
                 if (!mScroller.isFinished())
                     mScroller.abortAnimation();
                 mLastX = x;
@@ -210,8 +216,15 @@ public class FlingViewGroup extends ViewGroup {
                     mVelocityTracker = null;
                 }
 
-                if (mViewSwitchListener != null)
+                if (mViewSwitchListener != null) {
                     mViewSwitchListener.onTouchUp();
+                    final float dx = x - mInitialMotionX;
+                    final float dy = y - mInitialMotionY;
+                    ViewConfiguration config = ViewConfiguration.get(getContext());
+                    final int slop = config.getScaledTouchSlop();
+                    if (dx * dx + dy * dy < slop * slop)
+                        mViewSwitchListener.onTouchClick();
+                }
 
                 break;
         }
@@ -270,6 +283,8 @@ public class FlingViewGroup extends ViewGroup {
         void onTouchDown();
 
         void onTouchUp();
+
+        void onTouchClick();
     }
 
 }



More information about the Android mailing list