Java源码示例:androidx.recyclerview.widget.RecyclerView.OnScrollListener

示例1
private void initializeResources() {
  long oldThreadId = threadId;

  int startingPosition  = this.getActivity().getIntent().getIntExtra(ConversationActivity.STARTING_POSITION_EXTRA, -1);

  this.recipient         = Recipient.live(getActivity().getIntent().getParcelableExtra(ConversationActivity.RECIPIENT_EXTRA));
  this.threadId          = this.getActivity().getIntent().getLongExtra(ConversationActivity.THREAD_ID_EXTRA, -1);
  this.unknownSenderView = new UnknownSenderView(getActivity(), recipient.get(), threadId, () -> clearHeaderIfNotTyping(getListAdapter()));

  deferred.setDeferred(true);
  conversationViewModel.onConversationDataAvailable(threadId, startingPosition);

  OnScrollListener scrollListener = new ConversationScrollListener(getActivity());
  list.addOnScrollListener(scrollListener);

  if (oldThreadId != threadId) {
    ApplicationContext.getInstance(requireContext()).getTypingStatusRepository().getTypists(oldThreadId).removeObservers(this);
  }
}
 
示例2
@SuppressWarnings("unchecked")
GridModel(
        GridHost<K> host,
        ItemKeyProvider<K> keyProvider,
        SelectionPredicate<K> selectionPredicate) {

    checkArgument(host != null);
    checkArgument(keyProvider != null);
    checkArgument(selectionPredicate != null);

    mHost = host;
    mKeyProvider = keyProvider;
    mSelectionPredicate = selectionPredicate;

    mScrollListener = new OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            GridModel.this.onScrolled(recyclerView, dx, dy);
        }
    };

    mHost.addOnScrollListener(mScrollListener);
}
 
示例3
@OnUnbind
static void onUnbind(
    ComponentContext context,
    SectionsRecyclerView sectionsRecycler,
    @Prop Binder<RecyclerView> binder,
    @Prop(optional = true) RecyclerEventsController recyclerEventsController,
    @Prop(optional = true, varArg = "onScrollListener")
        List<OnScrollListener> onScrollListeners) {
  final LithoRecylerView recyclerView = (LithoRecylerView) sectionsRecycler.getRecyclerView();

  if (recyclerView == null) {
    throw new IllegalStateException(
        "RecyclerView not found, it should not be removed from SwipeRefreshLayout "
            + "before unmounting");
  }

  binder.unbind(recyclerView);

  if (recyclerEventsController != null) {
    recyclerEventsController.setSectionsRecyclerView(null);
  }

  if (onScrollListeners != null) {
    for (OnScrollListener onScrollListener : onScrollListeners) {
      recyclerView.removeOnScrollListener(onScrollListener);
    }
  }

  recyclerView.setTouchInterceptor(null);

  sectionsRecycler.setOnRefreshListener(null);
}
 
示例4
private void initializeResources() {
    this.chatId            = this.getActivity().getIntent().getIntExtra(ConversationActivity.CHAT_ID_EXTRA, -1);
    this.recipient         = Recipient.from(getActivity(), Address.fromChat((int)this.chatId));
    this.startingPosition  = this.getActivity().getIntent().getIntExtra(ConversationActivity.STARTING_POSITION_EXTRA, -1);
    this.firstLoad         = true;

    OnScrollListener scrollListener = new ConversationScrollListener(getActivity());
    list.addOnScrollListener(scrollListener);
}
 
示例5
/**
 * See {@link BandSelectionHelper#create}.
 */
