类android.support.v4.widget.ViewDragHelper源码实例Demo

下面列出了怎么用android.support.v4.widget.ViewDragHelper的API类实例代码及写法,或者点击链接到github查看源代码。

@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);
}
 
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);
}
 
@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);
    }
}
 
源代码4 项目: Slide   文件: NewsActivity.java
/**
 * 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");
    }
}
 
源代码5 项目: ToolbarPanel   文件: ToolbarPanelLayout.java
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);
}
 
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);
}
 
源代码7 项目: AntennaPodSP   文件: SlidingUpPanelLayout.java
@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;
        }
    }
}
 
源代码8 项目: AutoLoadListView   文件: ZSwipeItem.java
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();
}
 
源代码9 项目: AccountBook   文件: SlideFrameLayout.java
/**
 * 构造方法
 */
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));
}
 
源代码10 项目: PullToDismissPager   文件: PullToDismissPager.java
@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);
        }
    }
}
 
源代码11 项目: ZListVIew   文件: ZSwipeItem.java
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();
}
 
源代码12 项目: SwipeRevealLayout   文件: SwipeRevealLayout.java
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);
}
 
源代码13 项目: something.apk   文件: MarginDrawerLayout.java
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);
}
 
源代码14 项目: BlackLight   文件: SlidingUpPanelLayout.java
@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;
        }
    }
}
 
源代码15 项目: AndroidProjects   文件: SwipeBackLayout.java
@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;
        }
    }
}
 
源代码16 项目: Hify   文件: SwipeItem.java
public SwipeItem(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    // scroll threshold
    ViewConfiguration vc = ViewConfiguration.get(this.getContext());
    mTouchSlop = vc.getScaledTouchSlop();

    mDragHelper = ViewDragHelper.create(this, new DragHelperCallback());
}
 
源代码17 项目: ResideLayout   文件: ResideLayout.java
public ResideLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final float density = context.getResources().getDisplayMetrics().density;
    mOverhangSize = (int) (DEFAULT_OVERHANG_SIZE * density + 0.5f);

    setWillNotDraw(false);

    mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback());
    mDragHelper.setMinVelocity(MIN_FLING_VELOCITY * density);
}
 
源代码18 项目: OmniList   文件: SlidingUpPanelLayout.java
@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);
        } else if (mSlideState != SlideState.ANCHORED) {
            updateObscuredViewVisibility();
            mSlideState = SlideState.ANCHORED;
            dispatchOnPanelAnchored(mSlideableView);
        }
    }
}
 
