Search in sources :

Example 6 with PagerAdapter

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));
}
Also used : Sprite(com.github.ybq.android.spinkit.sprite.Sprite) ViewGroup(android.view.ViewGroup) ViewPager(androidx.viewpager.widget.ViewPager) SpinKitView(com.github.ybq.android.spinkit.SpinKitView) TextView(android.widget.TextView) View(android.view.View) PagerAdapter(androidx.viewpager.widget.PagerAdapter) SuppressLint(android.annotation.SuppressLint) Style(com.github.ybq.android.spinkit.Style) TextView(android.widget.TextView) SpinKitView(com.github.ybq.android.spinkit.SpinKitView)

Example 7 with PagerAdapter

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());
    }
}
Also used : TextView(android.widget.TextView) PagerAdapter(androidx.viewpager.widget.PagerAdapter)

Example 8 with PagerAdapter

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();
}
Also used : Context(android.content.Context) LinearLayout(android.widget.LinearLayout) AttrRes(androidx.annotation.AttrRes) CarbonTablayoutTabBinding(carbon.databinding.CarbonTablayoutTabBinding) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) PagerAdapter(androidx.viewpager.widget.PagerAdapter) RowFactory(carbon.recycler.RowFactory) Parcel(android.os.Parcel) TypedArray(android.content.res.TypedArray) Component(carbon.component.Component) AttributeSet(android.util.AttributeSet) View(android.view.View) LayoutComponent(carbon.component.LayoutComponent) Canvas(android.graphics.Canvas) Build(android.os.Build) TargetApi(android.annotation.TargetApi) ViewCompat(androidx.core.view.ViewCompat) Parcelable(android.os.Parcelable) R(carbon.R) ViewGroup(android.view.ViewGroup) StyleRes(androidx.annotation.StyleRes) SparseArray(android.util.SparseArray) Paint(android.graphics.Paint) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ValueAnimator(android.animation.ValueAnimator) PagerAdapter(androidx.viewpager.widget.PagerAdapter)

Example 9 with PagerAdapter

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);
}
Also used : ViewGroup(android.view.ViewGroup) TabLayout(carbon.widget.TabLayout) ViewPagerIndicator(carbon.widget.ViewPagerIndicator) NonNull(androidx.annotation.NonNull) RelativeLayout(carbon.widget.RelativeLayout) ViewPager(carbon.widget.ViewPager) View(android.view.View) PagerAdapter(androidx.viewpager.widget.PagerAdapter)

Example 10 with PagerAdapter

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");
    }
}
Also used : FragmentStatePagerAdapter(androidx.fragment.app.FragmentStatePagerAdapter) ScrollView(android.widget.ScrollView) FragmentPagerAdapter(androidx.fragment.app.FragmentPagerAdapter) AbsListView(android.widget.AbsListView) RecyclerView(androidx.recyclerview.widget.RecyclerView) WebView(android.webkit.WebView) Fragment(androidx.fragment.app.Fragment) PagerAdapter(androidx.viewpager.widget.PagerAdapter) FragmentPagerAdapter(androidx.fragment.app.FragmentPagerAdapter) FragmentStatePagerAdapter(androidx.fragment.app.FragmentStatePagerAdapter)

Aggregations

PagerAdapter (androidx.viewpager.widget.PagerAdapter)12 View (android.view.View)7 ViewGroup (android.view.ViewGroup)4 TextView (android.widget.TextView)4 LinearLayout (android.widget.LinearLayout)3 NonNull (androidx.annotation.NonNull)3 ViewPager (androidx.viewpager.widget.ViewPager)3 HorizontalScrollView (android.widget.HorizontalScrollView)2 FragmentPagerAdapter (androidx.fragment.app.FragmentPagerAdapter)2 ValueAnimator (android.animation.ValueAnimator)1 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 Context (android.content.Context)1 Intent (android.content.Intent)1 TypedArray (android.content.res.TypedArray)1 Canvas (android.graphics.Canvas)1 Paint (android.graphics.Paint)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Parcel (android.os.Parcel)1