Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supports umanoPanelHeightOffset #632

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ or `?attr/actionBarSize` to support older API versions.

* If you are using a custom `umanoDragView`, the panel will pass through the click events to the main layout. Make your second layout `clickable` to prevent this.
* You can change the panel height by using the `setPanelHeight` method or `umanoPanelHeight` attribute.
* You can change the panel height relative to container height by using the `setPanelHeightOffset` method or `umanoPanelHeightOffset` attribute.
* If you would like to hide the shadow above the sliding panel, set `shadowHeight` attribute to 0.
* Use `setEnabled(false)` to completely disable the sliding panel (including touch and programmatic sliding)
* Use `setTouchEnabled(false)` to disables panel's touch responsiveness (drag and click), you can still control the panel programatically
Expand Down
1 change: 1 addition & 0 deletions library/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<declare-styleable name="SlidingUpPanelLayout">
<attr name="umanoPanelHeight" format="dimension" />
<attr name="umanoPanelHeightOffset" format="dimension" />
<attr name="umanoShadowHeight" format="dimension" />
<attr name="umanoParallaxOffset" format="dimension" />
<attr name="umanoFadeColor" format="color" />
Expand Down
58 changes: 51 additions & 7 deletions library/src/com/sothree/slidinguppanel/SlidingUpPanelLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public class SlidingUpPanelLayout extends ViewGroup {
*/
private int mPanelHeight = -1;

/**
* The size offset of the overhang relative to height in pixels.
*/
private int mPanelHeightOffset = -1;

/**
* The size of the shadow in pixels.
*/
Expand Down Expand Up @@ -320,6 +325,7 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {

if (ta != null) {
mPanelHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoPanelHeight, -1);
mPanelHeightOffset = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoPanelHeightOffset, -1);
mShadowHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoShadowHeight, -1);
mParallaxOffset = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoParallaxOffset, -1);

Expand Down Expand Up @@ -440,6 +446,30 @@ public void setPanelHeight(int val) {
}

mPanelHeight = val;
mPanelHeightOffset = -1;
if (!mFirstLayout) {
requestLayout();
}

if (getPanelState() == PanelState.COLLAPSED) {
smoothToBottom();
invalidate();
return;
}
}

/**
* Set the collapsed panel height offset in pixels
*
* @param val A height offset in pixels
*/
public void setPanelHeightOffset(int val) {
if (getPanelHeightOffset() == val) {
return;
}

mPanelHeightOffset = val;
mPanelHeight = -1;
if (!mFirstLayout) {
requestLayout();
}
Expand Down Expand Up @@ -481,6 +511,13 @@ public int getPanelHeight() {
return mPanelHeight;
}

/**
* @return The current collapsed panel height offset
*/
public int getPanelHeightOffset() {
return mPanelHeightOffset;
}

/**
* @return The current parallax offset
*/
Expand Down Expand Up @@ -783,7 +820,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = layoutWidth;
if (child == mMainView) {
if (!mOverlayContent && mSlideState != PanelState.HIDDEN) {
height -= mPanelHeight;
height -= calculatePanelHeight(heightSize);
}

width -= lp.leftMargin + lp.rightMargin;
Expand Down Expand Up @@ -818,7 +855,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
child.measure(childWidthSpec, childHeightSpec);

if (child == mSlideableView) {
mSlideRange = mSlideableView.getMeasuredHeight() - mPanelHeight;
mSlideRange = mSlideableView.getMeasuredHeight() - calculatePanelHeight(heightSize);
}
}

Expand All @@ -841,7 +878,8 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
mSlideOffset = mAnchorPoint;
break;
case HIDDEN:
int newTop = computePanelTopPosition(0.0f) + (mIsSlidingUp ? +mPanelHeight : -mPanelHeight);
final int panelHeight = calculatePanelHeight(getMeasuredHeight());
int newTop = computePanelTopPosition(0.0f) + (mIsSlidingUp ? +panelHeight : -panelHeight);
mSlideOffset = computeSlideOffset(newTop);
break;
default:
Expand Down Expand Up @@ -1055,8 +1093,8 @@ private int computePanelTopPosition(float slideOffset) {
int slidePixelOffset = (int) (slideOffset * mSlideRange);
// Compute the top of the panel if its collapsed
return mIsSlidingUp
? getMeasuredHeight() - getPaddingBottom() - mPanelHeight - slidePixelOffset
: getPaddingTop() - slidingViewHeight + mPanelHeight + slidePixelOffset;
? getMeasuredHeight() - getPaddingBottom() - calculatePanelHeight(getMeasuredHeight()) - slidePixelOffset
: getPaddingTop() - slidingViewHeight + calculatePanelHeight(getMeasuredHeight()) + slidePixelOffset;
}

/*
Expand Down Expand Up @@ -1114,7 +1152,8 @@ public void setPanelState(PanelState state) {
smoothSlideTo(1.0f, 0);
break;
case HIDDEN:
int newTop = computePanelTopPosition(0.0f) + (mIsSlidingUp ? +mPanelHeight : -mPanelHeight);
final int panelHeight = calculatePanelHeight(getHeight());
int newTop = computePanelTopPosition(0.0f) + (mIsSlidingUp ? +panelHeight : -panelHeight);
smoothSlideTo(computeSlideOffset(newTop), 0);
break;
}
Expand Down Expand Up @@ -1147,7 +1186,7 @@ private void onPanelDragged(int newTop) {
// If the slide offset is negative, and overlay is not on, we need to increase the
// height of the main content
LayoutParams lp = (LayoutParams) mMainView.getLayoutParams();
int defaultHeight = getHeight() - getPaddingBottom() - getPaddingTop() - mPanelHeight;
int defaultHeight = getHeight() - getPaddingBottom() - getPaddingTop() - calculatePanelHeight(getHeight());

if (mSlideOffset <= 0 && !mOverlayContent) {
// expand the main view
Expand Down Expand Up @@ -1329,6 +1368,11 @@ public void onRestoreInstanceState(Parcelable state) {
mSlideState = ss.mSlideState != null ? ss.mSlideState : DEFAULT_SLIDE_STATE;
}

private int calculatePanelHeight(int heightSize) {
if (mPanelHeightOffset != -1) return heightSize - mPanelHeightOffset;
return mPanelHeight;
}

private class DragHelperCallback extends ViewDragHelper.Callback {

@Override
Expand Down