Example usage for android.app FragmentTransaction setCustomAnimations

List of usage examples for android.app FragmentTransaction setCustomAnimations

Introduction

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

Prototype

public abstract FragmentTransaction setCustomAnimations(@AnimatorRes int enter, @AnimatorRes int exit,
        @AnimatorRes int popEnter, @AnimatorRes 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:com.android.purenexussettings.TinkerActivity.java

private void removeCurrent() {
    // update the main content by replacing fragments, first by removing the old
    FragmentTransaction fragtrans = fragmentManager.beginTransaction();
    fragtrans.setCustomAnimations(R.anim.fadein, R.anim.fadeout, R.anim.fadein, R.anim.fadeout);
    fragtrans.remove(fragmentManager.findFragmentById(R.id.frame_container));
    fragtrans.commit();/*from  w  w  w  . j a  v  a  2  s.c om*/
}

From source file:com.android.purenexussettings.TinkerActivity.java

private void displayView(int position) {
    // before anything else - check to see if position matches intent-launching "frags" - for example
    // if ( navMenuTitles[position].equals("TARGETNAME") ) { position = 0; do something}
    boolean mKeepStack = checkPosition(position);

    // update the main content by replacing fragments
    Fragment frags = null;//from w  w  w .ja v a2s.  c o  m
    String fragname = navMenuFrags[position];
    try {
        frags = (Fragment) Class.forName(mPackageName + "." + fragname).newInstance();
    } catch (Exception e) {
        frags = null;
    }
    if (frags != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

        try {
            FragmentTransaction fragtrans = fragmentManager.beginTransaction();
            if (mFromClick || mMenu || mBackPress) {
                fragtrans.setCustomAnimations(R.anim.fadein, R.anim.fadeout, R.anim.fadein, R.anim.fadeout);
            }
            fragtrans.add(R.id.frame_container, frags);
            // The backstack should be cleared if not coming from a fragment flagged as stack keeping or from a backpress
            // After clearing the only entry should be About/main
            if (!mKeepStack && !mBackPress) {
                fragmentStack.clear();
                fragmentStack.push(navMenuFrags[0]);
            }
            // add fragment name to custom stack for backstack tracking
            // only do it if not a backpress, flagged as stack keeping, or dup of last entry
            if (!mBackPress && !mKeepStack
                    && !(fragmentStack.size() >= 1 && fragmentStack.peek().equals(navMenuFrags[position]))) {
                fragmentStack.push(navMenuFrags[position]);
            }

            fragtrans.commit();
        } catch (Exception e) {
        }

        // update selected item and title, then close the drawer
        if (mFromClick || mBackPress) {
            mFromClick = false;
            mBackPress = false;
        } else {
            setTitle(navMenuTitles[position]);
            if (mMenu) {
                mMenu = false;
                mItemPosition = position;
            } else {
                mDrawerLayout.closeDrawer(mNavView);
            }
        }
        invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
    } else {
        // error in creating fragment
        Log.e("TinkerActivity", "Error in creating fragment");
    }
}

From source file:com.sintef_energy.ubisolar.activities.DrawerActivity.java

/**
 * Helper method to add fragments to the view.
 *
 * @param fragment Fragment to swap in// ww  w  .  j  a v a  2s.  co m
 * @param animate True if swap shall have an animation
 * @param addToBackStack True if the Fragment shall go to the back stack
 * @param tag String for the back stack
 */
public void addFragment(Fragment fragment, boolean animate, boolean addToBackStack, String tag) {
    FragmentManager manager = getFragmentManager();

    FragmentTransaction ft = manager.beginTransaction();
    if (animate) {
        ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right,
                // Pop enter
                android.R.anim.fade_in, android.R.anim.fade_out);
    }

    if (addToBackStack) {
        ft.addToBackStack(tag);
    }

    ft.replace(R.id.container, fragment, tag);
    ft.commit();
}

From source file:com.dvn.vindecoder.ui.seller.GetAllVehicalSellerDetails.java

void addFragmentToStack() {
    mStackLevel++;/*w w  w .j  av a  2  s  .  co  m*/

    // Instantiate a new fragment.
    Fragment newFragment = GetNewVehicalFragment.newInstance(GetAllVehicalSellerDetails.this);

    // Add the fragment to the activity, pushing this transaction
    // on to the back stack.
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
            R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
    ft.replace(R.id.fragment1, newFragment);
    // ft.addToBackStack(null);
    ft.commit();
}

From source file:com.dvn.vindecoder.ui.seller.GetAllVehicalSellerDetails.java

