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

The following examples show how to use androidx.fragment.app.FragmentTransaction#setTransition() . 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: 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 2
Source File: PreferenceActivity.java    From AndroidPreferenceActivity with Apache License 2.0 6 votes vote down vote up
/**
 * Removes the currently preference fragment, regardless of whether the split screen layout is
 * used, or not.
 */
private void removePreferenceFragmentUnconditionally() {
    if (isPreferenceFragmentShown()) {
        resetTitle();
        hideToolbarNavigationIcon();
        adaptBreadCrumbVisibility();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.remove(preferenceFragment);

        if (!isSplitScreen()) {
            transaction.show(navigationFragment);
        }

        transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
        transaction.commit();
        notifyOnPreferenceFragmentHidden(preferenceFragment);
        preferenceFragment = null;
    }
}
 
Example 3
Source File: SettingsActivity.java    From APDE with GNU General Public License v2.0 6 votes vote down vote up
public void selectSettingsFragment(String preferencesXml) {
	Bundle args = new Bundle(1);
	args.putString("resource", preferencesXml);
	
	StockPreferenceFragment newFragment = new StockPreferenceFragment();
	newFragment.setArguments(args);
	
	FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
	transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
	
	transaction.remove(getSupportFragmentManager().findFragmentById(R.id.settings_fragment_container));
	
	transaction.add(R.id.settings_fragment_container, newFragment);
	if (!isMultiPane()) {
		transaction.addToBackStack(null);
	}
	
	transaction.commit();
}
 
Example 4
Source File: SettingsActivity.java    From GotoSleep with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPreferenceStartScreen(androidx.preference.PreferenceFragmentCompat caller, PreferenceScreen pref) {
    final String TAG = "onPreferenceStartScreen";
    SettingsFragment fragment = new SettingsFragment();
    Bundle args = new Bundle();
    args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, pref.getKey());
    fragment.setArguments(args);

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.replace(R.id.fragment, fragment, pref.getKey());
    ft.addToBackStack(pref.getKey());
    ft.commitAllowingStateLoss();

    Log.d(TAG, pref + "");
    return true;
}
 
Example 5
Source File: FragmentController.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
public void navigateToFragment(Fragment fragment, String tag, boolean addToBackStack, TransitionEffect animation, int containerResId) {

        FragmentTransaction transaction = fragmentManager.beginTransaction();

        if (animation != null && animation.isAnimation()) {
            transaction.setCustomAnimations(animation.enter, animation.exit, animation.popEnter, animation.popExit);
        }

        if (animation != null && animation.isTransition()) {
            transaction.setTransition(animation.transitionId);
        }

        transaction.replace(containerResId, fragment, fragment.getClass().getName());
        if (addToBackStack)
            transaction.addToBackStack(tag);

        try {
            transaction.commitAllowingStateLoss();
        } catch (Exception e) {
            logger.error("An error occurred while navigating to fragment.", e);
        }
    }
 
Example 6
Source File: FilterSearchResults.java    From box-android-browse-sdk with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_filter_search_results2);
    if (savedInstanceState != null) {
        mFilters = (BoxSearchFilters) savedInstanceState.getSerializable(EXTRA_FILTERS);
    }
    else {
        mFilters = (BoxSearchFilters) getIntent().getExtras().getSerializable(EXTRA_FILTERS);
    }

    mFragment = (BoxFilterSearchResultsFragment) getSupportFragmentManager().findFragmentById(R.id.fragmentContainer);
    if (mFragment == null) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.setTransition(FragmentTransaction.TRANSIT_NONE);
        mFragment = BoxFilterSearchResultsFragment.newInstance(mFilters);
        ft.add(R.id.fragmentContainer, mFragment);
        ft.commit();
    }
}
 
Example 7
Source File: MainActivity.java    From VoIpUSSD with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    int id = item.getItemId();
    Fragment newFragment = null;
    String tittle = null;
    if (id == R.id.op1) {
        newFragment = new MainFragment();
        tittle = getResources().getString(R.string.title_activity_cp1);
    }
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    getSupportActionBar().setTitle(tittle);
    ft.replace(R.id.fragment_layout, newFragment); // f1_container is your FrameLayout container
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.addToBackStack(null);
    ft.commit();
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example 8
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 9
Source File: DNSServersAdapter.java    From InviZible with GNU General Public License v3.0 6 votes vote down vote up
private void openDNSRelaysPref(int position) {
    DNSServerItem dnsServer = getItem(position);
    Bundle bundle = new Bundle();
    bundle.putString("dnsServerName", dnsServer.getName());
    bundle.putSerializable("routesCurrent", routes_current);
    bundle.putBoolean("dnsServerIPv6", dnsServer.isIpv6());
    PreferencesDNSCryptRelays preferencesDNSCryptRelays = new PreferencesDNSCryptRelays();
    preferencesDNSCryptRelays.setOnRoutesChangeListener(preferencesDNSCryptServers);
    preferencesDNSCryptRelays.setArguments(bundle);
    if (fragmentManager != null) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        fragmentTransaction.replace(android.R.id.content, preferencesDNSCryptRelays);
        fragmentTransaction.addToBackStack("preferencesDNSCryptRelaysTag");
        fragmentTransaction.commit();
    }
}
 
