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

The following examples show how to use androidx.fragment.app.FragmentTransaction#commit() . 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: EditorActivity.java    From PHONK with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Toggle API drawer
 */
public void showAPIDrawer(boolean b) {

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left, R.anim.slide_out_left,
            R.anim.slide_out_left);

    if (b) {
        webviewFragment = new APIWebviewFragment();
        Bundle bundle = new Bundle();
        bundle.putString("url", "http://localhost:8585/reference.html");
        webviewFragment.setArguments(bundle);
        ft.add(R.id.fragmentWebview, webviewFragment).addToBackStack(null);

        editorFragment.getView().animate().translationX(-50).setDuration(500).start();
    } else {
        editorFragment.getView().animate().translationX(0).setDuration(500).start();
        ft.remove(webviewFragment);
    }

    ft.commit();
}
 
Example 2
Source File: OdysseyMainActivity.java    From odyssey with GNU General Public License v3.0 6 votes vote down vote up
private void onDirectorySelected(final String dirPath, final boolean isRootDirectory, final boolean addToBackStack) {
    // Create fragment and give it an argument for the selected directory
    final FilesFragment newFragment = FilesFragment.newInstance(dirPath, isRootDirectory);

    final FragmentManager fragmentManager = getSupportFragmentManager();

    final FragmentTransaction transaction = fragmentManager.beginTransaction();

    if (!isRootDirectory) {
        // no root directory so set a enter / exit transition
        final int layoutDirection = getResources().getConfiguration().getLayoutDirection();
        newFragment.setEnterTransition(new Slide(GravityCompat.getAbsoluteGravity(GravityCompat.START, layoutDirection)));
        newFragment.setExitTransition(new Slide(GravityCompat.getAbsoluteGravity(GravityCompat.END, layoutDirection)));
    }

    transaction.replace(R.id.fragment_container, newFragment);
    if (!isRootDirectory && addToBackStack) {
        // add fragment only to the backstack if it's not a root directory
        transaction.addToBackStack("FilesFragment");
    }

    // Commit the transaction
    transaction.commit();
}
 
Example 3
Source File: PreferencesTorFragment.java    From InviZible with GNU General Public License v3.0 6 votes vote down vote up
private void openCountrySelectFragment(int nodesType, String keyStr) {
    if (!isAdded()) {
        return;
    }

    FragmentTransaction fTrans = getParentFragmentManager().beginTransaction();
    fTrans.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    Fragment frg = new CountrySelectFragment();
    Bundle bndl = new Bundle();
    bndl.putInt("nodes_type", nodesType);
    bndl.putString("countries", val_tor.get(key_tor.indexOf(keyStr)));
    frg.setArguments(bndl);
    fTrans.replace(android.R.id.content, frg, "CountrySelectFragment");
    fTrans.addToBackStack("CountrySelectFragmentTag");
    fTrans.commit();
}
 
Example 4
Source File: OdysseyMainActivity.java    From odyssey with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void openArtworkSettings() {
    // Create fragment and give it an argument for the selected directory
    ArtworkSettingsFragment newFragment = ArtworkSettingsFragment.newInstance();

    FragmentManager fragmentManager = getSupportFragmentManager();

    FragmentTransaction transaction = fragmentManager.beginTransaction();

    // set enter / exit animation
    final int layoutDirection = getResources().getConfiguration().getLayoutDirection();
    newFragment.setEnterTransition(new Slide(GravityCompat.getAbsoluteGravity(GravityCompat.START, layoutDirection)));
    newFragment.setExitTransition(new Slide(GravityCompat.getAbsoluteGravity(GravityCompat.END, layoutDirection)));

    transaction.addToBackStack("ArtworkSettingsFragment");

    transaction.replace(R.id.fragment_container, newFragment);

    // Commit the transaction
    transaction.commit();
}
 
Example 5
Source File: ChromaDoze.java    From chromadoze with GNU General Public License v3.0 6 votes vote down vote up
private void changeFragment(Fragment f, boolean allowBack) {
    FragmentManager fragmentManager = getSupportFragmentManager();

    // Prune the stack, so "back" always leads home.
    if (fragmentManager.getBackStackEntryCount() > 0) {
        onSupportNavigateUp();
    }

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.fragment_container, f);
    if (allowBack) {
        transaction.addToBackStack(null);
        transaction
                .setTransition(FragmentTransaction.TRANSIT_NONE);
    }
    transaction.commit();
}
 
Example 6
Source File: MainActivity.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Open {@link EditPoiFragment} to add more info o POi
 *
 * @param poi {@link ParcelablePOI} to edit
 */
