androidx.recyclerview.widget.RecyclerView Java Examples
The following examples show how to use
androidx.recyclerview.widget.RecyclerView.
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: ExpandCard.java From Pixiv-Shaft with MIT License | 6 votes |
public void close() { if(isExpand){ ViewGroup.LayoutParams layoutParams = getLayoutParams(); layoutParams.height = maxHeight; for (int i = 0; i < getChildCount(); i++) { if (getChildAt(i) instanceof RecyclerView) { final RecyclerView recyclerView = ((RecyclerView) getChildAt(i)); if (recyclerView.getLayoutManager() instanceof ScrollChange) { ((ScrollChange) recyclerView.getLayoutManager()).setScrollEnabled(false); } } } setLayoutParams(layoutParams); isExpand = false; } }
Example #2
Source File: GridDividerDecoration.java From pandora with Apache License 2.0 | 6 votes |
private boolean isLastRow(RecyclerView parent, int pos, int spanCount, int childCount) { RecyclerView.LayoutManager layoutManager = parent.getLayoutManager(); if (layoutManager instanceof GridLayoutManager) { int lines = childCount % spanCount == 0 ? childCount / spanCount : childCount / spanCount + 1; return lines == pos / spanCount + 1; } else if (layoutManager instanceof StaggeredGridLayoutManager) { int orientation = ((StaggeredGridLayoutManager) layoutManager) .getOrientation(); if (orientation == StaggeredGridLayoutManager.VERTICAL) { childCount = childCount - childCount % spanCount; if (pos >= childCount) return true; } else { if ((pos + 1) % spanCount == 0) { return true; } } } return false; }
Example #3
Source File: ScrollingHelper.java From BaldPhone with Apache License 2.0 | 6 votes |
@Override public void onChanged() { if (child instanceof RecyclerView) { RecyclerView.Adapter<?> adapter = ((RecyclerView) child).getAdapter(); if (adapter != null && emptyView != null) { if (adapter.getItemCount() == 0) { if (!gone) setArrowsVisibility(false); if (emptyView instanceof TextView) { ((TextView) emptyView).setText(empty); } else emptyView.setVisibility(VISIBLE); } else { if (emptyView instanceof TextView) { ((TextView) emptyView).setText(""); } else emptyView.setVisibility(INVISIBLE); if (!gone) setArrowsVisibility(true); } } } }
Example #4
Source File: ReorderDecoration.java From RecyclerExt with Apache License 2.0 | 6 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); if (dragState == DragState.ENDED) { finishReorder(view); return; } int itemPosition = recyclerView.getChildAdapterPosition(view); if (itemPosition == selectedDragItemPosition) { view.setVisibility(View.INVISIBLE); return; } //Make sure the view is visible view.setVisibility(View.VISIBLE); //Calculate the new offsets updateFloatingItemCenter(); setVerticalOffsets(view, itemPosition, floatingItemCenter, outRect); setHorizontalOffsets(view, itemPosition, floatingItemCenter, outRect); }
Example #5
Source File: GridSpacingItemDecoration.java From MyBookshelf with GNU General Public License v3.0 | 6 votes |
private void drawVertical(Canvas canvas, RecyclerView parent) { final int top = parent.getPaddingTop(); final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom(); final int childSize = parent.getChildCount(); for (int i = 0; i < childSize; i++) { final View child = parent.getChildAt(i); RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); final int left = child.getRight() + layoutParams.rightMargin; final int right = left + space; if (mDivider != null) { mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); } if (mPaint != null) { canvas.drawRect(left, top, right, bottom, mPaint); } } }
Example #6
Source File: SectionedRecyclerViewAdapter.java From SectionedRecyclerViewAdapter with MIT License | 6 votes |
private RecyclerView.ViewHolder getItemViewHolder(final ViewGroup parent, final Section section) { View view; if (section.isItemViewWillBeProvided()) { view = section.getItemView(parent); if (view == null) { throw new NullPointerException("Section.getItemView() returned null"); } } else { final Integer resId = section.getItemResourceId(); if (resId == null) { throw new NullPointerException("Missing 'item' resource id"); } view = inflate(resId, parent); } return section.getItemViewHolder(view); }
Example #7
Source File: ItemFragment.java From materialistic with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable final Bundle savedInstanceState) { if (isNewInstance()) { mFragmentView = inflater.inflate(R.layout.fragment_item, container, false); mEmptyView = mFragmentView.findViewById(R.id.empty); mRecyclerView = (RecyclerView) mFragmentView.findViewById(R.id.recycler_view); mRecyclerView.setLayoutManager(new SnappyLinearLayoutManager(getActivity(), true)); mItemDecoration = new CommentItemDecoration(getActivity()); mRecyclerView.addItemDecoration(mItemDecoration); mSwipeRefreshLayout = (SwipeRefreshLayout) mFragmentView.findViewById(R.id.swipe_layout); mSwipeRefreshLayout.setColorSchemeResources(R.color.white); mSwipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.redA200); mSwipeRefreshLayout.setOnRefreshListener(() -> { if (TextUtils.isEmpty(mItemId)) { return; } mCacheMode = ItemManager.MODE_NETWORK; if (mAdapter != null) { mAdapter.setCacheMode(mCacheMode); } loadKidData(); }); } return mFragmentView; }
Example #8
Source File: BaseQuickAdapter.java From BaseProject with Apache License 2.0 | 6 votes |
/** * add animation when you want to show time * * @param holder */ private void addAnimation(RecyclerView.ViewHolder holder) { if (mOpenAnimationEnable) { if (!mFirstOnlyEnable || holder.getLayoutPosition() > mLastPosition) { BaseAnimation animation = null; if (mCustomAnimation != null) { animation = mCustomAnimation; } else { animation = mSelectAnimation; } for (Animator anim : animation.getAnimators(holder.itemView)) { startAnim(anim, holder.getLayoutPosition()); } mLastPosition = holder.getLayoutPosition(); } } }
Example #9
Source File: GridSpacingItemDecoration.java From SSForms with GNU General Public License v3.0 | 6 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = parent.getChildAdapterPosition(view); int column = position % spanCount; if (includeEdge) { outRect.left = spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing) outRect.right = (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing) if (position < spanCount) { outRect.top = spacing; } outRect.bottom = spacing; } else { outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing) outRect.right = spacing - (column + 1) * spacing / spanCount; // spacing - (column + 1) * ((1f / spanCount) * spacing) if (position >= spanCount) { outRect.top = spacing; } } }
Example #10
Source File: ThemeSelectionDialogFragment.java From SAI with GNU General Public License v3.0 | 6 votes |
@Override protected void onContentViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onContentViewCreated(view, savedInstanceState); setTitle(R.string.installer_select_theme); getPositiveButton().setVisibility(View.GONE); getNegativeButton().setOnClickListener(v -> dismiss()); RecyclerView recycler = (RecyclerView) view; recycler.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)); ThemeAdapter adapter = new ThemeAdapter(requireContext()); adapter.setThemes(Theme.getInstance(requireContext()).getThemes()); adapter.setOnThemeInteractionListener(this); mBillingManager.getDonationStatus().observe(this, adapter::setDonationStatus); recycler.setAdapter(adapter); revealBottomSheet(); }
Example #11
Source File: LicensesActivity.java From SAI with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_licenses); RecyclerView recyclerView = findViewById(R.id.rv_licenses); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.getRecycledViewPool().setMaxRecycledViews(0, 16); LicensesAdapter adapter = new LicensesAdapter(this); recyclerView.setAdapter(adapter); LicensesViewModel viewModel = new ViewModelProvider(this).get(LicensesViewModel.class); viewModel.getLicenses().observe(this, adapter::setLicenses); }
Example #12
Source File: IndexFastScrollRecyclerSection.java From AlphabetIndex-Fast-Scroll-RecyclerView with Apache License 2.0 | 5 votes |
public void setAdapter(RecyclerView.Adapter adapter) { if (adapter instanceof SectionIndexer) { adapter.registerAdapterDataObserver(this); mIndexer = (SectionIndexer) adapter; mSections = (String[]) mIndexer.getSections(); } }
Example #13
Source File: LocationActivityAdapter.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public boolean isEnabled(RecyclerView.ViewHolder holder) { int viewType = holder.getItemViewType(); if (viewType == 6) { return !(LocationController.getInstance(currentAccount).getSharingLocationInfo(dialogId) == null && gpsLocation == null); } return viewType == 1 || viewType == 3 || viewType == 7; }
Example #14
Source File: DefaultItemDecoration.java From SwipeRecyclerView with Apache License 2.0 | 5 votes |
private int getSpanCount(RecyclerView.LayoutManager layoutManager) { if (layoutManager instanceof GridLayoutManager) { return ((GridLayoutManager)layoutManager).getSpanCount(); } else if (layoutManager instanceof StaggeredGridLayoutManager) { return ((StaggeredGridLayoutManager)layoutManager).getSpanCount(); } return 1; }
Example #15
Source File: GeoPackageAdapter.java From geopackage-mapcache-android with MIT License | 5 votes |
/** * Bind the Header object of a geopackage view * @param holder - GeoPackageHeaderViewHolder * @param position - position to bind (should be 0) */ private void bindHeader(RecyclerView.ViewHolder holder, int position){ if(holder instanceof GeoPackageHeaderViewHolder){ GeoPackageHeaderViewHolder viewHolder = (GeoPackageHeaderViewHolder)holder; viewHolder.getTitle().setText("GeoPackages"); } }
Example #16
Source File: ViewPagerLayoutManager.java From OmegaRecyclerView with MIT License | 5 votes |
private int scrollBy(int amount, RecyclerView.Recycler recycler) { if (getChildCount() == 0) { return 0; } Direction direction = Direction.fromDelta(amount); int leftToScroll = calculateAllowedScrollIn(direction); if (leftToScroll <= 0) { return 0; } int delta = direction.applyTo(Math.min(leftToScroll, Math.abs(amount))); mScrolled += delta; if (mPendingScroll != 0) { mPendingScroll -= delta; } mOrientationHelper.offsetChildren(-delta, this); if (mIsInfinite || mOrientationHelper.hasNewBecomeVisible(this)) { fill(recycler); } notifyScroll(); applyItemTransformToChildren(); return delta; }
Example #17
Source File: ThemesHorizontalListCell.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { InnerThemeView view = (InnerThemeView) holder.itemView; ArrayList<Theme.ThemeInfo> arrayList; int p = position; if (position < defaultThemes.size()) { arrayList = defaultThemes; } else { arrayList = darkThemes; p -= defaultThemes.size(); } view.setTheme(arrayList.get(p), position == getItemCount() - 1, position == 0); }
Example #18
Source File: MoreBundleFragment.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
@Override public Observable<HomeEvent> visibleBundles() { return RxRecyclerView.scrollEvents(bundlesList) .subscribeOn(AndroidSchedulers.mainThread()) .map(recyclerViewScrollEvent -> layoutManager.findFirstVisibleItemPosition()) .filter(position -> position != RecyclerView.NO_POSITION) .distinctUntilChanged() .map(visibleItem -> new HomeEvent(adapter.getBundle(visibleItem), visibleItem, null)); }
Example #19
Source File: BookListFragment.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
@Override protected void bindView() { super.bindView(); unbinder = ButterKnife.bind(this, view); int bookshelfLayout = preferences.getInt("bookshelfLayout", 0); if (bookshelfLayout == 0) { rvBookshelf.setLayoutManager(new LinearLayoutManager(getContext())); bookShelfAdapter = new BookShelfListAdapter(getActivity()); } else { rvBookshelf.setLayoutManager(new GridLayoutManager(getContext(), bookshelfLayout + 2)); bookShelfAdapter = new BookShelfGridAdapter(getActivity()); } rvBookshelf.setAdapter((RecyclerView.Adapter) bookShelfAdapter); refreshLayout.setColorSchemeColors(ThemeStore.accentColor(MApplication.getInstance())); }
Example #20
Source File: SimpleAdapter.java From UltimateRecyclerView with Apache License 2.0 | 5 votes |
@Override public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) { if (position < getItemCount() && (customHeaderView != null ? position <= stringList.size() : position < stringList.size()) && (customHeaderView != null ? position > 0 : true)) { ((ViewHolder) holder).textViewSample.setText(stringList.get(customHeaderView != null ? position - 1 : position)); // ((ViewHolder) holder).itemView.setActivated(selectedItems.get(position, false)); if (mDragStartListener != null) { // ((ViewHolder) holder).imageViewSample.setOnTouchListener(new View.OnTouchListener() { // @Override // public boolean onTouch(View v, MotionEvent event) { // if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) { // mDragStartListener.onStartDrag(holder); // } // return false; // } // }); ((ViewHolder) holder).item_view.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return false; } }); } } }
Example #21
Source File: ApplicationFragment.java From EdXposedManager with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_app_list, container, false); mSwipeRefreshLayout = view.findViewById(R.id.swipeRefreshLayout); RecyclerView mRecyclerView = view.findViewById(R.id.recyclerView); Button mSettingsButton = view.findViewById(R.id.btnSettings); mSettingsButton.setOnClickListener(v -> startActivity(new Intent(requireContext(), SettingsActivity.class))); if (!XposedApp.getPreferences().getBoolean("black_white_list_switch", false)) { view.findViewById(R.id.cardAppListWarning).setVisibility(View.VISIBLE); } final boolean isWhiteListMode = isWhiteListMode(); mAppAdapter = new ApplicationListAdapter(requireActivity(), isWhiteListMode); mRecyclerView.setAdapter(mAppAdapter); mAppAdapter.setCallback(this); mSwipeRefreshLayout.setRefreshing(true); mSwipeRefreshLayout.setOnRefreshListener(mAppAdapter::refresh); mSearchListener = new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { mAppAdapter.filter(query); return false; } @Override public boolean onQueryTextChange(String newText) { mAppAdapter.filter(newText); return false; } }; return view; }
Example #22
Source File: ThemeActivity.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { switch (viewType) { case 0: { return new RecyclerListView.Holder(new InnerAccentView(mContext)); } case 1: default: { return new RecyclerListView.Holder(new InnerCustomAccentView(mContext)); } } }
Example #23
Source File: AboutAdapter.java From Weather with GNU General Public License v3.0 | 5 votes |
@NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { // Inflate out card list item View view; switch (viewType) { case AboutModel.ABOUT_1: view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.about_card_layout_1, parent, false); return new About1ViewHolder(view); case AboutModel.ABOUT_2: view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.about_card_layout_2, parent, false); return new About2ViewHolder(view); case AboutModel.ABOUT_3: view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.about_card_layout_3, parent, false); return new About3ViewHolder(view); case AboutModel.ABOUT_4: view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.about_card_layout_4, parent, false); return new About4ViewHolder(view); case AboutModel.ABOUT_5: view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.about_card_layout_5, parent, false); return new About5ViewHolder(view); default: return null; } }
Example #24
Source File: WeSwipeHelper.java From monero-wallet-android-app with MIT License | 5 votes |
private int checkHorizontalSwipe(RecyclerView.ViewHolder viewHolder, int flags) { if ((flags & (LEFT | RIGHT)) != 0) { final int dirFlag = mDx > 0 ? RIGHT : LEFT; if (mVelocityTracker != null && mActivePointerId > -1) { mVelocityTracker.computeCurrentVelocity(PIXELS_PER_SECOND, mCallback.getSwipeVelocityThreshold(mMaxSwipeVelocity)); final float xVelocity = mVelocityTracker.getXVelocity(mActivePointerId); final float yVelocity = mVelocityTracker.getYVelocity(mActivePointerId); final int velDirFlag = xVelocity > 0f ? RIGHT : LEFT; final float absXVelocity = Math.abs(xVelocity); if ((velDirFlag & flags) != 0 && dirFlag == velDirFlag && absXVelocity >= mCallback.getSwipeEscapeVelocity(mSwipeEscapeVelocity) && absXVelocity > Math.abs(yVelocity)) { return velDirFlag; } } int width = mRecyclerView.getWidth(); //If the target layout follows the item view, the RecyclerView is wider than itself. if (swipeTypeIsFollowing()) { float swipeWidth = getSwipeWidth(viewHolder); width += (int) swipeWidth; } final float threshold = width * mCallback .getSwipeThreshold(viewHolder); if ((flags & dirFlag) != 0 && Math.abs(mDx) > threshold) { return dirFlag; } } return 0; }
Example #25
Source File: SubredditMultiselectionRecyclerViewAdapter.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof SubscribedSubredditViewHolder) { ((SubscribedSubredditViewHolder) holder).nameTextView.setText(subscribedSubreddits.get(position).getName()); glide.load(subscribedSubreddits.get(position).getIconUrl()) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .error(glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) .into(((SubscribedSubredditViewHolder) holder).iconImageView); if (subscribedSubreddits.get(position).isSelected()) { ((SubscribedSubredditViewHolder) holder).checkBox.setChecked(true); } else { ((SubscribedSubredditViewHolder) holder).checkBox.setChecked(false); } ((SubscribedSubredditViewHolder) holder).checkBox.setOnClickListener(view -> { if (subscribedSubreddits.get(position).isSelected()) { ((SubscribedSubredditViewHolder) holder).checkBox.setChecked(false); subscribedSubreddits.get(position).setSelected(false); } else { ((SubscribedSubredditViewHolder) holder).checkBox.setChecked(true); subscribedSubreddits.get(position).setSelected(true); } }); ((SubscribedSubredditViewHolder) holder).itemView.setOnClickListener(view -> ((SubscribedSubredditViewHolder) holder).checkBox.performClick()); } }
Example #26
Source File: StickyNavLayout.java From NewFastFrame with Apache License 2.0 | 5 votes |
@Override public boolean onNestedPreFling(View target, float velocityX, float velocityY) { final RecyclerView recyclerView = (RecyclerView) target; final View firstChild = recyclerView.getChildAt(0); final int childAdapterPosition = recyclerView.getChildAdapterPosition(firstChild); Log.e("onNestedPreFling", "position:" + childAdapterPosition + " x:" + firstChild.getY() + ""); //不做拦截 可以传递给子View return false; }
Example #27
Source File: InfoFragment.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 5 votes |
@NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { final int resource = viewType == kViewType_Service ? R.layout.layout_info_service_item : viewType == kViewType_Characteristic ? R.layout.layout_info_characteristic_item : R.layout.layout_info_descriptor_item; View view = LayoutInflater.from(parent.getContext()).inflate(resource, parent, false); switch (viewType) { case kViewType_Characteristic: return new CharacteristicViewHolder(view); case kViewType_Descriptor: return new DescriptorViewHolder(view); default: return new ServiceViewHolder(view); } }
Example #28
Source File: UserListingRecyclerViewAdapter.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { if (holder instanceof UserListingRecyclerViewAdapter.DataViewHolder) { glide.clear(((UserListingRecyclerViewAdapter.DataViewHolder) holder).iconGifImageView); ((UserListingRecyclerViewAdapter.DataViewHolder) holder).subscribeButton.setVisibility(View.GONE); } }
Example #29
Source File: ScaleInBottomAnimator.java From recyclerview-animators with Apache License 2.0 | 5 votes |
@Override protected void animateRemoveImpl(final RecyclerView.ViewHolder holder) { ViewCompat.animate(holder.itemView) .scaleX(0) .scaleY(0) .setDuration(getRemoveDuration()) .setInterpolator(mInterpolator) .setListener(new DefaultRemoveVpaListener(holder)) .setStartDelay(getRemoveDelay(holder)) .start(); }
Example #30
Source File: FamiliarWrapRecyclerViewAdapter.java From FamiliarRecyclerView with MIT License | 5 votes |
@Override public void onViewRecycled(RecyclerView.ViewHolder holder) { super.onViewRecycled(holder); int position = holder.getAdapterPosition(); if (null == mReqAdapter || isHeaderView(position) || isFooterView(position)) { return; } mReqAdapter.onViewRecycled(holder); }