Example 10
Source File: TriviaGameActivity.java    From LibreTrivia with GNU General Public License v3.0 5 votes vote down vote up
private void onNetworkError() {
    String msg = getResources().getString(R.string.error_network);
    Fragment errorFragment = TriviaGameErrorFragment.newInstance(msg);

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.frame_trivia_game, errorFragment);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.commit();
}
 
Example 11
Source File: TabBarFragment.java    From AndroidNavigation with MIT License 5 votes vote down vote up
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 12
Source File: NavigationFragment.java    From AndroidNavigation with MIT License 5 votes vote down vote up
private void redirectToFragmentInternal(AwesomeFragment fragment, AwesomeFragment target, boolean animated) {
    FragmentManager fragmentManager = getChildFragmentManager();

    AwesomeFragment topFragment = getTopFragment();
    if (topFragment == null) {
        return;
    }

    if (target == null) {
        target = topFragment;
    }

    AwesomeFragment aheadFragment = FragmentHelper.getAheadFragment(fragmentManager, target);

    topFragment.setAnimation(animated ? PresentAnimation.Redirect : PresentAnimation.Fade);
    if (aheadFragment != null && aheadFragment.isAdded()) {
        aheadFragment.setAnimation(animated ? PresentAnimation.Redirect : PresentAnimation.Fade);
    }

    fragmentManager.beginTransaction().setMaxLifecycle(topFragment, Lifecycle.State.STARTED).commit();

    fragmentManager.popBackStack(target.getSceneId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.setReorderingAllowed(true);
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    if (aheadFragment != null && aheadFragment.isAdded()) {
        transaction.hide(aheadFragment);
        transaction.setMaxLifecycle(aheadFragment, Lifecycle.State.STARTED);
    }
    fragment.setAnimation(animated ? PresentAnimation.Push : PresentAnimation.None);
    transaction.add(R.id.navigation_content, fragment, fragment.getSceneId());
    transaction.addToBackStack(fragment.getSceneId());
    transaction.commit();
    FragmentHelper.executePendingTransactionsSafe(fragmentManager);
}
 
Example 13
Source File: GitHistoryActivity.java    From APDE with GNU General Public License v2.0 5 votes vote down vote up
protected void loadFragment(Fragment fragment, int id, boolean transition) {
	FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
	transaction.replace(id, fragment);
	if (transition) {
		transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
		transaction.addToBackStack(null);
	}
	transaction.commit();
}
 
Example 14
Source File: MainActivity.java    From guanggoo-android with Apache License 2.0 5 votes vote down vote up
public static void addFragmentToStack(FragmentManager fm, Fragment fragment) {
    FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.fragment_container, fragment);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.addToBackStack(sStackName);
    ft.commit();
}
 
Example 15
Source File: TreatmentsFragment.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setFragment(Fragment selectedFragment) {
    FragmentTransaction ft = getChildFragmentManager().beginTransaction();
    ft.replace(R.id.treatments_fragment_container, selectedFragment); // f2_container is your FrameLayout container
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.addToBackStack(null);
    ft.commit();
}
 
Example 16
Source File: WhitelistActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.activity_whitelist_title);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    
    if (savedInstanceState == null) {
        Fragment f = new WhitelistFragment();
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction t = fm.beginTransaction();
        t.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        t.add(android.R.id.content, f, "continar");
        t.commit();
    }
}
 
Example 17
Source File: ConfigEditorFragment.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
public static void openEditorFragment(FragmentManager fragmentManager, String fileName) {
    Bundle bundle = new Bundle();
    bundle.putString("fileName", fileName);
    ConfigEditorFragment configEditorFragment = new ConfigEditorFragment();
    configEditorFragment.setArguments(bundle);
    if (fragmentManager != null) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        fragmentTransaction.replace(android.R.id.content, configEditorFragment);
        fragmentTransaction.addToBackStack("configEditorFragmentTag");
        fragmentTransaction.commit();
    }
}
 
Example 18
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 19
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 20
Source File: AppUtil.java    From weather with Apache License 2.0 5 votes vote down vote up
/**
 * Show fragment with fragment manager with animation parameter
 *
 * @param fragment        instance of {@link Fragment}
 * @param fragmentManager instance of {@link FragmentManager}
 * @param withAnimation   boolean value
 */
public static void showFragment(Fragment fragment, FragmentManager fragmentManager, boolean withAnimation) {
  FragmentTransaction transaction = fragmentManager.beginTransaction();
  if (withAnimation) {
    transaction.setCustomAnimations(R.anim.slide_up_anim, R.anim.slide_down_anim);
  } else {
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
  }
  transaction.add(android.R.id.content, fragment).addToBackStack(null).commit();
}