Java Code Examples for android.view.View.canScrollVertically()

The following are Jave code examples for showing how to use canScrollVertically() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: JD-Test   File: PtrDefaultHandler.java   Source Code and License Vote up 8 votes
public static boolean canChildScrollUp(View view) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (view instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else if(view instanceof  RecyclerView){
            RecyclerView recyclerView = (RecyclerView)view;
            RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
            if(layoutManager instanceof LinearLayoutManager){
                int position = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
                return position != 0;
            }else{
                if(layoutManager instanceof StaggeredGridLayoutManager ){
                    StaggeredGridLayoutManager stagger = (StaggeredGridLayoutManager) layoutManager;
                    int[] positions = stagger.findFirstCompletelyVisibleItemPositions(null);
                    return positions[0] != 0;
                }else{
                    throw new RuntimeException("can not support this LayoutManager ");
                }
            }
        }else{
            return view.getScrollY() > 0;
        }
    } else {
        return view.canScrollVertically(-1);
    }
}
 
Example 2
Project: GitHub   File: ScrollBoundaryUtil.java   Source Code and License Vote up 6 votes
public static boolean canScrollUp(View targetView) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (targetView instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) targetView;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else {
            return targetView.getScrollY() > 0;
        }
    } else {
        return targetView.canScrollVertically(-1);
    }
}
 
Example 3
Project: GitHub   File: ScrollBoundaryUtil.java   Source Code and License Vote up 6 votes
public static boolean canScrollDown(View targetView) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (targetView instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) targetView;
            return absListView.getChildCount() > 0
                    && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1
                    || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom());
        } else {
            return targetView.getScrollY() < 0;
        }
    } else {
        return targetView.canScrollVertically(1);
    }
}
 
Example 4
Project: GitHub   File: PtrDefaultHandler.java   Source Code and License Vote up 6 votes
public static boolean canChildScrollUp(View view) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (view instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else {
            return view.getScrollY() > 0;
        }
    } else {
        return view.canScrollVertically(-1);
    }
}
 
Example 5
Project: Rxjava2.0Demo   File: ScrollBoundaryUtil.java   Source Code and License Vote up 6 votes
public static boolean canScrollDown(View targetView) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (targetView instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) targetView;
            return absListView.getChildCount() > 0
                    && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1
                    || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom());
        } else {
            return targetView.getScrollY() < 0;
        }
    } else {
        return targetView.canScrollVertically(1);
    }
}
 
Example 6
Project: Swface   File: PtrDefaultHandler.java   Source Code and License Vote up 6 votes
public static boolean canChildScrollUp(View view) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (view instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else {
            return view.getScrollY() > 0;
        }
    } else {
        return view.canScrollVertically(-1);
    }
}
 
Example 7
Project: cwac-crossport   File: BottomSheetBehavior.java   Source Code and License Vote up 6 votes
@Override
public boolean tryCaptureView(View child, int pointerId) {
  if (mState == STATE_DRAGGING) {
    return false;
  }
  if (mTouchingScrollingChild) {
    return false;
  }
  if (mState == STATE_EXPANDED && mActivePointerId == pointerId) {
    View scroll = mNestedScrollingChildRef.get();
        if (scroll != null && scroll.canScrollVertically(-1)) {
      // Let the content scroll up
      return false;
    }
  }
  return mViewRef != null && mViewRef.get() == child;
}
 
Example 8
Project: SmartRefresh   File: RefreshContentWrapper.java   Source Code and License Vote up 6 votes
private static boolean canScrollUp(View targetView) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (targetView instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) targetView;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else {
            return targetView.getScrollY() > 0;
        }
    } else {
        return targetView.canScrollVertically(-1);
    }
}
 
Example 9
Project: SmartRefresh   File: RefreshContentWrapper.java   Source Code and License Vote up 6 votes
private static boolean canScrollDown(View mScrollableView) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (mScrollableView instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) mScrollableView;
            return absListView.getChildCount() > 0
                    && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1
                    || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom());
        } else {
            return mScrollableView.getScrollY() < 0;
        }
    } else {
        return mScrollableView.canScrollVertically(1);
    }
}
 
Example 10
Project: android-Ultra-Pull-To-Refresh   File: PtrDefaultHandler.java   Source Code and License Vote up 6 votes
public static boolean canChildScrollUp(View view) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (view instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else {
            return view.getScrollY() > 0;
        }
    } else {
        return view.canScrollVertically(-1);
    }
}
 
