android.support.v4.widget.ViewDragHelper Java Examples

The following examples show how to use android.support.v4.widget.ViewDragHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ToolbarPanelLayout.java    From ToolbarPanel with MIT License 6 votes vote down vote up
public ToolbarPanelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
            R.styleable.ToolbarPanelLayout, 0, 0);

    try {
        toolbarId = a.getResourceId(R.styleable.ToolbarPanelLayout_pullableToolbarId, -1);
        panelId = a.getResourceId(R.styleable.ToolbarPanelLayout_panelId, -1);
    } finally {
        a.recycle();
    }

    if (toolbarId == -1 && panelId == -1) {
        throw new IllegalStateException("Need to specify toolbarId and panelId");
    }

    Resources resources = getResources();

    final float density = resources.getDisplayMetrics().density;
    shadowDrawable = resources.getDrawable(R.drawable.drop_shadow);
    setWillNotDraw(false);

    dragHelper = ViewDragHelper.create(this, 1.2f, new DragHelperCallback());
    dragHelper.setMinVelocity(MIN_FLING_VELOCITY * density);
}
 
Example #2
Source File: SwipeRevealLayout.java    From SwipeRevealLayoutExample with MIT License 6 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (isDragLocked()) {
        return super.onInterceptTouchEvent(ev);
    }

    mDragHelper.processTouchEvent(ev);
    mGestureDetector.onTouchEvent(ev);
    accumulateDragDist(ev);

    boolean couldBecomeClick = couldBecomeClick(ev);
    boolean settling = mDragHelper.getViewDragState() == ViewDragHelper.STATE_SETTLING;
    boolean idleAfterScrolled = mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE
            && mIsScrolling;

    // must be placed as the last statement
    mPrevX = ev.getX();

    // return true => intercept, cannot trigger onClick event
    return !couldBecomeClick && (settling || idleAfterScrolled);
}
 
Example #3
Source File: ZSwipeItem.java    From AutoLoadListView with Apache License 2.0 6 votes vote down vote up
public ZSwipeItem(Context context, AttributeSet attrs, int defStyle) {
	super(context, attrs, defStyle);

	mDragHelper = ViewDragHelper.create(this, mDragHelperCallback);

	TypedArray a = context.obtainStyledAttributes(attrs,
			R.styleable.ZSwipeItem);
	// 默认是右边缘检测
	int ordinal = a.getInt(R.styleable.ZSwipeItem_drag_edge,
			DragEdge.Right.ordinal());
	mDragEdge = DragEdge.values()[ordinal];
	// 默认模式是拉出
	ordinal = a.getInt(R.styleable.ZSwipeItem_show_mode,
			ShowMode.PullOut.ordinal());
	mShowMode = ShowMode.values()[ordinal];

	mHorizontalSwipeOffset = a.getDimension(
			R.styleable.ZSwipeItem_horizontalSwipeOffset, 0);
	mVerticalSwipeOffset = a.getDimension(
			R.styleable.ZSwipeItem_verticalSwipeOffset, 0);

	a.recycle();
}
 
Example #4
Source File: PullToDismissPager.java    From PullToDismissPager with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewDragStateChanged(int state) {
    if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
        mSlideOffset = computeSlideOffset(mSlideableView.getTop());

        if (mSlideOffset == 1) {
            if (mSlideState != SlideState.EXPANDED) {
                updateObscuredViewVisibility();
                mSlideState = SlideState.EXPANDED;
                dispatchOnPanelExpanded(mSlideableView);
            }
        } else if (mSlideOffset == 0) {
            if (mSlideState != SlideState.COLLAPSED) {
                mSlideState = SlideState.COLLAPSED;
                dispatchOnPanelCollapsed(mSlideableView);
            }
        } else if (mSlideOffset < 0) {
            mSlideState = SlideState.HIDDEN;
            mSlideableView.setVisibility(View.GONE);
            dispatchOnPanelHidden(mSlideableView);
        }
    }
}
 
