FileDocCategorySizeDatePackage
ActivityTransitionState.javaAPI DocAndroid 5.1 API12138Thu Mar 12 22:22:10 GMT 2015android.app

ActivityTransitionState

public class ActivityTransitionState extends Object
This class contains all persistence-related functionality for Activity Transitions. Activities start exit and enter Activity Transitions through this class.

Fields Summary
private static final String
ENTERING_SHARED_ELEMENTS
private static final String
EXITING_MAPPED_FROM
private static final String
EXITING_MAPPED_TO
private ArrayList
mEnteringNames
The shared elements that the calling Activity has said that they transferred to this Activity.
private ArrayList
mExitingFrom
The names of shared elements that were shared to the called Activity.
private ArrayList
mExitingTo
The names of local Views that were shared out, mapped to those elements in mExitingFrom.
private ArrayList
mExitingToView
The local Views that were shared out, mapped to those elements in mExitingFrom.
private ExitTransitionCoordinator
mCalledExitCoordinator
The ExitTransitionCoordinator used to start an Activity. Used to make the elements restore Visibility of exited Views.
private ExitTransitionCoordinator
mReturnExitCoordinator
The ExitTransitionCoordinator used to return to a previous Activity when called with {@link android.app.Activity#finishAfterTransition()}.
private EnterTransitionCoordinator
mEnterTransitionCoordinator
We must be able to cancel entering transitions to stop changing the Window to opaque when we exit before making the Window opaque.
private ActivityOptions
mEnterActivityOptions
ActivityOptions used on entering this Activity.
private boolean
mHasExited
Has an exit transition been started? If so, we don't want to double-exit.
private boolean
mIsEnterPostponed
Postpone painting and starting the enter transition until this is false.
private android.util.SparseArray
mExitTransitionCoordinators
Potential exit transition coordinators.
private int
mExitTransitionCoordinatorsKey
Next key for mExitTransitionCoordinator.
private boolean
mIsEnterTriggered
Constructors Summary
public ActivityTransitionState()


      
    
Methods Summary
public intaddExitTransitionCoordinator(ExitTransitionCoordinator exitTransitionCoordinator)

        if (mExitTransitionCoordinators == null) {
            mExitTransitionCoordinators =
                    new SparseArray<WeakReference<ExitTransitionCoordinator>>();
        }
        WeakReference<ExitTransitionCoordinator> ref = new WeakReference(exitTransitionCoordinator);
        // clean up old references:
        for (int i = mExitTransitionCoordinators.size() - 1; i >= 0; i--) {
            WeakReference<ExitTransitionCoordinator> oldRef
                    = mExitTransitionCoordinators.valueAt(i);
            if (oldRef.get() == null) {
                mExitTransitionCoordinators.removeAt(i);
            }
        }
        int newKey = mExitTransitionCoordinatorsKey++;
        mExitTransitionCoordinators.append(newKey, ref);
        return newKey;
    
public voidclear()

        mEnteringNames = null;
        mExitingFrom = null;
        mExitingTo = null;
        mExitingToView = null;
        mCalledExitCoordinator = null;
        mEnterTransitionCoordinator = null;
        mEnterActivityOptions = null;
        mExitTransitionCoordinators = null;
    
public voidenterReady(Activity activity)

        if (mEnterActivityOptions == null || mIsEnterTriggered) {
            return;
        }
        mIsEnterTriggered = true;
        mHasExited = false;
        ArrayList<String> sharedElementNames = mEnterActivityOptions.getSharedElementNames();
        ResultReceiver resultReceiver = mEnterActivityOptions.getResultReceiver();
        if (mEnterActivityOptions.isReturning()) {
            restoreExitedViews();
            activity.getWindow().getDecorView().setVisibility(View.VISIBLE);
        }
        mEnterTransitionCoordinator = new EnterTransitionCoordinator(activity,
                resultReceiver, sharedElementNames, mEnterActivityOptions.isReturning());

        if (!mIsEnterPostponed) {
            startEnter();
        }
    
public voidonResume()

        restoreExitedViews();
    
public voidonStop()

        restoreExitedViews();
        if (mEnterTransitionCoordinator != null) {
            mEnterTransitionCoordinator.stop();
            mEnterTransitionCoordinator = null;
        }
        if (mReturnExitCoordinator != null) {
            mReturnExitCoordinator.stop();
            mReturnExitCoordinator = null;
        }
    
public voidpostponeEnterTransition()

        mIsEnterPostponed = true;
    
public voidreadState(android.os.Bundle bundle)

        if (bundle != null) {
            if (mEnterTransitionCoordinator == null || mEnterTransitionCoordinator.isReturning()) {
                mEnteringNames = bundle.getStringArrayList(ENTERING_SHARED_ELEMENTS);
            }
            if (mEnterTransitionCoordinator == null) {
                mExitingFrom = bundle.getStringArrayList(EXITING_MAPPED_FROM);
                mExitingTo = bundle.getStringArrayList(EXITING_MAPPED_TO);
            }
        }
    
private voidrestoreExitedViews()

        if (mCalledExitCoordinator != null) {
            mCalledExitCoordinator.resetViews();
            mCalledExitCoordinator = null;
        }
    
public voidsaveState(android.os.Bundle bundle)

        if (mEnteringNames != null) {
            bundle.putStringArrayList(ENTERING_SHARED_ELEMENTS, mEnteringNames);
        }
        if (mExitingFrom != null) {
            bundle.putStringArrayList(EXITING_MAPPED_FROM, mExitingFrom);
            bundle.putStringArrayList(EXITING_MAPPED_TO, mExitingTo);
        }
    
public voidsetEnterActivityOptions(Activity activity, ActivityOptions options)

        if (activity.getWindow().hasFeature(Window.FEATURE_ACTIVITY_TRANSITIONS)
                && options != null && mEnterActivityOptions == null
                && mEnterTransitionCoordinator == null
                && options.getAnimationType() == ActivityOptions.ANIM_SCENE_TRANSITION) {
            mEnterActivityOptions = options;
            mIsEnterTriggered = false;
            if (mEnterActivityOptions.isReturning()) {
                restoreExitedViews();
                int result = mEnterActivityOptions.getResultCode();
                if (result != 0) {
                    activity.onActivityReenter(result, mEnterActivityOptions.getResultData());
                }
            }
        }
    
private voidstartEnter()

        if (mEnterActivityOptions.isReturning()) {
            if (mExitingToView != null) {
                mEnterTransitionCoordinator.viewInstancesReady(mExitingFrom, mExitingTo,
                        mExitingToView);
            } else {
                mEnterTransitionCoordinator.namedViewsReady(mExitingFrom, mExitingTo);
            }
        } else {
            mEnterTransitionCoordinator.namedViewsReady(null, null);
            mEnteringNames = mEnterTransitionCoordinator.getAllSharedElementNames();
        }

        mExitingFrom = null;
        mExitingTo = null;
        mExitingToView = null;
        mEnterActivityOptions = null;
    
public booleanstartExitBackTransition(Activity activity)

        if (mEnteringNames == null) {
            return false;
        } else {
            if (!mHasExited) {
                mHasExited = true;
                Transition enterViewsTransition = null;
                ViewGroup decor = null;
                boolean delayExitBack = false;
                if (mEnterTransitionCoordinator != null) {
                    enterViewsTransition = mEnterTransitionCoordinator.getEnterViewsTransition();
                    decor = mEnterTransitionCoordinator.getDecor();
                    delayExitBack = mEnterTransitionCoordinator.cancelEnter();
                    mEnterTransitionCoordinator = null;
                    if (enterViewsTransition != null && decor != null) {
                        enterViewsTransition.pause(decor);
                    }
                }

                mReturnExitCoordinator =
                        new ExitTransitionCoordinator(activity, mEnteringNames, null, null, true);
                if (enterViewsTransition != null && decor != null) {
                    enterViewsTransition.resume(decor);
                }
                if (delayExitBack && decor != null) {
                    final ViewGroup finalDecor = decor;
                    decor.getViewTreeObserver().addOnPreDrawListener(
                            new ViewTreeObserver.OnPreDrawListener() {
                                @Override
                                public boolean onPreDraw() {
                                    finalDecor.getViewTreeObserver().removeOnPreDrawListener(this);
                                    if (mReturnExitCoordinator != null) {
                                        mReturnExitCoordinator.startExit(activity.mResultCode,
                                                activity.mResultData);
                                    }
                                    return true;
                                }
                            });
                } else {
                    mReturnExitCoordinator.startExit(activity.mResultCode, activity.mResultData);
                }
            }
            return true;
        }
    
public voidstartExitOutTransition(Activity activity, android.os.Bundle options)

        if (!activity.getWindow().hasFeature(Window.FEATURE_ACTIVITY_TRANSITIONS)) {
            return;
        }
        ActivityOptions activityOptions = new ActivityOptions(options);
        mEnterTransitionCoordinator = null;
        if (activityOptions.getAnimationType() == ActivityOptions.ANIM_SCENE_TRANSITION) {
            int key = activityOptions.getExitCoordinatorKey();
            int index = mExitTransitionCoordinators.indexOfKey(key);
            if (index >= 0) {
                mCalledExitCoordinator = mExitTransitionCoordinators.valueAt(index).get();
                mExitTransitionCoordinators.removeAt(index);
                if (mCalledExitCoordinator != null) {
                    mExitingFrom = mCalledExitCoordinator.getAcceptedNames();
                    mExitingTo = mCalledExitCoordinator.getMappedNames();
                    mExitingToView = mCalledExitCoordinator.copyMappedViews();
                    mCalledExitCoordinator.startExit();
                }
            }
        }
    
public voidstartPostponedEnterTransition()

        if (mIsEnterPostponed) {
            mIsEnterPostponed = false;
            if (mEnterTransitionCoordinator != null) {
                startEnter();
            }
        }