Java Code Examples for androidx.fragment.app.FragmentTransaction#add()

The following examples show how to use androidx.fragment.app.FragmentTransaction#add() . 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: SubsonicFragmentActivity.java    From Audinaut with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void replaceFragment(SubsonicFragment fragment, int tag, boolean replaceCurrent) {
    if (slideUpPanel != null && isNowPlayingOpen() && !isPanelClosing) {
        secondaryFragment = fragment;
        nowPlayingFragment.setPrimaryFragment(false);
        secondaryFragment.setPrimaryFragment(true);
        supportInvalidateOptionsMenu();

        FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
        trans.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right);
        trans.hide(nowPlayingFragment);
        trans.add(R.id.now_playing_fragment_container, secondaryFragment, tag + "");
        trans.commit();
    } else {
        super.replaceFragment(fragment, tag, replaceCurrent);
    }
}
 
Example 2
Source File: BaseActivity.java    From NewFastFrame with Apache License 2.0 6 votes vote down vote up
protected void addBackStackFragment(Fragment fragment, boolean needAddBackStack, View... views) {
    if (backStackLayoutId == 0) {
        return;
    }
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();


    if (views != null && views.length > 0) {
        fragmentTransaction.replace(backStackLayoutId, fragment);
        for (View item :
                views) {
            fragmentTransaction.addSharedElement(item, ViewCompat.getTransitionName(item));
        }
    } else {
        fragmentTransaction
                .add(backStackLayoutId, fragment);
    }
    if (needAddBackStack) {
        fragmentTransaction.addToBackStack(null);
    }
    fragmentTransaction.commit();
}
 
Example 3
Source File: DevicePluginListActivity.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTitle(R.string.activity_devicepluginlist_title);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    if (savedInstanceState == null) {
        Fragment f = new DevicePluginListFragment();
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction t = fm.beginTransaction();
        t.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        t.add(android.R.id.content, f, "container");
        t.commit();
    }
}
 
Example 4
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * Shows a specific preference fragment.
 *
 * @param navigationPreference
 *         The navigation preference, the fragment, which should be shown, is associated with,
 *         as an instance of the class {@link NavigationPreference}. The navigation preference
 *         may not be null
 * @param fragment
 *         The fragment, which should be shown, as an instance of the class Fragment. The
 *         fragment may not be null
 */
private void showPreferenceFragment(@NonNull final NavigationPreference navigationPreference,
                                    @NonNull final Fragment fragment) {
    fragment.setRetainInstance(true);
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    if (!isSplitScreen()) {
        transaction.hide(navigationFragment);

        if (preferenceFragment != null) {
            transaction.remove(preferenceFragment);
            notifyOnPreferenceFragmentHidden(preferenceFragment);
        }

        transaction.add(R.id.navigation_fragment_container, fragment, PREFERENCE_FRAGMENT_TAG);
    } else {
        if (preferenceFragment != null) {
            notifyOnPreferenceFragmentHidden(preferenceFragment);
        }

        transaction
                .replace(R.id.preference_fragment_container, fragment, PREFERENCE_FRAGMENT_TAG);
    }

    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    transaction.commit();
    this.preferenceFragment = fragment;
    showToolbarNavigationIcon();
    adaptBreadCrumbVisibility(selectedPreferenceFragmentArguments);
    notifyOnPreferenceFragmentShown(navigationPreference, fragment);
}
 
Example 5
Source File: MainActivity.java    From WanAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 装载Fragments
 */
private void loadMultipleFragment(int containerId, int showFragment, Fragment... fragments){
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    for(int i = 0; i < fragments.length; i++){
        Fragment fragment = fragments[i];
        transaction.add(containerId, fragment, fragment.getClass().getName());
        if(i != showFragment){
            transaction.hide(fragment);
        }
    }
    transaction.commitAllowingStateLoss();
}
 
Example 6
Source File: ThetaDeviceActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mDeviceMgr = getDeviceManager();
    mDeviceMgr.startDeviceDetection();
    Fragment fragment = getSupportFragmentManager().findFragmentByTag(TAG_LIST);
    if (fragment == null) {
        fragment = ThetaGalleryFragment.newInstance(mDeviceMgr);
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add(android.R.id.content, fragment, TAG_LIST);
        ft.commit();
    }
}
 
