[Android] Audio player: react to all sliding up touch events

Adrien Maglo git at videolan.org
Thu Jan 9 16:40:17 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Thu Jan  9 16:39:35 2014 +0100| [01b878caec0812ee2f245d49cc921ca6084e01ff] | committer: Adrien Maglo

Audio player: react to all sliding up touch events

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

 vlc-android/res/layout/main.xml                    |    4 +--
 .../videolan/vlc/widget/ContentLinearLayout.java   |   29 ++++++++++++++++++++
 .../org/videolan/vlc/widget/SlidingPaneLayout.java |   13 +++++++++
 3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/vlc-android/res/layout/main.xml b/vlc-android/res/layout/main.xml
index 1cf7477..78b8364 100644
--- a/vlc-android/res/layout/main.xml
+++ b/vlc-android/res/layout/main.xml
@@ -4,7 +4,7 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent" >
 
-    <LinearLayout
+    <org.videolan.vlc.widget.ContentLinearLayout
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:layout_weight="1"
@@ -42,7 +42,7 @@
                 android:singleLine="true"
                 android:textColor="#FFFFFFFF" />
         </RelativeLayout>
-    </LinearLayout>
+    </org.videolan.vlc.widget.ContentLinearLayout>
 
     <FrameLayout
         android:id="@+id/audio_mini_player"
diff --git a/vlc-android/src/org/videolan/vlc/widget/ContentLinearLayout.java b/vlc-android/src/org/videolan/vlc/widget/ContentLinearLayout.java
new file mode 100644
index 0000000..724efca
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/widget/ContentLinearLayout.java
@@ -0,0 +1,29 @@
+package org.videolan.vlc.widget;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.widget.LinearLayout;
+
+
+/**
+ * This class extends the linear layout class and override its onInterceptTouchEvent
+ * method to intercept the touch events that should not be handled by its children.
+ * This is necessary since else the layout children receive events even if the
+ * audio player is displayed just under the touch event position.
+ */
+public class ContentLinearLayout extends LinearLayout {
+
+    public ContentLinearLayout(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    @Override
+    public boolean onInterceptTouchEvent(MotionEvent ev) {
+        SlidingPaneLayout slidingPaneLayout = (SlidingPaneLayout)getParent();
+        if (slidingPaneLayout.isSecondChildUnder((int)ev.getX(), (int)ev.getY()))
+            return true;
+        else
+            return super.onInterceptHoverEvent(ev);
+    }
+}
diff --git a/vlc-android/src/org/videolan/vlc/widget/SlidingPaneLayout.java b/vlc-android/src/org/videolan/vlc/widget/SlidingPaneLayout.java
index fa898aa..1d40851 100644
--- a/vlc-android/src/org/videolan/vlc/widget/SlidingPaneLayout.java
+++ b/vlc-android/src/org/videolan/vlc/widget/SlidingPaneLayout.java
@@ -855,6 +855,19 @@ public class SlidingPaneLayout extends ViewGroup {
         }
     }
 
+    /**
+     * Test if the second child is displayed under the coordinates given in parameters.
+     * @param x
+     * @param y
+     * @return true if the second child is displayed else false.
+     */
+    public boolean isSecondChildUnder(int x, int y) {
+        View secondChild = getChildAt(1);
+        if (secondChild == null)
+            return false;
+        return mDragHelper.isViewUnder(secondChild, x, y);
+    }
+
     public static class LayoutParams extends ViewGroup.MarginLayoutParams {
 
         /**



More information about the Android mailing list