From 1157c9368ac98fd0972dab8c8c870f4a06120596 Mon Sep 17 00:00:00 2001 From: tokudu Date: Tue, 8 Jul 2014 09:56:13 -0700 Subject: [PATCH] Added support for expandPanel,collapsePanel,hidePanel and showPanel before first layout --- .../slidinguppanel/SlidingUpPanelLayout.java | 52 +++++++++++++++---- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/library/src/com/sothree/slidinguppanel/SlidingUpPanelLayout.java b/library/src/com/sothree/slidinguppanel/SlidingUpPanelLayout.java index daa008ce..a7d2670c 100644 --- a/library/src/com/sothree/slidinguppanel/SlidingUpPanelLayout.java +++ b/library/src/com/sothree/slidinguppanel/SlidingUpPanelLayout.java @@ -842,8 +842,14 @@ private float computeSlideOffset(int topPosition) { * @return true if the pane was slideable and is now collapsed/in the process of collapsing */ public boolean collapsePanel() { - if (mSlideState == SlideState.HIDDEN || mSlideState == SlideState.COLLAPSED) return false; - return collapsePanel(mSlideableView, 0); + if (mFirstLayout) { + mSlideState = SlideState.COLLAPSED; + return true; + } else { + if (mSlideState == SlideState.HIDDEN || mSlideState == SlideState.COLLAPSED) + return false; + return collapsePanel(mSlideableView, 0); + } } /** @@ -852,7 +858,12 @@ public boolean collapsePanel() { * @return true if the pane was slideable and is now expanded/in the process of expading */ public boolean expandPanel() { - return expandPanel(1.0f); + if (mFirstLayout) { + mSlideState = SlideState.EXPANDED; + return true; + } else { + return expandPanel(1.0f); + } } /** @@ -861,7 +872,12 @@ public boolean expandPanel() { * @return true if the pane was slideable and is now expanded/in the process of expading */ public boolean anchorPanel() { - return expandPanel(mAnchorPoint); + if (mFirstLayout) { + mSlideState = SlideState.ANCHORED; + return true; + } else { + return expandPanel(mAnchorPoint); + } } /** @@ -903,17 +919,31 @@ public boolean isPanelHidden() { return mSlideState == SlideState.HIDDEN; } + /** + * Shows the panel from the hidden state + */ public void showPanel() { - if (mSlideableView == null || mSlideState != SlideState.HIDDEN) return; - mSlideableView.setVisibility(View.VISIBLE); - requestLayout(); - smoothSlideTo(0, 0); + if (mFirstLayout) { + mSlideState = SlideState.COLLAPSED; + } else { + if (mSlideableView == null || mSlideState != SlideState.HIDDEN) return; + mSlideableView.setVisibility(View.VISIBLE); + requestLayout(); + smoothSlideTo(0, 0); + } } + /** + * Hides the sliding panel entirely. + */ public void hidePanel() { - if (mSlideState == SlideState.DRAGGING || mSlideState == SlideState.HIDDEN) return; - int newTop = computePanelTopPosition(0.0f) + (mIsSlidingUp ? +mPanelHeight : -mPanelHeight); - smoothSlideTo(computeSlideOffset(newTop), 0); + if (mFirstLayout) { + mSlideState = SlideState.HIDDEN; + } else { + if (mSlideState == SlideState.DRAGGING || mSlideState == SlideState.HIDDEN) return; + int newTop = computePanelTopPosition(0.0f) + (mIsSlidingUp ? +mPanelHeight : -mPanelHeight); + smoothSlideTo(computeSlideOffset(newTop), 0); + } } @SuppressLint("NewApi")