com.blankj.utilcode.util.FragmentUtils Java Examples
The following examples show how to use
com.blankj.utilcode.util.FragmentUtils.
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: Demo1Fragment.java From Android-UtilCode with Apache License 2.0 | 6 votes |
@Override public void onWidgetClick(View view) { tvAboutFragment.setText(""); switch (view.getId()) { case R.id.btn_show_about_fragment: tvAboutFragment.setText("lastAdd: " + FragmentUtils.getLastAddFragment(getFragmentManager()).getClass().getSimpleName() + "\nlastAddInStack: " + (FragmentUtils.getLastAddFragmentInStack(getFragmentManager()) != null ? FragmentUtils.getLastAddFragmentInStack(getFragmentManager()).getClass().getSimpleName() : "null") + "\ntopShow: " + FragmentUtils.getTopShowFragment(getFragmentManager()).getClass().getSimpleName() + "\ntopShowInStack: " + (FragmentUtils.getTopShowFragmentInStack(getFragmentManager()) != null ? FragmentUtils.getTopShowFragmentInStack(getFragmentManager()).getClass().getSimpleName() : "null") + "\n---all of fragments---\n" + FragmentUtils.getAllFragments(getFragmentManager()).toString() + "\n----------------------\n\n" + "---stack top---\n" + FragmentUtils.getAllFragmentsInStack(getFragmentManager()).toString() + "\n---stack bottom---\n\n" ); break; case R.id.btn_hide_show: FragmentUtils.hideAllShowFragment(((FragmentActivity) getActivity()).rootFragment); break; } }
Example #2
Source File: Demo0Fragment.java From Android-UtilCode with Apache License 2.0 | 6 votes |
@Override public void initView(Bundle savedInstanceState, View view) { Random random = new Random(); FragmentUtils.setBackgroundColor(this, Color.rgb(random.nextInt(256), random.nextInt(256), random.nextInt(256))); btnShowAboutFragment = (Button) view.findViewById(R.id.btn_show_about_fragment); btnShowAboutFragment.setOnClickListener(this); view.findViewById(R.id.btn_add_hide).setOnClickListener(this); view.findViewById(R.id.btn_add_show).setOnClickListener(this); view.findViewById(R.id.btn_add_child).setOnClickListener(this); view.findViewById(R.id.btn_pop_to_root).setOnClickListener(this); view.findViewById(R.id.btn_pop_add).setOnClickListener(this); view.findViewById(R.id.btn_hide_show).setOnClickListener(this); view.findViewById(R.id.btn_replace).setOnClickListener(this); ivSharedElement = (ImageView) view.findViewById(R.id.iv_shared_element); tvAboutFragment = (TextView) view.findViewById(R.id.tv_about_fragment); demo0Fragment = this; sharedElement = new FragmentUtils.SharedElement(ivSharedElement, getString(R.string.fragment_transition)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setExitTransition(new Fade()); } }
Example #3
Source File: Demo3Fragment.java From Android-UtilCode with Apache License 2.0 | 6 votes |
@Override public void initView(Bundle savedInstanceState, View view) { Random random = new Random(); FragmentUtils.setBackgroundColor(this, Color.rgb(random.nextInt(256), random.nextInt(256), random.nextInt(256))); btnShowAboutFragment = (Button) view.findViewById(R.id.btn_show_about_fragment); btnShowAboutFragment.setOnClickListener(this); view.findViewById(R.id.btn_add_hide).setOnClickListener(this); view.findViewById(R.id.btn_add_show).setOnClickListener(this); view.findViewById(R.id.btn_add_child).setOnClickListener(this); view.findViewById(R.id.btn_pop_to_root).setOnClickListener(this); view.findViewById(R.id.btn_pop_add).setOnClickListener(this); view.findViewById(R.id.btn_hide_show).setOnClickListener(this); view.findViewById(R.id.btn_replace).setOnClickListener(this); ivSharedElement = (ImageView) view.findViewById(R.id.iv_shared_element); tvAboutFragment = (TextView) view.findViewById(R.id.tv_about_fragment); }
Example #4
Source File: Demo2Fragment.java From Android-UtilCode with Apache License 2.0 | 6 votes |
@Override public void onWidgetClick(View view) { tvAboutFragment.setText(""); switch (view.getId()) { case R.id.btn_show_about_fragment: tvAboutFragment.setText("lastAdd: " + FragmentUtils.getLastAddFragment(getFragmentManager()).getClass().getSimpleName() + "\nlastAddInStack: " + (FragmentUtils.getLastAddFragmentInStack(getFragmentManager()) != null ? FragmentUtils.getLastAddFragmentInStack(getFragmentManager()).getClass().getSimpleName() : "null") + "\ntopShow: " + FragmentUtils.getTopShowFragment(getFragmentManager()).getClass().getSimpleName() + "\ntopShowInStack: " + (FragmentUtils.getTopShowFragmentInStack(getFragmentManager()) != null ? FragmentUtils.getTopShowFragmentInStack(getFragmentManager()).getClass().getSimpleName() : "null") + "\n---all of fragments---\n" + FragmentUtils.getAllFragments(getFragmentManager()).toString() + "\n----------------------\n\n" + "---stack top---\n" + FragmentUtils.getAllFragmentsInStack(getFragmentManager()).toString() + "\n---stack bottom---\n\n" ); break; case R.id.btn_pop: FragmentUtils.popFragment(getFragmentManager()); break; } }
Example #5
Source File: DetailVideoActivity.java From YCAudioPlayer with Apache License 2.0 | 5 votes |
/** * 展示页面 */ private void showPlayingFragment() { if (isPlayFragmentShow) { return; } FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.setCustomAnimations(R.anim.fragment_slide_up, 0); if (mDetailAudioFragment == null) { mDetailAudioFragment = DetailAudioFragment.newInstance("Video"); ft.add(android.R.id.content, mDetailAudioFragment); } else { ft.show(mDetailAudioFragment); } ft.commitAllowingStateLoss(); isPlayFragmentShow = true; AppLogUtils.e("fragment数量+DetailVideoActivity" + FragmentUtils.getAllFragments(getSupportFragmentManager()).size()); if (videoPlayer.isPlaying() || videoPlayer.isBufferingPlaying()) { videoPlayer.pause(); } //当视频正在播放,准备播放时,点击音视频切换按钮,先暂停视频,然后记录视频播放位置,show音频播放页面 //当视频已经暂停,播放错误,播放停止时,点击音视频切换按钮,直接记录视频播放位置,show音频播放页面 BaseConfig.INSTANCE.setPosition(videoPlayer.getCurrentPosition()); AppLogUtils.e("播放位置----视频页开始显示音频--" + videoPlayer.getCurrentPosition()); if (mDetailAudioFragment != null) { mDetailAudioFragment.setViewData(BaseAppHelper.get().getMusicList().get(0)); if (getPlayService().isDefault() || getPlayService().isPausing()) { getPlayService().seekTo((int) BaseConfig.INSTANCE.getPosition()); getPlayService().playPause(); } } }
Example #6
Source File: Demo1Fragment.java From Android-UtilCode with Apache License 2.0 | 5 votes |
@Override public void initView(Bundle savedInstanceState, View view) { Random random = new Random(); FragmentUtils.setBackgroundColor(this, Color.rgb(random.nextInt(256), random.nextInt(256), random.nextInt(256))); view.findViewById(R.id.btn_show_about_fragment).setOnClickListener(this); view.findViewById(R.id.btn_hide_show).setOnClickListener(this); tvAboutFragment = (TextView) view.findViewById(R.id.tv_about_fragment); }
Example #7
Source File: Demo2Fragment.java From Android-UtilCode with Apache License 2.0 | 5 votes |
@Override public void initView(Bundle savedInstanceState, View view) { Random random = new Random(); FragmentUtils.setBackgroundColor(this, Color.rgb(random.nextInt(256), random.nextInt(256), random.nextInt(256))); view.findViewById(R.id.btn_show_about_fragment).setOnClickListener(this); view.findViewById(R.id.btn_pop).setOnClickListener(this); tvAboutFragment = (TextView) view.findViewById(R.id.tv_about_fragment); }
Example #8
Source File: UserInFragmentActivity.java From XBanner with Apache License 2.0 | 5 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_user_in_fragment); RadioGroup rbTab = findViewById(R.id.rg_tab); RadioButton radioButton= (RadioButton) rbTab.getChildAt(0); radioButton.setChecked(true); mFragmentList=new ArrayList<>(); mFragmentList.add(BannerFragment.newInstance()); mFragmentList.add(BannerFragment.newInstance()); mFragmentList.add(BannerFragment.newInstance()); mFragmentList.add(BannerFragment.newInstance()); FragmentUtils.add(getSupportFragmentManager(),mFragmentList,R.id.fragment_content,0); rbTab.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.tab_1: FragmentUtils.showHide(0,mFragmentList); break; case R.id.tab_2: FragmentUtils.showHide(1,mFragmentList); break; case R.id.tab_3: FragmentUtils.showHide(2,mFragmentList); break; case R.id.tab_4: FragmentUtils.showHide(3,mFragmentList); break; default: break; } } }); }
Example #9
Source File: Demo0Fragment.java From Android-UtilCode with Apache License 2.0 | 4 votes |
@Override public void onWidgetClick(View view) { tvAboutFragment.setText(""); switch (view.getId()) { case R.id.btn_show_about_fragment: tvAboutFragment.setText("lastAdd: " + FragmentUtils.getLastAddFragment(getFragmentManager()).getClass().getSimpleName() + "\nlastAddInStack: " + (FragmentUtils.getLastAddFragmentInStack(getFragmentManager()) != null ? FragmentUtils.getLastAddFragmentInStack(getFragmentManager()).getClass().getSimpleName() : "null") + "\ntopShow: " + (FragmentUtils.getTopShowFragment(getFragmentManager()) != null ? FragmentUtils.getTopShowFragment(getFragmentManager()).getClass().getSimpleName() : "null") + "\ntopShowInStack: " + (FragmentUtils.getTopShowFragmentInStack(getFragmentManager()) != null ? FragmentUtils.getTopShowFragmentInStack(getFragmentManager()).getClass().getSimpleName() : "null") + "\n---all of fragments---\n" + FragmentUtils.getAllFragments(getFragmentManager()).toString() + "\n----------------------\n\n" + "---stack top---\n" + FragmentUtils.getAllFragmentsInStack(getFragmentManager()).toString() + "\n---stack bottom---\n\n" ); break; case R.id.btn_add_hide: FragmentUtils.hideAddFragment(getFragmentManager(), demo0Fragment, addSharedElement(Demo1Fragment.newInstance()), R.id.fragment_container, false, true, sharedElement); break; case R.id.btn_add_show: FragmentUtils.addFragment(getFragmentManager(), addSharedElement(Demo1Fragment.newInstance()), R.id.fragment_container, false, false, sharedElement); break; case R.id.btn_add_child: FragmentUtils.addFragment(getChildFragmentManager(), Demo2Fragment.newInstance(), R.id.child_fragment_container, false, true); break; case R.id.btn_pop_to_root: FragmentUtils.popToFragment(getFragmentManager(), Demo1Fragment.class, true); break; case R.id.btn_pop_add: FragmentUtils.popAddFragment(getFragmentManager(), addSharedElement(Demo2Fragment.newInstance()), R.id.fragment_container, true, sharedElement); break; case R.id.btn_hide_show: Fragment fragment1 = FragmentUtils.findFragment(getFragmentManager(), Demo1Fragment.class); if (fragment1 != null) { FragmentUtils.hideShowFragment(this, fragment1); } else { ToastUtils.showLong("please add demo1 first!"); } break; case R.id.btn_replace: ((FragmentActivity) getActivity()).rootFragment = FragmentUtils.replaceFragment(this, addSharedElement(Demo3Fragment.newInstance()), false, sharedElement); break; } }
Example #10
Source File: Demo3Fragment.java From Android-UtilCode with Apache License 2.0 | 4 votes |
@Override public void onWidgetClick(View view) { tvAboutFragment.setText(""); switch (view.getId()) { case R.id.btn_show_about_fragment: tvAboutFragment.setText("lastAdd: " + FragmentUtils.getLastAddFragment(getFragmentManager()).getClass().getSimpleName() + "\nlastAddInStack: " + (FragmentUtils.getLastAddFragmentInStack(getFragmentManager()) != null ? FragmentUtils.getLastAddFragmentInStack(getFragmentManager()).getClass().getSimpleName() : "null") + "\ntopShow: " + FragmentUtils.getTopShowFragment(getFragmentManager()).getClass().getSimpleName() + "\ntopShowInStack: " + (FragmentUtils.getTopShowFragmentInStack(getFragmentManager()) != null ? FragmentUtils.getTopShowFragmentInStack(getFragmentManager()).getClass().getSimpleName() : "null") + "\n---all of fragments---\n" + FragmentUtils.getAllFragments(getFragmentManager()).toString() + "\n----------------------\n\n" + "---stack top---\n" + FragmentUtils.getAllFragmentsInStack(getFragmentManager()).toString() + "\n---stack bottom---\n\n" ); break; case R.id.btn_add_hide: FragmentUtils.addFragment(getFragmentManager(), Demo1Fragment.newInstance(), R.id.fragment_container, true, true); break; case R.id.btn_add_show: FragmentUtils.addFragment(getFragmentManager(), Demo1Fragment.newInstance(), R.id.fragment_container, false, true); break; case R.id.btn_add_child: FragmentUtils.addFragment(getChildFragmentManager(), Demo2Fragment.newInstance(), R.id.child_fragment_container, false, true); break; case R.id.btn_pop_to_root: FragmentUtils.popToFragment(getFragmentManager(), Demo1Fragment.class, true); break; case R.id.btn_pop_add: FragmentUtils.popAddFragment(getFragmentManager(), Demo2Fragment.newInstance(), R.id.fragment_container, true, new FragmentUtils.SharedElement(this.btnShowAboutFragment, "btnShowAboutFragment")); break; case R.id.btn_hide_show: Fragment fragment1 = FragmentUtils.findFragment(getFragmentManager(), Demo1Fragment.class); if (fragment1 != null) { FragmentUtils.hideShowFragment(this, fragment1); } else { ToastUtils.showLong("please add demo1 first!"); } break; case R.id.btn_replace: Demo0Fragment demo0Fragment = Demo0Fragment.newInstance(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { demo0Fragment.setSharedElementEnterTransition(new DetailTransition()); setExitTransition(new Fade()); demo0Fragment.setEnterTransition(new Fade()); demo0Fragment.setSharedElementReturnTransition(new DetailTransition()); } ((FragmentActivity) getActivity()).rootFragment = FragmentUtils.replaceFragment(this, demo0Fragment, false, new FragmentUtils.SharedElement(ivSharedElement, getString(R.string.fragment_transition))); break; } }
Example #11
Source File: FragmentActivity.java From Android-UtilCode with Apache License 2.0 | 4 votes |
@Override public void doBusiness(Context context) { ArrayList<Fragment> fragments = new ArrayList<>(); fragments.add(Demo0Fragment.newInstance()); rootFragment = FragmentUtils.addFragments(getSupportFragmentManager(), fragments, R.id.fragment_container, 0); }
Example #12
Source File: FragmentActivity.java From Android-UtilCode with Apache License 2.0 | 4 votes |
@Override public void onBackPressed() { if (!FragmentUtils.dispatchBackPress(getSupportFragmentManager())) { super.onBackPressed(); } }