Java Code Examples for androidx.recyclerview.widget.RecyclerView#postDelayed()

The following examples show how to use androidx.recyclerview.widget.RecyclerView#postDelayed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EpoxyModelTouchCallback.java    From epoxy with Apache License 2.0 6 votes vote down vote up
@Override
protected void clearView(final RecyclerView recyclerView, EpoxyViewHolder viewHolder) {
  super.clearView(recyclerView, viewHolder);
  //noinspection unchecked
  clearView((T) viewHolder.getModel(), viewHolder.itemView);

  // If multiple touch helpers are in use, one touch helper can pick up buffered touch inputs
  // immediately after another touch event finishes. This leads to things like a view being
  // selected for drag when another view finishes its swipe off animation. To prevent that we
  // keep the recyclerview marked as having an active selection for a brief period after a
  // touch event ends.
  recyclerView.postDelayed(new Runnable() {
    @Override
    public void run() {
      clearRecyclerViewSelectionMarker(recyclerView);
    }
  }, TOUCH_DEBOUNCE_MILLIS);
}
 
Example 2
Source File: SearchPreferenceResult.java    From SearchPreference with MIT License 5 votes vote down vote up
private void doHighlight(final PreferenceFragmentCompat prefsFragment) {
    final Preference prefResult = prefsFragment.findPreference(getKey());

    if (prefResult == null) {
        Log.e("doHighlight", "Preference not found on given screen");
        return;
    }
    final RecyclerView recyclerView = prefsFragment.getListView();
    final RecyclerView.Adapter<?> adapter = recyclerView.getAdapter();
    if (adapter instanceof PreferenceGroup.PreferencePositionCallback) {
        PreferenceGroup.PreferencePositionCallback callback = (PreferenceGroup.PreferencePositionCallback) adapter;
        final int position = callback.getPreferenceAdapterPosition(prefResult);
        if (position != RecyclerView.NO_POSITION) {
            recyclerView.scrollToPosition(position);
            recyclerView.postDelayed(() -> {
                RecyclerView.ViewHolder holder = recyclerView.findViewHolderForAdapterPosition(position);
                if (holder != null) {
                    Drawable background = holder.itemView.getBackground();
                    if (Build.VERSION.SDK_INT >= 21 && background instanceof RippleDrawable) {
                        forceRippleAnimation((RippleDrawable) background);
                        return;
                    }
                }
                highlightFallback(prefsFragment, prefResult);
            }, 200);
            return;
        }
    }
    highlightFallback(prefsFragment, prefResult);
}
 
Example 3
Source File: BaseFragment.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
private void setupSkeleton(RecyclerView recyclerView, MyAdapter mAdapter) {
    final SkeletonScreen skeletonScreen = Skeleton.bind(recyclerView)
            .adapter(mAdapter)
            .shimmer(true)
            .angle(20)
            .frozen(false)
            .duration(500)
            .count(10)
            .load(R.layout.demo_info_skeleton_item)
            .show(); //default count is 10
    recyclerView.postDelayed(skeletonScreen::hide, 1000);
}
 
Example 4
Source File: BaseQuickAdapter.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
/**
 * check if full page after {@link #setNewData(List)}, if full, it will enable load more again.
 * <p>
 * 不是配置项!!
 * <p>
 * 这个方法是用来检查是否满一屏的,所以只推荐在 {@link #setNewData(List)} 之后使用
 * 原理很简单,先关闭 load more,检查完了再决定是否开启
 * <p>
 * 不是配置项!!
 *
 * @param recyclerView your recyclerView
 * @see #setNewData(List)
 */
public void disableLoadMoreIfNotFullPage(RecyclerView recyclerView) {
    setEnableLoadMore(false);
    if (recyclerView == null) return;
    RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
    if (manager == null) return;
    if (manager instanceof LinearLayoutManager) {
        final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) manager;
        recyclerView.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (isFullScreen(linearLayoutManager)) {
                    setEnableLoadMore(true);
                }
            }
        }, 50);
    } else if (manager instanceof StaggeredGridLayoutManager) {
        final StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) manager;
        recyclerView.postDelayed(new Runnable() {
            @Override
            public void run() {
                final int[] positions = new int[staggeredGridLayoutManager.getSpanCount()];
                staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(positions);
                int pos = getTheBiggestNumber(positions) + 1;
                if (pos != getItemCount()) {
                    setEnableLoadMore(true);
                }
            }
        }, 50);
    }
}