Example 11
Project: cwac-crossport   File: BottomSheetBehavior.java   Source Code and License Vote up 6 votes
@Override
  public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, V child, View target, int dx,
          int dy, int[] consumed) {
  View scrollingChild = mNestedScrollingChildRef.get();
  if (target != scrollingChild) {
    return;
  }
  int currentTop = child.getTop();
  int newTop = currentTop - dy;
  if (dy > 0) { // Upward
    if (newTop < mMinOffset) {
      consumed[1] = currentTop - mMinOffset;
      ViewCompat.offsetTopAndBottom(child, -consumed[1]);
      setStateInternal(STATE_EXPANDED);
    } else {
      consumed[1] = dy;
      ViewCompat.offsetTopAndBottom(child, -dy);
      setStateInternal(STATE_DRAGGING);
    }
  } else if (dy < 0) { // Downward
          if (!target.canScrollVertically(-1)) {
      if (newTop <= mMaxOffset || mHideable) {
        consumed[1] = dy;
        ViewCompat.offsetTopAndBottom(child, -dy);
        setStateInternal(STATE_DRAGGING);
      } else {
        consumed[1] = currentTop - mMaxOffset;
        ViewCompat.offsetTopAndBottom(child, -consumed[1]);
        setStateInternal(STATE_COLLAPSED);
      }
    }
  }
  dispatchOnSlide(child.getTop());
  mLastNestedScrollDy = dy;
  mNestedScrolled = true;
}
 
Example 12
Project: ViewPrinter   File: DocumentHelper.java   Source Code and License Vote up 6 votes
/**
 * To be called after the View has been laid out. If the view is presumably to small,
 * this will call {@link #onSpaceOver(View)} for you.
 *
 * @param view The view that has been laid out
 */
public static void onLayout(View view) {
    if (view.getLayoutParams().height == ViewGroup.LayoutParams.WRAP_CONTENT) {
        // TODO: don't do this if getMaxLines is >= 0 (< MAX_VALUE). Same for getMaxheight.
        if (view.canScrollVertically(-1) || view.canScrollVertically(1)) {
            LOG.w("onLayout:", preview(view), "We can scroll. Notifying the parent column.");
            onSpaceOver(view);
        }
    }
}
 
Example 13
Project: PaoMovie   File: PtrDefaultHandler.java   Source Code and License Vote up 6 votes
public static boolean canChildScrollUp(View view) {
    if (android.os.Build.VERSION.SDK_INT < 14) {
        if (view instanceof AbsListView) {
            final AbsListView absListView = (AbsListView) view;
            return absListView.getChildCount() > 0
                    && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                    .getTop() < absListView.getPaddingTop());
        } else {
            return view.getScrollY() > 0;
        }
    } else {
        return view.canScrollVertically(-1);
    }
}
 
Example 14
Project: Aequorea   File: SwipeBackCoordinatorLayout.java   Source Code and License Vote up 5 votes
public static boolean canSwipeBackForThisView(View v, int dir) {
    return !v.canScrollVertically(dir);
}
 
Example 15
Project: letv   File: ViewCompatICS.java   Source Code and License Vote up 5 votes
public static boolean canScrollVertically(View v, int direction) {
    return v.canScrollVertically(direction);
}
 
Example 16
Project: Camera-Roll-Android-App   File: SwipeBackCoordinatorLayout.java   Source Code and License Vote up 5 votes
public static boolean canSwipeBackForThisView(View v, int dir) {
    return !v.canScrollVertically(dir);
}
 
Example 17
Project: switchbutton   File: FTouchHelper.java   Source Code and License Vote up 2 votes
/**
 * view是否已经滚动到最顶部
 *
 * @param view
 * @return
 */
public static boolean isScrollToTop(View view)
{
    return !view.canScrollVertically(-1);
}
 
Example 18
Project: switchbutton   File: FTouchHelper.java   Source Code and License Vote up 2 votes
/**
 * view是否已经滚动到最底部
 *
 * @param view
 * @return
 */
public static boolean isScrollToBottom(View view)
{
    return !view.canScrollVertically(1);
}
 
Example 19
Project: pulltorefresh   File: FTouchHelper.java   Source Code and License Vote up 2 votes
/**
 * view是否已经滚动到最底部
 *
 * @param view
 * @return
 */
public static boolean isScrollToBottom(View view)
{
    return !view.canScrollVertically(1);
}
 
Example 20
Project: pulltorefresh   File: FTouchHelper.java   Source Code and License Vote up 2 votes
/**
 * view是否已经滚动到最顶部
 *
 * @param view
 * @return
 */
public static boolean isScrollToTop(View view)
{
    return !view.canScrollVertically(-1);
}