源代码19 项目: Klyph   文件: KlyphDrawerLayout.java
/**
 * 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 absGrav = GravityCompat.getAbsoluteGravity(edgeGravity,
            ViewCompat.getLayoutDirection(this));
    if (absGrav == Gravity.LEFT) {
        mLockModeLeft = lockMode;
    } else if (absGrav == Gravity.RIGHT) {
        mLockModeRight = lockMode;
    }
    if (lockMode != LOCK_MODE_UNLOCKED) {
        // Cancel interaction in progress
        final ViewDragHelper helper = absGrav == Gravity.LEFT ? mLeftDragger : mRightDragger;
        helper.cancel();
    }
    switch (lockMode) {
        case LOCK_MODE_LOCKED_OPEN:
            final View toOpen = findDrawerWithGravity(absGrav);
            if (toOpen != null) {
                openDrawer(toOpen);
            }
            break;
        case LOCK_MODE_LOCKED_CLOSED:
            final View toClose = findDrawerWithGravity(absGrav);
            if (toClose != null) {
                closeDrawer(toClose);
            }
            break;
        // default: do nothing
    }
}
 
源代码20 项目: SwipeRevealLayout   文件: SwipeRevealLayout.java
@Override
public void onViewDragStateChanged(int state) {
    super.onViewDragStateChanged(state);
    final int prevState = mState;

    switch (state) {
        case ViewDragHelper.STATE_DRAGGING:
            mState = STATE_DRAGGING;
            break;

        case ViewDragHelper.STATE_IDLE:

            // drag edge is left or right
            if (mDragEdge == DRAG_EDGE_LEFT || mDragEdge == DRAG_EDGE_RIGHT) {
                if (mMainView.getLeft() == mRectMainClose.left) {
                    mState = STATE_CLOSE;
                } else {
                    mState = STATE_OPEN;
                }
            }

            // drag edge is top or bottom
            else {
                if (mMainView.getTop() == mRectMainClose.top) {
                    mState = STATE_CLOSE;
                } else {
                    mState = STATE_OPEN;
                }
            }
            break;
    }

    if (mDragStateChangeListener != null && !mAborted && prevState != mState) {
        mDragStateChangeListener.onDragStateChanged(mState);
    }
}
 
源代码21 项目: FriendBook   文件: BaseActivity.java
protected void onSlideStateChanged(int state) {
    if(getWindowIsTranslucent()){
        return;
    }
    if (state == ViewDragHelper.STATE_DRAGGING) {
        Drawable windowBackground = getWindowBackground();
        if (windowBackground != null) {
            getWindow().setBackgroundDrawable(windowBackground);
        } else {
            getWindow().setBackgroundDrawable(getDefaultWindowBackground());
        }
    }
}
 
@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
    if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) {
        ViewCompat.setFitsSystemWindows(child, true);
    }
    int savedTop = child.getTop();
    // First let the parent lay it out
    parent.onLayoutChild(child, layoutDirection);
    // Offset the bottom sheet
    mParentHeight = parent.getHeight();
    int peekHeight;
    if (mPeekHeightAuto) {
        if (mPeekHeightMin == 0) {
            mPeekHeightMin = parent.getResources().getDimensionPixelSize(
                    R.dimen.design_bottom_sheet_peek_height_min);
        }
        peekHeight = Math.max(mPeekHeightMin, mParentHeight - parent.getWidth() * 9 / 16);
    } else {
        peekHeight = mPeekHeight;
    }
    mMinOffset = Math.max(0, mParentHeight - child.getHeight());
    mMaxOffset = Math.max(mParentHeight - peekHeight, mMinOffset);
    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);
    } else if (mState == STATE_DRAGGING || mState == STATE_SETTLING) {
        ViewCompat.offsetTopAndBottom(child, savedTop - child.getTop());
    }
    if (mViewDragHelper == null) {
        mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
    }
    mViewRef = new WeakReference<>(child);
    mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
    return true;
}
 
源代码23 项目: Sky31Radio   文件: SlidingUpPanelLayout.java
@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);
        } else if (mSlideState != SlideState.ANCHORED) {
            updateObscuredViewVisibility();
            mSlideState = SlideState.ANCHORED;
            dispatchOnPanelAnchored(mSlideableView);
        }
    }
}
 
源代码24 项目: SlideActivity   文件: SlideLayout.java
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    if (widthMode != MeasureSpec.EXACTLY) {
        throw new IllegalStateException("Width must have an exact value or MATCH_PARENT");
    }

    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    if (heightMode != MeasureSpec.EXACTLY) {
        throw new IllegalStateException("Width must have an exact value or MATCH_PARENT");
    }

    final int childCount = getChildCount();

    // We'll find the current one below.
    mSlideableView = null;

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        int childWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
        int childHeightSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);

        child.measure(childWidthSpec, childHeightSpec);
        lp.slideable = true;
        mSlideableView = child;
    }

    setMeasuredDimension(widthSize, heightSize);
    mCanSlide = true;

    if (mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE) {
        // Cancel scrolling in progress, it's no longer relevant.
        mDragHelper.abort();
    }
}
 
public TranslucentDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
    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.setImportantForAccessibility(this,
            ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);

    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
    ViewGroupCompat.setMotionEventSplittingEnabled(this, false);
    if (ViewCompat.getFitsSystemWindows(this)) {
        IMPL.configureApplyInsets(this);
        mStatusBarBackground = IMPL.getDefaultStatusBarBackground(context);
    }

    mDrawerElevation = DRAWER_ELEVATION * density;

    mNonDrawerViews = new ArrayList<View>();
}
 
源代码26 项目: SwipeBack   文件: SwipeBackLayout.java
@Override
public void onViewDragStateChanged(int state) {
    if (state == draggingState) return;

    if ((draggingState == ViewDragHelper.STATE_DRAGGING || draggingState == ViewDragHelper.STATE_SETTLING) &&
            state == ViewDragHelper.STATE_IDLE) {
        // the view stopped from moving.
        if (draggingOffset == getDragRange()) {
            onFinishListener.onFinishState();
        }
    }

    draggingState = state;
}
 
源代码27 项目: DrawerBehavior   文件: BehaviorDelegate.java
boolean onInterceptTouchEvent(MotionEvent ev) {
  boolean interceptForDrag = dragger.shouldInterceptTouchEvent(ev);
  boolean interceptForTap = false;
  switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN: {
      float x = ev.getX();
      float y = ev.getY();
      initialMotionX = x;
      initialMotionY = y;
      if (onScreen > 0) {
        View child = dragger.findTopChildUnder((int) x, (int) y);
        if (child != null && isContentView(child)) {
          interceptForTap = true;
        }
      }
      childrenCanceledTouch = false;
      break;
    }

    case MotionEvent.ACTION_MOVE: {
      // If we cross the touch slop, don't perform the delayed peek for an edge touch.
      if (dragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) {
        removeCallbacks();
      }
      break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
      closeDrawers(true);
      childrenCanceledTouch = false;
      break;
    }
  }

  return interceptForDrag || interceptForTap || isPeeking || childrenCanceledTouch;
}
 
源代码28 项目: o2oa   文件: SwipeLayoutConv.java
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];
}
 
源代码29 项目: paper-launcher   文件: BottomSheetBehaviorV2.java
private void reset() {
    mActivePointerId = ViewDragHelper.INVALID_POINTER;
    if (mVelocityTracker != null) {
        mVelocityTracker.recycle();
        mVelocityTracker = null;
    }
}
 
源代码30 项目: TestChat   文件: DragLayout.java
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());
        }