Permalink
Browse files

added scrollable container support with top padding http://android.am…

…berfog.com/?p=915 - for foursquare-like map animation
  • Loading branch information...
dlukashev committed May 19, 2014
1 parent 60e2e6f commit e7edb89af96a760423d5d00342ad237d78b75b85
Showing with 30 additions and 10 deletions.
  1. +30 −10 library/src/com/sothree/slidinguppanel/SlidingUpPanelLayout.java
@@ -23,8 +23,8 @@
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import com.nineoldandroids.view.animation.AnimatorProxy;
import com.sothree.slidinguppanel.library.R;
import com.nineoldandroids.view.animation.AnimatorProxy;
public class SlidingUpPanelLayout extends ViewGroup {
@@ -137,6 +137,15 @@
*/
private View mMainView;
/**
* Scrollable container
*/
private ViewGroup mScrollableView;
/**
*
*/
private int mScrollableViewTopPadding;
/**
* Current state of the slideable view.
*/
@@ -255,14 +264,14 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs) {
public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if(isInEditMode()) {
mShadowDrawable = null;
mScrollTouchSlop = 0;
mDragHelper = null;
return;
}
if (attrs != null) {
TypedArray defAttrs = context.obtainStyledAttributes(attrs, DEFAULT_ATTRS);
@@ -629,17 +638,15 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int childHeight = child.getMeasuredHeight();
if (lp.slideable) {
mSlideRange = childHeight - mPanelHeight;
mSlideRange = childHeight - (mPanelHeight + mScrollableViewTopPadding);
}
int childTop;
if (mIsSlidingUp) {
childTop = lp.slideable ? slidingTop + (int) (mSlideRange * mSlideOffset) : paddingTop;
} else {
childTop = lp.slideable ? slidingTop - (int) (mSlideRange * mSlideOffset) : paddingTop;
if (!lp.slideable && !mOverlayContent) {
childTop += mPanelHeight;
}
}
final int childBottom = childTop + childHeight;
final int childLeft = paddingLeft;
@@ -720,7 +727,11 @@ else if (ady > mScrollTouchSlop) {
}
}
if ((ady > dragSlop && adx > ady) || !isDragViewUnder((int) x, (int) y)) {
// check if scroll down or scroll up and ListView is in top position
boolean isCanScrollUp = mSlideOffset == 0 && (y < mInitialMotionY ||
(mScrollableView != null && mScrollableView.getChildAt(0) != null &&
mScrollableView.getChildAt(0).getTop() != 0));
if (isCanScrollUp || (ady > dragSlop && adx > ady) || !isDragViewUnder((int) x, (int) y)) {
mDragHelper.cancel();
mIsUnableToDrag = true;
return false;
@@ -751,7 +762,7 @@ public boolean onTouchEvent(MotionEvent ev) {
final float y = ev.getY();
mInitialMotionX = x;
mInitialMotionY = y;
break;
return isDragViewUnder((int) x, (int) y);
}
case MotionEvent.ACTION_UP: {
@@ -788,7 +799,7 @@ private boolean isDragViewUnder(int x, int y) {
int screenX = parentLocation[0] + x;
int screenY = parentLocation[1] + y;
return screenX >= viewLocation[0] && screenX < viewLocation[0] + dragView.getWidth() &&
screenY >= viewLocation[1] && screenY < viewLocation[1] + dragView.getHeight();
(screenY >= viewLocation[1] + mScrollableViewTopPadding) && screenY < viewLocation[1] + dragView.getHeight();
}
private boolean expandPane(View pane, int initialVelocity, float mSlideOffset) {
@@ -914,6 +925,9 @@ private void onPanelDragged(int newTop) {
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
if (mScrollableView != null) {
return super.drawChild(canvas, child, drawingTime);
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
boolean result;
final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);
@@ -1268,4 +1282,10 @@ public SavedState createFromParcel(Parcel in) {
}
};
}
public void setScrollableView(ViewGroup scrollableView, int topPadding) {
mScrollableView = scrollableView;
mScrollableViewTopPadding = topPadding;
mSlideState = SlideState.EXPANDED;
}
}

0 comments on commit e7edb89

Please sign in to comment.