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:la.marsave.fullscreentest.MainActivity.java

/**
 * This method is used to toggle between the two fragment states by
 * calling the appropriate animations between them. The entry and exit
 * animations of the text fragment are specified in R.animator resource
 * files. The entry and exit animations of the image fragment are
 * specified in the slideBack and slideForward methods below. The reason
 * for separating the animation logic in this way is because the translucent
 * dark hover view must fade in at the same time as the image fragment
 * animates into the background, which would be difficult to time
 * properly given that the setCustomAnimations method can only modify the
 * two fragments in the transaction./* w  ww.jav a 2 s  . co m*/
 */
private void switchFragments() {
    if (mIsAnimating) {
        return;
    }
    mIsAnimating = true;
    if (mDidSlideOut) {
        mDidSlideOut = false;
        getFragmentManager().popBackStack();
    } else {
        mDidSlideOut = true;

        Animator.AnimatorListener listener = new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator arg0) {
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.setCustomAnimations(R.animator.slide_fragment_in, 0, 0,
                        R.animator.slide_fragment_out);
                transaction.add(R.id.move_to_back_container, mTextFragment);
                transaction.addToBackStack(null);
                transaction.commit();
            }
        };
        slideBack(listener);
    }
}

From source file:com.murati.oszk.audiobook.ui.MusicPlayerActivity.java

private void navigateToBrowser(String mediaId) {
    //TODO: maybe place navigate block here

    LogHelper.d(TAG, "navigateToBrowser, mediaId=" + mediaId);
    MediaBrowserFragment fragment = getBrowseFragment();
    updateBookButtons(mediaId);/*from   w  ww  .  java2 s  .  com*/

    if (fragment == null || !TextUtils.equals(fragment.getMediaId(), mediaId)) {
        // Create Transaction
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.setCustomAnimations(R.animator.slide_in_from_right, R.animator.slide_out_to_left,
                R.animator.slide_in_from_left, R.animator.slide_out_to_right);

        // Create Backstack
        // Not an empty, root or the same where we are currently, for refresh retries
        if (fragment != null && mediaId != null && mediaId != getMediaId()) {
            transaction.addToBackStack(null);
        }

        //Create new fragment and navigate
        fragment = new MediaBrowserFragment();
        fragment.setMediaId(mediaId);
        transaction.replace(R.id.container, fragment, FRAGMENT_TAG);

        //Do it
        transaction.commit();
    }
}

From source file:com.silentcircle.silenttext.activity.AccountCreationActivity.java

@Override
public void onNext(Fragment fragment) {
    FragmentTransaction tx = getFragmentManager().beginTransaction();

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
        tx.setCustomAnimations(R.animator.slide_in_from_right, R.animator.slide_out_to_left,
                R.animator.slide_in_from_left, R.animator.slide_out_to_right);
    }/*from  www.j  av a2  s .co m*/

    if (tx.isAddToBackStackAllowed()) {
        tx.addToBackStack(null);
    }
    tx.replace(R.id.content, fragment);
    tx.commit();
}

From source file:ab.util.AbDialogUtil.java

/**
 * /*from ww  w  .j av  a2s  .c  o  m*/
 * ???().
 * 
 * @param view
 * @param animEnter
 * @param animExit
 * @param animPopEnter
 * @param animPopExit
 * @param gravity
 *            ?
 * @return
 */
public static AbSampleDialogFragment showDialog(View view, int animEnter, int animExit, int animPopEnter,
        int animPopExit, int gravity) {
    FragmentActivity activity = (FragmentActivity) view.getContext();
    // Create and show the dialog.
    AbSampleDialogFragment newFragment = AbSampleDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE,
            android.R.style.Theme_Holo_Light_Dialog, gravity);
    newFragment.setContentView(view);
    // 
    FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
    ft.setCustomAnimations(animEnter, animExit, animPopEnter, animPopExit);
    newFragment.show(ft, mDialogTag);
    return newFragment;
}

From source file:ab.util.AbDialogUtil.java

/**
 * /*from  w w  w  .j  a  va 2 s  . com*/
 * ???().
 * 
 * @param view
 * @param animEnter
 * @param animExit
 * @param animPopEnter
 * @param animPopExit
 * @param gravity
 * @param onCancelListener
 * @return
 */
public static AbSampleDialogFragment showDialog(View view, int animEnter, int animExit, int animPopEnter,
        int animPopExit, int gravity, DialogInterface.OnCancelListener onCancelListener) {
    FragmentActivity activity = (FragmentActivity) view.getContext();
    // Create and show the dialog.
    AbSampleDialogFragment newFragment = AbSampleDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE,
            android.R.style.Theme_Holo_Light_Dialog, gravity);
    newFragment.setContentView(view);
    FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
    ft.setCustomAnimations(animEnter, animExit, animPopEnter, animPopExit);
    newFragment.setOnCancelListener(onCancelListener);
    newFragment.show(ft, mDialogTag);
    return newFragment;
}

