@Override
 public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
   super.onScrolled(recyclerView, dx, dy);
   LinearLayoutManager mLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
   lastVisibleItem = mLayoutManager.findLastVisibleItemPosition();
   pulldown = (dy > 0);
 }
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
      super.onScrolled(recyclerView, dx, dy);

      int childCount = recyclerView.getChildCount();
      int width = recyclerView.getChildAt(0).getWidth();
      int padding = (recyclerView.getWidth() - width) / 2;

      for (int i = 0; i < childCount; i++) {
        View view = recyclerView.getChildAt(i);

        float ratio = 0;

        if (view.getLeft() <= padding) {
          if (view.getLeft() >= padding - view.getWidth()) {
            ratio = (padding - view.getLeft()) * 1f / view.getWidth();
          } else {
            ratio = 1;
          }
          view.setScaleY(1 - ratio * 0.5f);
          view.setScaleX(1 - ratio * 0.5f);

        } else {

          if (view.getLeft() <= recyclerView.getWidth() - padding) {
            ratio = (recyclerView.getWidth() - padding - view.getLeft()) * 1f / view.getWidth();
          }
          view.setScaleY(0.5f + ratio * 0.5f);
          view.setScaleX(0.5f + ratio * 0.5f);
        }
      }
    }
  //    We dont use this method because its action is called per pixel value change
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    //  Check scrolled distance against the minimum
    if (isVisible && scrollDist > HIDE_THRESHOLD) {
      //  Hide fab & reset scrollDist
      hide();
      scrollDist = 0;
      isVisible = false;
    }
    //  -MINIMUM because scrolling up gives - dy values
    else if (!isVisible && scrollDist < -SHOW_THRESHOLD) {
      //  Show fab & reset scrollDist
      show();

      scrollDist = 0;
      isVisible = true;
    }

    //  Whether we scroll up or down, calculate scroll distance
    if ((isVisible && dy > 0) || (!isVisible && dy < 0)) {
      scrollDist += dy;
    }
  }
Exemplo n.º 4
0
  /*
  One simple method
   */
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    int firstVisibleItem =
        ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
    if (firstVisibleItem == 0) {
      if (!controlsVisible) {
        onShow();
        controlsVisible = true;
      }
    } else {
      if (scrolledDistance < -HIDE_THRESHOLD && !controlsVisible) {
        onShow();
        scrolledDistance = 0;
        controlsVisible = true;
      } else if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) {
        onHide();
        controlsVisible = false;
        scrolledDistance = 0;
      }
    }

    if ((controlsVisible && dy > 0) || (!controlsVisible && dy < 0)) {
      scrolledDistance += dy;
    }
  }
  @Override
  public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);

    switch (newState) {
      case RecyclerView.SCROLL_STATE_IDLE:
        {
          if (mTotalScrolledDistance < mToolbarHeight) {
            setVisible();
          } else {
            if (mControlsVisible) {
              if (mToolbarOffset > HIDE_THRESHOLD) {
                setInvisible();
              } else {
                setVisible();
              }
            } else {
              if ((mToolbarHeight - mToolbarOffset) > SHOW_THRESHOLD) {
                setVisible();
              } else {
                setInvisible();
              }
            }
          }
          break;
        }
    }
  }
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    gridLayoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
    visibleItemCount = recyclerView.getChildCount();
    totalItemCount = gridLayoutManager.getItemCount();
    firstVisibleItem = gridLayoutManager.findFirstVisibleItemPosition();

    if (isVisible && scrollDist > MINIMUM) {
      onHideShow(true);
      scrollDist = 0;
      isVisible = false;
    } else if (!isVisible && scrollDist < -MINIMUM) {
      onHideShow(false);
      scrollDist = 0;
      isVisible = true;
    }
    if ((isVisible && dy > 0) || (!isVisible && dy < 0)) {
      scrollDist += dy;
    }

    if (loading) {
      if (totalItemCount > previousTotal + 1) {
        loading = false;
        previousTotal = totalItemCount;
      }
    }
    if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
      // End has been reached
      // Do something
      current_page++;
      onLoadMore(current_page, totalItemCount);
      loading = true;
    }
  }
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    visibleItemCount = recyclerView.getChildCount();
    totalItemCount = mLinearLayoutManager.getItemCount();
    firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();

    if (loading) {
      if (totalItemCount > previousTotal) {
        loading = false;
        previousTotal = totalItemCount;
      }
    }
    if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
      // End has been reached

      // Do something
      current_page++;

      onLoadMore(current_page);

      loading = true;
    }
  }
