Example usage for android.support.v4.app FragmentTransaction setCustomAnimations

List of usage examples for android.support.v4.app FragmentTransaction setCustomAnimations

Introduction

In this page you can find the example usage for android.support.v4.app FragmentTransaction setCustomAnimations.

Prototype

public abstract FragmentTransaction setCustomAnimations(int enter, int exit, int popEnter, int popExit);

Source Link

Document

Set specific animation resources to run for the fragments that are entering and exiting in this transaction.

Usage

From source file:Main.java

public static void replaceFragment(FragmentManager manager, Class<? extends Fragment> fragmentClass,
        boolean isAddToBackStack) {

    Fragment fragment = manager.findFragmentByTag(fragmentClass.getSimpleName());

    if (null == fragment) {
        try {//  w  w  w  .jav a 2 s  . com

            fragment = fragmentClass.newInstance();

        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }

    FragmentTransaction ft = manager.beginTransaction();
    ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out, android.R.anim.fade_in,
            android.R.anim.fade_out);
    if (!fragment.isAdded()) {
        ft.replace(android.R.id.content, fragment, fragment.getClass().getSimpleName());
        if (isAddToBackStack) {
            ft.addToBackStack(null);
        }
    }
    ft.commit();

}

From source file:Main.java

/**
 * This method loads fragment in a backstack.
 * /*  w w w  . j  av  a 2 s . c  o  m*/
 * @param fragmentActivity
 * @param fragmentContainerId
 * @param fragmentClass
 * @param bundle
 * @param tag
 * @return true if loaded successfully, false otherwise
 */
public static boolean loadFragmentInBackstack(FragmentActivity fragmentActivity, int fragmentContainerId,
        Class<? extends Fragment> fragmentClass, Bundle bundle, String tag) {
    // TODO Auto-generated method stub
    boolean status = false;
    try {
        FragmentManager fragmentManager = fragmentActivity.getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out,
                android.R.anim.fade_in, android.R.anim.fade_out);
        Fragment fragment = fragmentClass.newInstance();
        fragment.setArguments(bundle);
        fragmentTransaction.replace(fragmentContainerId, fragment, tag).addToBackStack(null).commit();
        // finish pending transactions
        fragmentManager.executePendingTransactions();
        status = true;
    } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return status;
}

From source file:com.whp.android.fragment.FragmentUtils.java

/**
 * showFragment// ww w . j a  v a2  s  . c  o m
 * 
 * @param fragment
 * @param tag
 * @param addToBackStack
 */
public static void showFragment(FragmentActivity fragmentActivity, Fragment fragment, String tag,
        boolean addToBackStack) {

    FragmentTransaction ft = fragmentActivity.getSupportFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit);
    ft.replace(R.id.fragment_container, fragment, tag);
    if (addToBackStack) {
        ft.addToBackStack(tag);
    }
    ft.commit();

}

From source file:Main.java

/**
 * This method clears backstack and loads fragment in a root.
 * /*w  ww.  ja v a 2 s .  c  o m*/
 * @param fragmentActivity
 * @param fragmentContainerId
 * @param fragmentClass
 * @param bundle
 * @param tag
 * @return true if loaded successfully, false otherwise
 */
public static boolean loadFragmentInRoot(FragmentActivity fragmentActivity, int fragmentContainerId,
        Class<? extends Fragment> fragmentClass, Bundle bundle, String tag) {
    // TODO Auto-generated method stub
    boolean status = false;

    FragmentManager fragmentManager = fragmentActivity.getSupportFragmentManager();
    // remove all fragments from back stack
    fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    // add new fragment
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out,
            android.R.anim.fade_in, android.R.anim.fade_out);
    Fragment fragment;
    try {
        fragment = fragmentClass.newInstance();
        fragment.setArguments(bundle);
        fragmentTransaction.replace(fragmentContainerId, fragment, tag).commit();
        // finish pending transactions
        fragmentManager.executePendingTransactions();
        status = true;
    } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return status;
}

From source file:com.microsoft.mimickeralarm.utilities.SettingsUtilities.java

public static void transitionFromAlarmToMimicsSettings(FragmentManager fragmentManager,
        ArrayList<String> enabledMimics) {
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left,
            R.anim.slide_out_right);//from w w w  .j  a  v  a2s .  c  o  m
    transaction.replace(R.id.fragment_container, MimicsSettingsFragment.newInstance(enabledMimics),
            MimicsSettingsFragment.MIMICS_SETTINGS_FRAGMENT_TAG);
    transaction.addToBackStack(null);
    transaction.commit();
}

From source file:mx.developerbus.foodbus.utl.foodBUtil.java

