List of usage examples for android.support.v4.view ViewCompat canScrollVertically
public static boolean canScrollVertically(View v, int direction)
From source file:com.hardsoftstudio.anchorbottomsheet.AnchorSheetBehavior.java
/** * Sets the state of the bottom sheet. The bottom sheet will transition to that state with * animation./*from w w w .j a v a 2 s . c o m*/ * * @param state One of {@link #STATE_COLLAPSED}, {@link #STATE_EXPANDED}, or * {@link #STATE_HIDDEN}. */ public final void setState(@State int state) { if (state == mState) { return; } if (mViewRef == null) { // The view is not laid out yet; modify mState and let onLayoutChild handle it later if (state == STATE_COLLAPSED || state == STATE_EXPANDED || state == STATE_ANCHOR || (mHideable && state == STATE_HIDDEN)) { mState = state; } return; } V child = mViewRef.get(); if (child == null) { return; } int top; if (state == STATE_COLLAPSED) { top = mMaxOffset; View scroll = mNestedScrollingChildRef.get(); if (scroll != null && ViewCompat.canScrollVertically(scroll, -1)) { scroll.scrollTo(0, 0); } } else if (state == STATE_EXPANDED) { top = mMinOffset; } else if (state == STATE_ANCHOR) { top = mAnchorOffset; } else if (mHideable && state == STATE_HIDDEN) { top = mParentHeight; } else { throw new IllegalArgumentException("Illegal state argument: " + state); } setStateInternal(STATE_SETTLING); if (mViewDragHelper.smoothSlideViewTo(child, child.getLeft(), top)) { ViewCompat.postOnAnimation(child, new SettleRunnable(child, state)); } }
From source file:com.hxqc.mall.core.views.CustomScrollView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { /*//from www.java2 s .co m * This method JUST determines whether we want to intercept the motion. * If we return true, onMotionEvent will be called and we do the actual * scrolling there. */ /* * Shortcut the most recurring case: the user is in the dragging * state and he is moving his finger. We want to intercept this * motion. */ final int action = ev.getAction(); if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) { DebugLog.d("CustomScrollView", "one" + ev.getX()); return true; } /* * Don't try to intercept touch if we can't scroll anyway. */ if (getScrollY() == 0 && !ViewCompat.canScrollVertically(this, 1)) { DebugLog.d("CustomScrollView", "two" + ev.getX()); return false; } switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_MOVE: { DebugLog.d("CustomScrollView", mIsBeingDragged + "ACTION_MOVE" + ev.getX()); /* * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check * whether the user has moved far enough from his original down touch. */ /* * Locally do absolute value. mLastMotionY is set to the y value * of the down event. */ final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { // If we don't have a valid id, the touch down wasn't on content. break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); if (pointerIndex == -1) { DebugLog.e(TAG, "Invalid pointerId=" + activePointerId + " in onInterceptTouchEvent"); break; } final int y = (int) MotionEventCompat.getY(ev, pointerIndex); final int yDiff = Math.abs(y - mLastMotionY); if (yDiff > mTouchSlop && (getNestedScrollAxes() & ViewCompat.SCROLL_AXIS_VERTICAL) == 0) { mIsBeingDragged = true; mLastMotionY = y; initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(ev); mNestedYOffset = 0; final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } } break; } case MotionEvent.ACTION_DOWN: { DebugLog.d("CustomScrollView", mIsBeingDragged + "ACTION_DOWN" + ev.getX()); mDownX = ev.getX(); final int y = (int) ev.getY(); if (!inChild((int) ev.getX(), y)) { mIsBeingDragged = false; recycleVelocityTracker(); break; } /* * Remember location of down touch. * ACTION_DOWN always refers to pointer index 0. */ mLastMotionY = y; mActivePointerId = MotionEventCompat.getPointerId(ev, 0); initOrResetVelocityTracker(); mVelocityTracker.addMovement(ev); /* * If being flinged and user touches the screen, initiate drag; * otherwise don't. mScroller.isFinished should be false when * being flinged. */ // mIsBeingDragged = !mScroller.isFinished(); startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: moveX = ev.getX() - mDownX; DebugLog.d("CustomScrollView", mIsBeingDragged + "ACTION_UP" + ev.getX()); /* Release the drag */ mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; recycleVelocityTracker(); stopNestedScroll(); break; case MotionEventCompat.ACTION_POINTER_UP: DebugLog.d("CustomScrollView", mIsBeingDragged + "ACTION_POINTER_UP" + ev.getX()); onSecondaryPointerUp(ev); break; } if (Math.abs(moveX) < 10 && ev.getAction() == MotionEvent.ACTION_UP) { DebugLog.d("CustomScrollView", "ON" + "\nmoveX" + moveX + "\nmD" + mDownX); moveX = 0.1f; return false; } DebugLog.d("CustomScrollView", mIsBeingDragged + ""); /* * The only time we want to intercept motion events is if we are in the * drag mode. */ return mIsBeingDragged; }
From source file:com.hxqc.mall.thirdshop.views.CustomScrollView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { /*// w w w . ja va2s . c o m * This method JUST determines whether we want to intercept the motion. * If we return true, onMotionEvent will be called and we do the actual * scrolling there. */ /* * Shortcut the most recurring case: the user is in the dragging * state and he is moving his finger. We want to intercept this * motion. */ final int action = ev.getAction(); if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) { DebugLog.d("CustomScrollView", "one" + ev.getX()); return true; } /* * Don't try to intercept touch if we can't scroll anyway. */ if (getScrollY() == 0 && !ViewCompat.canScrollVertically(this, 1)) { DebugLog.d("CustomScrollView", "two" + ev.getX()); return false; } switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_MOVE: { DebugLog.d("CustomScrollView", mIsBeingDragged + "ACTION_MOVE" + ev.getX()); /* * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check * whether the user has moved far enough from his original down touch. */ /* * Locally do absolute value. mLastMotionY is set to the y value * of the down event. */ final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { // If we don't have a valid id, the touch down wasn't on content. break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); if (pointerIndex == -1) { DebugLog.e(TAG, "Invalid pointerId=" + activePointerId + " in onInterceptTouchEvent"); break; } final int y = (int) MotionEventCompat.getY(ev, pointerIndex); final int yDiff = Math.abs(y - mLastMotionY); if (yDiff > mTouchSlop && (getNestedScrollAxes() & ViewCompat.SCROLL_AXIS_VERTICAL) == 0) { mIsBeingDragged = true; mLastMotionY = y; initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(ev); mNestedYOffset = 0; final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } } break; } case MotionEvent.ACTION_DOWN: { DebugLog.d("CustomScrollView", mIsBeingDragged + "ACTION_DOWN" + ev.getX()); mDownX = ev.getX(); final int y = (int) ev.getY(); if (!inChild((int) ev.getX(), y)) { mIsBeingDragged = false; recycleVelocityTracker(); break; } /* * Remember location of down touch. * ACTION_DOWN always refers to pointer index 0. */ mLastMotionY = y; mActivePointerId = MotionEventCompat.getPointerId(ev, 0); initOrResetVelocityTracker(); mVelocityTracker.addMovement(ev); /* * If being flinged and user touches the screen, initiate drag; * otherwise don't. mScroller.isFinished should be false when * being flinged. */ // mIsBeingDragged = !mScroller.isFinished(); startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: moveX = ev.getX() - mDownX; DebugLog.d("CustomScrollView", mIsBeingDragged + "ACTION_UP" + ev.getX()); /* Release the drag */ mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; recycleVelocityTracker(); stopNestedScroll(); break; case MotionEventCompat.ACTION_POINTER_UP: DebugLog.d("CustomScrollView", mIsBeingDragged + "ACTION_POINTER_UP" + ev.getX()); onSecondaryPointerUp(ev); break; default: break; } if (Math.abs(moveX) < 10 && ev.getAction() == MotionEvent.ACTION_UP) { DebugLog.d("CustomScrollView", "ON" + "\nmoveX" + moveX + "\nmD" + mDownX); moveX = 0.1f; return false; } DebugLog.d("CustomScrollView", mIsBeingDragged + ""); /* * The only time we want to intercept motion events is if we are in the * drag mode. */ return mIsBeingDragged; }
From source file:com.nxt.zyl.ui.widget.pulltorefresh.SwipeRefreshLayout.java
public boolean canChildScrollDown() { if (android.os.Build.VERSION.SDK_INT < 14) { if (mTarget instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTarget; View lastChild = absListView.getChildAt(absListView.getChildCount() - 1); return lastChild != null && (absListView.getLastVisiblePosition() == (absListView.getCount() - 1)) && lastChild.getBottom() > absListView.getPaddingBottom(); } else {/*from w ww .j a v a 2 s. c o m*/ return mTarget.getHeight() - mTarget.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(mTarget, 1); } }
From source file:com.cdwx.moka.widget.SwipeRefreshLayout.java
public boolean canChildScrollDown() { if (android.os.Build.VERSION.SDK_INT < 14) { if (mTarget instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTarget; View lastChild = absListView.getChildAt(absListView.getChildCount() - 1); if (lastChild != null) { return (absListView.getLastVisiblePosition() == (absListView.getCount() - 1)) && lastChild.getBottom() > absListView.getPaddingBottom(); } else { return false; }/*from ww w . j av a 2s. co m*/ } else { return mTarget.getHeight() - mTarget.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(mTarget, 1); } }
From source file:com.hynet.mergepay.components.widget.panellayout.ViewDragHelper.java
protected boolean canScroll(View v, boolean checkV, int dx, int dy, int x, int y) { if (v instanceof ViewGroup) { final ViewGroup group = (ViewGroup) v; final int scrollX = v.getScrollX(); final int scrollY = v.getScrollY(); final int count = group.getChildCount(); // Count backwards - let topmost views consume scroll distance first. for (int i = count - 1; i >= 0; i--) { // TODO: Add versioned support here for transformed views. // This will not work for transformed views in Honeycomb+ final View child = group.getChildAt(i); if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child, true, dx, dy, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; }/*w w w.ja v a 2 s.c o m*/ } } return checkV && (ViewCompat.canScrollHorizontally(v, -dx) || ViewCompat.canScrollVertically(v, -dy)); }
From source file:chinanurse.cn.nurse.list.WaveSwipeRefreshLayout.java
/** * @return ScrollUp?????/*from ww w. ja v a 2s.c om*/ */ public boolean canChildScrollUp() { if (mTarget == null) { return false; } if (android.os.Build.VERSION.SDK_INT < 14) { if (mTarget instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTarget; return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0).getTop() < absListView.getPaddingTop()); } else { return mTarget.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(mTarget, -1); } }
From source file:com.telerik.examples.primitives.ExampleViewPagerBase.java
private boolean getCanScroll(View v, int dx) { if (this.orientation == LinearLayout.HORIZONTAL) { return ViewCompat.canScrollHorizontally(v, -dx); }/*w w w.j a va 2 s. c om*/ return ViewCompat.canScrollVertically(v, -dx); }
From source file:com.telerik.examples.primitives.ExampleViewPagerBase.java
private boolean getInvertedCanScroll(View v, int dx) { if (this.orientation == LinearLayout.VERTICAL) { return ViewCompat.canScrollHorizontally(v, -dx); }/*from w w w . ja v a2 s . c o m*/ return ViewCompat.canScrollVertically(v, -dx); }
From source file:com.limxing.library.PullToRefresh.SwipeRefreshLayout.java
/** * @return Whether it is possible for the child view of this layout to * scroll down. Override this if the child view is a custom view. *//*from w w w. ja v a2 s . c o m*/ public boolean canChildScrollDown() { if (android.os.Build.VERSION.SDK_INT < 14) { if (mTarget instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTarget; View lastChild = absListView.getChildAt(absListView.getChildCount() - 1); if (lastChild != null) { if ((absListView.getLastVisiblePosition() == (absListView.getCount() - 1)) && lastChild.getBottom() >= absListView.getPaddingBottom()) { return false; } return true; } else { return false; } } else { return mTarget.getHeight() - mTarget.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(mTarget, 1); } }