Exemplo n.º 8
0
 private void simulateScroll() {
   if (scrollHandler instanceof ScrollHandler) {
     scrollHandler.onScrolled(content, 0, 0);
   } else {
     // simulate a scroll to "null"
     offsetMediaView(true, 0.0f);
   }
 }
    @Override
    public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
      if (mOnScrollListener != null) {
        mOnScrollListener.onScrollStateChanged(recyclerView, newState);
      }

      super.onScrollStateChanged(recyclerView, newState);
    }
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
      if (mOnScrollListener != null) {
        mOnScrollListener.onScrolled(recyclerView, dx, dy);
      }

      super.onScrolled(recyclerView, dx, dy);
    }
Exemplo n.º 11
0
 @Override
 public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
   super.onScrollStateChanged(recyclerView, newState);
   if (newState == RecyclerView.SCROLL_STATE_IDLE
       && pulldown
       && (lastVisibleItem + 1) == mRecordAdapter.getItemCount()) {
     checkLoadRecordSportsData(mRecordAdapter);
   }
 }
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    clipToolbarOffset();
    onMoved(toolbarOffset);

    if ((toolbarOffset < toolbarHeight && dy > 0) || (toolbarOffset > 0 && dy < 0)) {
      toolbarOffset += dy;
    }
  }
Exemplo n.º 13
0
 /*
 onScrollStateChanged在listview状态改变时被调用,可以用来获取当前listview的状态:
 空闲SCROLL_STATE_IDLE 、滑动SCROLL_STATE_TOUCH_SCROLL和惯性滑动SCROLL_STATE_FLING
  */
 @Override
 public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
   super.onScrollStateChanged(recyclerView, newState);
   if (myListAdapter != null
       && newState == RecyclerView.SCROLL_STATE_IDLE
       && lastVisibleItem + 1 == myListAdapter.getItemCount()) {
     // 滚动到底部了,可以进行数据加载等操作
     // 包含OnloadLIstenerd的发送请求以及界面的各种控制
     myListAdapter.loadMore();
   }
 }
 @Override
 public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
   super.onScrollStateChanged(recyclerView, newState);
   currentScrollState = newState;
   RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
   int visibleItemCount = layoutManager.getChildCount();
   int totalItemCount = layoutManager.getItemCount();
   if ((visibleItemCount > 0
       && currentScrollState == RecyclerView.SCROLL_STATE_IDLE
       && (lastVisibleItemPosition) >= totalItemCount - 1)) {
     if (null != onBottomListener) onBottomListener.onBottom();
   }
 }
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    if (mLinearLayoutManager == null) {
      mLinearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    }

    firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();
    visibleItemCount = recyclerView.getChildCount();
    totalItemCount = mLinearLayoutManager.getItemCount();

    if (infiniteScrollingEnabled) {
      if (loading) {
        if (totalItemCount > previousTotal) {
          loading = false;
          previousTotal = totalItemCount;
        }
      }

      if (!loading && (totalItemCount - visibleItemCount <= firstVisibleItem + visibleThreshold)) {
        // End has been reached
        // do something
        onLoadMore();
        loading = true;
      }
    }

    if (firstVisibleItem == 0) {
      if (!controlsVisible) {
        onScrollUp();
        controlsVisible = true;
      }

      return;
    }

    if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) {
      onScrollDown();
      controlsVisible = false;
      scrolledDistance = 0;
    } else if (scrolledDistance < -HIDE_THRESHOLD && !controlsVisible) {
      onScrollUp();
      controlsVisible = true;
      scrolledDistance = 0;
    }

    if ((controlsVisible && dy > 0) || (!controlsVisible && dy < 0)) {
      scrolledDistance += dy;
    }
  }
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    clipToolbarOffset();
    onMoved(toolbarOffset);

    off += dy;

    if (((toolbarOffset < toolbarHeight && dy > 0) || (toolbarOffset > 0 && dy < 0))
        && off >= (((240 * scale) + 0.5f) - toolbarHeight)) {
      toolbarOffset += dy;
    }
  }
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    // use for FloatingActionButton
    boolean isSignificantDelta = Math.abs(dy) > mScrollThreshold;

    if (isSignificantDelta) {
      if (dy > 0) {
        onScrolledUp();
      } else {
        onScrolledDown();
      }
    }
  }
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    clipToolbarOffset();
    onMoved(mToolbarOffset);

    if ((mToolbarOffset < mToolbarHeight && dy > 0) || (mToolbarOffset > 0 && dy < 0)) {
      mToolbarOffset += dy;
    }
    if (mTotalScrolledDistance < 0) {
      mTotalScrolledDistance = 0;
    } else {
      mTotalScrolledDistance += dy;
    }
  }