public void editPoi(ParcelablePOI poi) {
    //check authentication before editing
    if (!checkAuthentication()) return;
    //close PoiListFragment if it is open
    PoiListFragment poiListFragment = (PoiListFragment) getSupportFragmentManager().findFragmentByTag("PoiListFragment");
    if (poiListFragment != null)
        getSupportFragmentManager()
                .beginTransaction()
                .remove(poiListFragment)
                .commit();

    //if MapFragment is open close any routing
    MapFragment MapFragment = (MapFragment) getSupportFragmentManager().findFragmentByTag("MapFragment");
    if (MapFragment != null) {
        MapFragment.clearMapDisplay();
    }

    Fragment fragment = EditPoiFragment.newInstance(poi);
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.container, fragment, "EditPoiFragment");// give your fragment container id in first parameter
    transaction.addToBackStack(null);  // if written, this transaction will be added to backstack
    transaction.commit();
    hideNavigation();
}
 
Example 7
Source File: MainActivity.java    From Open-Source-Android-Weather-App with MIT License 6 votes vote down vote up
private void openCreditFragment() {
    // If there is at least one fragment already created.
    if (getSupportFragmentManager().getFragments().size() > 0) {
        /*Check if the CreditFragment already exists (on the top of the current backstack)
    (and if it's the current fragment on the screen, so we don't do anything)*/
        if (isLastFragmentInBackStack(CREDIT_FRAGMENT)) return;
    }


    CreditFragment creditFragment = (CreditFragment) getSupportFragmentManager().findFragmentByTag(CREDIT_FRAGMENT);
    FrameLayout frameLayout = findViewById(R.id.blankFrameLayoutForFragments);
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();

    /*this fragment isn't present on the backstack*/
    if (creditFragment == null)
        fragmentTransaction.replace(frameLayout.getId(), CreditFragment.newInstance(), CREDIT_FRAGMENT).addToBackStack(CREDIT_FRAGMENT);

        /* put back the old fragment on the top of the backstack*/
    else
        fragmentTransaction.replace(frameLayout.getId(), creditFragment, CREDIT_FRAGMENT);
    fragmentTransaction.commit();
}
 
Example 8
Source File: MainActivity.java    From googleads-mobile-android-examples with Apache License 2.0 6 votes vote down vote up
@Override
public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction trans = fragmentManager.beginTransaction();

    switch (position) {
        case 0: trans.replace(R.id.container, new AdMobAdListenerFragment()); break;
        case 1: trans.replace(R.id.container, new AdMobAdTargetingFragment()); break;
        case 2: trans.replace(R.id.container, new AdMobBannerSizesFragment()); break;
        case 3: trans.replace(R.id.container, new AdMobCustomMuteThisAdFragment()); break;
        case 4: trans.replace(R.id.container, new DFPFluidSizeFragment()); break;
        case 5: trans.replace(R.id.container, new DFPPPIDFragment()); break;
        case 6: trans.replace(R.id.container, new DFPCustomTargetingFragment()); break;
        case 7: trans.replace(R.id.container, new DFPCategoryExclusionFragment()); break;
        case 8: trans.replace(R.id.container, new DFPMultipleAdSizesFragment()); break;
        case 9: trans.replace(R.id.container, new DFPAppEventsFragment()); break;
        case 10: trans.replace(R.id.container, new DFPCustomControlsFragment()); break;
    }

    trans.commit();
}
 
Example 9
Source File: OdysseyMainActivity.java    From odyssey with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onArtistSelected(ArtistModel artist, Bitmap bitmap) {
    // Create fragment and give it an argument for the selected article
    ArtistAlbumsFragment newFragment = ArtistAlbumsFragment.newInstance(artist, bitmap);

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    // set enter / exit animation
    newFragment.setEnterTransition(new Slide(Gravity.BOTTOM));
    newFragment.setExitTransition(new Slide(Gravity.TOP));

    // Replace whatever is in the fragment_container view with this
    // fragment,
    // and add the transaction to the back stack so the user can navigate
    // back
    transaction.replace(R.id.fragment_container, newFragment);
    transaction.addToBackStack("ArtistFragment");

    // Commit the transaction
    transaction.commit();
}
 
Example 10
Source File: DetailFragment.java    From animation-samples with Apache License 2.0 5 votes vote down vote up
private void showStreetViewFragment(Detail detail) {
    StreetViewFragment streetViewFragment = getStreetViewFragment(detail);
    FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    /*
        The StreetViewFragment has to be added (not replaced)
        in order to get the transition animation right.
     */
    transaction.add(android.R.id.content, streetViewFragment, StreetViewFragment.TAG)
            .addToBackStack(StreetViewFragment.TAG);
    transaction.commit();
}
 
Example 11
Source File: MainActivity.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onLeftGame() {
    currentGame = null;
    ongoingGameFragment = null;
    gameChatFragment = null;
    AnalyticsApplication.sendAnalytics(Utils.ACTION_LEFT_GAME);

    inflateNavigation(Layout.LOBBY);
    navigation.setSelectedItem(Item.GAMES);

    synchronized (fragmentsLock) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();

        try {
            Fragment ongoingGame = manager.findFragmentByTag(Item.ONGOING_GAME.tag);
            if (ongoingGame != null) transaction.remove(ongoingGame);

            Fragment gameChat = manager.findFragmentByTag(Item.GAME_CHAT.tag);
            if (gameChat != null) transaction.remove(gameChat);

            transaction.commit();
        } catch (IllegalStateException ex) {
            Log.d(TAG, "Failed fragments transaction on left game.", ex);
        }
    }
}
 
