androidx.fragment.app.FragmentPagerAdapter Java Examples

The following examples show how to use androidx.fragment.app.FragmentPagerAdapter. 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: MainActivity.java    From Pixiv-Shaft with MIT License 6 votes vote down vote up
private void initFragment() {
    baseFragments = new BaseFragment[]{
            new FragmentLeft(),
            new FragmentCenter(),
            new FragmentRight()
    };
    baseBind.viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int i) {
            return baseFragments[i];
        }

        @Override
        public int getCount() {
            return baseFragments.length;
        }
    });
    baseBind.navigationView.setupWithViewPager(baseBind.viewPager);
}
 
Example #2
Source File: HealthFragment.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
private void initView() {
    mFragments.clear();
    mFragments.add(new HealthFragmentChild0());
    mFragments.add(new HealthFragmentChild1());
    mHomeTitleBar = findViewById(R.id.title_bar);
    mHomeTitleBar.setListener(new HomeTitleBar.OnTitleBarClickListener() {
        @Override
        public void onRightClick() {
            finish();
        }
    });
    mVerticalViewPager = findViewById(R.id.view_pager);
    mFragmentPagerAdapter = new FragmentPagerAdapter(getChildFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }
    };
    mVerticalViewPager.setAdapter(mFragmentPagerAdapter);
}
 
Example #3
Source File: FragmentAnime.java    From Pixiv-Shaft with MIT License 5 votes vote down vote up
@Override
public void initView(View view) {
    baseBind.viewPager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {
        @NonNull
        @Override
        public Fragment getItem(int position) {
            return FragmentColor.newInstance(COLORS[position]);
        }

        @Override
        public int getCount() {
            return COLORS.length;
        }
    });
}
 
Example #4
Source File: LoopPagerAdapterWrapper.java    From CircleIndicator with 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 #5
Source File: LoopPagerAdapterWrapper.java    From CircleIndicator with 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 File: LoopPagerAdapterWrapper.java    From BaseProject with 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 #7
Source File: LoopPagerAdapterWrapper.java    From BaseProject with 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 #8
Source File: MainActivity.java    From Stylish-Widget-for-Android with Apache License 2.0 5 votes vote down vote up
private void initViewPager() {
    viewPager = findViewById(R.id.viewPager);
    final Fragment[] fragments = new Fragment[]{
            MeterFragment.newInstance(),
            WidgetFragment.newInstance(),
            ButtonPlainFragment.newInstance(),
            ButtonFillFragment.newInstance(),
            ButtonOutlineFragment.newInstance(),
            MessageBoxFragment.newInstance(),
            ProgressBarFragment.newInstance(),
    };
    viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            if (position<fragments.length)
                return fragments[position];
            else
                return new Fragment();
        }

        @Override
        public int getCount() {
            return tabLayout.getTabCount();
        }
    });

    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
}
 
Example #9
Source File: ViewPagerActivity.java    From fragment-back with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_viewpager);

    viewPager = findViewById(R.id.view_pager);

    viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    return FirstFragment.newInstance();
                case 1:
                    return SecondFragment.newInstance();
                default:
                    throw new RuntimeException("Invalid item index.");
            }
        }

        @Override
        public int getCount() {
            return 2;
        }
    });
}
 
Example #10
Source File: ImageTransferFormatSelectorDialogFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {

    // Set animations
    Dialog dialog = getDialog();
    if (dialog != null) {
        //dialog.setTitle(R.string.imagetransfer_resolution_choose);
        //dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        Window window = dialog.getWindow();
        if (window != null) {
            window.setWindowAnimations(R.style.DialogAnimation);
        }
    }

    // Configure tabs and viewpager
    ViewPager viewPager = view.findViewById(R.id.viewpager);
    ResolutionsPageAdapter adapter = new ResolutionsPageAdapter(getChildFragmentManager(), FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, mResolution);
    viewPager.setAdapter(adapter);

    TabLayout tabLayout = view.findViewById(R.id.tabLayout);
    tabLayout.setupWithViewPager(viewPager);

    // Force titles
    TabLayout.Tab standardResolutions = tabLayout.getTabAt(0);
    if (standardResolutions != null) {
        standardResolutions.setText(R.string.imagetransfer_resolution_mode_standard);
    }
    TabLayout.Tab eInkResolutions = tabLayout.getTabAt(1);
    if (eInkResolutions != null) {
        eInkResolutions.setText(R.string.imagetransfer_resolution_mode_eink);
    }

    // Set initial item
    viewPager.setCurrentItem(mIsEInkModeEnabled ? 1 : 0);
}
 
