List of usage examples for android.app FragmentTransaction setCustomAnimations
public abstract FragmentTransaction setCustomAnimations(@AnimatorRes int enter, @AnimatorRes int exit, @AnimatorRes int popEnter, @AnimatorRes int popExit);
From source file:com.geecko.QuickLyric.MainActivity.java
private void selectItem(int position) { FragmentManager fragmentManager = getFragmentManager(); Fragment newFragment;/*from w w w . j ava 2s . co m*/ String tag; switch (position) { default: // Lyrics tag = LYRICS_FRAGMENT_TAG; newFragment = fragmentManager.findFragmentByTag(tag); if (newFragment == null || !(newFragment instanceof LyricsViewFragment)) newFragment = new LyricsViewFragment(); ((LyricsViewFragment) newFragment).showTransitionAnim = true; break; case 1: // Saved Lyrics tag = LOCAL_LYRICS_FRAGMENT_TAG; newFragment = fragmentManager.findFragmentByTag(tag); if (newFragment == null || !(newFragment instanceof LocalLyricsFragment)) newFragment = new LocalLyricsFragment(); ((LocalLyricsFragment) newFragment).showTransitionAnim = true; break; case 2: // Separator return; case 3: // Settings if (drawer instanceof DrawerLayout) ((DrawerLayout) drawer).closeDrawer(drawerView); drawer.postDelayed(new Runnable() { @Override public void run() { Intent settingsIntent = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(settingsIntent, 77); } }, 250); return; case 4: // Feedback return; case 5: // About Dialog if (drawer instanceof DrawerLayout) ((DrawerLayout) drawer).closeDrawer(drawerView); drawer.postDelayed(new Runnable() { @Override public void run() { Intent aboutIntent = new Intent(MainActivity.this, AboutActivity.class); startActivityForResult(aboutIntent, 77); } }, 250); return; } final Fragment activeFragment = getDisplayedFragment(getActiveFragments()); prepareAnimations(activeFragment); // Insert the fragment by replacing any existing fragment if (newFragment != activeFragment) { if (mActionMode != null) mActionMode.finish(); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.setCustomAnimations(R.animator.slide_in_start, R.animator.slide_out_start, R.animator.slide_in_start, R.animator.slide_out_start); fragmentTransaction.hide(activeFragment); if (newFragment.isAdded()) fragmentTransaction.show(newFragment); else fragmentTransaction.add(id.main_fragment_container, newFragment, tag); ((CollapsingToolbarLayout) findViewById(R.id.toolbar_layout)).setCollapsedTitleTextColor(Color.WHITE); fragmentTransaction.commit(); if (activeFragment instanceof LyricsViewFragment || newFragment instanceof LyricsViewFragment) { final Fragment newFragmentCopy = newFragment; activeFragment.getView().postDelayed(new Runnable() { @Override public void run() { if (activeFragment instanceof LyricsViewFragment) { expandToolbar(false); showRefreshFab(false); } else if (newFragmentCopy instanceof LyricsViewFragment) { expandToolbar(true); showRefreshFab(true); } } }, getResources().getInteger(android.R.integer.config_longAnimTime)); } } if (drawer instanceof DrawerLayout && (newFragment == activeFragment)) ((DrawerLayout) drawer).closeDrawer(drawerView); }
From source file:org.iota.wallet.ui.activity.MainActivity.java
/** * Shows a fragment and hides the old one if there was a fragment previously visible *///from w ww . j a v a2 s. c o m private void showFragment(Fragment fragment, boolean addToBackStack, boolean killFragments) { if (fragment == null) { // Do nothing return; } FragmentManager fragmentManager = getFragmentManager(); Fragment currentFragment = fragmentManager.findFragmentByTag(currentFragmentTag); if (currentFragment != null && currentFragment.getClass().getName().equals(fragment.getClass().getName())) { // Fragment already shown, do nothing return; } FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); if (killFragments) { Class[] fragmentsToKill = { AboutFragment.class, GenerateQRCodeFragment.class, NeighborsFragment.class, NodeInfoFragment.class, PasswordLoginFragment.class, QRScannerFragment.class, SeedLoginFragment.class, SettingsFragment.class, TangleExplorerTabFragment.class, NewTransferFragment.class, WalletAddressesFragment.class, WalletTabFragment.class, WalletTransfersFragment.class }; for (Class fragmentClass : fragmentsToKill) { String tag = fragmentClass.getSimpleName(); if (tag.equals(fragment.getClass().getSimpleName())) { continue; } Fragment fragmentToKill = fragmentManager.findFragmentByTag(tag); if (fragmentToKill != null) { fragmentTransaction.remove(fragmentToKill); } } } fragmentTransaction.setCustomAnimations(R.animator.fade_in, R.animator.fade_out, R.animator.fade_in, R.animator.fade_out); if (currentFragment != null) { // Hide old fragment fragmentTransaction.hide(currentFragment); } String tag = fragment.getClass().getSimpleName(); Fragment cachedFragment = fragmentManager.findFragmentByTag(tag); if (cachedFragment != null) { // Cached fragment available fragmentTransaction.show(cachedFragment); } else { fragmentTransaction.add(FRAGMENT_CONTAINER_ID, fragment, tag); } if (addToBackStack) { fragmentTransaction.addToBackStack(null); } fragmentTransaction.commit(); if (fragment instanceof OnBackPressedClickListener) { onBackPressedClickListener = (OnBackPressedClickListener) fragment; } else onBackPressedClickListener = null; // setChecked if open from WalletItemDialog if (fragment instanceof TangleExplorerTabFragment) navigationView.getMenu().findItem(R.id.nav_tangle_explorer).setChecked(true); currentFragmentTag = tag; }