Example 12
Source File: FolderChooserDialog.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();
    fragmentTransaction.add(R.id.dialogchooserfl, FolderListFragment.newInstance("", true));
    fragmentTransaction.commit();

    super.onActivityCreated(savedInstanceState);
}
 
Example 13
Source File: FleetConnectivityActivity.java    From here-android-sdk-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Pushes the @{link JobsFragment} on the stack.
 */
@Override
public void showJobs() {
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.anim.bottom_enter, R.anim.bottom_exit, R.anim.bottom_enter, R.anim.bottom_exit);
    ft.add(R.id.container, JobsFragment.newInstance(), JobsFragment.TAG);
    ft.addToBackStack(JobsFragment.TAG);
    ft.commit();
}
 
Example 14
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 15
Source File: FleetConnectivityActivity.java    From here-android-sdk-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Pushes the @{link JobDetailsFragment} on the stack.
 *
 * @param jobId ID of the job of which the details should be displayed.
 */
@Override
public void showJobDetails(String jobId) {
    FragmentManager fm = getSupportFragmentManager();
    if (fm.getBackStackEntryCount() > 0 && JobDetailsFragment.TAG.equals(fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1).getName())) {
        fm.popBackStack();
    }
    FragmentTransaction ft = fm.beginTransaction();
    ft.setCustomAnimations(R.anim.right_enter, R.anim.right_exit, R.anim.right_enter, R.anim.right_exit);
    ft.add(R.id.container, JobDetailsFragment.newInstance(jobId), JobDetailsFragment.TAG);
    ft.addToBackStack(JobDetailsFragment.TAG);
    ft.commit();
}
 
Example 16
Source File: ThetaFeatureActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * Fragment の遷移.
 * @param f Fragment
 */
private void moveFragment(final Fragment f) {
    FragmentTransaction t = getSupportFragmentManager().beginTransaction();
    t.setTransition(FragmentTransaction.TRANSIT_NONE);
    t.replace(android.R.id.content, f);
    t.addToBackStack(null);
    t.commit();

}
 
Example 17
Source File: BaseActivity.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
public void moveToFrag(Fragment frag) {
    //mFragment = frag;
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction().replace(R.id.basecontent, frag);
    if (frag != mDefaultFragment)
        transaction.addToBackStack(null);
    transaction.commit();
}
 
Example 18
Source File: ActivityView.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
private void onEditRule(Intent intent) {
    FragmentRule fragment = new FragmentRule();
    fragment.setArguments(intent.getExtras());
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("rule");
    fragmentTransaction.commit();
}
 
Example 19
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();
}
 
Example 20
Source File: MainActivity.java    From AndroidApp with Mozilla Public License 2.0 4 votes vote down vote up
@Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            Fragment fragment;
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            switch (item.getItemId()) {
                case R.id.navigation_categories:
                    fragment = CategoriesFragment.newInstance();
                    transaction.replace(R.id.content, fragment, "CategoriesFragment");
                    transaction.commit();
                    floatingActionButton.setVisibility(View.GONE);
                    fabPoiDetailsAfterRoute.hide();
                    return true;
                case R.id.navigation_map:
                    if (navigation.getSelectedItemId() != R.id.navigation_map) {
                        fragment = MapFragment.newInstance();
                        transaction.replace(R.id.content, fragment, "MapFragment");
                        transaction.commit();
                        floatingActionButton.setVisibility(View.VISIBLE);
//                        fabPoiDetailsAfterRoute.setVisibility(View.VISIBLE);
                    }
                    toggleFabPoiDetailsAfterRoute();

                    return true;
                case R.id.navigation_search:
                    fragment = SearchFragment.newInstance();
                    transaction.replace(R.id.content, fragment, "SearchFragment");
                    transaction.commit();
                    floatingActionButton.setVisibility(View.GONE);
                    fabPoiDetailsAfterRoute.hide();
                    return true;
                case R.id.navigation_favorites:
                    fragment = FavoritesFragment.newInstance();
                    transaction.replace(R.id.content, fragment, "FavoritesFragment");
                    transaction.commit();
                    floatingActionButton.setVisibility(View.GONE);
                    fabPoiDetailsAfterRoute.hide();
                    return true;
                case R.id.navigation_settings:
                    fragment = SettingsFragment.newInstance();
                    transaction.replace(R.id.content, fragment, "SettingsFragment");
                    transaction.commit();
                    floatingActionButton.setVisibility(View.GONE);
                    fabPoiDetailsAfterRoute.hide();
                    return true;
            }
            return false;
        }