Example #5
Source File: ZSwipeItem.java    From ZListVIew with Apache License 2.0 6 votes vote down vote up
public ZSwipeItem(Context context, AttributeSet attrs, int defStyle) {
	super(context, attrs, defStyle);

	mDragHelper = ViewDragHelper.create(this, mDragHelperCallback);

	TypedArray a = context.obtainStyledAttributes(attrs,
			R.styleable.ZSwipeItem);
	// 默认是右边缘检测
	int ordinal = a.getInt(R.styleable.ZSwipeItem_drag_edge,
			DragEdge.Right.ordinal());
	mDragEdge = DragEdge.values()[ordinal];
	// 默认模式是拉出
	ordinal = a.getInt(R.styleable.ZSwipeItem_show_mode,
			ShowMode.PullOut.ordinal());
	mShowMode = ShowMode.values()[ordinal];

	mHorizontalSwipeOffset = a.getDimension(
			R.styleable.ZSwipeItem_horizontalSwipeOffset, 0);
	mVerticalSwipeOffset = a.getDimension(
			R.styleable.ZSwipeItem_verticalSwipeOffset, 0);

	a.recycle();
}
 
Example #6
Source File: SwipeRevealLayout.java    From SwipeRevealLayout with MIT License 6 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    if (attrs != null && context != null) {
        TypedArray a = context.getTheme().obtainStyledAttributes(
                attrs,
                R.styleable.SwipeRevealLayout,
                0, 0
        );

        mDragEdge = a.getInteger(R.styleable.SwipeRevealLayout_dragEdge, DRAG_EDGE_LEFT);
        mMinFlingVelocity = a.getInteger(R.styleable.SwipeRevealLayout_flingVelocity, DEFAULT_MIN_FLING_VELOCITY);
        mMode = a.getInteger(R.styleable.SwipeRevealLayout_mode, MODE_NORMAL);

        mMinDistRequestDisallowParent = a.getDimensionPixelSize(
                R.styleable.SwipeRevealLayout_minDistRequestDisallowParent,
                dpToPx(DEFAULT_MIN_DIST_REQUEST_DISALLOW_PARENT)
        );
    }

    mDragHelper = ViewDragHelper.create(this, 1.0f, mDragHelperCallback);
    mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_ALL);

    mGestureDetector = new GestureDetectorCompat(context, mGestureListener);
}
 
Example #7
Source File: SlideFrameLayout.java    From AccountBook with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 构造方法
 */
public SlideFrameLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setWillNotDraw(false);
    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);

    mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback());
    mDragHelper.setMinVelocity(dip2px(MIN_FLING_VELOCITY));
    setEdgeSize(dip2px(20));

    mPreviousSnapshotView = new PreviewView(context);
    addView(mPreviousSnapshotView, new LayoutParams(
        ViewGroup.LayoutParams.MATCH_PARENT,
        ViewGroup.LayoutParams.MATCH_PARENT));
}
 
Example #8
Source File: SwipeRevealLayout.java    From SwipeRevealLayoutExample with MIT License 6 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    if (attrs != null && context != null) {
        TypedArray a = context.getTheme().obtainStyledAttributes(
                attrs,
                R.styleable.SwipeRevealLayout,
                0, 0
        );

        mDragEdge = a.getInteger(R.styleable.SwipeRevealLayout_dragFromEdge, DRAG_EDGE_LEFT);
        mMode = MODE_NORMAL;
        mMinFlingVelocity = DEFAULT_MIN_FLING_VELOCITY;
        mMinDistRequestDisallowParent = DEFAULT_MIN_DIST_REQUEST_DISALLOW_PARENT;
    }

    mDragHelper = ViewDragHelper.create(this, 1.0f, mDragHelperCallback);
    mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_ALL);

    mGestureDetector = new GestureDetectorCompat(context, mGestureListener);
}
 
Example #9
Source File: SwipeRevealLayout.java    From SwipeRevealLayoutExample with MIT License 6 votes vote down vote up
@Override
public void onEdgeDragStarted(int edgeFlags, int pointerId) {
    super.onEdgeDragStarted(edgeFlags, pointerId);

    if (mLockDrag) {
        return;
    }

    boolean edgeStartLeft = (mDragEdge == DRAG_EDGE_RIGHT)
            && edgeFlags == ViewDragHelper.EDGE_LEFT;

    boolean edgeStartRight = (mDragEdge == DRAG_EDGE_LEFT)
            && edgeFlags == ViewDragHelper.EDGE_RIGHT;

    if (edgeStartLeft || edgeStartRight) {
        mDragHelper.captureChildView(mMainView, pointerId);
    }
}
 