@Override
public void onDataComplete(int i, String image_path) {
    if (i == 1) {
        Bitmap bitmap = ((BitmapDrawable) car_image.getDrawable()).getBitmap();
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
        File destination = new File(getCacheDir(), "car.jpg");
        FileOutputStream fo;/*from  w  ww.  j  a  va2 s .co  m*/
        try {
            fo = new FileOutputStream(destination);
            fo.write(bytes.toByteArray());
            fo.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        image_path = destination.getAbsolutePath();
        // car_image.setImageBitmap(bitmap);
        newFragment.setImagePath(image_path);
    } else if (i == 2) {
        /*car_image.setOnClickListener(null);
        car_image1.setOnClickListener(null);*/
        collapsingToolbarLayout.setVisibility(View.GONE);
        Fragment newFragment = UserAddNewVehicalSecond.newInstance(GetAllVehicalSellerDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        //  ft.addToBackStack(null);
        ft.commit();
    } else if (i == 3) {
        Fragment newFragment = UserAddNewVehicalThird.newInstance(GetAllVehicalSellerDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        // ft.addToBackStack(null);
        ft.commit();
    } else if (i == 4) {
        Fragment newFragment = UserNewVehicalFourth.newInstance(GetAllVehicalSellerDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        //   ft.addToBackStack(null);
        ft.commit();
    } else if (i == 5) {
        Fragment newFragment = UserAddNewVehicalFifth.newInstance(GetAllVehicalSellerDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        //  ft.addToBackStack(null);
        ft.commit();
    }

    else if (i == 0) {

        Glide.with(GetAllVehicalSellerDetails.this).load(image_path).asBitmap()
                .into(new SimpleTarget<Bitmap>(300, 300) {
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
                        //setBackgroundImage(resource);
                        car_image.setImageBitmap(resource);
                        car_image1.setImageBitmap(resource);
                    }
                });
    }
}

From source file:com.dvn.vindecoder.ui.user.GetAllVehicalDetails.java

void addFragmentToStack() {
    mStackLevel++;// w ww . j a  v a2  s. co m

    // Instantiate a new fragment.
    Fragment newFragment = GetNewVehicalFragment.newInstance(GetAllVehicalDetails.this);

    // Add the fragment to the activity, pushing this transaction
    // on to the back stack.
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
            R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
    ft.replace(R.id.fragment1, newFragment);
    // ft.addToBackStack(null);
    ft.commit();
}

From source file:com.geecko.QuickLyric.MainActivity.java

private LyricsViewFragment init(FragmentManager fragmentManager, boolean startEmpty) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) fragmentManager
            .findFragmentByTag(LYRICS_FRAGMENT_TAG);
    if (lyricsViewFragment == null || lyricsViewFragment.isDetached())
        lyricsViewFragment = new LyricsViewFragment();
    lyricsViewFragment.startEmpty(startEmpty);
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.animator.slide_in_end, R.animator.slide_out_start,
            R.animator.slide_in_start, R.animator.slide_out_end);
    if (!lyricsViewFragment.isAdded()) {
        fragmentTransaction.add(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }/*from w w  w  .j  av a  2  s .  co m*/

    Fragment[] activeFragments = getActiveFragments();
    displayedFragment = getDisplayedFragment(activeFragments);

    for (Fragment fragment : activeFragments)
        if (fragment != null) {
            if (fragment != displayedFragment && !fragment.isHidden()) {
                fragmentTransaction.hide(fragment);
                fragment.onHiddenChanged(true);
            } else if (fragment == displayedFragment)
                fragmentTransaction.show(fragment);
        }
    fragmentTransaction.commit();
    return lyricsViewFragment;
}

From source file:com.geecko.QuickLyric.MainActivity.java

public void updateLyricsFragment(int outAnim, int inAnim, boolean transition, Lyrics lyrics) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) getFragmentManager()
            .findFragmentByTag(LYRICS_FRAGMENT_TAG);
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(inAnim, outAnim, inAnim, outAnim);
    Fragment activeFragment = getDisplayedFragment(getActiveFragments());
    if (lyricsViewFragment != null && lyricsViewFragment.getView() != null) {
        SharedPreferences preferences = getSharedPreferences("current_music", Context.MODE_PRIVATE);
        String artist = preferences.getString("artist", null);
        String track = preferences.getString("track", null);
        if (lyrics.isLRC()
                && !(lyrics.getOriginalArtist().equals(artist) && lyrics.getOriginalTrack().equals(track))) {
            LrcView parser = new LrcView(this, null);
            parser.setOriginalLyrics(lyrics);
            parser.setSourceLrc(lyrics.getText());
            lyrics = parser.getStaticLyrics();
        }/*from   w  ww. ja  v a 2 s .  c  om*/
        lyricsViewFragment.update(lyrics, lyricsViewFragment.getView(), true);
        if (transition) {
            fragmentTransaction.hide(activeFragment).show(lyricsViewFragment);
            prepareAnimations(activeFragment);
            prepareAnimations(lyricsViewFragment);
        }
        showRefreshFab(true);
        lyricsViewFragment.expandToolbar();
    } else {
        Bundle lyricsBundle = new Bundle();
        try {
            lyricsBundle.putByteArray("lyrics", lyrics.toBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
        lyricsViewFragment = new LyricsViewFragment();
        lyricsViewFragment.setArguments(lyricsBundle);
        if (!(activeFragment instanceof LyricsViewFragment) && activeFragment != null)
            fragmentTransaction.hide(activeFragment).add(id.main_fragment_container, lyricsViewFragment,
                    LYRICS_FRAGMENT_TAG);
        else
            fragmentTransaction.replace(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }
    fragmentTransaction.commitAllowingStateLoss();
}

From source file:com.geecko.QuickLyric.MainActivity.java

public void updateLyricsFragment(int outAnim, String... params) { // Should only be called from SearchFragment or IdDecoder
    String artist = params[0];//w  ww.j  ava2  s  .co m
    String song = params[1];
    String url = null;
    if (params.length > 2)
        url = params[2];
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) getFragmentManager()
            .findFragmentByTag(LYRICS_FRAGMENT_TAG);
    if (lyricsViewFragment != null)
        lyricsViewFragment.fetchLyrics(artist, song, url);
    else {
        Lyrics lyrics = new Lyrics(Lyrics.SEARCH_ITEM);
        lyrics.setArtist(artist);
        lyrics.setTitle(song);
        lyrics.setURL(url);
        Bundle lyricsBundle = new Bundle();
        try {
            if (artist != null && song != null)
                lyricsBundle.putByteArray("lyrics", lyrics.toBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
        lyricsViewFragment = new LyricsViewFragment();
        lyricsViewFragment.setArguments(lyricsBundle);

        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.setCustomAnimations(R.animator.slide_in_start, outAnim, R.animator.slide_in_start,
                outAnim);
        Fragment activeFragment = getDisplayedFragment(getActiveFragments());
        if (activeFragment != null) {
            prepareAnimations(activeFragment);
            fragmentTransaction.hide(activeFragment);
        }
        fragmentTransaction.add(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
        lyricsViewFragment.isActiveFragment = true;
        fragmentTransaction.commit();
    }
    if (drawer instanceof DrawerLayout && !mDrawerToggle.isDrawerIndicatorEnabled()) {
        mDrawerToggle.setDrawerIndicatorEnabled(true);
        ((DrawerLayout) drawer).setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
    }
}

From source file:com.dvn.vindecoder.ui.user.GetAllVehicalDetails.java

@Override
public void onDataComplete(int i, String image_path) {
    if (i == 1) {
        /* Bitmap bitmap = ((BitmapDrawable)car_image.getDrawable()).getBitmap();
         ByteArrayOutputStream bytes = new ByteArrayOutputStream();
         bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
         File destination = new File(getCacheDir(),"car.jpg");
         FileOutputStream fo;//from  w  w  w  . j ava2 s .  com
         try {
        fo = new FileOutputStream(destination);
        fo.write(bytes.toByteArray());
        fo.close();
         } catch (IOException e) {
        e.printStackTrace();
         }
         image_path=destination.getAbsolutePath();
         // car_image.setImageBitmap(bitmap);
         newFragment.setImagePath(image_path);*/
    } else if (i == 2) {
        /*car_image.setOnClickListener(null);
        car_image1.setOnClickListener(null);*/
        //   collapsingToolbarLayout.setVisibility(View.GONE);
        Fragment newFragment = UserAddNewVehicalSecond.newInstance(GetAllVehicalDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        //  ft.addToBackStack(null);
        ft.commit();
    } else if (i == 3) {
        Fragment newFragment = UserAddNewVehicalThird.newInstance(GetAllVehicalDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        // ft.addToBackStack(null);
        ft.commit();
    } else if (i == 4) {
        Fragment newFragment = UserNewVehicalFourth.newInstance(GetAllVehicalDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        //   ft.addToBackStack(null);
        ft.commit();
    } else if (i == 5) {
        Fragment newFragment = UserAddNewVehicalFifth.newInstance(GetAllVehicalDetails.this);

        // Add the fragment to the activity, pushing this transaction
        // on to the back stack.
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit,
                R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit);
        ft.replace(R.id.fragment1, newFragment);
        //  ft.addToBackStack(null);
        ft.commit();
    }

    else if (i == 0) {

        Glide.with(GetAllVehicalDetails.this).load(image_path).asBitmap()
                .into(new SimpleTarget<Bitmap>(300, 300) {
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
                        //setBackgroundImage(resource);
                        //  car_image.setImageBitmap(resource);
                        // car_image1.setImageBitmap(resource);
                    }
                });
    }
}