androidx.fragment.app.FragmentStatePagerAdapter Java Examples

The following examples show how to use androidx.fragment.app.FragmentStatePagerAdapter. 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 Project: bubble-icon-tabbar-android   Author: Cuberto   File: MainActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mFragmentList.add(new TabFragment(titles[0], colors[0]));
    mFragmentList.add(new TabFragment(titles[1], colors[1]));
    mFragmentList.add(new TabFragment(titles[2], colors[2]));
    mFragmentList.add(new TabFragment(titles[3], colors[3]));
    ViewPager viewPager = findViewById(R.id.viewPager);
    FragmentStatePagerAdapter adapter = new FragmentStatePagerAdapter(getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }
    };
    viewPager.setAdapter(adapter);
    TabLayout tabLayout = findViewById(R.id.tabLayout);
    tabLayout.setupWithViewPager(viewPager);
    tabBubbleAnimator = new TabBubbleAnimator(tabLayout);
    tabBubbleAnimator.addTabItem(titles[0], R.drawable.ic_grid, colors[0]);
    tabBubbleAnimator.addTabItem(titles[1], R.drawable.ic_clock,colors[1]);
    tabBubbleAnimator.addTabItem(titles[2], R.drawable.ic_folder, colors[2]);
    tabBubbleAnimator.addTabItem(titles[3], R.drawable.ic_menu, colors[3]);
    tabBubbleAnimator.setUnselectedColorId(Color.BLACK);
    tabBubbleAnimator.highLightTab(0);
    viewPager.addOnPageChangeListener(tabBubbleAnimator);
}
 
Example #2
Source Project: BaseProject   Author: feer921   File: LoopPagerAdapterWrapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, int position) {
	int realPosition = (mAdapter instanceof FragmentPagerAdapter || mAdapter instanceof FragmentStatePagerAdapter) ? position
			: toRealPosition(position);

	if (mBoundaryCaching) {
		ToDestroy toDestroy = mToDestroy.get(position);
		if (toDestroy != null) {
			mToDestroy.remove(position);
			return toDestroy.object;
		}
	}
	return mAdapter.instantiateItem(container, realPosition);
}
 
Example #3
Source Project: BaseProject   Author: feer921   File: LoopPagerAdapterWrapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
	int realFirst = getRealFirstPosition();
	int realLast = getRealLastPosition();
	int realPosition = (mAdapter instanceof FragmentPagerAdapter || mAdapter instanceof FragmentStatePagerAdapter) ? position
			: toRealPosition(position);

	if (mBoundaryCaching && (position == realFirst || position == realLast)) {
		mToDestroy.put(position, new ToDestroy(container, realPosition, object));
	} else {
		mAdapter.destroyItem(container, realPosition, object);
	}
}
 
Example #4
Source Project: LollipopContactsRecyclerViewFastScroller   Author: AndroidDeveloperLB   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    //note : part of the design library sample code was taken from : https://github.com/sitepoint-editors/Design-Demo/

    DesignDemoPagerAdapter adapter = new DesignDemoPagerAdapter(getSupportFragmentManager(), FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    ViewPager viewPager = findViewById(R.id.viewpager);
    viewPager.setAdapter(adapter);
    TabLayout tabLayout = findViewById(R.id.tablayout);
    tabLayout.setupWithViewPager(viewPager);
}
 
Example #5
Source Project: CircleIndicator   Author: ongakuer   File: LoopPagerAdapterWrapper.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull @Override public Object instantiateItem(@NonNull ViewGroup container, int position) {
    int realPosition = (mAdapter instanceof FragmentPagerAdapter
            || mAdapter instanceof FragmentStatePagerAdapter) ? position
            : toRealPosition(position);

    if (mBoundaryCaching) {
        ToDestroy toDestroy = mToDestroy.get(position);
        if (toDestroy != null) {
            mToDestroy.remove(position);
            return toDestroy.object;
        }
    }
    return mAdapter.instantiateItem(container, realPosition);
}
 
Example #6
Source Project: CircleIndicator   Author: ongakuer   File: LoopPagerAdapterWrapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
    int realFirst = getRealFirstPosition();
    int realLast = getRealLastPosition();
    int realPosition = (mAdapter instanceof FragmentPagerAdapter
            || mAdapter instanceof FragmentStatePagerAdapter) ? position
            : toRealPosition(position);

    if (mBoundaryCaching && (position == realFirst || position == realLast)) {
        mToDestroy.put(position, new ToDestroy(container, realPosition, object));
    } else {
        mAdapter.destroyItem(container, realPosition, object);
    }
}
 