Exemplo n.º 19
0
  @Override
  public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);

    LinearLayoutManager lm = (LinearLayoutManager) recyclerView.getLayoutManager();

    if (mCenterPivot == 0) {

      mCenterPivot =
          lm.getOrientation() == LinearLayoutManager.HORIZONTAL
              ? (recyclerView.getLeft() + recyclerView.getRight())
              : (recyclerView.getTop() + recyclerView.getBottom());
    }
    if (!mAutoSet) {

      if (newState == RecyclerView.SCROLL_STATE_IDLE) {

        View view = findCenterView(lm);

        int position = recyclerView.getChildPosition(view);

        Log.i("CenterLockListener", "list-position" + position);

        Toast.makeText(context, "list-position" + position, Toast.LENGTH_SHORT).show();

        int viewCenter =
            lm.getOrientation() == LinearLayoutManager.HORIZONTAL
                ? (view.getLeft() + view.getRight()) / 2
                : (view.getTop() + view.getBottom()) / 2;

        int scrollNeeded = viewCenter - mCenterPivot;

        if (lm.getOrientation() == LinearLayoutManager.HORIZONTAL) {

          recyclerView.smoothScrollBy(scrollNeeded, 0);
        } else {
          recyclerView.smoothScrollBy(0, (int) (scrollNeeded));
        }
        mAutoSet = true;
      }
    }
    if (newState == RecyclerView.SCROLL_STATE_DRAGGING
        || newState == RecyclerView.SCROLL_STATE_SETTLING) {

      mAutoSet = false;
    }
  }
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    if (isVisible && scrollDist > MINIMUM) {
      hide();
      scrollDist = 0;
      isVisible = false;
    } else if (!isVisible && scrollDist < -MINIMUM) {

      show();
      scrollDist = 0;
      isVisible = true;
    }

    if ((isVisible && dy > 0) || (!isVisible && dy < 0)) scrollDist += dy;
  }
