Java Code Examples for android.support.v7.widget.RecyclerView#postDelayed()

The following examples show how to use android.support.v7.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: PathLayoutManager.java    From PathLayoutManager with Apache License 2.0 6 votes vote down vote up
private void delayNotifyDataSetChanged(final RecyclerView recyclerView) {
    if (recyclerView.isComputingLayout()) {
        isPosting = true;
        recyclerView.postDelayed(new Runnable() {
            @Override
            public void run() {
                delayNotifyDataSetChanged(recyclerView);
            }
        }, 5);
    } else {
        if (isPosting) {
            isPosting = false;
            recyclerView.getAdapter().notifyDataSetChanged();
        }
    }
}
 
Example 2
Source File: PicassoOnScrollListener.java    From AndroidAgeraTutorial with Apache License 2.0 6 votes vote down vote up
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {
    if(scrollState == RecyclerView.SCROLL_STATE_IDLE) {
        recyclerView.removeCallbacks(mSettlingResumeRunnable);
        sPicasso.resumeTag(TAG);

    } else if(scrollState == RecyclerView.SCROLL_STATE_SETTLING) {
        mSettlingResumeRunnable = new Runnable() {
            @Override
            public void run() {
                sPicasso.resumeTag(TAG);
            }
        };

        recyclerView.postDelayed(mSettlingResumeRunnable, SETTLING_DELAY);

    }
    //else {
    //    sPicasso.pauseTag(TAG);
    //}
}
 
Example 3
Source File: SampleActivity.java    From RecyclerViewTools with Apache License 2.0 6 votes vote down vote up
@Override public void onLoadMore(RecyclerView recyclerView) {
   toast("Load more");

   recyclerView.postDelayed(new Runnable() {
      @Override public void run() {

         for (int i = 0; i < 5; i++) {
            adapter.data.add(Data.newRandom(SampleActivity.this));
         }

         if (recycler.getLayoutManager() instanceof StaggeredGridLayoutManager) {
            StaggeredLayoutManagerUtils.onItemChanged(recycler, 0);
         }
         adapter.notifyDataSetChanged();

      }
   }, 1000);
}
 
Example 4
Source File: FastScrollToTop.java    From RecyclerViewTools with Apache License 2.0 6 votes vote down vote up
public FastScrollToTop(RecyclerView recyclerView, int threshold, int lastScroll, long scrollToPositionDelay) {
   this.lastScroll = lastScroll;

   if (recyclerView.getChildCount() == 0) {
      weakRecycler = null;
      return;
   }

   View v = recyclerView.getChildAt(0);
   int position = recyclerView.getChildAdapterPosition(v);
   if (position < threshold) {
      recyclerView.smoothScrollToPosition(0);
      weakRecycler = null;
      return;
   }

   // here is where the fun happens
   weakRecycler = new WeakReference<>(recyclerView);
   recyclerView.smoothScrollToPosition(0);
   recyclerView.postDelayed(runAfterSpeedUp, scrollToPositionDelay);
}
 
Example 5
Source File: BaseQuickAdapter.java    From imsdk-android with MIT License 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 ((linearLayoutManager.findLastCompletelyVisibleItemPosition() + 1) != getItemCount()) {
                    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);
    }
}
 
Example 6
Source File: BaseQuickAdapter.java    From demo4Fish with MIT License 5 votes vote down vote up
/**
 * check if full page after {@link #setNewData(List)}, if full, it will enable load more again.
 *
 * @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 ((linearLayoutManager.findLastCompletelyVisibleItemPosition() + 1) != getItemCount()) {
                    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);
    }
}
 
Example 7
Source File: BaseQuickAdapter.java    From JD-Test 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.
 *
 * @param recyclerView your recyclerView
 * @see #setNewData(List)
 */
public void disableLoadMoreIfNotFullPage(RecyclerView recyclerView) {
    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 ((linearLayoutManager.findLastCompletelyVisibleItemPosition() + 1) != getItemCount()) {
                    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);
    }
}
 
Example 8
Source File: DiffRcvActivity.java    From CommonAdapter with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RecyclerView recyclerView = new RecyclerView(this);
    LayoutUtil.setContentView(this, recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    final DiffRcvAdapter<DemoModel> adapter = new DiffRcvAdapter<DemoModel>(DataManager.loadData(this, 3)) {
        @NonNull
        @Override
        public AdapterItem createItem(Object type) {
            return new TextItem();
        }

        @Override
        protected boolean isContentSame(DemoModel oldItemData, DemoModel newItemData) {
            return oldItemData.content.equals(newItemData.content);
        }
    };
    
    recyclerView.setAdapter(adapter);

    recyclerView.postDelayed(new Runnable() {
        @Override
        public void run() {
            adapter.setData(DataManager.loadData(DiffRcvActivity.this, 3));
        }
    }, 1000);
}
 
Example 9
Source File: CBAlignTextViewRecyclerViewExample.java    From AlignTextView with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager
            .LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_align_text_view_recycler_view);

    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    final CBAlignTextViewAdapter adapter = new CBAlignTextViewAdapter(this);
    List<String> texts = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        texts.add("欢迎访问codeboy.me,序号:" + i + "欢迎访问codeboy.me,序号:" + i + "欢迎访问codeboy.me,序号:" + i);
    }
    adapter.setData(texts);
    recyclerView.setAdapter(adapter);

    recyclerView.postDelayed(new Runnable() {
        @Override
        public void run() {
            List<String> texts2 = new ArrayList<>();
            for (int i = 20; i < 40; i++) {
                texts2.add("欢迎访问codeboy.me,序号:" + i);
            }
            adapter.appendData(texts2);
            adapter.notifyDataSetChanged();
        }
    }, 100);

}
 
