Java Code Examples for androidx.fragment.app.FragmentManager#getFragments()
The following examples show how to use
androidx.fragment.app.FragmentManager#getFragments() .
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: BackPressEventDispatchHelper.java From SmsCode with GNU General Public License v3.0 | 6 votes |
public static boolean dispatchBackPressedEvent(FragmentManager fragmentManager) { List<Fragment> fragments = fragmentManager.getFragments(); if (fragments == null) return false; for (int i = fragments.size() - 1; i >= 0; i--) { Fragment fragment = fragments.get(i); if (isBackPressedIntercepted(fragment)) { ((BackPressedListener) fragment).onBackPressed(); return true; } } if (fragmentManager.getBackStackEntryCount() > 0) { fragmentManager.popBackStack(); return true; } return false; }
Example 2
Source File: BackPressEventDispatchHelper.java From XposedSmsCode with GNU General Public License v3.0 | 6 votes |
public static boolean dispatchBackPressedEvent(FragmentManager fragmentManager) { List<Fragment> fragments = fragmentManager.getFragments(); if (fragments == null) return false; for (int i = fragments.size() - 1; i >= 0; i--) { Fragment fragment = fragments.get(i); if (isBackPressedIntercepted(fragment)) { ((BackPressedListener) fragment).onBackPressed(); return true; } } if (fragmentManager.getBackStackEntryCount() > 0) { fragmentManager.popBackStack(); return true; } return false; }
Example 3
Source File: Main2Activity.java From AndroidGodEye with Apache License 2.0 | 6 votes |
private void showFragment(int index) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); List<Fragment> fragments = fragmentManager.getFragments(); for (int i = 0; i < fragments.size(); i++) { fragmentTransaction.hide(fragments.get(i)); } String fragmentName = ""; if (index == 0) { fragmentName = InstallFragment.class.getSimpleName(); } else if (index == 1) { fragmentName = ConsumeFragment.class.getSimpleName(); } else if (index == 2) { fragmentName = ToolsFragment.class.getSimpleName(); } fragmentTransaction.show(Objects.requireNonNull(fragmentManager.findFragmentByTag(fragmentName))).commit(); }
Example 4
Source File: EditProfileActivity.java From Easer with GNU General Public License v3.0 | 6 votes |
@Override protected void init() { editText_profile_name = findViewById(R.id.editText_profile_title); operationSelectorFragment = new OperationSelectorFragment(); operationSelectorFragment.setSelectedListener(this); findViewById(R.id.button_add_operation).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { operationSelectorFragment.show(getSupportFragmentManager(), "add_op"); } }); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); for (Fragment fragment : fragmentManager.getFragments()) { transaction.remove(fragment); } transaction.commit(); }
Example 5
Source File: IRKitSettingActivity.java From DeviceConnect-Android with MIT License | 6 votes |
/** * getFragments()とgetViewPager().getCurrentItem()の紐付けを行う。 * 表示していたFragmentを返す。 * @return 表示していたFragment */ private Fragment getCurrentFragment(final int current) { FragmentManager fm = getSupportFragmentManager(); Fragment f = null; List<Fragment> list = fm.getFragments(); if (list.size() == 0) { return f; } String className = PAGES[current].getSimpleName(); for (Fragment fragment : list) { if (fragment.getClass().getSimpleName().equals(className)) { f = fragment; } } return f; }
Example 6
Source File: ActivityView.java From FairEmail with GNU General Public License v3.0 | 5 votes |
private void init() { Bundle args = new Bundle(); long account = getIntent().getLongExtra("account", -1); FragmentBase fragment; switch (startup) { case "accounts": fragment = new FragmentAccounts(); args.putBoolean("settings", false); break; case "folders": fragment = new FragmentFolders(); args.putLong("account", account); break; case "primary": fragment = new FragmentFolders(); if (account < 0) args.putBoolean("primary", true); else args.putLong("account", account); break; default: fragment = new FragmentMessages(); } fragment.setArguments(args); FragmentManager fm = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); for (Fragment existing : fm.getFragments()) fragmentTransaction.remove(existing); fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("unified"); fragmentTransaction.commit(); }
Example 7
Source File: ViewCheckInfoDokitView.java From DoraemonKit with Apache License 2.0 | 5 votes |
private String getVisibleFragment(Activity activity) { if (activity == null) { return null; } StringBuilder builder = new StringBuilder(); if (activity instanceof AppCompatActivity) { AppCompatActivity compatActivity = (AppCompatActivity) activity; FragmentManager fragmentManager = compatActivity.getSupportFragmentManager(); List<Fragment> fragments = fragmentManager.getFragments(); if (fragments != null && fragments.size() != 0) { for (int i = 0; i < fragments.size(); i++) { Fragment fragment = fragments.get(i); if (fragment != null && fragment.isVisible()) { builder.append(fragment.getClass().getSimpleName() + "#" + fragment.getId()); if (i < fragments.size() - 1) { builder.append(";"); } } } return builder.toString(); } else { return getFragmentForActivity(activity); } } else { return getFragmentForActivity(activity); } }
Example 8
Source File: FragmentHelper.java From AndroidNavigation with MIT License | 5 votes |
@Nullable public static Fragment findDescendantFragment(@NonNull FragmentManager fragmentManager, @NonNull String tag) { Fragment target = fragmentManager.findFragmentByTag(tag); if (target == null) { List<Fragment> fragments = fragmentManager.getFragments(); int count = fragments.size(); for (int i = count - 1; i > -1; i--) { Fragment f = fragments.get(i); if (f.isAdded()) { if (f instanceof AwesomeFragment) { AwesomeFragment af = (AwesomeFragment) f; if (af.getSceneId().equals(tag)) { target = af; } } if (target == null) { target = findDescendantFragment(f.getChildFragmentManager(), tag); } if (target != null) { break; } } } } return target; }
Example 9
Source File: FragmentHelper.java From AndroidNavigation with MIT License | 5 votes |
@NonNull public static List<AwesomeFragment> getFragmentsAtAddedList(@NonNull FragmentManager fragmentManager) { List<AwesomeFragment> children = new ArrayList<>(); List<Fragment> fragments = fragmentManager.getFragments(); for (int i = 0, size = fragments.size(); i < size; i++) { Fragment fragment = fragments.get(i); if (fragment instanceof AwesomeFragment && fragment.isAdded()) { children.add((AwesomeFragment) fragment); } } return children; }
Example 10
Source File: MainActivity.java From microMathematics with GNU General Public License v3.0 | 5 votes |
@SuppressLint("RestrictedApi") public BaseFragment getVisibleFragment() { FragmentManager fragmentManager = MainActivity.this.getSupportFragmentManager(); List<Fragment> fragments = fragmentManager.getFragments(); for (Fragment fragment : fragments) { if (fragment != null && fragment.isVisible() && (fragment instanceof BaseFragment)) { return (BaseFragment) fragment; } } return null; }
Example 11
Source File: BasisFragment.java From FastLib with Apache License 2.0 | 5 votes |
/** * 检查Fragment或FragmentActivity承载的Fragment是否只有一个 * * @return */ protected boolean isSingleFragment() { int size = 0; FragmentManager manager = getFragmentManager(); if (manager != null && manager.getFragments() != null) { size = manager.getFragments().size(); } LoggerManager.i(TAG, TAG + ";FragmentManager承载Fragment数量:" + size); return size <= 1; }
Example 12
Source File: NoteTakingActivity.java From science-journal with Apache License 2.0 | 5 votes |
private void hideAllFragmentsInToolPane() { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); for (Fragment fragment : fragmentManager.getFragments()) { if (!fragment.equals(defaultFragment)) { ft.hide(fragment); } } ft.commit(); }
Example 13
Source File: UiUtils.java From tindroid with Apache License 2.0 | 5 votes |
@Nullable static Fragment getVisibleFragment(@NonNull FragmentManager fm) { List<Fragment> fragments = fm.getFragments(); for (Fragment f : fragments) { if (f.isVisible()) { return f; } } return null; }
Example 14
Source File: BaseLazyLoadFragment.java From MVPArms with Apache License 2.0 | 5 votes |
/** * ViewPager场景下,当前fragment可见时,如果其子fragment也可见,则让子fragment请求数据 */ private void dispatchParentVisibleState() { FragmentManager fragmentManager = getChildFragmentManager(); List<Fragment> fragments = fragmentManager.getFragments(); if (fragments.isEmpty()) { return; } for (Fragment child : fragments) { if (child instanceof BaseLazyLoadFragment && ((BaseLazyLoadFragment) child).isVisibleToUser) { ((BaseLazyLoadFragment) child).tryLoadData(); } } }
Example 15
Source File: AccessLogActivity.java From DeviceConnect-Android with MIT License | 5 votes |
/** * Fragment の {@link BaseFragment#onReturn()} を呼び出します. */ private void callFragment() { FragmentManager manager = getSupportFragmentManager(); List<Fragment> fragments = manager.getFragments(); for (Fragment fragment : fragments) { if (fragment instanceof BaseFragment) { ((BaseFragment) fragment).onReturn(); } } }
Example 16
Source File: ThetaDeviceSettingsActivity.java From DeviceConnect-Android with MIT License | 5 votes |
private void onModelSelected(final ThetaDeviceModel model) { FragmentManager fragmentMgr = getSupportFragmentManager(); List<Fragment> list = fragmentMgr.getFragments(); if (list != null) { for (Fragment f : list) { if (f instanceof SettingsFragment) { ((SettingsFragment) f).onModelSelected(model); } } } }