Example 7
Source File: AppRunnerActivity.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
public void initAppRunner() {
    // Set the Activity UI
    setContentView(R.layout.apprunner_activity);
    setupActivity();

    // Add debug fragment
    if (AppRunnerSettings.DEBUG) addDebugFragment();

    // add AppRunnerFragment
    mAppRunnerFragment = AppRunnerFragment.newInstance(mBundle, scriptSettings);
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    FrameLayout fl = findViewById(R.id.apprunner_fragment);
    ft.add(fl.getId(), mAppRunnerFragment, String.valueOf(fl.getId()));
    ft.commit();
}
 
Example 8
Source File: StartConversationActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Fragment instantiateItem(@NonNull ViewGroup container, int position) {
    final Fragment fragment = getItem(position);
    final FragmentTransaction trans = fragmentManager.beginTransaction();
    trans.add(container.getId(), fragment, "fragment:" + position);
    try {
        trans.commit();
    } catch (IllegalStateException e) {
        //ignore
    }
    return fragment;
}
 
Example 9
Source File: FileManagerDialog.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
    FileManagerFragment fmf = FileManagerFragment.newInstance();
    Bundle bundle = new Bundle();
    bundle.putString(FileManagerFragment.ROOT_FOLDER, "/sdcard/phonk_io/examples");
    fmf.setArguments(bundle);
    fragmentTransaction.add(R.id.dialogchooserfl, fmf);
    fragmentTransaction.commit();

    super.onActivityCreated(savedInstanceState);
}
 
Example 10
Source File: FragmentLifecycleActivity.java    From AndroidAll with Apache License 2.0 5 votes vote down vote up
public void showFragment(@NonNull Fragment fragment) {
    //相当于new一个实例FragmentTransaction
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    if (fragment.isAdded()) {
        ft.show(fragment);
    } else {
        //把该ft加入到栈中进行管理
        ft.addToBackStack(fragment.getClass().getSimpleName());
        ft.add(R.id.container, fragment);
    }
    ft.commitAllowingStateLoss();
    Log.e("Lifecycle", "getBackStackEntryCount: " + getSupportFragmentManager().getBackStackEntryCount());
}
 
Example 11
Source File: EditorActivity.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
public void addFileManagerDrawer(Bundle savedInstance, boolean b) {
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_left);

    if (b) {

        if (savedInstance == null) {
            fileFragment = FileManagerFragment.newInstance();
            Bundle bundle = new Bundle();
            bundle.putString(FileManagerFragment.ROOT_FOLDER, mCurrentProject.getFullPath());

            // we pass the initial route to hide
            bundle.putString(FileManagerFragment.PATH_HIDE_PATH_FROM, mCurrentProject.geFoldertPath());
            fileFragment.setArguments(bundle);

            if (isTablet) {
                ft.add(R.id.fragmentFileManager, fileFragment, FRAGMENT_FILE_PREVIEWER);
            } else {
                ft.add(R.id.fragmentFileManager, fileFragment, FRAGMENT_FILE_PREVIEWER).addToBackStack("filemanager");
            }
        } else {
            if (isTablet) {
                filePreviewerFragment = (FilePreviewerFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_FILE_PREVIEWER);
            } else {
                filePreviewerFragment = (FilePreviewerFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_FILE_PREVIEWER);
            }
        }

    } else {
        ft.remove(fileFragment);
    }

    ft.commit();
}
 
Example 12
Source File: BaseActivity.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
public void addFragment(Fragment fragment, int fragmentPosition, String tag, boolean addToBackStack) {
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
    ft.add(fragmentPosition, fragment, tag);
    // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    if (addToBackStack) {
        ft.addToBackStack(null);
    }
    ft.commit();
}
 