From source file:com.evandroid.musica.MainLyricActivity.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();
        }//www  .  j av  a 2s  .  c  om
        lyricsViewFragment.update(lyrics, lyricsViewFragment.getView(), true);
        if (transition) {
            fragmentTransaction.hide(activeFragment).show(lyricsViewFragment);
            prepareAnimations(activeFragment);
            prepareAnimations(lyricsViewFragment);
        }
    } 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(R.id.main_fragment_container, lyricsViewFragment,
                    LYRICS_FRAGMENT_TAG);
        else
            fragmentTransaction.replace(R.id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }
    fragmentTransaction.commitAllowingStateLoss();
}

From source file:com.grepsound.activities.MainActivity.java

/**
 * This method is used to toggle between the two fragment states by
 * calling the appropriate animations between them. The entry and exit
 * animations of the text fragment are specified in R.animator resource
 * files. The entry and exit animations of the image fragment are
 * specified in the slideBack and slideForward methods below. The reason
 * for separating the animation logic in this way is because the translucent
 * dark hover view must fade in at the same time as the image fragment
 * animates into the background, which would be difficult to time
 * properly given that the setCustomAnimations method can only modify the
 * two fragments in the transaction.//w  w  w . j  ava2s .  c  o m
 */
private void switchFragments() {
    if (mIsAnimating) {
        Log.i(TAG, "IS animating!");
        return;
    }
    mIsAnimating = true;
    if (mDidSlideOut) {
        Log.i(TAG, "Did Slide Out!");
        mDidSlideOut = false;
        getFragmentManager().popBackStack();
    } else {
        mDidSlideOut = true;

        Animator.AnimatorListener listener = new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator arg0) {
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.setCustomAnimations(R.animator.slide_fragment_left, 0, 0,
                        R.animator.slide_fragment_right);
                transaction.add(R.id.move_to_back_container, mDetailsFragment);
                transaction.addToBackStack(null);
                transaction.commit();
                mDidSlideOut = false;
            }
        };
        slideBack(listener);
    }
}

From source file:ua.boberproduction.bbr.BaseActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_settings) {
        startActivity(new Intent(this, EditPreferencesActivity.class));
        return true;

    } else if (id == R.id.action_rate_app) {
        final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
        try {/*from  ww  w  .jav a2  s  . c  o m*/
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
        } catch (android.content.ActivityNotFoundException anfe) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
        }
    } else if (id == R.id.action_feedback) {
        FragmentTransaction ft = this.getFragmentManager().beginTransaction();
        FeedbackFragment fragment = new FeedbackFragment();
        ft.setCustomAnimations(R.animator.slide_in_right, R.animator.slide_out_left, R.animator.slide_in_left,
                R.animator.slide_out_right);
        ft.replace(R.id.main_frame, fragment).addToBackStack(null).commit();
    } else if (id == R.id.action_remove_ads) {
        // if Google Services are available, launch the billing. If not, show error message.
        // Showing status
        if (isGoogleServicesAvailable())
            billing.purchaseRemoveAds();
        else
            Toast.makeText(this, getString(R.string.toast_error_google_services_unavailable),
                    Toast.LENGTH_SHORT).show();
    }

    return drawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
}

From source file:us.shandian.blacklight.ui.main.MainActivity.java

private void switchTo(int id) {
    FragmentTransaction ft = mManager.beginTransaction();
    ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out, android.R.animator.fade_in,
            android.R.animator.fade_out);

    for (int i = 0; i < mFragments.length; i++) {
        Fragment f = mFragments[i];//from w ww  .jav a 2  s .  co m

        if (f != null) {
            if (i != id) {
                ft.hide(f);
            } else {
                ft.show(f);
            }
        }
    }

    ft.commit();

    mCurrent = id;
    mNext = id;
}

From source file:ua.boberproduction.bbr.BaseActivity.java

public void openCategory(int id, String category) {
    // Check if there are any subcategories for the chosen category.
    Observable.fromCallable(() -> SQLiteStructureRepository.getInstance().getChapters(id))
            .subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).doOnError((e) -> {
                Log.e(BBRApplication.TAG_BBR, "Error getting category list.", e);
                Utils.toastError(this, getString(R.string.error_loading_categories), Toast.LENGTH_SHORT);
            }).subscribe((categories) -> {
                Fragment fragment;//from  ww  w.  j a va2  s.  co  m
                Bundle bundle = new Bundle();
                // If there are, load another ListMenuFragment.
                // Also, it will need the 'parent' category to put it into the actionBar's subtitle, so we're putting it into the bundle.
                if (categories.size() > 0) {
                    fragment = new ListMenuFragment();
                } else
                    // If not, load content.
                    fragment = new TextContentFragment();

                // put the clicked category name into a bundle, and put the bundle into the fragment
                bundle.putInt(getString(R.string.tag_category_id), id);
                bundle.putString(getString(R.string.tag_category), category);
                FragmentTransaction ft = this.getFragmentManager().beginTransaction();
                fragment.setArguments(bundle);
                //set sliding animations
                ft.setCustomAnimations(R.animator.slide_in_right, R.animator.slide_out_left,
                        R.animator.slide_in_left, R.animator.slide_out_right);
                ft.replace(R.id.main_frame, fragment).addToBackStack(null).commit();
                this.getFragmentManager().executePendingTransactions();
            });
}