Skip to content

Multiple Drag views are now allowed to set for Sliding panel. #605

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
83 changes: 57 additions & 26 deletions library/src/com/sothree/slidinguppanel/SlidingUpPanelLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import com.nineoldandroids.view.animation.AnimatorProxy;
import com.sothree.slidinguppanel.library.R;

import java.util.ArrayList;
import java.util.List;

public class SlidingUpPanelLayout extends ViewGroup {

private static final String TAG = SlidingUpPanelLayout.class.getSimpleName();
Expand Down Expand Up @@ -133,10 +136,11 @@ public class SlidingUpPanelLayout extends ViewGroup {
private boolean mClipPanel = DEFAULT_CLIP_PANEL_FLAG;

/**
* If provided, the panel can be dragged by only this view. Otherwise, the entire panel can be
* If provided, the panel can be dragged by only those views. Otherwise, the entire panel can be
* used for dragging.
*/
private View mDragView;
private List<View> mDragViews = new ArrayList<View>();


/**
* If provided, the panel can be dragged by only this view. Otherwise, the entire panel can be
Expand Down Expand Up @@ -535,31 +539,52 @@ public void setPanelSlideListener(PanelSlideListener listener) {
* @param dragView A view that will be used to drag the panel.
*/
public void setDragView(View dragView) {
if (mDragView != null) {
mDragView.setOnClickListener(null);
}
mDragView = dragView;
if (mDragView != null) {
mDragView.setClickable(true);
mDragView.setFocusable(false);
mDragView.setFocusableInTouchMode(false);
mDragView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!isEnabled() || !isTouchEnabled()) return;
if (mSlideState != PanelState.EXPANDED && mSlideState != PanelState.ANCHORED) {
if (mAnchorPoint < 1.0f) {
setPanelState(PanelState.ANCHORED);
} else {
setPanelState(PanelState.EXPANDED);
}
clearDragViews();

if (dragView != null) {
setupViewForDragView(dragView);
mDragViews.add(dragView);
}
}

public void setDragViews(List<View> views) {
clearDragViews();

for (View dragView : views) {
setupViewForDragView(dragView);
mDragViews.add(dragView);
}
}

private boolean hasAnyDragViews() {
return mDragViews.size() > 0;
}

private void clearDragViews(){
for (View oldDragView : mDragViews)
oldDragView.setOnClickListener(null);
mDragViews.clear();
}

private void setupViewForDragView(View dragView){
dragView.setClickable(true);
dragView.setFocusable(false);
dragView.setFocusableInTouchMode(false);
dragView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!isEnabled() || !isTouchEnabled()) return;
if (mSlideState != PanelState.EXPANDED && mSlideState != PanelState.ANCHORED) {
if (mAnchorPoint < 1.0f) {
setPanelState(PanelState.ANCHORED);
} else {
setPanelState(PanelState.COLLAPSED);
setPanelState(PanelState.EXPANDED);
}
} else {
setPanelState(PanelState.COLLAPSED);
}
});
;
}
}
});
}

/**
Expand Down Expand Up @@ -751,7 +776,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

mMainView = getChildAt(0);
mSlideableView = getChildAt(1);
if (mDragView == null) {
if (!hasAnyDragViews()) {
setDragView(mSlideableView);
}

Expand Down Expand Up @@ -910,7 +935,13 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
final float ady = Math.abs(y - mInitialMotionY);
final int dragSlop = mDragHelper.getTouchSlop();

if ((ady > dragSlop && adx > ady) || !isViewUnder(mDragView, (int) mInitialMotionX, (int) mInitialMotionY)) {
int dragViewsUnderCurrentViewCount = 0;

for (View dragView : mDragViews) {
dragViewsUnderCurrentViewCount += (isViewUnder(dragView, (int)mInitialMotionX, (int)mInitialMotionY)) ? 1 : 0;
}

if ((ady > dragSlop && adx > ady) || dragViewsUnderCurrentViewCount == 0) {
mDragHelper.cancel();
mIsUnableToDrag = true;
return false;
Expand Down