Example 10
Source File: AlignTextViewRecyclerViewExample.java    From AlignTextView with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager
            .LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_align_text_view_recycler_view);

    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    final AlignTextViewAdapter adapter = new AlignTextViewAdapter(this);
    List<String> texts = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        texts.add("欢迎访问codeboy.me,序号:" + i);
    }
    adapter.setData(texts);
    recyclerView.setAdapter(adapter);

    recyclerView.postDelayed(new Runnable() {
        @Override
        public void run() {
            List<String> texts2 = new ArrayList<>();
            for (int i = 20; i < 40; i++) {
                texts2.add("欢迎访问codeboy.me,序号:" + i);
            }
            adapter.appendData(texts2);
            adapter.notifyDataSetChanged();
        }
    }, 5000);

}
 
Example 11
Source File: TextViewRecyclerViewExample.java    From AlignTextView with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager
            .LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_align_text_view_recycler_view);

    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    final TextViewAdapter adapter = new TextViewAdapter(this);
    List<String> texts = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        texts.add("欢迎访问codeboy.me,序号:" + i + "欢迎访问codeboy.me,序号:" + i + "欢迎访问codeboy.me,序号:" + i);
    }
    adapter.setData(texts);
    recyclerView.setAdapter(adapter);

    recyclerView.postDelayed(new Runnable() {
        @Override
        public void run() {
            List<String> texts2 = new ArrayList<>();
            for (int i = 20; i < 40; i++) {
                texts2.add("欢迎访问codeboy.me,序号:" + i);
            }
            adapter.appendData(texts2);
            adapter.notifyDataSetChanged();
        }
    }, 100);

}
 
Example 12
Source File: HeaderFooterActivity.java    From CommonAdapter with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    recyclerView = new RecyclerView(this);
    LayoutUtil.setContentView(this, recyclerView);

    layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    layoutManager1 = new GridLayoutManager(this, 2);
    layoutManager2 = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(layoutManager);

    data.addAll(DataManager.loadData(getBaseContext()));

    final CommonRcvAdapter<DemoModel> adapter = initAdapter();

    wrapper = new RcvAdapterWrapper(adapter, recyclerView.getLayoutManager());

    final Button header = new Button(this);
    header.setText("Header\n\n (click to add)");
    header.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, 300));

    final Button footer = new Button(this);
    footer.setText("footer");

    wrapper.setHeaderView(header);
    wrapper.setFooterView(null);

    final Button empty = new Button(this);
    empty.setBackgroundColor(Color.RED);
    empty.setText("empty text");
    wrapper.setEmptyView(empty, recyclerView);

    recyclerView.setAdapter(wrapper);
    
    handItemClick();

    recyclerView.postDelayed(new Runnable() {
        @Override
        public void run() {
            data.reset(DataManager.loadData(getBaseContext(),10));
            wrapper.setFooterView(footer);
        }
    }, 1000);
}
 
Example 13
Source File: BehaviorActivity.java    From AndroidPlayground with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_behavoir);

    final TextView title = findById(this, R.id.mTvTitle);
    LinearLayout lLStatistics = findById(this, R.id.mLlStatistics);

    NestedScrollView nestedScrollView = findById(this, R.id.mNestedScrollView);
    nestedScrollView.getViewTreeObserver()
            .addOnScrollChangedListener(new NSVHeaderScrollOutPercentListener(
                    new NSVHeaderScrollOutPercentListener.HeaderScrollOutPercentageListener() {
                        @Override
                        public void onHeaderScrollOffPercent(float percent) {
                            int alpha = (int) (percent * 191);
                            title.setTextColor(alpha << 24 | 0xFFFFFF);
                        }
                    }, lLStatistics, 0.47F, 0.64F));

    final TextView tvName = findById(this, R.id.mTvPublisherName);

    RecyclerView detailRV = findById(this, R.id.mRvDetails);
    final DetailAdapter detailAdapter = new DetailAdapter(this);
    detailRV.setNestedScrollingEnabled(false);
    detailRV.setLayoutManager(new FixedHeightGridLayoutManager(this, 4));
    detailRV.setAdapter(detailAdapter);

    RecyclerView publishersRV = findById(this, R.id.mRvPublishers);
    final PublisherAdapter publisherAdapter =
            new PublisherAdapter(new PublisherAdapter.OnClickListener() {

                @Override
                public void onClicked(String name) {
                    tvName.setText(name + " 的打赏详情");
                    detailAdapter.setName(name);
                }
            });
    publishersRV.setLayoutManager(
            new WrapContentHorizontalLinearLayoutManager(this, false, 59, 53, 5, 5, 0, 0));
    publishersRV.setAdapter(publisherAdapter);

    detailRV.postDelayed(new Runnable() {
        @Override
        public void run() {
            detailAdapter.setName("A");
            detailAdapter.setContentCount(100);
            publisherAdapter.setContentCount(10);
            tvName.setText("A 的打赏详情");
        }
    }, 200);

    findById(this, R.id.mIbClose).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            publisherAdapter.setContentCount(3);
        }
    });
}