BandSelectionHelper(
        @NonNull BandHost<K> host,
        @NonNull AutoScroller scroller,
        @NonNull ItemKeyProvider<K> keyProvider,
        @NonNull SelectionTracker<K> selectionTracker,
        @NonNull BandPredicate bandPredicate,
        @NonNull FocusDelegate<K> focusDelegate,
        @NonNull OperationMonitor lock) {

    checkArgument(host != null);
    checkArgument(scroller != null);
    checkArgument(keyProvider != null);
    checkArgument(selectionTracker != null);
    checkArgument(bandPredicate != null);
    checkArgument(focusDelegate != null);
    checkArgument(lock != null);

    mHost = host;
    mKeyProvider = keyProvider;
    mSelectionTracker = selectionTracker;
    mBandPredicate = bandPredicate;
    mFocusDelegate = focusDelegate;
    mLock = lock;

    mHost.addOnScrollListener(
            new OnScrollListener() {
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    BandSelectionHelper.this.onScrolled(recyclerView, dx, dy);
                }
            });

    mScroller = scroller;

    mGridObserver = new GridModel.SelectionObserver<K>() {
        @Override
        public void onSelectionChanged(Set<K> updatedSelection) {
            mSelectionTracker.setProvisionalSelection(updatedSelection);
        }
    };
}
 
示例6
@Override
void addOnScrollListener(@NonNull OnScrollListener listener) {
    mRecyclerView.addOnScrollListener(listener);
}
 
示例7
@Override
void removeOnScrollListener(@NonNull OnScrollListener listener) {
    mRecyclerView.removeOnScrollListener(listener);
}
 
示例8
@OnBind
protected static void onBind(
    ComponentContext context,
    SectionsRecyclerView sectionsRecycler,
    @Prop Binder<RecyclerView> binder,
    @Prop(optional = true) final RecyclerEventsController recyclerEventsController,
    @Prop(optional = true, varArg = "onScrollListener") List<OnScrollListener> onScrollListeners,
    @Prop(optional = true) SnapHelper snapHelper,
    @Prop(optional = true) boolean pullToRefresh,
    @Prop(optional = true) LithoRecylerView.TouchInterceptor touchInterceptor,
    @Nullable @Prop(optional = true) final EventHandler refreshHandler) {

  // contentDescription should be set on the recyclerView itself, and not the sectionsRecycler.
  sectionsRecycler.setContentDescription(null);

  sectionsRecycler.setEnabled(pullToRefresh && refreshHandler != null);
  sectionsRecycler.setOnRefreshListener(
      new OnRefreshListener() {
        @Override
        public void onRefresh() {
          Recycler.dispatchPTRRefreshEvent(refreshHandler);
        }
      });

  final LithoRecylerView recyclerView = (LithoRecylerView) sectionsRecycler.getRecyclerView();

  if (recyclerView == null) {
    throw new IllegalStateException(
        "RecyclerView not found, it should not be removed from SwipeRefreshLayout "
            + "before unmounting");
  }

  if (onScrollListeners != null) {
    for (OnScrollListener onScrollListener : onScrollListeners) {
      recyclerView.addOnScrollListener(onScrollListener);
    }
  }

  if (touchInterceptor != null) {
    recyclerView.setTouchInterceptor(touchInterceptor);
  }

  // We cannot detach the snap helper in unbind, so it may be possible for it to get
  // attached twice which causes SnapHelper to raise an exception.
  if (snapHelper != null && recyclerView.getOnFlingListener() == null) {
    snapHelper.attachToRecyclerView(recyclerView);
  }

  binder.bind(recyclerView);

  if (recyclerEventsController != null) {
    recyclerEventsController.setSectionsRecyclerView(sectionsRecycler);
  }

  if (sectionsRecycler.hasBeenDetachedFromWindow()) {
    recyclerView.requestLayout();
    sectionsRecycler.setHasBeenDetachedFromWindow(false);
  }
}
 
示例9
/**
 * Add a listener to be notified on scroll events.
 */
abstract void addOnScrollListener(@NonNull OnScrollListener listener);
 
示例10
/**
 * Remove the listener.
 *
 * @param listener
 */
abstract void removeOnScrollListener(@NonNull OnScrollListener listener);