use of androidx.viewpager.widget.PagerAdapter in project Android-SpinKit by ybq.
the class DetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
viewPager.setOffscreenPageLimit(0);
viewPager.setAdapter(new PagerAdapter() {
@Override
public int getCount() {
return Style.values().length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
@SuppressLint("InflateParams") View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_pager, null);
SpinKitView spinKitView = (SpinKitView) view.findViewById(R.id.spin_kit);
TextView name = (TextView) view.findViewById(R.id.name);
Style style = Style.values()[position];
name.setText(style.name().toLowerCase());
Sprite drawable = SpriteFactory.create(style);
spinKitView.setIndeterminateDrawable(drawable);
container.addView(view);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
});
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
int color = (int) ArgbEvaluator.getInstance().evaluate(positionOffset, colors[position % colors.length], colors[(position + 1) % colors.length]);
getWindow().getDecorView().setBackgroundColor(color);
}
@Override
public void onPageSelected(int position) {
getWindow().getDecorView().setBackgroundColor(colors[position % colors.length]);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
viewPager.setCurrentItem(getIntent().getIntExtra("position", 0));
}
use of androidx.viewpager.widget.PagerAdapter in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SlidingTabLayout method populateTabStrip.
private void populateTabStrip() {
final PagerAdapter adapter = mViewPager.getAdapter();
for (int i = 0; i < adapter.getCount(); i++) {
final TextView tabTitleView = (TextView) mLayoutInflater.inflate(R.layout.sliding_tab_title_view, mTitleView, false);
tabTitleView.setText(adapter.getPageTitle(i));
tabTitleView.setOnClickListener(this);
mTitleView.addView(tabTitleView);
tabTitleView.setSelected(i == mViewPager.getCurrentItem());
}
}
use of androidx.viewpager.widget.PagerAdapter in project Carbon by ZieIony.
the class TabLayout method setViewPager.
public void setViewPager(final ViewPager viewPager) {
if (viewPager != null)
viewPager.removeOnPageChangeListener(pageChangeListener);
this.viewPager = viewPager;
if (viewPager != null) {
viewPager.addOnPageChangeListener(pageChangeListener);
PagerAdapter adapter = viewPager.getAdapter();
if (adapter != null && items == null)
items = Stream.range(0, adapter.getCount()).map(it -> new Item(adapter.getPageTitle(it))).toArray(Item[]::new);
}
initTabs();
}
use of androidx.viewpager.widget.PagerAdapter in project Carbon by ZieIony.
the class TabsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initToolbar();
ViewPager pager = findViewById(R.id.pager);
pager.setAdapter(new PagerAdapter() {
@Override
public CharSequence getPageTitle(int position) {
return "Page " + position;
}
View getView(int position, ViewPager pager) {
return new RelativeLayout(pager.getContext(), null, R.attr.carbon_cardViewStyle);
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
@Override
public int getCount() {
return 7;
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
ViewPager pager = (ViewPager) container;
View view = getView(position, pager);
pager.addView(view);
return view;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object view) {
container.removeView((View) view);
}
});
TabLayout tabs = findViewById(R.id.tabs);
tabs.setViewPager(pager);
ViewPagerIndicator indicator = findViewById(R.id.indicator);
indicator.setViewPager(pager);
}
use of androidx.viewpager.widget.PagerAdapter in project BGARefreshLayout-Android by bingoogolapple.
the class BGAStickyNavLayout method regetNestedContentView.
/**
* 重新获取嵌套的内容视图
*/
private void regetNestedContentView() {
int currentItem = mDirectViewPager.getCurrentItem();
PagerAdapter adapter = mDirectViewPager.getAdapter();
if (adapter instanceof FragmentPagerAdapter || adapter instanceof FragmentStatePagerAdapter) {
Fragment item = (Fragment) adapter.instantiateItem(mDirectViewPager, currentItem);
mNestedContentView = item.getView();
// 清空之前的
mNestedNormalView = null;
mNestedAbsListView = null;
mNestedRecyclerView = null;
mNestedScrollView = null;
mNestedWebView = null;
if (mNestedContentView instanceof AbsListView) {
mNestedAbsListView = (AbsListView) mNestedContentView;
mNestedAbsListView.setOnScrollListener(mLvOnScrollListener);
if (!isHeaderViewCompleteInvisible()) {
mNestedAbsListView.setSelection(0);
}
} else if (mNestedContentView instanceof RecyclerView) {
mNestedRecyclerView = (RecyclerView) mNestedContentView;
mNestedRecyclerView.removeOnScrollListener(mRvOnScrollListener);
mNestedRecyclerView.addOnScrollListener(mRvOnScrollListener);
if (!isHeaderViewCompleteInvisible()) {
mNestedRecyclerView.scrollToPosition(0);
}
} else if (mNestedContentView instanceof ScrollView) {
mNestedScrollView = (ScrollView) mNestedContentView;
if (!isHeaderViewCompleteInvisible()) {
mNestedScrollView.scrollTo(mNestedScrollView.getScrollX(), 0);
}
} else if (mNestedContentView instanceof WebView) {
mNestedWebView = (WebView) mNestedContentView;
if (!isHeaderViewCompleteInvisible()) {
mNestedWebView.scrollTo(mNestedWebView.getScrollX(), 0);
}
} else {
mNestedNormalView = mNestedContentView;
}
} else {
throw new IllegalStateException(BGAStickyNavLayout.class.getSimpleName() + "的第三个子控件为ViewPager时,其adapter必须是FragmentPagerAdapter或者FragmentStatePagerAdapter");
}
}
Aggregations