[Android] SlidePaneLayout: add a listener to send event on panel sliding

Adrien Maglo git at videolan.org
Wed Jan 15 16:53:29 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Wed Jan 15 16:49:31 2014 +0100| [266dbd4278da65c43fdfb11252c51dfda4d51c73] | committer: Adrien Maglo

SlidePaneLayout: add a listener to send event on panel sliding

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

 .../org/videolan/vlc/widget/SlidingPaneLayout.java |   53 ++++++++++++++++++--
 1 file changed, 50 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/widget/SlidingPaneLayout.java b/vlc-android/src/org/videolan/vlc/widget/SlidingPaneLayout.java
index df3b9f6..54bb050 100644
--- a/vlc-android/src/org/videolan/vlc/widget/SlidingPaneLayout.java
+++ b/vlc-android/src/org/videolan/vlc/widget/SlidingPaneLayout.java
@@ -143,6 +143,34 @@ public class SlidingPaneLayout extends ViewGroup {
         }
     }
 
+    private PanelSlideListener mPanelSlideListener;
+
+    /**
+     * Listener for monitoring events about the sliding pane.
+     */
+    public interface PanelSlideListener {
+        /**
+         * Called when the sliding pane position changes.
+         * @param slideOffset The new offset of this sliding pane within its range, from 0-1
+         */
+        public void onPanelSlide(float slideOffset);
+
+        /**
+         * Called when the sliding pane becomes slid open.
+         */
+        public void onPanelOpened();
+
+        /**
+         * Called when the sliding pane becomes slid open entirely.
+         */
+        public void onPanelOpenedEntirely();
+
+        /**
+         * Called when a sliding pane becomes slid completely closed.
+         */
+        public void onPanelClosed();
+    }
+
     public SlidingPaneLayout(Context context) {
         this(context, null);
     }
@@ -180,6 +208,14 @@ public class SlidingPaneLayout extends ViewGroup {
     }
 
     /**
+     * Set the panel slide listener.
+     * @param l the PanelSlideListener
+     */
+    public void setPanelSlideListener(PanelSlideListener l) {
+        mPanelSlideListener = l;
+    }
+
+    /**
      * Set the color used to fade the pane covered by the sliding pane out when the pane
      * will become fully covered in the closed state.
      *
@@ -851,16 +887,27 @@ public class SlidingPaneLayout extends ViewGroup {
         public void onViewDragStateChanged(int state) {
             if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
                 if (mSlideOffset == 0) {
-                    if (mState != STATE_CLOSED)
+                    if (mState != STATE_CLOSED) {
                         mState = STATE_CLOSED;
+                        if (mPanelSlideListener != null)
+                            mPanelSlideListener.onPanelClosed();
+                    }
                 } else if (mSlideOffset == 1 - (float)mOverhangSize/mSlideRange) {
                     if (mState != STATE_OPENED) {
                         mState = STATE_OPENED;
+                        if (mPanelSlideListener != null)
+                            mPanelSlideListener.onPanelOpened();
+                    }
+                } else if (mSlideOffset == 1) {
+                    if (mState != STATE_OPENED_ENTIRELY) {
+                        mState = STATE_OPENED_ENTIRELY;
+                        if (mPanelSlideListener != null)
+                            mPanelSlideListener.onPanelOpenedEntirely();
                     }
-                } else if (mState != STATE_OPENED_ENTIRELY) {
-                    mState = STATE_OPENED_ENTIRELY;
                 }
             }
+            else if (mPanelSlideListener != null)
+                    mPanelSlideListener.onPanelSlide((float)mSlideOffset / mSlideRange);
         }
 
         @Override



More information about the Android mailing list