public static boolean setFragmentWorkspace(boolean multipane, FragmentManager fragmentManager,
        Class<? extends Fragment> fragmentClass, Bundle args, int enter, int exit, int popEnter, int popExit,
        boolean staked) throws Exception {
    boolean replace = false;
    try {/* ww w  .  j a  v a2 s .  c om*/

        if (fragmentClass != null) {
            Fragment fp = fragmentManager.findFragmentById(R.id.frgWorkspace);
            FragmentTransaction tra = fragmentManager.beginTransaction();

            if (enter > 0 && exit > 0 && popEnter > 0 && popExit > 0) {
                tra.setCustomAnimations(enter, exit, popEnter, popExit);
                tra.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            } else {
                tra.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            }

            Fragment f = fragmentClass.newInstance();
            Bundle b = new Bundle();
            b.putBoolean("multipane", multipane);
            if (args != null) {
                b.putAll(args);
            }
            f.setArguments(b);

            if (fp != null) {
                if (fp.getClass() != fragmentClass) {
                    tra.replace(R.id.frgWorkspace, f);
                    if (staked) {
                        tra.addToBackStack(null);
                    }
                    replace = true;
                }
            } else {
                tra.add(R.id.frgWorkspace, f);
                replace = true;
            }
            tra.commit();
        }
    } catch (Exception e) {
        throw new Exception("ERROR Home - setFragment : " + e.getMessage());
    }
    return replace;
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.ApptentiveBaseFragment.java

public static void replaceFragment(FragmentManager fragmentManager, int fragmentContainerId, Fragment fragment,
        String tag, String parentFragment, boolean showAnimation, boolean executePendingTransactions) {
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    if (showAnimation) {
        fragmentTransaction.setCustomAnimations(R.anim.apptentive_slide_right_in,
                R.anim.apptentive_slide_left_out, R.anim.apptentive_slide_left_in,
                R.anim.apptentive_slide_right_out);
    }//from   w  w w  . ja v a 2 s  . c o m

    fragmentTransaction.replace(fragmentContainerId, fragment, tag);
    if (!TextUtils.isEmpty(parentFragment)) {
        fragmentTransaction.addToBackStack(parentFragment);
    }

    fragmentTransaction.commit();
    if (executePendingTransactions) {
        fragmentManager.executePendingTransactions();
    }

}

From source file:com.bluros.music.utils.NavigationUtils.java

@TargetApi(21)
public static void navigateToAlbum(Activity context, long albumID, Pair<View, String> transitionViews) {

    FragmentTransaction transaction = ((AppCompatActivity) context).getSupportFragmentManager()
            .beginTransaction();/*from  w  w  w.j av a2 s  .c  o  m*/
    Fragment fragment;

    if (MusicUtils.isLollipop() && transitionViews != null
            && PreferencesUtility.getInstance(context).getAnimations()) {
        Transition changeImage = TransitionInflater.from(context)
                .inflateTransition(R.transition.image_transform);
        transaction.addSharedElement(transitionViews.first, transitionViews.second);
        fragment = AlbumDetailFragment.newInstance(albumID, true, transitionViews.second);
        fragment.setSharedElementEnterTransition(changeImage);
    } else {
        transaction.setCustomAnimations(R.anim.activity_fade_in, R.anim.activity_fade_out,
                R.anim.activity_fade_in, R.anim.activity_fade_out);
        fragment = AlbumDetailFragment.newInstance(albumID, false, null);
    }
    transaction.hide(((AppCompatActivity) context).getSupportFragmentManager()
            .findFragmentById(R.id.fragment_container));
    transaction.add(R.id.fragment_container, fragment);
    transaction.addToBackStack(null).commit();

}

From source file:com.bluros.music.utils.NavigationUtils.java

@TargetApi(21)
public static void navigateToArtist(Activity context, long artistID, Pair<View, String> transitionViews) {

    FragmentTransaction transaction = ((AppCompatActivity) context).getSupportFragmentManager()
            .beginTransaction();//from  w  w  w  . ja  va  2  s.  c o  m
    Fragment fragment;

    if (MusicUtils.isLollipop() && transitionViews != null
            && PreferencesUtility.getInstance(context).getAnimations()) {
        Transition changeImage = TransitionInflater.from(context)
                .inflateTransition(R.transition.image_transform);
        transaction.addSharedElement(transitionViews.first, transitionViews.second);
        fragment = ArtistDetailFragment.newInstance(artistID, true, transitionViews.second);
        fragment.setSharedElementEnterTransition(changeImage);
    } else {
        transaction.setCustomAnimations(R.anim.activity_fade_in, R.anim.activity_fade_out,
                R.anim.activity_fade_in, R.anim.activity_fade_out);
        fragment = ArtistDetailFragment.newInstance(artistID, false, null);
    }
    transaction.hide(((AppCompatActivity) context).getSupportFragmentManager()
            .findFragmentById(R.id.fragment_container));
    transaction.add(R.id.fragment_container, fragment);
    transaction.addToBackStack(null).commit();

}

From source file:com.devalladolid.musictoday.utils.NavigationUtils.java

@TargetApi(21)
public static void navigateToAlbum(Activity context, long albumID, Pair<View, String> transitionViews) {

    FragmentTransaction transaction = ((AppCompatActivity) context).getSupportFragmentManager()
            .beginTransaction();//  w  w w.j a  v a 2 s .  com
    Fragment fragment;

    if (TimberUtils.isLollipop() && transitionViews != null
            && PreferencesUtility.getInstance(context).getAnimations()) {
        Transition changeImage = TransitionInflater.from(context)
                .inflateTransition(R.transition.image_transform);
        transaction.addSharedElement(transitionViews.first, transitionViews.second);
        fragment = AlbumDetailFragment.newInstance(albumID, true, transitionViews.second);
        fragment.setSharedElementEnterTransition(changeImage);
    } else {
        transaction.setCustomAnimations(R.anim.activity_fade_in, R.anim.activity_fade_out,
                R.anim.activity_fade_in, R.anim.activity_fade_out);
        fragment = AlbumDetailFragment.newInstance(albumID, false, null);
    }
    transaction.hide(((AppCompatActivity) context).getSupportFragmentManager()
            .findFragmentById(R.id.fragment_container));
    transaction.add(R.id.fragment_container, fragment);
    transaction.addToBackStack(null).commit();

}