Java Code Examples for androidx.viewpager.widget.PagerAdapter#getCount()
The following examples show how to use
androidx.viewpager.widget.PagerAdapter#getCount() .
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: TabPageIndicator.java From material with Apache License 2.0 | 6 votes |
private void notifyDataSetInvalidated() { PagerAdapter adapter = mViewPager.getAdapter(); final int count = adapter.getCount(); for (int i = 0; i < count; i++) { TextView tv = getTabView(i); if(tv != null) { CharSequence title = adapter.getPageTitle(i); if (title == null) title = "NULL"; tv.setText(title); } } requestLayout(); }
Example 2
Source File: CircleIndicator.java From CircleIndicator with Apache License 2.0 | 6 votes |
@Override public void onChanged() { super.onChanged(); if (mViewpager == null) { return; } PagerAdapter adapter = mViewpager.getAdapter(); int newCount = adapter != null ? adapter.getCount() : 0; int currentCount = getChildCount(); if (newCount == currentCount) { // No change return; } else if (mLastPosition < newCount) { mLastPosition = mViewpager.getCurrentItem(); } else { mLastPosition = -1; } createIndicators(); }
Example 3
Source File: TabPageIndicator.java From arcusandroid with Apache License 2.0 | 6 votes |
public void notifyDataSetChanged() { mTabLayout.removeAllViews(); PagerAdapter adapter = mViewPager.getAdapter(); IconPagerAdapter iconAdapter = null; if (adapter instanceof IconPagerAdapter) { iconAdapter = (IconPagerAdapter)adapter; } final int count = adapter.getCount(); for (int i = 0; i < count; i++) { CharSequence title = adapter.getPageTitle(i); if (title == null) { title = EMPTY_TITLE; } int iconResId = 0; if (iconAdapter != null) { iconResId = iconAdapter.getIconResId(i); } addTab(i, title, iconResId); } if (mSelectedTabIndex > count) { mSelectedTabIndex = count - 1; } setCurrentItem(mSelectedTabIndex); requestLayout(); }
Example 4
Source File: RtlViewPager.java From rtl-viewpager with Apache License 2.0 | 6 votes |
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { // The documentation says that `getPageWidth(...)` returns the fraction of the _measured_ width that that page takes up. However, the code seems to // use the width so we will here too. final int width = getWidth(); PagerAdapter adapter = RtlViewPager.super.getAdapter(); if (isRtl() && adapter != null) { int count = adapter.getCount(); int remainingWidth = (int) (width * (1 - adapter.getPageWidth(position))) + positionOffsetPixels; while (position < count && remainingWidth > 0) { position += 1; remainingWidth -= (int) (width * adapter.getPageWidth(position)); } position = count - position - 1; positionOffsetPixels = -remainingWidth; positionOffset = positionOffsetPixels / (width * adapter.getPageWidth(position)); } mListener.onPageScrolled(position, positionOffset, positionOffsetPixels); }
Example 5
Source File: RtlViewPager.java From rtl-viewpager with Apache License 2.0 | 5 votes |
@Override public void onPageSelected(int position) { PagerAdapter adapter = RtlViewPager.super.getAdapter(); if (isRtl() && adapter != null) { position = adapter.getCount() - position - 1; } mListener.onPageSelected(position); }
Example 6
Source File: TabStripHelper.java From ProjectX with Apache License 2.0 | 5 votes |
int getPageCount() { if (mPager == null) return 0; final PagerAdapter adapter = mPager.getAdapter(); if (adapter == null) return 0; return adapter.getCount(); }
Example 7
Source File: CircleIndicator.java From CircleIndicator with Apache License 2.0 | 5 votes |
private void createIndicators() { PagerAdapter adapter = mViewpager.getAdapter(); int count; if (adapter == null) { count = 0; } else { count = adapter.getCount(); } createIndicators(count, mViewpager.getCurrentItem()); }
Example 8
Source File: ViewActions.java From Kore with Apache License 2.0 | 5 votes |
public static ViewAction setCurrentViewPagerItem(final int pageTitleResourceId) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return new TypeSafeMatcher<View>() { @Override protected boolean matchesSafely(View item) { return item instanceof ViewPager; } @Override public void describeTo(Description description) { description.appendText("is a SeekBar."); } }; } @Override public String getDescription() { return null; } @Override public void perform(UiController uiController, View view) { ViewPager viewPager = (ViewPager) view; String expectedTitle = view.getResources().getString(pageTitleResourceId); PagerAdapter pagerAdapter = viewPager.getAdapter(); for(int i = 0; i < pagerAdapter.getCount(); i++) { if (expectedTitle.contentEquals(pagerAdapter.getPageTitle(i))) { viewPager.setCurrentItem(i); return; } } } }; }
Example 9
Source File: LoopBarView.java From LoopBar with MIT License | 5 votes |
/** * You can setup {@code {@link LoopBarView#mOuterAdapter }} through {@link ViewPager} adapter. * Your {@link ViewPager} adapter must implement {@link ILoopBarPagerAdapter} otherwise - the icons will not be shown * * @param viewPager - viewPager, which must have {@link ILoopBarPagerAdapter} */ public void setupWithViewPager(@NonNull ViewPager viewPager) { PagerAdapter pagerAdapter = viewPager.getAdapter(); List<ICategoryItem> categoryItems = new ArrayList<>(pagerAdapter.getCount()); ILoopBarPagerAdapter loopBarPagerAdapter = pagerAdapter instanceof ILoopBarPagerAdapter ? (ILoopBarPagerAdapter) pagerAdapter : null; for (int i = 0, size = pagerAdapter.getCount(); i < size; i++) { categoryItems.add(new CategoryItem( loopBarPagerAdapter != null ? loopBarPagerAdapter.getPageDrawable(i) : null, String.valueOf(pagerAdapter.getPageTitle(i)) )); } setCategoriesAdapter(new SimpleCategoriesAdapter(categoryItems)); }
Example 10
Source File: PagerBullet.java From PagerBullet with MIT License | 5 votes |
private void setItemText(int index) { final PagerAdapter adapter = viewPager.getAdapter(); if (null != adapter) { final int count = adapter.getCount(); textIndicator.setText( String.format(getContext().getString(R.string.pager_bullet_separator), String.valueOf(index + 1), String.valueOf(count) ) ); } }
Example 11
Source File: RtlViewPager.java From rtl-viewpager with Apache License 2.0 | 5 votes |
@Override public void setCurrentItem(int position) { PagerAdapter adapter = super.getAdapter(); if (adapter != null && isRtl()) { position = adapter.getCount() - position - 1; } super.setCurrentItem(position); }
Example 12
Source File: RtlViewPager.java From rtl-viewpager with Apache License 2.0 | 5 votes |
@Override public void setCurrentItem(int position, boolean smoothScroll) { PagerAdapter adapter = super.getAdapter(); if (adapter != null && isRtl()) { position = adapter.getCount() - position - 1; } super.setCurrentItem(position, smoothScroll); }
Example 13
Source File: RtlViewPager.java From rtl-viewpager with Apache License 2.0 | 5 votes |
@Override public int getCurrentItem() { int item = super.getCurrentItem(); PagerAdapter adapter = super.getAdapter(); if (adapter != null && isRtl()) { item = adapter.getCount() - item - 1; } return item; }
Example 14
Source File: OverScrollViewPager.java From AsteroidOSSync with GNU General Public License v3.0 | 5 votes |
private boolean canOverScrollAtEnd() { SwipeableViewPager viewPager = getOverScrollView(); PagerAdapter adapter = viewPager.getAdapter(); if (null != adapter && adapter.getCount() > 0) { if (viewPager.alphaExitTransitionEnabled() && viewPager.getCurrentItem() == adapter.getCount() - 1) { return true; } return false; } return false; }
Example 15
Source File: AutoRefreshUtil.java From SmoothRefreshLayout with MIT License | 5 votes |
public void autoLoadMore(boolean atOnce, boolean autoRefreshUseSmoothScroll) { if (mRefreshLayout != null) { if (mStatus != SmoothRefreshLayout.SR_STATUS_INIT) return; if (mRefreshLayout.isNotYetInEdgeCannotMoveFooter()) { if (mRefreshLayout.isVerticalOrientation()) { ScrollCompat.flingCompat(mTargetView, mMaximumFlingVelocity); } else { if (mTargetView instanceof ViewPager) { final ViewPager pager = (ViewPager) mTargetView; final PagerAdapter adapter = pager.getAdapter(); if (adapter == null) return; if (adapter.getCount() <= 0) return; pager.setCurrentItem(adapter.getCount() - 1, true); } else { HorizontalScrollCompat.flingCompat(mTargetView, mMaximumFlingVelocity); } } mNeedToTriggerLoadMore = true; mCachedActionAtOnce = atOnce; mCachedAutoRefreshUseSmoothScroll = autoRefreshUseSmoothScroll; } else { mRefreshLayout.autoLoadMore(atOnce, autoRefreshUseSmoothScroll); mNeedToTriggerLoadMore = false; mCachedActionAtOnce = false; mCachedAutoRefreshUseSmoothScroll = false; } ViewCompat.postOnAnimation(mRefreshLayout, this); } }
Example 16
Source File: AutoRefreshUtil.java From SmoothRefreshLayout with MIT License | 5 votes |
public void autoRefresh(boolean atOnce, boolean autoRefreshUseSmoothScroll) { if (mRefreshLayout != null) { if (mStatus != SmoothRefreshLayout.SR_STATUS_INIT) return; if (mRefreshLayout.isNotYetInEdgeCannotMoveHeader()) { if (mRefreshLayout.isVerticalOrientation()) { ScrollCompat.flingCompat(mTargetView, -mMaximumFlingVelocity); } else { if (ViewCatcherUtil.isViewPager(mTargetView)) { final ViewPager pager = (ViewPager) mTargetView; final PagerAdapter adapter = pager.getAdapter(); if (adapter == null) return; if (adapter.getCount() <= 0) return; pager.setCurrentItem(0, true); } else { HorizontalScrollCompat.flingCompat(mTargetView, -mMaximumFlingVelocity); } } mNeedToTriggerRefresh = true; mCachedActionAtOnce = atOnce; mCachedAutoRefreshUseSmoothScroll = autoRefreshUseSmoothScroll; } else { mRefreshLayout.autoRefresh(atOnce, autoRefreshUseSmoothScroll); mNeedToTriggerRefresh = false; mCachedActionAtOnce = false; mCachedAutoRefreshUseSmoothScroll = false; } ViewCompat.postOnAnimation(mRefreshLayout, this); } }
Example 17
Source File: PagerBullet.java From PagerBullet with MIT License | 4 votes |
private boolean hasSeparator() { final PagerAdapter pagerAdapter = viewPager.getAdapter(); return null != pagerAdapter && pagerAdapter.getCount() > offset; }
Example 18
Source File: NoScrollViewPager.java From AndroidProject with Apache License 2.0 | 4 votes |
public int getCount() { PagerAdapter adapter = getAdapter(); return adapter != null ? adapter.getCount() : 0; }
Example 19
Source File: TabPageIndicator.java From material with Apache License 2.0 | 4 votes |
private void notifyDataSetChanged() { mTabContainer.removeAllViews(); PagerAdapter adapter = mViewPager.getAdapter(); final int count = adapter.getCount(); if (mSelectedPosition > count) mSelectedPosition = count - 1; for (int i = 0; i < count; i++) { CharSequence title = adapter.getPageTitle(i); if (title == null) title = "NULL"; CheckedTextView tv = new CheckedTextView(getContext()); tv.setCheckMarkDrawable(null); tv.setText(title); tv.setGravity(Gravity.CENTER); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { tv.setTextAlignment(CheckedTextView.TEXT_ALIGNMENT_GRAVITY); } tv.setTextAppearance(getContext(), mTextAppearance); if(mTabSingleLine) tv.setSingleLine(true); else { tv.setSingleLine(false); tv.setMaxLines(2); } tv.setEllipsize(TruncateAt.END); tv.setOnClickListener(this); tv.setTag(i); if(mTabRippleStyle > 0) ViewUtil.setBackground(tv, new RippleDrawable.Builder(getContext(), mTabRippleStyle).build()); tv.setPadding(mTabPadding, 0, mTabPadding, 0); mTabContainer.addView(tv, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); } setCurrentItem(mSelectedPosition); requestLayout(); }
Example 20
Source File: SlidingTabLayout.java From arcusandroid with Apache License 2.0 | 4 votes |
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null; Version1TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (Version1TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && Version1TextView.class.isInstance(tabView)) { tabTitleView = (Version1TextView) tabView; } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } tabTitleView.setText(adapter.getPageTitle(i)); tabTitleView.setTextSize(12); tabTitleView.setTypeface(FontUtils.getDemi(getContext())); tabTitleView.setTextColor(getResources().getColorStateList(R.color.sliding_tab_text_color_selector)); tabView.setOnClickListener(tabClickListener); String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } } }