Example usage for android.animation Animator cancel

List of usage examples for android.animation Animator cancel

Introduction

In this page you can find the example usage for android.animation Animator cancel.

Prototype

public void cancel() 

Source Link

Document

Cancels the animation.

Usage

From source file:com.jmstudios.redmoon.presenter.ScreenFilterPresenter.java

private void cancelRunningAnimator(Animator animator) {
    if (animator != null && animator.isRunning()) {
        animator.cancel();
    }
}

From source file:android.support.transition.TransitionPort.java

/**
 * This method cancels a transition that is currently running.
 *
 * @hide//from  w  w w  .  j  av a  2 s .  co  m
 */
@RestrictTo(GROUP_ID)
protected void cancel() {
    int numAnimators = mCurrentAnimators.size();
    for (int i = numAnimators - 1; i >= 0; i--) {
        Animator animator = mCurrentAnimators.get(i);
        animator.cancel();
    }
    if (mListeners != null && mListeners.size() > 0) {
        ArrayList<TransitionListener> tmpListeners = (ArrayList<TransitionListener>) mListeners.clone();
        int numListeners = tmpListeners.size();
        for (int i = 0; i < numListeners; ++i) {
            tmpListeners.get(i).onTransitionCancel(this);
        }
    }
}

From source file:android.support.transition.TransitionPort.java

/**
 * Pauses this transition, sending out calls to {@link
 * TransitionListener#onTransitionPause(TransitionPort)} to all listeners
 * and pausing all running animators started by this transition.
 *
 * @hide/*from   w  ww.  ja v  a  2 s .co m*/
 */
@RestrictTo(GROUP_ID)
public void pause(View sceneRoot) {
    if (!mEnded) {
        ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
        int numOldAnims = runningAnimators.size();
        WindowIdPort windowId = WindowIdPort.getWindowId(sceneRoot);
        for (int i = numOldAnims - 1; i >= 0; i--) {
            AnimationInfo info = runningAnimators.valueAt(i);
            if (info.view != null && windowId.equals(info.windowId)) {
                Animator anim = runningAnimators.keyAt(i);
                anim.cancel(); // pause() is API Level 19
            }
        }
        if (mListeners != null && mListeners.size() > 0) {
            ArrayList<TransitionListener> tmpListeners = (ArrayList<TransitionListener>) mListeners.clone();
            int numListeners = tmpListeners.size();
            for (int i = 0; i < numListeners; ++i) {
                tmpListeners.get(i).onTransitionPause(this);
            }
        }
        mPaused = true;
    }
}

From source file:android.support.transition.Transition.java

/**
 * This method cancels a transition that is currently running.
 *
 * @hide// w  w  w .java 2s .co  m
 */
protected void cancel() {
    int numAnimators = mCurrentAnimators.size();
    for (int i = numAnimators - 1; i >= 0; i--) {
        Animator animator = mCurrentAnimators.get(i);
        animator.cancel();
    }
    if (mListeners != null && mListeners.size() > 0) {
        ArrayList<TransitionListener> tmpListeners = (ArrayList<TransitionListener>) mListeners.clone();
        int numListeners = tmpListeners.size();
        for (int i = 0; i < numListeners; ++i) {
            tmpListeners.get(i).onTransitionCancel(this);
        }
    }
}

From source file:android.support.transition.TransitionPort.java

/**
 * Called by TransitionManager to play the transition. This calls
 * createAnimators() to set things up and create all of the animations and then
 * runAnimations() to actually start the animations.
 *//*w  ww  .ja va  2  s  . c  o  m*/
void playTransition(ViewGroup sceneRoot) {
    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    int numOldAnims = runningAnimators.size();
    for (int i = numOldAnims - 1; i >= 0; i--) {
        Animator anim = runningAnimators.keyAt(i);
        if (anim != null) {
            AnimationInfo oldInfo = runningAnimators.get(anim);
            if (oldInfo != null && oldInfo.view != null
                    && oldInfo.view.getContext() == sceneRoot.getContext()) {
                boolean cancel = false;
                TransitionValues oldValues = oldInfo.values;
                View oldView = oldInfo.view;
                TransitionValues newValues = mEndValues.viewValues != null ? mEndValues.viewValues.get(oldView)
                        : null;
                if (newValues == null) {
                    newValues = mEndValues.idValues.get(oldView.getId());
                }
                if (oldValues != null) {
                    // if oldValues null, then transition didn't care to stash values,
                    // and won't get canceled
                    if (newValues != null) {
                        for (String key : oldValues.values.keySet()) {
                            Object oldValue = oldValues.values.get(key);
                            Object newValue = newValues.values.get(key);
                            if (oldValue != null && newValue != null && !oldValue.equals(newValue)) {
                                cancel = true;
                                if (DBG) {
                                    Log.d(LOG_TAG, "Transition.playTransition: " + "oldValue != newValue for "
                                            + key + ": old, new = " + oldValue + ", " + newValue);
                                }
                                break;
                            }
                        }
                    }
                }
                if (cancel) {
                    if (anim.isRunning() || anim.isStarted()) {
                        if (DBG) {
                            Log.d(LOG_TAG, "Canceling anim " + anim);
                        }
                        anim.cancel();
                    } else {
                        if (DBG) {
                            Log.d(LOG_TAG, "removing anim from info list: " + anim);
                        }
                        runningAnimators.remove(anim);
                    }
                }
            }
        }
    }

    createAnimators(sceneRoot, mStartValues, mEndValues);
    runAnimators();
}

From source file:android.transitions.everywhere.Transition.java

/**
 * Called by TransitionManager to play the transition. This calls
 * createAnimators() to set things up and create all of the animations and then
 * runAnimations() to actually start the animations.
 *//*  ww  w.  j  a  va  2s. co  m*/
void playTransition(ViewGroup sceneRoot) {
    mStartValuesList = new ArrayList<TransitionValues>();
    mEndValuesList = new ArrayList<TransitionValues>();
    matchStartAndEnd(mStartValues, mEndValues);

    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    int numOldAnims = runningAnimators.size();
    Object windowId = ViewUtils.getWindowId(sceneRoot);
    for (int i = numOldAnims - 1; i >= 0; i--) {
        Animator anim = runningAnimators.keyAt(i);
        if (anim != null) {
            AnimationInfo oldInfo = runningAnimators.get(anim);
            if (oldInfo != null && oldInfo.view != null && oldInfo.windowId == windowId) {
                TransitionValues oldValues = oldInfo.values;
                View oldView = oldInfo.view;
                TransitionValues startValues = getTransitionValues(oldView, true);
                TransitionValues endValues = getMatchedTransitionValues(oldView, true);
                boolean cancel = (startValues != null || endValues != null)
                        && oldInfo.transition.areValuesChanged(oldValues, endValues);
                if (cancel) {
                    if (anim.isRunning() || AnimatorUtils.isAnimatorStarted(anim)) {
                        if (DBG) {
                            Log.d(LOG_TAG, "Canceling anim " + anim);
                        }
                        anim.cancel();
                    } else {
                        if (DBG) {
                            Log.d(LOG_TAG, "removing anim from info list: " + anim);
                        }
                        runningAnimators.remove(anim);
                    }
                }
            }
        }
    }

    createAnimators(sceneRoot, mStartValues, mEndValues, mStartValuesList, mEndValuesList);
    runAnimators();
}

From source file:com.transitionseverywhere.Transition.java

/**
 * Called by TransitionManager to play the transition. This calls
 * createAnimators() to set things up and create all of the animations and then
 * runAnimations() to actually start the animations.
 *//*from ww  w.j a  v  a2s  .  c  om*/
void playTransition(ViewGroup sceneRoot) {
    mStartValuesList = new ArrayList<TransitionValues>();
    mEndValuesList = new ArrayList<TransitionValues>();
    matchStartAndEnd(mStartValues, mEndValues);

    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    synchronized (sRunningAnimators) {
        int numOldAnims = runningAnimators.size();
        Object windowId = ViewUtils.getWindowId(sceneRoot);
        for (int i = numOldAnims - 1; i >= 0; i--) {
            Animator anim = runningAnimators.keyAt(i);
            if (anim != null) {
                AnimationInfo oldInfo = runningAnimators.get(anim);
                if (oldInfo != null && oldInfo.view != null && oldInfo.windowId == windowId) {
                    TransitionValues oldValues = oldInfo.values;
                    View oldView = oldInfo.view;
                    TransitionValues startValues = getTransitionValues(oldView, true);
                    TransitionValues endValues = getMatchedTransitionValues(oldView, true);
                    if (startValues == null && endValues == null) {
                        endValues = mEndValues.viewValues.get(oldView);
                    }
                    boolean cancel = (startValues != null || endValues != null)
                            && oldInfo.transition.isTransitionRequired(oldValues, endValues);
                    if (cancel) {
                        if (anim.isRunning() || AnimatorUtils.isAnimatorStarted(anim)) {
                            if (DBG) {
                                Log.d(LOG_TAG, "Canceling anim " + anim);
                            }
                            anim.cancel();
                        } else {
                            if (DBG) {
                                Log.d(LOG_TAG, "removing anim from info list: " + anim);
                            }
                            runningAnimators.remove(anim);
                        }
                    }
                }
            }
        }
    }

    createAnimators(sceneRoot, mStartValues, mEndValues, mStartValuesList, mEndValuesList);
    runAnimators();
}

From source file:android.support.transition.Transition.java

/**
 * Called by TransitionManager to play the transition. This calls
 * createAnimators() to set things up and create all of the animations and then
 * runAnimations() to actually start the animations.
 *//*w  ww . ja  v  a2 s .  co m*/
void playTransition(ViewGroup sceneRoot) {
    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    int numOldAnims = runningAnimators.size();
    for (int i = numOldAnims - 1; i >= 0; i--) {
        Animator anim = runningAnimators.keyAt(i);
        if (anim != null) {
            AnimationInfo oldInfo = runningAnimators.get(anim);
            if (oldInfo != null) {
                boolean cancel = false;
                TransitionValues oldValues = oldInfo.values;
                View oldView = oldInfo.view;
                TransitionValues newValues = mEndValues.viewValues != null ? mEndValues.viewValues.get(oldView)
                        : null;
                if (newValues == null) {
                    newValues = mEndValues.idValues.get(oldView.getId());
                }
                if (oldValues != null) {
                    // if oldValues null, then transition didn't care to stash values,
                    // and won't get canceled
                    if (newValues != null) {
                        for (String key : oldValues.values.keySet()) {
                            Object oldValue = oldValues.values.get(key);
                            Object newValue = newValues.values.get(key);
                            if (oldValue != null && newValue != null && !oldValue.equals(newValue)) {
                                cancel = true;
                                if (DBG) {
                                    Log.d(LOG_TAG, "Transition.playTransition: " + "oldValue != newValue for "
                                            + key + ": old, new = " + oldValue + ", " + newValue);
                                }
                                break;
                            }
                        }
                    }
                }
                if (cancel) {
                    if (anim.isRunning() || anim.isStarted()) {
                        if (DBG) {
                            Log.d(LOG_TAG, "Canceling anim " + anim);
                        }
                        anim.cancel();
                    } else {
                        if (DBG) {
                            Log.d(LOG_TAG, "removing anim from info list: " + anim);
                        }
                        runningAnimators.remove(anim);
                    }
                }
            }
        }
    }

    createAnimators(sceneRoot, mStartValues, mEndValues);
    runAnimators();
}

From source file:android.app.FragmentManager.java

void moveToState(Fragment f, int newState, int transit, int transitionStyle, boolean keepActive) {
    if (DEBUG && false)
        Log.v(TAG, "moveToState: " + f + " oldState=" + f.mState + " newState=" + newState + " mRemoving="
                + f.mRemoving + " Callers=" + Debug.getCallers(5));

    // Fragments that are not currently added will sit in the onCreate() state.
    if ((!f.mAdded || f.mDetached) && newState > Fragment.CREATED) {
        newState = Fragment.CREATED;/*from   w  w  w .  j ava 2 s. c  om*/
    }
    if (f.mRemoving && newState > f.mState) {
        // While removing a fragment, we can't change it to a higher state.
        newState = f.mState;
    }
    // Defer start if requested; don't allow it to move to STARTED or higher
    // if it's not already started.
    if (f.mDeferStart && f.mState < Fragment.STARTED && newState > Fragment.STOPPED) {
        newState = Fragment.STOPPED;
    }
    if (f.mState < newState) {
        // For fragments that are created from a layout, when restoring from
        // state we don't want to allow them to be created until they are
        // being reloaded from the layout.
        if (f.mFromLayout && !f.mInLayout) {
            return;
        }
        if (f.mAnimatingAway != null) {
            // The fragment is currently being animated...  but!  Now we
            // want to move our state back up.  Give up on waiting for the
            // animation, move to whatever the final state should be once
            // the animation is done, and then we can proceed from there.
            f.mAnimatingAway = null;
            moveToState(f, f.mStateAfterAnimating, 0, 0, true);
        }
        switch (f.mState) {
        case Fragment.INITIALIZING:
            if (DEBUG)
                Log.v(TAG, "moveto CREATED: " + f);
            if (f.mSavedFragmentState != null) {
                f.mSavedViewState = f.mSavedFragmentState
                        .getSparseParcelableArray(FragmentManagerImpl.VIEW_STATE_TAG);
                f.mTarget = getFragment(f.mSavedFragmentState, FragmentManagerImpl.TARGET_STATE_TAG);
                if (f.mTarget != null) {
                    f.mTargetRequestCode = f.mSavedFragmentState
                            .getInt(FragmentManagerImpl.TARGET_REQUEST_CODE_STATE_TAG, 0);
                }
                f.mUserVisibleHint = f.mSavedFragmentState.getBoolean(FragmentManagerImpl.USER_VISIBLE_HINT_TAG,
                        true);
                if (!f.mUserVisibleHint) {
                    f.mDeferStart = true;
                    if (newState > Fragment.STOPPED) {
                        newState = Fragment.STOPPED;
                    }
                }
            }
            f.mActivity = mActivity;
            f.mParentFragment = mParent;
            f.mFragmentManager = mParent != null ? mParent.mChildFragmentManager : mActivity.mFragments;
            f.mCalled = false;
            f.onAttach(mActivity);
            if (!f.mCalled) {
                throw new SuperNotCalledException(
                        "Fragment " + f + " did not call through to super.onAttach()");
            }
            if (f.mParentFragment == null) {
                mActivity.onAttachFragment(f);
            }

            if (!f.mRetaining) {
                f.performCreate(f.mSavedFragmentState);
            }
            f.mRetaining = false;
            if (f.mFromLayout) {
                // For fragments that are part of the content view
                // layout, we need to instantiate the view immediately
                // and the inflater will take care of adding it.
                f.mView = f.performCreateView(f.getLayoutInflater(f.mSavedFragmentState), null,
                        f.mSavedFragmentState);
                if (f.mView != null) {
                    f.mView.setSaveFromParentEnabled(false);
                    if (f.mHidden)
                        f.mView.setVisibility(View.GONE);
                    f.onViewCreated(f.mView, f.mSavedFragmentState);
                }
            }
        case Fragment.CREATED:
            if (newState > Fragment.CREATED) {
                if (DEBUG)
                    Log.v(TAG, "moveto ACTIVITY_CREATED: " + f);
                if (!f.mFromLayout) {
                    ViewGroup container = null;
                    if (f.mContainerId != 0) {
                        container = (ViewGroup) mContainer.findViewById(f.mContainerId);
                        if (container == null && !f.mRestored) {
                            throwException(new IllegalArgumentException(
                                    "No view found for id 0x" + Integer.toHexString(f.mContainerId) + " ("
                                            + f.getResources().getResourceName(f.mContainerId)
                                            + ") for fragment " + f));
                        }
                    }
                    f.mContainer = container;
                    f.mView = f.performCreateView(f.getLayoutInflater(f.mSavedFragmentState), container,
                            f.mSavedFragmentState);
                    if (f.mView != null) {
                        f.mView.setSaveFromParentEnabled(false);
                        if (container != null) {
                            Animator anim = loadAnimator(f, transit, true, transitionStyle);
                            if (anim != null) {
                                anim.setTarget(f.mView);
                                anim.start();
                            }
                            container.addView(f.mView);
                        }
                        if (f.mHidden)
                            f.mView.setVisibility(View.GONE);
                        f.onViewCreated(f.mView, f.mSavedFragmentState);
                    }
                }

                f.performActivityCreated(f.mSavedFragmentState);
                if (f.mView != null) {
                    f.restoreViewState(f.mSavedFragmentState);
                }
                f.mSavedFragmentState = null;
            }
        case Fragment.ACTIVITY_CREATED:
        case Fragment.STOPPED:
            if (newState > Fragment.STOPPED) {
                if (DEBUG)
                    Log.v(TAG, "moveto STARTED: " + f);
                f.performStart();
            }
        case Fragment.STARTED:
            if (newState > Fragment.STARTED) {
                if (DEBUG)
                    Log.v(TAG, "moveto RESUMED: " + f);
                f.mResumed = true;
                f.performResume();
                // Get rid of this in case we saved it and never needed it.
                f.mSavedFragmentState = null;
                f.mSavedViewState = null;
            }
        }
    } else if (f.mState > newState) {
        switch (f.mState) {
        case Fragment.RESUMED:
            if (newState < Fragment.RESUMED) {
                if (DEBUG)
                    Log.v(TAG, "movefrom RESUMED: " + f);
                f.performPause();
                f.mResumed = false;
            }
        case Fragment.STARTED:
            if (newState < Fragment.STARTED) {
                if (DEBUG)
                    Log.v(TAG, "movefrom STARTED: " + f);
                f.performStop();
            }
        case Fragment.STOPPED:
        case Fragment.ACTIVITY_CREATED:
            if (newState < Fragment.ACTIVITY_CREATED) {
                if (DEBUG)
                    Log.v(TAG, "movefrom ACTIVITY_CREATED: " + f);
                if (f.mView != null) {
                    // Need to save the current view state if not
                    // done already.
                    if (!mActivity.isFinishing() && f.mSavedViewState == null) {
                        saveFragmentViewState(f);
                    }
                }
                f.performDestroyView();
                if (f.mView != null && f.mContainer != null) {
                    Animator anim = null;
                    if (mCurState > Fragment.INITIALIZING && !mDestroyed) {
                        anim = loadAnimator(f, transit, false, transitionStyle);
                    }
                    if (anim != null) {
                        final ViewGroup container = f.mContainer;
                        final View view = f.mView;
                        final Fragment fragment = f;
                        container.startViewTransition(view);
                        f.mAnimatingAway = anim;
                        f.mStateAfterAnimating = newState;
                        anim.addListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator anim) {
                                container.endViewTransition(view);
                                if (fragment.mAnimatingAway != null) {
                                    fragment.mAnimatingAway = null;
                                    moveToState(fragment, fragment.mStateAfterAnimating, 0, 0, false);
                                }
                            }
                        });
                        anim.setTarget(f.mView);
                        anim.start();

                    }
                    f.mContainer.removeView(f.mView);
                }
                f.mContainer = null;
                f.mView = null;
            }
        case Fragment.CREATED:
            if (newState < Fragment.CREATED) {
                if (mDestroyed) {
                    if (f.mAnimatingAway != null) {
                        // The fragment's containing activity is
                        // being destroyed, but this fragment is
                        // currently animating away.  Stop the
                        // animation right now -- it is not needed,
                        // and we can't wait any more on destroying
                        // the fragment.
                        Animator anim = f.mAnimatingAway;
                        f.mAnimatingAway = null;
                        anim.cancel();
                    }
                }
                if (f.mAnimatingAway != null) {
                    // We are waiting for the fragment's view to finish
                    // animating away.  Just make a note of the state
                    // the fragment now should move to once the animation
                    // is done.
                    f.mStateAfterAnimating = newState;
                    newState = Fragment.CREATED;
                } else {
                    if (DEBUG)
                        Log.v(TAG, "movefrom CREATED: " + f);
                    if (!f.mRetaining) {
                        f.performDestroy();
                    }

                    f.mCalled = false;
                    f.onDetach();
                    if (!f.mCalled) {
                        throw new SuperNotCalledException(
                                "Fragment " + f + " did not call through to super.onDetach()");
                    }
                    if (!keepActive) {
                        if (!f.mRetaining) {
                            makeInactive(f);
                        } else {
                            f.mActivity = null;
                            f.mParentFragment = null;
                            f.mFragmentManager = null;
                        }
                    }
                }
            }
        }
    }

    f.mState = newState;
}

From source file:android.app.FragmentManager.java

void moveToState(Fragment f, int newState, int transit, int transitionStyle, boolean keepActive) {
    if (DEBUG && false)
        Log.v(TAG, "moveToState: " + f + " oldState=" + f.mState + " newState=" + newState + " mRemoving="
                + f.mRemoving + " Callers=" + Debug.getCallers(5));

    // Fragments that are not currently added will sit in the onCreate() state.
    if ((!f.mAdded || f.mDetached) && newState > Fragment.CREATED) {
        newState = Fragment.CREATED;//  w ww .jav  a 2s.  c  o m
    }
    if (f.mRemoving && newState > f.mState) {
        // While removing a fragment, we can't change it to a higher state.
        newState = f.mState;
    }
    // Defer start if requested; don't allow it to move to STARTED or higher
    // if it's not already started.
    if (f.mDeferStart && f.mState < Fragment.STARTED && newState > Fragment.STOPPED) {
        newState = Fragment.STOPPED;
    }
    if (f.mState < newState) {
        // For fragments that are created from a layout, when restoring from
        // state we don't want to allow them to be created until they are
        // being reloaded from the layout.
        if (f.mFromLayout && !f.mInLayout) {
            return;
        }
        if (f.mAnimatingAway != null) {
            // The fragment is currently being animated...  but!  Now we
            // want to move our state back up.  Give up on waiting for the
            // animation, move to whatever the final state should be once
            // the animation is done, and then we can proceed from there.
            f.mAnimatingAway = null;
            moveToState(f, f.mStateAfterAnimating, 0, 0, true);
        }
        switch (f.mState) {
        case Fragment.INITIALIZING:
            if (DEBUG)
                Log.v(TAG, "moveto CREATED: " + f);
            if (f.mSavedFragmentState != null) {
                f.mSavedViewState = f.mSavedFragmentState
                        .getSparseParcelableArray(FragmentManagerImpl.VIEW_STATE_TAG);
                f.mTarget = getFragment(f.mSavedFragmentState, FragmentManagerImpl.TARGET_STATE_TAG);
                if (f.mTarget != null) {
                    f.mTargetRequestCode = f.mSavedFragmentState
                            .getInt(FragmentManagerImpl.TARGET_REQUEST_CODE_STATE_TAG, 0);
                }
                f.mUserVisibleHint = f.mSavedFragmentState.getBoolean(FragmentManagerImpl.USER_VISIBLE_HINT_TAG,
                        true);
                if (!f.mUserVisibleHint) {
                    f.mDeferStart = true;
                    if (newState > Fragment.STOPPED) {
                        newState = Fragment.STOPPED;
                    }
                }
            }
            f.mActivity = mActivity;
            f.mParentFragment = mParent;
            f.mFragmentManager = mParent != null ? mParent.mChildFragmentManager : mActivity.mFragments;
            f.mCalled = false;
            f.onAttach(mActivity);
            if (!f.mCalled) {
                throw new SuperNotCalledException(
                        "Fragment " + f + " did not call through to super.onAttach()");
            }
            if (f.mParentFragment == null) {
                mActivity.onAttachFragment(f);
            }

            if (!f.mRetaining) {
                f.performCreate(f.mSavedFragmentState);
            }
            f.mRetaining = false;
            if (f.mFromLayout) {
                // For fragments that are part of the content view
                // layout, we need to instantiate the view immediately
                // and the inflater will take care of adding it.
                f.mView = f.performCreateView(f.getLayoutInflater(f.mSavedFragmentState), null,
                        f.mSavedFragmentState);
                if (f.mView != null) {
                    f.mView.setSaveFromParentEnabled(false);
                    if (f.mHidden)
                        f.mView.setVisibility(View.GONE);
                    f.onViewCreated(f.mView, f.mSavedFragmentState);
                }
            }
        case Fragment.CREATED:
            if (newState > Fragment.CREATED) {
                if (DEBUG)
                    Log.v(TAG, "moveto ACTIVITY_CREATED: " + f);
                if (!f.mFromLayout) {
                    ViewGroup container = null;
                    if (f.mContainerId != 0) {
                        container = (ViewGroup) mContainer.findViewById(f.mContainerId);
                        if (container == null && !f.mRestored) {
                            throwException(new IllegalArgumentException(
                                    "No view found for id 0x" + Integer.toHexString(f.mContainerId) + " ("
                                            + f.getResources().getResourceName(f.mContainerId)
                                            + ") for fragment " + f));
                        }
                    }
                    f.mContainer = container;
                    f.mView = f.performCreateView(f.getLayoutInflater(f.mSavedFragmentState), container,
                            f.mSavedFragmentState);
                    if (f.mView != null) {
                        f.mView.setSaveFromParentEnabled(false);
                        if (container != null) {
                            Animator anim = loadAnimator(f, transit, true, transitionStyle);
                            if (anim != null) {
                                anim.setTarget(f.mView);
                                anim.start();
                            }
                            container.addView(f.mView);
                        }
                        if (f.mHidden)
                            f.mView.setVisibility(View.GONE);
                        f.onViewCreated(f.mView, f.mSavedFragmentState);
                    }
                }

                f.performActivityCreated(f.mSavedFragmentState);
                if (f.mView != null) {
                    f.restoreViewState(f.mSavedFragmentState);
                }
                f.mSavedFragmentState = null;
            }
        case Fragment.ACTIVITY_CREATED:
        case Fragment.STOPPED:
            if (newState > Fragment.STOPPED) {
                if (DEBUG)
                    Log.v(TAG, "moveto STARTED: " + f);
                f.performStart();
            }
        case Fragment.STARTED:
            if (newState > Fragment.STARTED) {
                if (DEBUG)
                    Log.v(TAG, "moveto RESUMED: " + f);
                f.mResumed = true;
                f.performResume();
                // Get rid of this in case we saved it and never needed it.
                f.mSavedFragmentState = null;
                f.mSavedViewState = null;
            }
        }
    } else if (f.mState > newState) {
        switch (f.mState) {
        case Fragment.RESUMED:
            if (newState < Fragment.RESUMED) {
                if (DEBUG)
                    Log.v(TAG, "movefrom RESUMED: " + f);
                f.performPause();
                f.mResumed = false;
            }
        case Fragment.STARTED:
            if (newState < Fragment.STARTED) {
                if (DEBUG)
                    Log.v(TAG, "movefrom STARTED: " + f);
                f.performStop();
            }
        case Fragment.STOPPED:
        case Fragment.ACTIVITY_CREATED:
            if (newState < Fragment.ACTIVITY_CREATED) {
                if (DEBUG)
                    Log.v(TAG, "movefrom ACTIVITY_CREATED: " + f);
                if (f.mView != null) {
                    // Need to save the current view state if not
                    // done already.
                    if (!mActivity.isFinishing() && f.mSavedViewState == null) {
                        saveFragmentViewState(f);
                    }
                }
                f.performDestroyView();
                if (f.mView != null && f.mContainer != null) {
                    Animator anim = null;
                    if (mCurState > Fragment.INITIALIZING && !mDestroyed) {
                        anim = loadAnimator(f, transit, false, transitionStyle);
                    }
                    if (anim != null) {
                        final ViewGroup container = f.mContainer;
                        final View view = f.mView;
                        final Fragment fragment = f;
                        container.startViewTransition(view);
                        f.mAnimatingAway = anim;
                        f.mStateAfterAnimating = newState;
                        anim.addListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator anim) {
                                container.endViewTransition(view);
                                if (fragment.mAnimatingAway != null) {
                                    fragment.mAnimatingAway = null;
                                    moveToState(fragment, fragment.mStateAfterAnimating, 0, 0, false);
                                }
                            }
                        });
                        anim.setTarget(f.mView);
                        anim.start();

                    }
                    f.mContainer.removeView(f.mView);
                }
                f.mContainer = null;
                f.mView = null;
            }
        case Fragment.CREATED:
            if (newState < Fragment.CREATED) {
                if (mDestroyed) {
                    if (f.mAnimatingAway != null) {
                        // The fragment's containing activity is
                        // being destroyed, but this fragment is
                        // currently animating away.  Stop the
                        // animation right now -- it is not needed,
                        // and we can't wait any more on destroying
                        // the fragment.
                        Animator anim = f.mAnimatingAway;
                        f.mAnimatingAway = null;
                        anim.cancel();
                    }
                }
                if (f.mAnimatingAway != null) {
                    // We are waiting for the fragment's view to finish
                    // animating away.  Just make a note of the state
                    // the fragment now should move to once the animation
                    // is done.
                    f.mStateAfterAnimating = newState;
                    newState = Fragment.CREATED;
                } else {
                    if (DEBUG)
                        Log.v(TAG, "movefrom CREATED: " + f);
                    if (!f.mRetaining) {
                        f.performDestroy();
                    }

                    f.mCalled = false;
                    f.onDetach();
                    if (!f.mCalled) {
                        throw new SuperNotCalledException(
                                "Fragment " + f + " did not call through to super.onDetach()");
                    }
                    if (!keepActive) {
                        if (!f.mRetaining) {
                            makeInactive(f);
                        } else {
                            f.mActivity = null;
                            f.mParentFragment = null;
                            f.mFragmentManager = null;
                            f.mChildFragmentManager = null;
                        }
                    }
                }
            }
        }
    }

    f.mState = newState;
}