Exemplo n.º 21
0
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    int lastVisibleItem = 0;
    int firstVisibleItem = 0;
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    int totalItemCount = layoutManager.getItemCount();
    if (layoutManager instanceof LinearLayoutManager) {
      LinearLayoutManager linearLayoutManager = ((LinearLayoutManager) layoutManager);
      lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
      firstVisibleItem = linearLayoutManager.findFirstCompletelyVisibleItemPosition();
    } else if (layoutManager instanceof GridLayoutManager) {
      GridLayoutManager gridLayoutManager = ((GridLayoutManager) layoutManager);
      // 通过LayoutManager找到当前显示的最后的item的position
      lastVisibleItem = gridLayoutManager.findLastVisibleItemPosition();
      firstVisibleItem = gridLayoutManager.findFirstCompletelyVisibleItemPosition();
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
      StaggeredGridLayoutManager staggeredGridLayoutManager =
          ((StaggeredGridLayoutManager) layoutManager);
      // 因为StaggeredGridLayoutManager的特殊性可能导致最后显示的item存在多个,所以这里取到的是一个数组
      // 得到这个数组后再取到数组中position值最大的那个就是最后显示的position值了
      int[] lastPositions = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
      staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
      lastVisibleItem = findMax(lastPositions);
      firstVisibleItem = staggeredGridLayoutManager.findFirstVisibleItemPositions(lastPositions)[0];
    }
    if (firstVisibleItem == 0) {
      if (!mPullLoadMoreRecyclerView.isLoadMore()) {
        mPullLoadMoreRecyclerView.setPullRefreshEnable(true);
      }
    } else {
      mPullLoadMoreRecyclerView.setPullRefreshEnable(false);
    }

    /** 无论水平还是垂直 */
    if (!mPullLoadMoreRecyclerView.isRefresh()
        && mPullLoadMoreRecyclerView.isHasMore()
        && (lastVisibleItem >= totalItemCount - 1)
        && !mPullLoadMoreRecyclerView.isLoadMore()
        && (dx > 0 || dy > 0)) {
      mPullLoadMoreRecyclerView.setIsLoadMore(true);
      mPullLoadMoreRecyclerView.loadMore();
    }
  }
Exemplo n.º 22
0
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
      super.onScrolled(recyclerView, dx, dy);

      scrollDistance += dy;
      logoViewContainer += dy;
      float logoViewTranslation = logoViewContainer / 2;
      int logoContainerHeight = parentFragment.logoContainer.getHeight();
      if (logoViewTranslation > logoContainerHeight) logoViewTranslation = logoContainerHeight;
      else if (logoViewTranslation < 0) logoViewTranslation = 0;
      ViewHelper.setTranslationY(parentFragment.logoContainer, -logoViewTranslation);

      viewContainerOffset += dy;
      int viewContainerHeight = parentFragment.viewContainer.getHeight();
      if (viewContainerOffset > viewContainerHeight) viewContainerOffset = viewContainerHeight;
      else if (viewContainerOffset < 0) viewContainerOffset = 0;
      ViewHelper.setTranslationY(parentFragment.viewContainer, -viewContainerOffset);

      int toolbarHeight = parentFragment.toolbar.getHeight();
      if (viewContainerOffset
              >= viewContainerHeight - toolbarHeight - parentFragment.mTabs.getHeight()
          || dy < 0) {
        toolbarOffset += dy;
        if (toolbarOffset > toolbarHeight) toolbarOffset = toolbarHeight;
        else if (toolbarOffset < 0) toolbarOffset = 0;
        ViewHelper.setTranslationY(parentFragment.toolbar, -toolbarOffset);
      }

      if (!isColored && scrollDistance >= viewContainerHeight - toolbarHeight && dy < 0) {
        parentFragment.toolbar.setBackgroundColor(
            context.getResources().getColor(R.color.color_primary));
        parentFragment.descriptionText.setVisibility(View.VISIBLE);
        parentFragment.viewContainerBackground.setBackgroundColor(
            context.getResources().getColor(R.color.color_primary));
        isColored = true;
      }

      if (isColored && scrollDistance == 0) {
        parentFragment.toolbar.setBackgroundColor(Color.TRANSPARENT);
        parentFragment.viewContainerBackground.startAnimation(parentFragment.animation);
        isColored = false;
      }
    }
 @Override
 public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
   super.onScrolled(recyclerView, dx, dy);
   try {
     if (!isScrollAble) {
       offsetX += dx;
       if (offsetX > itemWidth) {
         offsetX = itemWidth;
         onScrollStateChanged(recyclerView, RecyclerView.SCROLL_STATE_IDLE);
       } else if (offsetX < -itemWidth) {
         offsetX = -itemWidth;
         onScrollStateChanged(recyclerView, RecyclerView.SCROLL_STATE_IDLE);
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
     onScrollStateChanged(recyclerView, RecyclerView.SCROLL_STATE_IDLE);
   }
 }
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    totalItemCount = recyclerView.getAdapter().getItemCount();
    lastVisibleItem = mLinearLayoutManager.findLastVisibleItemPosition();

    if (loading) {

      if (totalItemCount > previousTotal) {
        loading = false;
        previousTotal = totalItemCount;
      }
    }

    if (!loading && (totalItemCount <= (lastVisibleItem + VISIBLE_THRESHOLD))) {
      loading = true;
      onLoadMore();
    }
  }
