List of usage examples for android.support.v4.view ViewCompat canScrollVertically
public static boolean canScrollVertically(View v, int direction)
From source file:com.peerless2012.twowaynestedscrollview.TwoWayNestedScrollView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { /*//ww w.j a va2 s . c om * 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)) { return true; } /* * Don't try to intercept touch if we can't scroll anyway. */ if (getScrollY() == 0 && !ViewCompat.canScrollVertically(this, 1)) { return false; } switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_MOVE: { /* * 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) { Log.e(TAG, "Invalid pointerId=" + activePointerId + " in onInterceptTouchEvent"); break; } final int x = (int) MotionEventCompat.getX(ev, pointerIndex); final int xDiff = Math.abs(x - mLastMotionX); 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); } } else if (xDiff > mTouchSlop && (getNestedScrollAxes() & ViewCompat.SCROLL_AXIS_VERTICAL) == 0) { mIsBeingDragged = true; mLastMotionX = x; initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(ev); mNestedXOffset = 0; final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } } break; } case MotionEvent.ACTION_DOWN: { final int y = (int) ev.getY(); final int x = (int) ev.getX(); if (!inChild(x, y)) { mIsBeingDragged = false; scrollDirection = DIRECTION_INVALIDATE; recycleVelocityTracker(); break; } /* * Remember location of down touch. ACTION_DOWN always refers to * pointer index 0. */ mLastMotionY = y; mLastMotionX = x; 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: /* Release the drag */ mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; recycleVelocityTracker(); stopNestedScroll(); break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } /* * The only time we want to intercept motion events is if we are in the * drag mode. */ return mIsBeingDragged; }
From source file:bhav.swipeaction.SwipeAction.java
/** * @return Whether it is possible for the child view of this layout to * scroll up. Override this if the child view is a custom view. *//* w w w. j av a 2 s. co m*/ public boolean canChildScrollUp() { return ViewCompat.canScrollVertically(mTarget, -1); }
From source file:com.dystu.toolbar.widget.MySwipeRefreshLayout.java
/** * @return Whether it is possible for the child view of this layout to * scroll up. Override this if the child view is a custom view. *///ww w . j a v a 2s.com public boolean canChildScrollUp() { 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 { //Log.d(TAG, "canChildScrollUp :"+ mTarget.getScrollY()+" "+mTarget); boolean flag = mTarget.getScrollY() > 0; if (mTarget instanceof RecyclerView) { RecyclerView rv = (RecyclerView) mTarget; int firstVisiblePosition = rv.getChildPosition(rv.getChildAt(0)); if (firstVisiblePosition == 0) return rv.getChildAt(0).getTop() == 0 ? false : true; else return true; } return flag;//ViewCompat.canScrollVertically(mTarget, -1); } } else { return ViewCompat.canScrollVertically(mTarget, -1); } }
From source file:br.com.leoleal.swipetorefresh.SwipeRefreshLayout.java
/** * @return Whether it is possible for the child view of this layout to * scroll up. Override this if the child view is a custom view. *//*from www.j a va2s . c o m*/ public boolean canChildScrollUp() { 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 ViewCompat.canScrollVertically(mTarget, -1) || mTarget.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(mTarget, -1); } }
From source file:com.adhere.view.swipe.SwipeRefreshLayout.java
/** * @return Whether it is possible for the child view of this layout to * scroll up. Override this if the child view is a custom view. *//* ww w. jav a 2s .c o m*/ public boolean canChildScrollUp() { // //For make it can work when my recycler view is in Gone. // 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 ViewCompat.canScrollVertically(mTarget, -1) || mTarget.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(mTarget, -1); } }
From source file:com.ray.appchallenge.view.SwipeRefreshLayoutBottom.java
/** * @return Whether it is possible for the child view of this layout to scroll up. Override this if the child view * is a custom view./*www . j av a 2 s .c o m*/ */ /* * public boolean canChildScrollUp() { * 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); * } *}*/ public boolean canChildScrollUp() { Log.w("ANDREY", "canChildScrollUp()"); if (android.os.Build.VERSION.SDK_INT < 14) { if (mTarget instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTarget; Log.e("ANDREY", " absListView.getFirstVisiblePosition() " + absListView.getFirstVisiblePosition()); Log.e("ANDREY", " absListView.getLastVisiblePosition() " + absListView.getLastVisiblePosition()); Log.e("ANDREY", " absListView.getCount() " + absListView.getCount()); if (absListView.getLastVisiblePosition() + 1 == absListView.getCount()) { int lastIndex = absListView.getLastVisiblePosition() - absListView.getFirstVisiblePosition(); Log.e("ANDREY", " lastIndex " + lastIndex); boolean res = absListView.getChildAt(lastIndex).getBottom() == absListView.getPaddingBottom(); if (!res) { Log.e("ANDREY", "return " + res); } return res; } // Log.e("ANDREY", "return TRUE"); return true; /* * return absListView.getChildCount() > 0 * && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0).getTop() < * absListView.getPaddingTop());*/ } else { Log.e("ANDREY", "return 222 " + (mTarget.getScrollY() > 0)); return mTarget.getScrollY() > 0; } } else { Log.e("ANDREY", "return 333 " + (ViewCompat.canScrollVertically(mTarget, 1))); return ViewCompat.canScrollVertically(mTarget, 1); } // return ViewCompat.canScrollVertically(mTarget, 1); }
From source file:com.com.mytoolsproject.SwipeRefreshLayout.java
/** * @return Whether it is possible for the child view of this layout to * scroll up. Override this if the child view is a custom view. *//*w w w. j av a2 s . c o m*/ public boolean canChildScrollUp() { if (mChildScrollUpCallback != null) { return mChildScrollUpCallback.canChildScrollUp(this, mTarget); } 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 ViewCompat.canScrollVertically(mTarget, -1) || mTarget.getScrollY() > 0; } } else { return ViewCompat.canScrollVertically(mTarget, -1); } }
From source file:com.koresuniku.wishmaster.utilities.SwipeRefreshLayoutBottom.java
/** * @return Whether it is possible for the child view of this layout to * scroll up. Override this if the child view is a custom view. *///from w w w . j av a 2s. c o m /* public boolean canChildScrollUp() { 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); } }*/ public boolean canChildScrollUp() { Log.w("ANDREY", "canChildScrollUp()"); if (android.os.Build.VERSION.SDK_INT < 14) { if (mTarget instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTarget; Log.e("ANDREY", " absListView.getFirstVisiblePosition() " + absListView.getFirstVisiblePosition()); Log.e("ANDREY", " absListView.getLastVisiblePosition() " + absListView.getLastVisiblePosition()); Log.e("ANDREY", " absListView.getCount() " + absListView.getCount()); if (absListView.getLastVisiblePosition() + 1 == absListView.getCount()) { int lastIndex = absListView.getLastVisiblePosition() - absListView.getFirstVisiblePosition(); Log.e("ANDREY", " lastIndex " + lastIndex); boolean res = absListView.getChildAt(lastIndex).getBottom() == absListView.getPaddingBottom(); if (!res) { Log.e("ANDREY", "return " + res); } return res; } //Log.e("ANDREY", "return TRUE"); return true; /* return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0).getTop() < absListView.getPaddingTop());*/ } else { Log.e("ANDREY", "return 222 " + (mTarget.getScrollY() > 0)); return mTarget.getScrollY() > 0; } } else { Log.e("ANDREY", "return 333 " + (ViewCompat.canScrollVertically(mTarget, 1))); return ViewCompat.canScrollVertically(mTarget, 1); } //return ViewCompat.canScrollVertically(mTarget, 1); }
From source file:android.kectech.com.stylingactionbar.lib.SwipyRefreshLayout.java
/** * @return Whether it is possible for the child view of this layout to * scroll up. Override this if the child view is a custom view. *//*from w w w . j a va 2s . c om*/ public boolean canChildScrollUp() { 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:anabolicandroids.chanobol.util.swipebottom.SwipeRefreshLayoutBottom.java
/** * @return Whether it is possible for the child view of this layout to * scroll up. Override this if the child view is a custom view. *//*from w ww . jav a 2s . c om*/ /* public boolean canChildScrollUp() { 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); } }*/ public boolean canChildScrollUp() { Log.w("ANDREY", "canChildScrollUp()"); if (android.os.Build.VERSION.SDK_INT < 14) { if (mTarget instanceof AbsListView) { final AbsListView absListView = (AbsListView) mTarget; Log.e("ANDREY", " absListView.getFirstVisiblePosition() " + absListView.getFirstVisiblePosition()); Log.e("ANDREY", " absListView.getLastVisiblePosition() " + absListView.getLastVisiblePosition()); Log.e("ANDREY", " absListView.getCount() " + absListView.getCount()); if (absListView.getLastVisiblePosition() + 1 == absListView.getCount()) { int lastIndex = absListView.getLastVisiblePosition() - absListView.getFirstVisiblePosition(); Log.e("ANDREY", " lastIndex " + lastIndex); boolean res = absListView.getChildAt(lastIndex).getBottom() == absListView.getPaddingBottom(); if (!res) { Log.e("ANDREY", "return " + res); } return res; } //Log.e("ANDREY", "return TRUE"); return true; /* return absListView.getChildCount() > 0 && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0).getTop() < absListView.getPaddingTop());*/ } else { Log.e("ANDREY", "return 222 " + (mTarget.getScrollY() > 0)); return mTarget.getScrollY() > 0; } } else { Log.e("ANDREY", "return 333 " + (ViewCompat.canScrollVertically(mTarget, 1))); return ViewCompat.canScrollVertically(mTarget, 1); } //return ViewCompat.canScrollVertically(mTarget, 1); }