コード例 #1
0
  private void scrollInternal(
      float distanceY,
      float distanceYconsumed,
      int[] offsetInWindow,
      boolean argNotifyAboutScrolling) {
    Log.v(TAG, "scrollInternal called");

    if (mTopPlayer == null) {
      mTopPlayer = (TopPlayer) findViewById(R.id.top_player);
    }

    if (mRecyclerView == null) {
      mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
    }

    int[] consumed = new int[2];
    consumed[1] = (int) distanceYconsumed;

    if (argNotifyAboutScrolling) startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);

    // int[] offsetInWindow = new int[2];
    if (argNotifyAboutScrolling)
      dispatchNestedPreScroll(0, (int) distanceY, consumed, offsetInWindow);

    int consumedY = consumed[1];
    int unconsumedY =
        (int) (distanceY); // int unconsumedY = (int)(distanceY-consumedY-offsetInWindow[1]);

    if (argNotifyAboutScrolling) dispatchNestedScroll(0, consumedY, 0, unconsumedY, offsetInWindow);

    if (mTopPlayer == null || mRecyclerView == null || mTopPlayer.isFullscreen()) {
      return;
    }

    if (distanceY < 0) {
      if (mRecyclerView.canScrollVertically(DOWN)) {
        // it cannot be larger, scroll recyclerview
        Log.v(TAG, "scroll.run, mRecyclerView1");
        mRecyclerView.scrollBy(0, (int) distanceY);
      } else {
        Log.v(TAG, "scroll.run, mTopPlayer2");
        // mTopPlayer.scrollExternal(distanceY, false);
        mTopPlayer.scrollBy(distanceY);
      }
    } else {
      if (mTopPlayer.isMinimumSize()) {
        Log.v(TAG, "scroll.run, mRecyclerView2");
        mRecyclerView.scrollBy(0, (int) distanceY);
      } else {
        int canscrollup = canScrollUp(mRecyclerView);
        if (canscrollup > 0) {
          Log.v(TAG, "scroll.run, mTopPlayer1 diffY: " + distanceY + " canscroll: " + canscrollup);

          distanceY = distanceY < canscrollup ? distanceY : canscrollup;
          // mTopPlayer.scrollExternal(distanceY, false);
          mTopPlayer.scrollBy(distanceY);
        }
      }
    }
  }
コード例 #2
0
 void handleDragScroll(RecyclerView rv, DragInfo dragInfo) {
   if (rv.getLayoutManager().canScrollHorizontally()) {
     if (rv.canScrollHorizontally(-1) && dragInfo.shouldScrollLeft()) {
       rv.scrollBy(-SCROLL_AMOUNT, 0);
       dragManager.clearNextMove();
     } else if (rv.canScrollHorizontally(1) && dragInfo.shouldScrollRight(rv.getWidth())) {
       rv.scrollBy(SCROLL_AMOUNT, 0);
       dragManager.clearNextMove();
     }
   } else if (rv.getLayoutManager().canScrollVertically()) {
     if (rv.canScrollVertically(-1) && dragInfo.shouldScrollUp()) {
       rv.scrollBy(0, -SCROLL_AMOUNT);
       dragManager.clearNextMove();
     } else if (rv.canScrollVertically(1) && dragInfo.shouldScrollDown(rv.getHeight())) {
       rv.scrollBy(0, SCROLL_AMOUNT);
       dragManager.clearNextMove();
     }
   }
 }
 @Override
 public boolean canScrollVertically(int direction) {
   return mRecyclerView != null && mRecyclerView.canScrollVertically(direction);
 }