Example #10
Source File: SlidingUpPanelLayout.java    From BlackLight with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onViewDragStateChanged(int state) {
    int anchoredTop = (int)(mAnchorPoint*mSlideRange);

    if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
        if (mSlideOffset == 0) {
            if (mSlideState != SlideState.EXPANDED) {
                updateObscuredViewVisibility();
                dispatchOnPanelExpanded(mSlideableView);
                mSlideState = SlideState.EXPANDED;
            }
        } else if (mSlideOffset == (float)anchoredTop/(float)mSlideRange) {
            if (mSlideState != SlideState.ANCHORED) {
                updateObscuredViewVisibility();
                dispatchOnPanelAnchored(mSlideableView);
                mSlideState = SlideState.ANCHORED;
            }
        } else if (mSlideState != SlideState.COLLAPSED) {
            dispatchOnPanelCollapsed(mSlideableView);
            mSlideState = SlideState.COLLAPSED;
        }
    }
}
 
Example #11
Source File: NewsActivity.java    From Slide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set the drawer edge (i.e. how sensitive the drawer is) Based on a given screen width
 * percentage.
 *
 * @param displayWidthPercentage larger the value, the more sensitive the drawer swipe is;
 *                               percentage of screen width
 * @param drawerLayout           drawerLayout to adjust the swipe edge
 */
public static void setDrawerEdge(Activity activity, final float displayWidthPercentage,
        DrawerLayout drawerLayout) {
    try {
        Field mDragger =
                drawerLayout.getClass().getSuperclass().getDeclaredField("mLeftDragger");
        mDragger.setAccessible(true);

        ViewDragHelper leftDragger = (ViewDragHelper) mDragger.get(drawerLayout);
        Field mEdgeSize = leftDragger.getClass().getDeclaredField("mEdgeSize");
        mEdgeSize.setAccessible(true);
        final int currentEdgeSize = mEdgeSize.getInt(leftDragger);

        Point displaySize = new Point();
        activity.getWindowManager().getDefaultDisplay().getSize(displaySize);
        mEdgeSize.setInt(leftDragger,
                Math.max(currentEdgeSize, (int) (displaySize.x * displayWidthPercentage)));
    } catch (Exception e) {
        LogUtil.e(e + ": Exception thrown while changing navdrawer edge size");
    }
}
 
Example #12
Source File: SlidingUpPanelLayout.java    From AntennaPodSP with MIT License 6 votes vote down vote up
@Override
public void onViewDragStateChanged(int state) {
    int anchoredTop = (int)(mAnchorPoint*mSlideRange);

    if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
        if (mSlideOffset == 0) {
            if (mSlideState != SlideState.EXPANDED) {
                updateObscuredViewVisibility();
                dispatchOnPanelExpanded(mSlideableView);
                mSlideState = SlideState.EXPANDED;
            }
        } else if (mSlideOffset == (float)anchoredTop/(float)mSlideRange) {
            if (mSlideState != SlideState.ANCHORED) {
                updateObscuredViewVisibility();
                dispatchOnPanelAnchored(mSlideableView);
                mSlideState = SlideState.ANCHORED;
            }
        } else if (mSlideState != SlideState.COLLAPSED) {
            dispatchOnPanelCollapsed(mSlideableView);
            mSlideState = SlideState.COLLAPSED;
        }
    }
}
 
Example #13
Source File: SlidingUpPanelLayout.java    From SlidingUpPanelLayout with Apache License 2.0 6 votes vote down vote up
public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlidingUpPanelLayout, defStyle, 0);
    isSlidingEnabled = !a.getBoolean(R.styleable.SlidingUpPanelLayout_spl_disableSliding, false);
    mExpandThreshold = a.getFloat(R.styleable.SlidingUpPanelLayout_spl_expandThreshold, 0.0f);
    mCollapseThreshold = a.getFloat(R.styleable.SlidingUpPanelLayout_spl_collapseThreshold, 0.7f);
    a.recycle();

    if (isInEditMode()) {
        mDragHelper = null;
        return;
    }

    mDragHelper = ViewDragHelper.create(this, 1.0f, new DragHelperCallback());
    mDragHelper.setMinVelocity(DEFAULT_MIN_FLING_VELOCITY * getResources().getDisplayMetrics().density);
}
 