Example #11
Source File: AdvancedInstallerFragment.java    From EdXposedManager with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.tab_advanced_installer, container, false);
    ViewPager mPager = view.findViewById(R.id.pager);
    mTabLayout = view.findViewById(R.id.tab_layout);

    tabsAdapter = new TabsAdapter(getChildFragmentManager(), FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    mPager.setAdapter(tabsAdapter);
    mTabLayout.setupWithViewPager(mPager);

    setHasOptionsMenu(true);
    new JSONParser().execute();

    if (!XposedApp.getPreferences().getBoolean("hide_install_warning", false)) {
        @SuppressLint("InflateParams") final View dontShowAgainView = inflater.inflate(R.layout.dialog_install_warning, null);

        new MaterialDialog.Builder(requireActivity())
                .title(R.string.install_warning_title)
                .customView(dontShowAgainView, false)
                .positiveText(R.string.ok)
                .onPositive((dialog, which) -> {
                    CheckBox checkBox = dontShowAgainView.findViewById(android.R.id.checkbox);
                    if (checkBox.isChecked())
                        XposedApp.getPreferences().edit().putBoolean("hide_install_warning", true).apply();
                })
                .cancelable(false).show();
    }

    return view;
}
 
Example #12
Source File: FragmentCenter.java    From Pixiv-Shaft with MIT License 5 votes vote down vote up
@Override
void initData() {
    if (Dev.isDev) {

    } else {
        Retro.getAppApi().getLoginBg(Shaft.sUserModel.getResponse().getAccess_token())
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new NullCtrl<ListIllust>() {
                    @Override
                    public void success(ListIllust listIllust) {
                        baseBind.viewPager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {
                            @NonNull
                            @Override
                            public Fragment getItem(int position) {
                                int index = position % listIllust.getList().size();
                                return FragmentImage.newInstance(listIllust.getIllusts()
                                        .get(index));
                            }

                            @Override
                            public int getCount() {
                                return Integer.MAX_VALUE;
                            }
                        });
                        baseBind.viewPager.setPageTransformer(true, new GalleryTransformer());
                        baseBind.viewPager.setOffscreenPageLimit(3);
                        baseBind.viewPager.setCurrentItem(listIllust.getList().size());
                    }
                });
    }
}
 
Example #13
Source File: FragmentNewNovel.java    From Pixiv-Shaft with MIT License 4 votes vote down vote up
@Override
public void initView(View view) {
    String[] TITLES = new String[]{
            Shaft.getContext().getString(R.string.recommend_illust),
            Shaft.getContext().getString(R.string.hot_tag)
    };

    ViewGroup.LayoutParams headParams = baseBind.head.getLayoutParams();
    headParams.height = Shaft.statusHeight;
    baseBind.head.setLayoutParams(headParams);

    baseBind.toolbar.setNavigationOnClickListener(v -> {
        mActivity.finish();
    });
    baseBind.toolbar.inflateMenu(R.menu.fragment_left);
    baseBind.toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getItemId() == R.id.action_search) {
                Intent intent = new Intent(mContext, TemplateActivity.class);
                intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "搜索");
                startActivity(intent);
                return true;
            }
            return false;
        }
    });
    baseBind.viewPager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager(), 0) {
        @NonNull
        @Override
        public Fragment getItem(int i) {
            if (i == 0) {
                return new FragmentRecmdNovel();
            } else {
                return FragmentHotTag.newInstance(Params.TYPE_NOVEL);
            }
        }

        @Override
        public int getCount() {
            return TITLES.length;
        }

        @NonNull
        @Override
        public CharSequence getPageTitle(int position) {
            return TITLES[position];
        }
    });
    baseBind.tabLayout.setupWithViewPager(baseBind.viewPager);
}
 
