[Android] Sliding pane: restore correctly the position of the pane after a screen rotation

Adrien Maglo git at videolan.org
Fri Jan 10 17:04:27 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Fri Jan 10 17:03:18 2014 +0100| [a163c25a6974b9e4a525387ab9d3b73409b7170c] | committer: Adrien Maglo

Sliding pane: restore correctly the position of the pane after a screen rotation

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

 .../org/videolan/vlc/widget/SlidingPaneLayout.java |   45 +++++++++++++++-----
 1 file changed, 34 insertions(+), 11 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/widget/SlidingPaneLayout.java b/vlc-android/src/org/videolan/vlc/widget/SlidingPaneLayout.java
index d128cb8..837b862 100644
--- a/vlc-android/src/org/videolan/vlc/widget/SlidingPaneLayout.java
+++ b/vlc-android/src/org/videolan/vlc/widget/SlidingPaneLayout.java
@@ -115,6 +115,7 @@ public class SlidingPaneLayout extends ViewGroup {
     public final int STATE_OPENED_ENTIRELY = 0;
     public final int STATE_OPENED = 1;
     public final int STATE_CLOSED = 2;
+    private int mState;
 
     private float mInitialMotionX;
     private float mInitialMotionY;
@@ -388,10 +389,6 @@ public class SlidingPaneLayout extends ViewGroup {
         int yStart = paddingTop;
         int nextYStart = yStart;
 
-        if (mFirstLayout) {
-            mSlideOffset = mCanSlide ? 1.f : 0.f;
-        }
-
         for (int i = 0; i < childCount; i++) {
             final View child = getChildAt(i);
 
@@ -412,6 +409,21 @@ public class SlidingPaneLayout extends ViewGroup {
                 final int margin = lp.topMargin + lp.bottomMargin;
                 final int range = Math.min(nextYStart, height - paddingBottom) - yStart - margin;
                 mSlideRange = range;
+
+                if (mFirstLayout) {
+                    switch (mState) {
+                    case STATE_CLOSED:
+                        mSlideOffset = mCanSlide ? 0.f : 1.f;
+                        break;
+                    case STATE_OPENED:
+                        mSlideOffset = mCanSlide ? 1 - (float)mOverhangSize / mSlideRange : 1.f;
+                        break;
+                    default: // STATE_OPENED_ENTIRELY
+                        mSlideOffset = 1.f;
+                        break;
+                    }
+                }
+
                 final int pos = (int) (range * mSlideOffset);
                 yStart += pos + lp.topMargin;
                 mSlideOffset = (float) pos / mSlideRange;
@@ -551,12 +563,7 @@ public class SlidingPaneLayout extends ViewGroup {
      */
     public int getState()
     {
-        if (mSlideOffset == 1.f)
-            return STATE_OPENED_ENTIRELY;
-        else if (mSlideOffset == 0.f)
-            return STATE_CLOSED;
-        else
-            return STATE_OPENED;
+        return mState;
     }
 
     /**
@@ -743,7 +750,7 @@ public class SlidingPaneLayout extends ViewGroup {
         Parcelable superState = super.onSaveInstanceState();
 
         SavedState ss = new SavedState(superState);
-        ss.state = getState();
+        ss.state = mState;
 
         return ss;
     }
@@ -784,6 +791,22 @@ public class SlidingPaneLayout extends ViewGroup {
         }
 
         @Override
+        public void onViewDragStateChanged(int state) {
+            if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
+                if (mSlideOffset == 0) {
+                    if (mState != STATE_CLOSED)
+                        mState = STATE_CLOSED;
+                } else if (mSlideOffset == 1 - (float)mOverhangSize/mSlideRange) {
+                    if (mState != STATE_OPENED) {
+                        mState = STATE_OPENED;
+                    }
+                } else if (mState != STATE_OPENED_ENTIRELY) {
+                    mState = STATE_OPENED_ENTIRELY;
+                }
+            }
+        }
+
+        @Override
         public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
             onPanelDragged(top);
             invalidate();



More information about the Android mailing list