Example 13
Source File: ExtendedDialogFragment.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void show(FragmentManager manager, String tag) {
    try {
        FragmentTransaction ft = manager.beginTransaction();
        ft.add(this, tag);
        ft.commitAllowingStateLoss();
    } catch (IllegalStateException e) {
        Log.w(LOG_TAG, "ExtendedDialogFragment Exception " + e.getMessage() + " " + e.getCause());
    }
}
 
Example 14
Source File: CombinedFolderAndProjectFragment.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    v = inflater.inflate(R.layout.fragment_combined, container, false);

    FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
    fragmentTransaction.add(R.id.folders, mFolderListFragment);
    fragmentTransaction.add(R.id.projects, mProjectListFragment);
    fragmentTransaction.commit();

    return v;

}
 
Example 15
Source File: MainActivity.java    From AndroidAll with Apache License 2.0 5 votes vote down vote up
private void showFragment(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, int frameId) {
    //Log.e("Lifecycle", "MainActivity fragment.isAdded() : " + fragment.isAdded() + ", " + fragment);
    FragmentTransaction ft = fragmentManager.beginTransaction();
    if (fragment.isAdded()) {
        ft.show(fragment);
    } else {
        ft.add(frameId, fragment);
    }
    ft.commitAllowingStateLoss();
}
 
Example 16
Source File: SetupWizardActivity.java    From talkback with Apache License 2.0 4 votes vote down vote up
private void displayScreen(SetupScreen screen) {
  FragmentManager fragmentManager = getSupportFragmentManager();
  /* Hide the previous fragment. */
  if (currentScreenFragment != null) {
    /* In order to ensure that state information from the previous fragment has been saved, hide
     * the previous fragment with a separate fragment transaction than the one used to show the
     * new fragment. */
    fragmentManager
        .beginTransaction()
        .hide(currentScreenFragment)
        .setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out)
        .commitAllowingStateLoss();
    fragmentManager.executePendingTransactions();
  }

  SetupWizardScreenFragment fragment =
      (SetupWizardScreenFragment) fragmentManager.findFragmentByTag(screen.name());
  FragmentTransaction transaction = fragmentManager.beginTransaction();

  transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
  if (fragment == null) {
    /* Create a new fragment. */
    fragment = createScreenFragment(screen);
    if (currentScreenFragment != null) {
      transaction.add(R.id.fragment_layout_container, fragment, screen.name());
    } else {
      transaction.replace(R.id.fragment_layout_container, fragment, screen.name());
    }
  } else {
    /* The desired fragment has been previously created, so show it. */
    transaction.show(fragment);
  }

  /* Update the view to reflect the new screen. */
  transaction.commitAllowingStateLoss();
  currentScreenFragment = fragment;
  currentSetupScreen = screen;
  setNavigationButtonText(currentScreenFragment);

  if (screenViewListener != null) {
    screenViewListener.onScreenShown(currentScreenFragment.getScreenName());
  }

  if (setupScreenListener != null) {
    setupScreenListener.onSetupScreenShown(currentSetupScreen);
  }
}
 
Example 17
Source File: BaseActivity.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
public void addFragment(Fragment f, int id, String tag) {
    FrameLayout fl = findViewById(id);
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.add(fl.getId(), f, tag);
    ft.commit();
}
 
Example 18
Source File: BaseDialogFragment.java    From android-styled-dialogs with Apache License 2.0 4 votes vote down vote up
public void showAllowingStateLoss(FragmentManager manager, String tag) {
    FragmentTransaction ft = manager.beginTransaction();
    ft.add(this, tag);
    ft.commitAllowingStateLoss();
}
 
Example 19
Source File: MainDiscoveryFragment.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
private void commitFragmentTransaction(@NonNull Fragment fragment, @Nullable String tag) {
    final FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
    fragmentTransaction.add(R.id.fl_container, fragment, tag);
    fragmentTransaction.commit();
}
 
Example 20
Source File: LicenseActivity.java    From science-journal with Apache License 2.0 4 votes vote down vote up
private void showLicense(License license) {
  FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
  ft.add(R.id.container, LicenseFragment.newInstance(license), "license");
  ft.addToBackStack(license.key);
  ft.commit();
}