Exemplo n.º 25
0
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
      super.onScrolled(recyclerView, dx, dy);

      RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
      int visibleItemCount = recyclerView.getChildCount();
      int totalItemCount = recyclerView.getLayoutManager().getItemCount();
      int firstVisibleItem;

      if (layoutManager instanceof LinearLayoutManager) {
        firstVisibleItem =
            ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
      } else {
        firstVisibleItem =
            ((GridLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
      }

      if (totalItemCount > 0 && firstVisibleItem + visibleItemCount >= totalItemCount - mTreshold) {
        mEventListener.onScrollToEnd();
      }
    }
 public void onScrolled(RecyclerView paramRecyclerView, int paramInt1, int paramInt2) {
   super.onScrolled(paramRecyclerView, paramInt1, paramInt2);
   this.visibleItemCount = paramRecyclerView.getChildCount();
   this.totalItemCount = this.linearLayoutManager.getItemCount();
   this.firstVisibleItem = this.linearLayoutManager.findFirstVisibleItemPosition();
   if (this.totalItemCount < this.previousTotal) {
     this.previousTotal = 0;
     if (this.totalItemCount == 0) {
       this.loading = true;
     }
   }
   if ((this.loading) && (this.totalItemCount > this.previousTotal)) {
     this.loading = false;
     this.previousTotal = this.totalItemCount;
   }
   if ((this.loadMoreAllowed)
       && (!this.loading)
       && (this.totalItemCount - this.visibleItemCount <= this.firstVisibleItem + 3)) {
     onLoadMore();
     this.loading = true;
   }
 }
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    //  int lastVisibleItemPosition = -1;
    if (layoutManagerType == null) {
      if (layoutManager instanceof LinearLayoutManager) {
        layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
      } else if (layoutManager instanceof GridLayoutManager) {
        layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
      } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
      } else {
        throw new RuntimeException(
            "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
      }
    }

    switch (layoutManagerType) {
      case LINEAR:
        lastVisibleItemPosition =
            ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
        break;
      case GRID:
        lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
        break;
      case STAGGERED_GRID:
        StaggeredGridLayoutManager staggeredGridLayoutManager =
            (StaggeredGridLayoutManager) layoutManager;
        if (lastPositions == null) {
          lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
        }
        staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
        lastVisibleItemPosition = findMax(lastPositions);
        break;
    }
  }
 @Override
 public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
   super.onScrollStateChanged(recyclerView, newState);
 }
Exemplo n.º 29
0
 @Override
 public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
   super.onScrolled(recyclerView, dx, dy);
 }
 @Override
 public void onScrolled(RecyclerView list, int dx, int dy) {
   super.onScrolled(list, dx, dy);
   scrollY += dy;
   onCourseListScrollChanged(scrollY);
 }