Java Code Examples for androidx.fragment.app.FragmentTransaction#setPrimaryNavigationFragment()
The following examples show how to use
androidx.fragment.app.FragmentTransaction#setPrimaryNavigationFragment() .
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: TabBarFragment.java From AndroidNavigation with MIT License | 6 votes |
private void setChildFragmentsInternal(List<AwesomeFragment> fragments) { FragmentManager fragmentManager = getChildFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); for (int i = 0, size = fragments.size(); i < size; i++) { AwesomeFragment fragment = fragments.get(i); fragmentTags.add(fragment.getSceneId()); transaction.add(R.id.tabs_content, fragment, fragment.getSceneId()); if (i == selectedIndex) { transaction.setMaxLifecycle(fragment, Lifecycle.State.RESUMED); transaction.setPrimaryNavigationFragment(fragment); } else { transaction.setMaxLifecycle(fragment, Lifecycle.State.STARTED); transaction.hide(fragment); } } transaction.commit(); FragmentHelper.executePendingTransactionsSafe(fragmentManager); }
Example 2
Source File: TabBarFragment.java From AndroidNavigation with MIT License | 5 votes |
private void setSelectedIndexInternal(int index) { if (tabBarProvider != null) { tabBarProvider.setSelectedIndex(index); } if (selectedIndex == index) { return; } selectedIndex = index; FragmentManager fragmentManager = getChildFragmentManager(); AwesomeFragment previous = (AwesomeFragment) fragmentManager.getPrimaryNavigationFragment(); AwesomeFragment current = fragments.get(index); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.setPrimaryNavigationFragment(current); if (previous != null && previous.isAdded()) { setPresentAnimation(current, previous); transaction.setMaxLifecycle(previous, Lifecycle.State.STARTED); transaction.hide(previous); } transaction.setMaxLifecycle(current, Lifecycle.State.RESUMED); transaction.show(current); transaction.commit(); FragmentHelper.executePendingTransactionsSafe(fragmentManager); if (tabBar != null) { NavigationFragment navigationFragment = current.getNavigationFragment(); if (navigationFragment != null && navigationFragment.shouldHideTabBarWhenPushed()) { if (navigationFragment.getChildFragmentCountAtBackStack() <= 1) { showTabBar(); } else { hideTabBar(); } } else { showTabBar(); } } }
Example 3
Source File: FragmentHelper.java From AndroidNavigation with MIT License | 5 votes |
public static void addFragmentToAddedList(@NonNull FragmentManager fragmentManager, int containerId, @NonNull AwesomeFragment fragment, @NonNull Lifecycle.State maxLifecycle, boolean primary) { if (fragmentManager.isDestroyed()) { return; } FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(containerId, fragment, fragment.getSceneId()); if (primary) { transaction.setPrimaryNavigationFragment(fragment); // primary } transaction.setMaxLifecycle(fragment, maxLifecycle); transaction.commit(); executePendingTransactionsSafe(fragmentManager); }
Example 4
Source File: MessageActivity.java From tindroid with Apache License 2.0 | 4 votes |
void showFragment(String tag, Bundle args, boolean addToBackstack) { if (isFinishing() || isDestroyed()) { return; } FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentByTag(tag); if (fragment == null) { switch (tag) { case FRAGMENT_MESSAGES: fragment = new MessagesFragment(); break; case FRAGMENT_INFO: fragment = new TopicInfoFragment(); break; case FRAGMENT_PERMISSIONS: fragment = new TopicPermissionsFragment(); break; case FRAGMENT_EDIT_MEMBERS: fragment = new EditMembersFragment(); break; case FRAGMENT_VIEW_IMAGE: fragment = new ImageViewFragment(); break; case FRAGMENT_FILE_PREVIEW: fragment = new FilePreviewFragment(); break; case FRAGMENT_INVALID: fragment = new InvalidTopicFragment(); break; } } else if (args == null) { // Retain old arguments. args = fragment.getArguments(); } if (fragment == null) { throw new NullPointerException(); } args = args != null ? args : new Bundle(); args.putString("topic", mTopicName); args.putString(MessagesFragment.MESSAGE_TO_SEND, mMessageText); if (fragment.getArguments() != null) { fragment.getArguments().putAll(args); } else { fragment.setArguments(args); } FragmentTransaction trx = fm.beginTransaction(); if (!fragment.isAdded()) { trx = trx.replace(R.id.contentFragment, fragment, tag) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); } else if (!fragment.isVisible()) { trx = trx.show(fragment); } else { addToBackstack = false; } if (FRAGMENT_MESSAGES.equals(tag)) { trx.setPrimaryNavigationFragment(fragment); } if (addToBackstack) { trx.addToBackStack(tag); } if (!trx.isEmpty()) { trx.commit(); } }