Example #14
Source File: MarginDrawerLayout.java    From something.apk with MIT License 6 votes vote down vote up
public MarginDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final float density = getResources().getDisplayMetrics().density;
    mMinDrawerMargin = (int) (MIN_DRAWER_MARGIN * density + 0.5f);
    final float minVel = MIN_FLING_VELOCITY * density;

    mLeftCallback = new ViewDragCallback(Gravity.LEFT);
    mRightCallback = new ViewDragCallback(Gravity.RIGHT);

    mLeftDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mLeftCallback);
    mLeftDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT);
    mLeftDragger.setMinVelocity(minVel);
    mLeftCallback.setDragger(mLeftDragger);

    mRightDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mRightCallback);
    mRightDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT);
    mRightDragger.setMinVelocity(minVel);
    mRightCallback.setDragger(mRightDragger);

    // So that we can catch the back button
    setFocusableInTouchMode(true);

    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
    ViewGroupCompat.setMotionEventSplittingEnabled(this, false);
}
 
Example #15
Source File: SlidingRootNavLayout.java    From SlidingRootNav with Apache License 2.0 5 votes vote down vote up
public SlidingRootNavLayout(Context context) {
    super(context);
    dragListeners = new ArrayList<>();
    dragStateListeners = new ArrayList<>();

    FLING_MIN_VELOCITY = ViewConfiguration.get(context).getScaledMinimumFlingVelocity();

    dragHelper = ViewDragHelper.create(this, new ViewDragCallback());

    dragProgress = 0f;
    isMenuHidden = true;
}
 
Example #16
Source File: SlideFrameLayout.java    From AccountBook with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewDragStateChanged(int state) {
    if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
        if (mSlideOffset == 0) {
            updateObscuredViewsVisibility(mSlideableView);
            mPreservedOpenState = false;
        } else {
            mPreservedOpenState = true;
        }
    }
}
 
Example #17
Source File: SwipeBackLayout.java    From AndroidProjects with MIT License 5 votes vote down vote up
@Override
public void onViewDragStateChanged(int state) {
    if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
        if (mSlideOffset == 0) {
            updateObscuredViewsVisibility(mSlideableView);
            dispatchOnPanelClosed(mSlideableView);
            mPreservedOpenState = false;
        } else {
            dispatchOnPanelOpened(mSlideableView);
            mPreservedOpenState = true;
        }
    }
}
 
Example #18
Source File: BottomSheetBehaviorGoogleMapsLike.java    From Nibo with MIT License 5 votes vote down vote up
@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
    // First let the parent lay it out
    if (mState != STATE_DRAGGING && mState != STATE_SETTLING) {
        if (ViewCompat.getFitsSystemWindows(parent) &&
                !ViewCompat.getFitsSystemWindows(child)) {
            ViewCompat.setFitsSystemWindows(child, true);
        }
        parent.onLayoutChild(child, layoutDirection);
    }
    // Offset the bottom sheet
    mParentHeight = parent.getHeight();
    mMinOffset = Math.max(0, mParentHeight - child.getHeight());
    mMaxOffset = Math.max(mParentHeight - mPeekHeight, mMinOffset);

    /**
     * New behavior
     */
    if (mState == STATE_ANCHOR_POINT) {
        ViewCompat.offsetTopAndBottom(child, mAnchorPoint);
    } else if (mState == STATE_EXPANDED) {
        ViewCompat.offsetTopAndBottom(child, mMinOffset);
    } else if (mHideable && mState == STATE_HIDDEN) {
        ViewCompat.offsetTopAndBottom(child, mParentHeight);
    } else if (mState == STATE_COLLAPSED) {
        ViewCompat.offsetTopAndBottom(child, mMaxOffset);
    }
    if (mViewDragHelper == null) {
        mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
    }
    mViewRef = new WeakReference<>(child);
    mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
    return true;
}
 
Example #19
Source File: SlidingRootNavLayout.java    From SlidingRootNav with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewDragStateChanged(int state) {
    if (dragState == ViewDragHelper.STATE_IDLE && state != ViewDragHelper.STATE_IDLE) {
        notifyDragStart();
    } else if (dragState != ViewDragHelper.STATE_IDLE && state == ViewDragHelper.STATE_IDLE) {
        isMenuHidden = calculateIsMenuHidden();
        notifyDragEnd(isMenuOpened());
    }
    dragState = state;
}
 