Example #7
Source Project: Pixiv-Shaft   Author: CeuiLiSA   File: RankActivity.java    License: MIT License 4 votes vote down vote up
@Override
protected void initView() {
    setSupportActionBar(baseBind.toolbar);
    baseBind.toolbar.setNavigationOnClickListener(v -> finish());
    dataType = getIntent().getStringExtra("dataType");
    queryDate = getIntent().getStringExtra("date");
    baseBind.viewPager.setPageTransformer(true, new DrawerTransformer());

    final String[] CHINESE_TITLES = new String[]{
            mContext.getString(R.string.daily_rank),
            mContext.getString(R.string.weekly_rank),
            mContext.getString(R.string.monthly_rank),
            mContext.getString(R.string.man_like),
            mContext.getString(R.string.woman_like),
            mContext.getString(R.string.self_done),
            mContext.getString(R.string.new_fish),
            mContext.getString(R.string.r_eighteen)
    };


    baseBind.viewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager(), 0) {
        @Override
        public Fragment getItem(int i) {
            if (allPages[i] == null) {
                if ("插画".equals(dataType)) {
                    allPages[i] = FragmentRankIllust.newInstance(i, queryDate, false);
                } else if ("漫画".equals(dataType)) {
                    allPages[i] = FragmentRankIllust.newInstance(i, queryDate, true);
                } else if ("小说".equals(dataType)) {
                    allPages[i] = FragmentRankNovel.newInstance(i, queryDate);
                }
            }
            return allPages[i];
        }

        @Override
        public int getCount() {
            if ("插画".equals(dataType)) {
                return CHINESE_TITLES.length;
            } else if ("漫画".equals(dataType)) {
                return CHINESE_TITLES_MANGA.length;
            } else if ("小说".equals(dataType)) {
                return CHINESE_TITLES_NOVEL.length;
            }
            return 0;
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            if ("插画".equals(dataType)) {
                return CHINESE_TITLES[position];
            } else if ("漫画".equals(dataType)) {
                return CHINESE_TITLES_MANGA[position];
            } else if ("小说".equals(dataType)) {
                return CHINESE_TITLES_NOVEL[position];
            }
            return "";
        }


    });
    baseBind.tabLayout.setupWithViewPager(baseBind.viewPager);
    //如果指定了跳转到某一个排行,就显示该页排行
    if (getIntent().getIntExtra("index", 0) >= 0) {
        baseBind.viewPager.setCurrentItem(getIntent().getIntExtra("index", 0));
    }
}
 
Example #8
Source Project: flashy-tabbar-android   Author: Cuberto   File: MainActivity.java    License: MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mFragmentList.add(new TabFragment(titles[0]));
    mFragmentList.add(new TabFragment(titles[1]));
    mFragmentList.add(new TabFragment(titles[2]));
    mFragmentList.add(new TabFragment(titles[3]));
    ViewPager viewPager = findViewById(R.id.view_pager);
    FragmentStatePagerAdapter adapter = new FragmentStatePagerAdapter(getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }
    };
    viewPager.setAdapter(adapter);
    TabLayout tabLayout = findViewById(R.id.tabLayout);
    tabLayout.setupWithViewPager(viewPager);
    tabFlashyAnimator = new TabFlashyAnimator(tabLayout);
    tabFlashyAnimator.addTabItem(titles[0], R.drawable.ic_events);
    tabFlashyAnimator.addTabItem(titles[1], R.drawable.ic_highlights);
    tabFlashyAnimator.addTabItem(titles[2], R.drawable.ic_search);
    tabFlashyAnimator.addTabItem(titles[3], R.drawable.ic_settings, R.color.colorAccent, getResources().getDimension(R.dimen.big_text));
    tabFlashyAnimator.highLightTab(0);
    viewPager.addOnPageChangeListener(tabFlashyAnimator);
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            tabFlashyAnimator.setBadge(1, 2);
        }
    }, 1000);
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            tabFlashyAnimator.setBadge(20, 2);
        }
    }, 2000);
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            tabFlashyAnimator.setBadge(200, 2);
        }
    }, 3000);
}
 
Example #9
Source Project: DNSHero   Author: devgianlu   File: PagerAdapter.java    License: GNU General Public License v3.0 4 votes vote down vote up
public PagerAdapter(FragmentManager fm, Fragment... fragments) {
    super(fm, FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    this.fragments = fragments;
}
 
Example #10
Source Project: Aria2App   Author: devgianlu   File: StatePagerAdapter.java    License: GNU General Public License v3.0 4 votes vote down vote up
public StatePagerAdapter(@NonNull FragmentManager fm, List<F> fragments) {
    super(fm, FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    this.fragments = fragments;
}
 
Example #11
Source Project: Aria2App   Author: devgianlu   File: StatePagerAdapter.java    License: GNU General Public License v3.0 4 votes vote down vote up
@SafeVarargs
public StatePagerAdapter(@NonNull FragmentManager fm, F... fragments) {
    super(fm, FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    this.fragments = Arrays.asList(fragments);
}
 
Example #12
Source Project: HaoReader   Author: Invinciblelee   File: ChoiceBookActivity.java    License: GNU General Public License v3.0 4 votes vote down vote up
PagerAdapter(@NonNull FragmentManager fm, List<FindKindBean> findKindBeans) {
    super(fm, FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    this.kindBeans = findKindBeans;
}
 
Example #13
Source Project: PretendYoureXyzzyAndroid   Author: devgianlu   File: PagerAdapter.java    License: GNU General Public License v3.0 4 votes vote down vote up
public PagerAdapter(FragmentManager fm, Fragment... fragments) {
    super(fm, FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    this.fragments = Arrays.asList(fragments);
}
 
Example #14
Source Project: deltachat-android   Author: deltachat   File: QrActivity.java    License: GNU General Public License v3.0 4 votes vote down vote up
ProfilePagerAdapter(FragmentManager fragmentManager) {
    super(fragmentManager, FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
}