Example #14
Source File: InboxActivity.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 4 votes vote down vote up
public SectionsPagerAdapter(@NonNull FragmentManager fm) {
    super(fm, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
}
 
Example #15
Source File: FragmentLeft.java    From Pixiv-Shaft with MIT License 4 votes vote down vote up
@Override
public void initView(View view) {
    String[] TITLES = new String[]{
            Shaft.getContext().getString(R.string.recommend_illust),
            Shaft.getContext().getString(R.string.hot_tag)
    };

    ViewGroup.LayoutParams headParams = baseBind.head.getLayoutParams();
    headParams.height = Shaft.statusHeight;
    baseBind.head.setLayoutParams(headParams);

    baseBind.toolbar.setNavigationOnClickListener(v -> {
        if (requireActivity() instanceof MainActivity) {
            ((MainActivity) requireActivity()).getDrawer().openDrawer(Gravity.START);
        }
    });
    baseBind.toolbar.inflateMenu(R.menu.fragment_left);
    baseBind.toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getItemId() == R.id.action_search) {
                Intent intent = new Intent(mContext, TemplateActivity.class);
                intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "搜索");
                startActivity(intent);
                return true;
            }
            return false;
        }
    });
    baseBind.viewPager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager(), 0) {
        @NonNull
        @Override
        public Fragment getItem(int i) {
            if (i == 0) {
                return FragmentRecmdIllust.newInstance("插画");
            } else {
                return FragmentHotTag.newInstance(Params.TYPE_ILLUST);
            }
        }

        @Override
        public int getCount() {
            return TITLES.length;
        }

        @NonNull
        @Override
        public CharSequence getPageTitle(int position) {
            return TITLES[position];
        }
    });
    baseBind.tabLayout.setupWithViewPager(baseBind.viewPager);
}
 
Example #16
Source File: MapInPagerDemoActivity.java    From android-samples with Apache License 2.0 4 votes vote down vote up
public MyAdapter(FragmentManager fm) {
    super(fm, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
}
 
Example #17
Source File: PolylineControlFragmentPagerAdapter.java    From android-samples with Apache License 2.0 4 votes vote down vote up
public PolylineControlFragmentPagerAdapter(FragmentManager fragmentManager, boolean isLiteMode) {
    super(fragmentManager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    positionsToFragments = new HashMap<>();
    this.isLiteMode = isLiteMode;
}
 
Example #18
Source File: LibraryViewModel.java    From Jockey with Apache License 2.0 4 votes vote down vote up
@Bindable
public FragmentPagerAdapter getPagerAdapter() {
    notifyPropertyChanged(BR.page);
    return mPagerAdapter;
}
 
Example #19
Source File: MyViewPager.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    IntroFragment frag = (IntroFragment) ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem());
    if (frag.allowTouch()) return super.onInterceptTouchEvent(ev);
    return true;
}
 
Example #20
Source File: RTLViewPager.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
private RTLAdapterWrapper(FragmentManager fm, @NonNull FragmentPagerAdapter adapter) {
    super(fm);
    this.adapter = adapter;
    adapter.registerDataSetObserver(observer);
}
 
Example #21
Source File: RTLViewPager.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
public void setRTLSupportAdapter(FragmentManager fm, @NonNull FragmentPagerAdapter adapter) {
    super.setAdapter(isRTL() ? new RTLAdapterWrapper(fm, adapter) : adapter);
}
 
Example #22
Source File: VPVPFrgActivity.java    From sa-sdk-android with Apache License 2.0 4 votes vote down vote up
public static FragmentPagerAdapter getFragmentPagerAdapter() {
    return pagerAdapter;
}
 
Example #23
Source File: Frg_2.java    From sa-sdk-android with Apache License 2.0 4 votes vote down vote up
public static FragmentPagerAdapter getFragmentPagerAdapter() {
    return pagerAdapter;
}
 
Example #24
Source File: SectionsPagerAdapter.java    From PixivforMuzei3 with GNU General Public License v3.0 4 votes vote down vote up
public SectionsPagerAdapter(Context context, FragmentManager fm)
{
    super(fm, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    mContext = context;
}
 
Example #25
Source File: MyViewPager.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    IntroFragment frag = (IntroFragment) ((FragmentPagerAdapter) getAdapter()).getItem(getCurrentItem());
    if (frag.allowTouch()) return super.onInterceptTouchEvent(ev);
    return true;
}
 
Example #26
Source File: RTLViewPager.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
private RTLAdapterWrapper(FragmentManager fm, @NonNull FragmentPagerAdapter adapter) {
    super(fm);
    this.adapter = adapter;
    adapter.registerDataSetObserver(observer);
}
 
Example #27
Source File: RTLViewPager.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
public void setRTLSupportAdapter(FragmentManager fm, @NonNull FragmentPagerAdapter adapter) {
    super.setAdapter(isRTL() ? new RTLAdapterWrapper(fm, adapter) : adapter);
}
 
Example #28
Source File: MainActivity.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
PagerAdapter(@NonNull FragmentManager fm, String[] titles) {
    super(fm, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    this.titles = titles;
}
 
Example #29
Source File: PagerAdapter.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
@SafeVarargs
public PagerAdapter(FragmentManager fm, F... fragments) {
    super(fm, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    this.fragments = Arrays.asList(fragments);
}
 
Example #30
Source File: PagerAdapter.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
public PagerAdapter(FragmentManager fm, List<F> fragments) {
    super(fm, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    this.fragments = fragments;
}