Example #20
Source File: SwipeLayoutConv.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public SwipeLayoutConv(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mDragHelper = ViewDragHelper.create(this, mDragHelperCallback);

    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.SwipeLayout);
    int ordinal = a.getInt(R.styleable.SwipeLayout_drag_edge,
            DragEdge.Right.ordinal());
    mDragEdge = DragEdge.values()[ordinal];
    ordinal = a.getInt(R.styleable.SwipeLayout_show_mode,
            ShowMode.PullOut.ordinal());
    mShowMode = ShowMode.values()[ordinal];
}
 
Example #21
Source File: SwipeBackLayout.java    From SwipeBackLibrary with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final boolean drawContent = child == mContentView;

    boolean ret = super.drawChild(canvas, child, drawingTime);
    if (mScrimOpacity > 0 && drawContent
            && mViewDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE) {
        if (mHasShadow) drawShadow(canvas, child);
        drawScrim(canvas, child);
    }
    return ret;
}
 
Example #22
Source File: MarginDrawerLayout.java    From something.apk with MIT License 5 votes vote down vote up
/**
 * Enable or disable interaction with the given drawer.
 *
 * <p>This allows the application to restrict the user's ability to open or close
 * the given drawer. DrawerLayout will still respond to calls to {@link #openDrawer(int)},
 * {@link #closeDrawer(int)} and friends if a drawer is locked.</p>
 *
 * <p>Locking a drawer open or closed will implicitly open or close
 * that drawer as appropriate.</p>
 *
 * @param lockMode The new lock mode for the given drawer. One of {@link #LOCK_MODE_UNLOCKED},
 *                 {@link #LOCK_MODE_LOCKED_CLOSED} or {@link #LOCK_MODE_LOCKED_OPEN}.
 * @param edgeGravity Gravity.LEFT, RIGHT, START or END.
 *                    Expresses which drawer to change the mode for.
 *
 * @see #LOCK_MODE_UNLOCKED
 * @see #LOCK_MODE_LOCKED_CLOSED
 * @see #LOCK_MODE_LOCKED_OPEN
 */
public void setDrawerLockMode(int lockMode, int edgeGravity) {
    final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity,
            ViewCompat.getLayoutDirection(this));
    if (absGravity == Gravity.LEFT) {
        mLockModeLeft = lockMode;
    } else if (absGravity == Gravity.RIGHT) {
        mLockModeRight = lockMode;
    }
    if (lockMode != LOCK_MODE_UNLOCKED) {
        // Cancel interaction in progress
        final ViewDragHelper helper = absGravity == Gravity.LEFT ? mLeftDragger : mRightDragger;
        helper.cancel();
    }
    switch (lockMode) {
        case LOCK_MODE_LOCKED_OPEN:
            final View toOpen = findDrawerWithGravity(absGravity);
            if (toOpen != null) {
                openDrawer(toOpen);
            }
            break;
        case LOCK_MODE_LOCKED_CLOSED:
            final View toClose = findDrawerWithGravity(absGravity);
            if (toClose != null) {
                closeDrawer(toClose);
            }
            break;
        // default: do nothing
    }
}
 
Example #23
Source File: DebugDrawerLayout.java    From u2020 with Apache License 2.0 5 votes vote down vote up
@Override
public void onEdgeDragStarted(int edgeFlags, int pointerId) {
  final View toCapture;
  if ((edgeFlags & ViewDragHelper.EDGE_LEFT) == ViewDragHelper.EDGE_LEFT) {
    toCapture = findDrawerWithGravity(Gravity.LEFT);
  } else {
    toCapture = findDrawerWithGravity(Gravity.RIGHT);
  }

  if (toCapture != null && getDrawerLockMode(toCapture) == LOCK_MODE_UNLOCKED) {
    mDragger.captureChildView(toCapture, pointerId);
  }
}
 
Example #24
Source File: DebugDrawerLayout.java    From debugdrawer with Apache License 2.0 5 votes vote down vote up
@Override
public void onEdgeDragStarted(int edgeFlags, int pointerId) {
	final View toCapture;
	if ((edgeFlags & ViewDragHelper.EDGE_LEFT) == ViewDragHelper.EDGE_LEFT) {
		toCapture = findDrawerWithGravity(Gravity.LEFT);
	} else {
		toCapture = findDrawerWithGravity(Gravity.RIGHT);
	}

	if (toCapture != null && getDrawerLockMode(toCapture) == LOCK_MODE_UNLOCKED) {
		mDragger.captureChildView(toCapture, pointerId);
	}
}
 
Example #25
Source File: KlyphDrawerLayout.java    From Klyph with MIT License 5 votes vote down vote up
@Override
public void onEdgeDragStarted(int edgeFlags, int pointerId) {
    final View toCapture;
    if ((edgeFlags & ViewDragHelper.EDGE_LEFT) == ViewDragHelper.EDGE_LEFT) {
        toCapture = findDrawerWithGravity(Gravity.LEFT);
    } else {
        toCapture = findDrawerWithGravity(Gravity.RIGHT);
    }

    if (toCapture != null && getDrawerLockMode(toCapture) == LOCK_MODE_UNLOCKED) {
        mDragger.captureChildView(toCapture, pointerId);
    }
}
 
Example #26
Source File: SlidingLayout.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewDragStateChanged(int state) {
    if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
        if (mSlideOffset == 0) {
            updateObscuredViewsVisibility(mSlideableView);
            dispatchOnPanelClosed(mSlideableView);
            mPreservedOpenState = false;
        } else {
            dispatchOnPanelOpened(mSlideableView);
            mPreservedOpenState = true;
        }
    }
}
 
Example #27
Source File: DragLayout.java    From TestChat with Apache License 2.0 5 votes vote down vote up
public DragLayout(Context context, AttributeSet attrs, int defStyleAttr) {
                super(context, attrs, defStyleAttr);
                mGestureDetector = new GestureDetector(context, new SimpleOnGestureListener() {
                        @Override
                        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
//                                如果水平方向的偏移量大于竖直方向的偏移量,就消化该事件,
                                return Math.abs(distanceX) > Math.abs(distanceY) || super.onScroll(e1, e2, distanceX, distanceY);

                        }
                });
//                永远要记得,该工具实现的拖拉是基于控件位置的改变来实现的
                mViewDragHelper = ViewDragHelper.create(this, new DragViewCallBack());
        }
 
Example #28
Source File: BottomSheetBehaviorV2.java    From paper-launcher with MIT License 5 votes vote down vote up
private void reset() {
    mActivePointerId = ViewDragHelper.INVALID_POINTER;
    if (mVelocityTracker != null) {
        mVelocityTracker.recycle();
        mVelocityTracker = null;
    }
}
 
Example #29
Source File: AnchorSheetBehavior.java    From AnchorSheetBehavior with Apache License 2.0 5 votes vote down vote up
private void reset() {
    mActivePointerId = ViewDragHelper.INVALID_POINTER;
    if (mVelocityTracker != null) {
        mVelocityTracker.recycle();
        mVelocityTracker = null;
    }
}
 
Example #30
Source File: SlidingUpPanelLayout.java    From SlidingUpPanelLayout with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewDragStateChanged(int state) {
    if (mDragHelper == null)
        return;

    if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
        mSlidedProgress = computeSlidedProgress(mSlidingUpPanel.getPanelView().getTop());

        if (mSlidedProgress == 1) {
            if (mSlidingUpPanel.getSlideState() != EXPANDED) {
                mSlidingUpPanel.setSlideState(EXPANDED);
                if (mPanelSlideListener != null) {
                    mPanelSlideListener.onPanelExpanded(mSlidingUpPanel);
                }
            }
        } else if (mSlidedProgress == 0) {
            if (mSlidingUpPanel.getSlideState() != COLLAPSED) {
                mSlidingUpPanel.setSlideState(COLLAPSED);
                if (mPanelSlideListener != null) {
                    mPanelSlideListener.onPanelCollapsed(mSlidingUpPanel);
                }
            }
        } else if (mSlidedProgress < 0) {
            mSlidingUpPanel.setSlideState(HIDDEN);
            if (mPanelSlideListener != null) {
                mPanelSlideListener.onPanelHidden(mSlidingUpPanel);
            }
        }
    }
}