Transition.java revision 7b75062fb05a9981faf3c0c9f840dbdb9e97e7f7
1faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase/*
2faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * Copyright (C) 2013 The Android Open Source Project
3faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase *
4faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * Licensed under the Apache License, Version 2.0 (the "License");
5faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * you may not use this file except in compliance with the License.
6faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * You may obtain a copy of the License at
7faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase *
8faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase *      http://www.apache.org/licenses/LICENSE-2.0
9faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase *
10faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * Unless required by applicable law or agreed to in writing, software
11faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * distributed under the License is distributed on an "AS IS" BASIS,
12faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * See the License for the specific language governing permissions and
14faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * limitations under the License.
15faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase */
166ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase
17d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haasepackage android.transition;
18faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
19faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport android.animation.Animator;
20faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport android.animation.AnimatorListenerAdapter;
21faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport android.animation.TimeInterpolator;
22d6107a3170df61d9e776fcd5666acfc9135c6f16George Mountimport android.graphics.Rect;
2308735185f8105710e18ad02297461bec9268e514Chet Haaseimport android.util.ArrayMap;
24c43524f3869cc0d36974fce61986017093f2ecd2Chet Haaseimport android.util.Log;
25faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport android.util.LongSparseArray;
26faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport android.util.SparseArray;
27d6107a3170df61d9e776fcd5666acfc9135c6f16George Mountimport android.util.SparseLongArray;
28faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport android.view.SurfaceView;
29faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport android.view.TextureView;
30faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport android.view.View;
31faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport android.view.ViewGroup;
32faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport android.view.ViewOverlay;
33cf68aad3164303df59b2a669d186a94533c9c743George Mountimport android.view.WindowId;
34faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport android.widget.ListView;
35ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haaseimport android.widget.Spinner;
36faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
37faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haaseimport java.util.ArrayList;
38d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haaseimport java.util.List;
39faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
40faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase/**
41faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * A Transition holds information about animations that will be run on its
42faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * targets during a scene change. Subclasses of this abstract class may
43d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * choreograph several child transitions ({@link TransitionSet} or they may
44faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * perform custom animations themselves. Any Transition has two main jobs:
45faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * (1) capture property values, and (2) play animations based on changes to
46faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * captured property values. A custom transition knows what property values
47faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * on View objects are of interest to it, and also knows how to animate
48faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * changes to those values. For example, the {@link Fade} transition tracks
49faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * changes to visibility-related properties and is able to construct and run
50faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * animations that fade items in or out based on changes to those properties.
51faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase *
52faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * <p>Note: Transitions may not work correctly with either {@link SurfaceView}
53faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * or {@link TextureView}, due to the way that these views are displayed
54faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * on the screen. For SurfaceView, the problem is that the view is updated from
55faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * a non-UI thread, so changes to the view due to transitions (such as moving
56faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * and resizing the view) may be out of sync with the display inside those bounds.
57faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * TextureView is more compatible with transitions in general, but some
58d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * specific transitions (such as {@link Fade}) may not be compatible
59faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * with TextureView because they rely on {@link ViewOverlay} functionality,
60faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase * which does not currently work with TextureView.</p>
61d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase *
62d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * <p>Transitions can be declared in XML resource files inside the <code>res/transition</code>
63d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * directory. Transition resources consist of a tag name for one of the Transition
64d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * subclasses along with attributes to define some of the attributes of that transition.
65d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount * For example, here is a minimal resource file that declares a {@link ChangeBounds} transition:
66d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase *
67d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * {@sample development/samples/ApiDemos/res/transition/changebounds.xml ChangeBounds}
68d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase *
69608b87d9e57b71a86374a439bf5c3febd1e142f2George Mount * <p>This TransitionSet contains {@link android.transition.Explode} for visibility,
70608b87d9e57b71a86374a439bf5c3febd1e142f2George Mount * {@link android.transition.ChangeBounds}, {@link android.transition.ChangeTransform},
71608b87d9e57b71a86374a439bf5c3febd1e142f2George Mount * and {@link android.transition.ChangeClipBounds} for non-<code>ImageView</code>s and
72608b87d9e57b71a86374a439bf5c3febd1e142f2George Mount * {@link android.transition.MoveImage} for <code>ImageView</code>s:</p>
73d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount *
74608b87d9e57b71a86374a439bf5c3febd1e142f2George Mount * {@sample development/samples/ApiDemos/res/transition/explode_move_together.xml MultipleTransform}
75d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount *
76d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * <p>Note that attributes for the transition are not required, just as they are
77d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * optional when declared in code; Transitions created from XML resources will use
78d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * the same defaults as their code-created equivalents. Here is a slightly more
79d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * elaborate example which declares a {@link TransitionSet} transition with
80d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * {@link ChangeBounds} and {@link Fade} child transitions:</p>
81d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase *
82d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * {@sample
83d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * development/samples/ApiDemos/res/transition/changebounds_fadeout_sequential.xml TransitionSet}
84d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase *
85d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * <p>In this example, the transitionOrdering attribute is used on the TransitionSet
86d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * object to change from the default {@link TransitionSet#ORDERING_TOGETHER} behavior
87d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * to be {@link TransitionSet#ORDERING_SEQUENTIAL} instead. Also, the {@link Fade}
88d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * transition uses a fadingMode of {@link Fade#OUT} instead of the default
89d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * out-in behavior. Finally, note the use of the <code>targets</code> sub-tag, which
90d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * takes a set of {@link android.R.styleable#TransitionTarget target} tags, each
91a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount * of which lists a specific <code>targetId</code>, <code>targetClass</code>,
9230da61d477bcb6cc7718f9516c444359352fe148George Mount * <code>targetViewName</code>, <code>excludeId</code>, <code>excludeClass</code>, or
9330da61d477bcb6cc7718f9516c444359352fe148George Mount * <code>excludeViewName</code>, which this transition acts upon.
94d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * Use of targets is optional, but can be used to either limit the time spent checking
95d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * attributes on unchanging views, or limiting the types of animations run on specific views.
96d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * In this case, we know that only the <code>grayscaleContainer</code> will be
97d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * disappearing, so we choose to limit the {@link Fade} transition to only that view.</p>
98d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase *
99d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * Further information on XML resource descriptions for transitions can be found for
100d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * {@link android.R.styleable#Transition}, {@link android.R.styleable#TransitionSet},
101d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount * {@link android.R.styleable#TransitionTarget}, {@link android.R.styleable#Fade}, and
102d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount * {@link android.R.styleable#Slide}.
103d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase *
104faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase */
1056ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haasepublic abstract class Transition implements Cloneable {
106faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
107faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    private static final String LOG_TAG = "Transition";
108faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    static final boolean DBG = false;
109faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1107b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    /**
1117b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * With {@link #setMatchOrder(int...)}, chooses to match by View instance.
1127b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     */
1137b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    public static final int MATCH_INSTANCE = 0x1;
1147b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    private static final int MATCH_FIRST = MATCH_INSTANCE;
1157b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount
1167b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    /**
1177b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * With {@link #setMatchOrder(int...)}, chooses to match by
1187b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * {@link android.view.View#getViewName()}. Null names will not be matched.
1197b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     */
1207b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    public static final int MATCH_VIEW_NAME = 0x2;
1217b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount
1227b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    /**
1237b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * With {@link #setMatchOrder(int...)}, chooses to match by
1247b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * {@link android.view.View#getId()}. Negative IDs will not be matched.
1257b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     */
1267b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    public static final int MATCH_ID = 0x3;
1277b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount
1287b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    /**
1297b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * With {@link #setMatchOrder(int...)}, chooses to match by the {@link android.widget.Adapter}
1307b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * item id. When {@link android.widget.Adapter#hasStableIds()} returns false, no match
1317b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * will be made for items.
1327b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     */
1337b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    public static final int MATCH_ITEM_ID = 0x4;
1347b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount
1357b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    private static final int MATCH_LAST = MATCH_ITEM_ID;
1367b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount
1377b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    private static final int[] DEFAULT_MATCH_ORDER = {
1387b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        MATCH_VIEW_NAME,
1397b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        MATCH_INSTANCE,
1407b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        MATCH_ID,
1417b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        MATCH_ITEM_ID,
1427b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    };
1437b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount
144199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    private String mName = getClass().getName();
145199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase
146faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    long mStartDelay = -1;
147faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    long mDuration = -1;
148faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    TimeInterpolator mInterpolator = null;
149d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    ArrayList<Integer> mTargetIds = new ArrayList<Integer>();
150d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    ArrayList<View> mTargets = new ArrayList<View>();
15130da61d477bcb6cc7718f9516c444359352fe148George Mount    ArrayList<String> mTargetNames = null;
15230da61d477bcb6cc7718f9516c444359352fe148George Mount    ArrayList<Class> mTargetTypes = null;
153ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    ArrayList<Integer> mTargetIdExcludes = null;
154ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    ArrayList<View> mTargetExcludes = null;
155ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    ArrayList<Class> mTargetTypeExcludes = null;
15630da61d477bcb6cc7718f9516c444359352fe148George Mount    ArrayList<String> mTargetNameExcludes = null;
157ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    ArrayList<Integer> mTargetIdChildExcludes = null;
158ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    ArrayList<View> mTargetChildExcludes = null;
159ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    ArrayList<Class> mTargetTypeChildExcludes = null;
1606ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase    private TransitionValuesMaps mStartValues = new TransitionValuesMaps();
1616ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase    private TransitionValuesMaps mEndValues = new TransitionValuesMaps();
162d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    TransitionSet mParent = null;
1637b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    private int[] mMatchOrder = DEFAULT_MATCH_ORDER;
1646ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase
165199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    // Per-animator information used for later canceling when future transitions overlap
166199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    private static ThreadLocal<ArrayMap<Animator, AnimationInfo>> sRunningAnimators =
167199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            new ThreadLocal<ArrayMap<Animator, AnimationInfo>>();
168199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase
169d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    // Scene Root is set at createAnimator() time in the cloned Transition
1706ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase    ViewGroup mSceneRoot = null;
1716ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase
172b7a7fc9d233bad507ce893882352618b13647058Chet Haase    // Whether removing views from their parent is possible. This is only for views
173b7a7fc9d233bad507ce893882352618b13647058Chet Haase    // in the start scene, which are no longer in the view hierarchy. This property
174b7a7fc9d233bad507ce893882352618b13647058Chet Haase    // is determined by whether the previous Scene was created from a layout
175b7a7fc9d233bad507ce893882352618b13647058Chet Haase    // resource, and thus the views from the exited scene are going away anyway
176b7a7fc9d233bad507ce893882352618b13647058Chet Haase    // and can be removed as necessary to achieve a particular effect, such as
177b7a7fc9d233bad507ce893882352618b13647058Chet Haase    // removing them from parents to add them to overlays.
178b7a7fc9d233bad507ce893882352618b13647058Chet Haase    boolean mCanRemoveViews = false;
179b7a7fc9d233bad507ce893882352618b13647058Chet Haase
180e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase    // Track all animators in use in case the transition gets canceled and needs to
181e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase    // cancel running animators
182e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase    private ArrayList<Animator> mCurrentAnimators = new ArrayList<Animator>();
183e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase
184faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    // Number of per-target instances of this Transition currently running. This count is
185199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    // determined by calls to start() and end()
186faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    int mNumInstances = 0;
187faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
188199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    // Whether this transition is currently paused, due to a call to pause()
189199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    boolean mPaused = false;
190c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase
191a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase    // Whether this transition has ended. Used to avoid pause/resume on transitions
192a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase    // that have completed
193a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase    private boolean mEnded = false;
194a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase
195c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase    // The set of listeners to be sent transition lifecycle events.
196faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    ArrayList<TransitionListener> mListeners = null;
197faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
198d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    // The set of animators collected from calls to createAnimator(),
199d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    // to be run in runAnimators()
200199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    ArrayList<Animator> mAnimators = new ArrayList<Animator>();
201c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase
202d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    // The function for calculating the Animation start delay.
203d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    TransitionPropagation mPropagation;
204d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount
205d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    // The rectangular region for Transitions like Explode and TransitionPropagations
206d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    // like CircularPropagation
207d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    EpicenterCallback mEpicenterCallback;
208d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount
209faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
210faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Constructs a Transition object with no target objects. A transition with
211faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * no targets defaults to running on all target objects in the scene hierarchy
212d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * (if the transition is not contained in a TransitionSet), or all target
213d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * objects passed down from its parent (if it is in a TransitionSet).
214faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
215faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    public Transition() {}
216faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
217faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
218faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Sets the duration of this transition. By default, there is no duration
219faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * (indicated by a negative number), which means that the Animator created by
220faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * the transition will have its own specified duration. If the duration of a
221faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Transition is set, that duration will override the Animator duration.
222faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
223faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @param duration The length of the animation, in milliseconds.
224faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @return This transition object.
225d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @attr ref android.R.styleable#Transition_duration
226faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
227faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    public Transition setDuration(long duration) {
228faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        mDuration = duration;
229faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        return this;
230faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
231faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
232199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    /**
233199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * Returns the duration set on this transition. If no duration has been set,
234199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * the returned value will be negative, indicating that resulting animators will
235199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * retain their own durations.
236199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     *
237d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @return The duration set on this transition, in milliseconds, if one has been
238d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * set, otherwise returns a negative number.
239199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     */
240faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    public long getDuration() {
241faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        return mDuration;
242faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
243faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
244faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
245faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Sets the startDelay of this transition. By default, there is no delay
246faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * (indicated by a negative number), which means that the Animator created by
247faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * the transition will have its own specified startDelay. If the delay of a
248faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Transition is set, that delay will override the Animator delay.
249faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
250faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @param startDelay The length of the delay, in milliseconds.
251d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @return This transition object.
252d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @attr ref android.R.styleable#Transition_startDelay
253faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
254d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    public Transition setStartDelay(long startDelay) {
255faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        mStartDelay = startDelay;
256d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        return this;
257faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
258faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
259199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    /**
260199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * Returns the startDelay set on this transition. If no startDelay has been set,
261199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * the returned value will be negative, indicating that resulting animators will
262199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * retain their own startDelays.
263199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     *
264d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @return The startDelay set on this transition, in milliseconds, if one has
265d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * been set, otherwise returns a negative number.
266199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     */
267faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    public long getStartDelay() {
268faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        return mStartDelay;
269faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
270faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
271faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
272faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Sets the interpolator of this transition. By default, the interpolator
273faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * is null, which means that the Animator created by the transition
274faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * will have its own specified interpolator. If the interpolator of a
275faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Transition is set, that interpolator will override the Animator interpolator.
276faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
277faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @param interpolator The time interpolator used by the transition
278d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @return This transition object.
279d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @attr ref android.R.styleable#Transition_interpolator
280faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
281d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    public Transition setInterpolator(TimeInterpolator interpolator) {
282faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        mInterpolator = interpolator;
283d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        return this;
284faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
285faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
286199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    /**
287199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * Returns the interpolator set on this transition. If no interpolator has been set,
288199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * the returned value will be null, indicating that resulting animators will
289199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * retain their own interpolators.
290199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     *
291199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * @return The interpolator set on this transition, if one has been set, otherwise
292199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * returns null.
293199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     */
294faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    public TimeInterpolator getInterpolator() {
295faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        return mInterpolator;
296faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
297faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
298faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
299199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * Returns the set of property names used stored in the {@link TransitionValues}
300d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * object passed into {@link #captureStartValues(TransitionValues)} that
301199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * this transition cares about for the purposes of canceling overlapping animations.
302199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * When any transition is started on a given scene root, all transitions
303199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * currently running on that same scene root are checked to see whether the
304199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * properties on which they based their animations agree with the end values of
305199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * the same properties in the new transition. If the end values are not equal,
306199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * then the old animation is canceled since the new transition will start a new
307199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * animation to these new values. If the values are equal, the old animation is
308199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * allowed to continue and no new animation is started for that transition.
309199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     *
310199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * <p>A transition does not need to override this method. However, not doing so
311199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * will mean that the cancellation logic outlined in the previous paragraph
312199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * will be skipped for that transition, possibly leading to artifacts as
313199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * old transitions and new transitions on the same targets run in parallel,
314199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * animating views toward potentially different end values.</p>
315199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     *
316199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * @return An array of property names as described in the class documentation for
317199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * {@link TransitionValues}. The default implementation returns <code>null</code>.
318199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     */
319199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    public String[] getTransitionProperties() {
320199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        return null;
321199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    }
322199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase
323199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    /**
324d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * This method creates an animation that will be run for this transition
325d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * given the information in the startValues and endValues structures captured
326d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * earlier for the start and end scenes. Subclasses of Transition should override
327d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * this method. The method should only be called by the transition system; it is
328d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * not intended to be called from external classes.
329d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     *
330d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * <p>This method is called by the transition's parent (all the way up to the
331faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * topmost Transition in the hierarchy) with the sceneRoot and start/end
3322ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * values that the transition may need to set up initial target values
3332ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * and construct an appropriate animation. For example, if an overall
334d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * Transition is a {@link TransitionSet} consisting of several
335faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * child transitions in sequence, then some of the child transitions may
336faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * want to set initial values on target views prior to the overall
3372ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * Transition commencing, to put them in an appropriate state for the
338faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * delay between that start and the child Transition start time. For
339faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * example, a transition that fades an item in may wish to set the starting
340faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * alpha value to 0, to avoid it blinking in prior to the transition
341faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * actually starting the animation. This is necessary because the scene
342faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * change that triggers the Transition will automatically set the end-scene
343faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * on all target views, so a Transition that wants to animate from a
344d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * different value should set that value prior to returning from this method.</p>
345faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
346faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * <p>Additionally, a Transition can perform logic to determine whether
347faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * the transition needs to run on the given target and start/end values.
348faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * For example, a transition that resizes objects on the screen may wish
349faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * to avoid running for views which are not present in either the start
350d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * or end scenes.</p>
3512ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     *
3522ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * <p>If there is an animator created and returned from this method, the
3532ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * transition mechanism will apply any applicable duration, startDelay,
3542ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * and interpolator to that animation and start it. A return value of
3552ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * <code>null</code> indicates that no animation should run. The default
3562ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * implementation returns null.</p>
357faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
358faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * <p>The method is called for every applicable target object, which is
359faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * stored in the {@link TransitionValues#view} field.</p>
360faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
361d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     *
362d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @param sceneRoot The root of the transition hierarchy.
363d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @param startValues The values for a specific target in the start scene.
364d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @param endValues The values for the target in the end scene.
365d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @return A Animator to be started at the appropriate time in the
366d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * overall transition for this scene change. A null value means no animation
367d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * should be run.
368faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
369d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
370faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            TransitionValues endValues) {
3712ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase        return null;
372faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
373faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
374faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
3757b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * Sets the order in which Transition matches View start and end values.
3767b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * <p>
3777b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * The default behavior is to match first by {@link android.view.View#getViewName()},
3787b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * then by View instance, then by {@link android.view.View#getId()} and finally
3797b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * by its item ID if it is in a direct child of ListView. The caller can
3807b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * choose to have only some or all of the values of {@link #MATCH_INSTANCE},
3817b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * {@link #MATCH_VIEW_NAME}, {@link #MATCH_ITEM_ID}, and {@link #MATCH_ID}. Only
3827b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * the match algorithms supplied will be used to determine whether Views are the
3837b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * the same in both the start and end Scene. Views that do not match will be considered
3847b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * as entering or leaving the Scene.
3857b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * </p>
3867b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     * @param matches A list of zero or more of {@link #MATCH_INSTANCE},
3877b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     *                {@link #MATCH_VIEW_NAME}, {@link #MATCH_ITEM_ID}, and {@link #MATCH_ID}.
3887b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     *                If none are provided, then the default match order will be set.
3897b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount     */
3907b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    public void setMatchOrder(int... matches) {
3917b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        if (matches == null || matches.length == 0) {
3927b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount            mMatchOrder = DEFAULT_MATCH_ORDER;
3937b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        } else {
3947b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount            for (int i = 0; i < matches.length; i++) {
3957b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                int match = matches[i];
3967b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                if (!isValidMatch(match)) {
3977b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                    throw new IllegalArgumentException("matches contains invalid value");
3987b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                }
3997b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                if (alreadyContains(matches, i)) {
4007b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                    throw new IllegalArgumentException("matches contains a duplicate value");
4017b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                }
4027b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount            }
4037b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount            mMatchOrder = matches.clone();
4047b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        }
4057b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    }
4067b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount
4077b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    private static boolean isValidMatch(int match) {
4087b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        return (match >= MATCH_FIRST && match <= MATCH_LAST);
4097b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    }
4107b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount
4117b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    private static boolean alreadyContains(int[] array, int searchIndex) {
4127b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        int value = array[searchIndex];
4137b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        for (int i = 0; i < searchIndex; i++) {
4147b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount            if (array[i] == value) {
4157b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                return true;
4167b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount            }
4177b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        }
4187b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        return false;
4197b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    }
4207b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount
4217b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    /**
42230da61d477bcb6cc7718f9516c444359352fe148George Mount     * Match start/end values by View instance. Adds matched values to startValuesList
42330da61d477bcb6cc7718f9516c444359352fe148George Mount     * and endValuesList and removes them from unmatchedStart and unmatchedEnd.
42430da61d477bcb6cc7718f9516c444359352fe148George Mount     */
42530da61d477bcb6cc7718f9516c444359352fe148George Mount    private void matchInstances(ArrayList<TransitionValues> startValuesList,
42630da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayList<TransitionValues> endValuesList,
42730da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayMap<View, TransitionValues> unmatchedStart,
42830da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayMap<View, TransitionValues> unmatchedEnd) {
42930da61d477bcb6cc7718f9516c444359352fe148George Mount        for (int i = unmatchedStart.size() - 1; i >= 0; i--) {
43030da61d477bcb6cc7718f9516c444359352fe148George Mount            View view = unmatchedStart.keyAt(i);
43130da61d477bcb6cc7718f9516c444359352fe148George Mount            TransitionValues end = unmatchedEnd.remove(view);
43230da61d477bcb6cc7718f9516c444359352fe148George Mount            if (end != null) {
43330da61d477bcb6cc7718f9516c444359352fe148George Mount                TransitionValues start = unmatchedStart.removeAt(i);
43430da61d477bcb6cc7718f9516c444359352fe148George Mount                startValuesList.add(start);
43530da61d477bcb6cc7718f9516c444359352fe148George Mount                endValuesList.add(end);
43630da61d477bcb6cc7718f9516c444359352fe148George Mount            }
43730da61d477bcb6cc7718f9516c444359352fe148George Mount        }
43830da61d477bcb6cc7718f9516c444359352fe148George Mount    }
43930da61d477bcb6cc7718f9516c444359352fe148George Mount
44030da61d477bcb6cc7718f9516c444359352fe148George Mount    /**
44130da61d477bcb6cc7718f9516c444359352fe148George Mount     * Match start/end values by Adapter item ID. Adds matched values to startValuesList
44230da61d477bcb6cc7718f9516c444359352fe148George Mount     * and endValuesList and removes them from unmatchedStart and unmatchedEnd, using
44330da61d477bcb6cc7718f9516c444359352fe148George Mount     * startItemIds and endItemIds as a guide for which Views have unique item IDs.
44430da61d477bcb6cc7718f9516c444359352fe148George Mount     */
44530da61d477bcb6cc7718f9516c444359352fe148George Mount    private void matchItemIds(ArrayList<TransitionValues> startValuesList,
44630da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayList<TransitionValues> endValuesList,
44730da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayMap<View, TransitionValues> unmatchedStart,
44830da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayMap<View, TransitionValues> unmatchedEnd,
44930da61d477bcb6cc7718f9516c444359352fe148George Mount            LongSparseArray<View> startItemIds, LongSparseArray<View> endItemIds) {
45030da61d477bcb6cc7718f9516c444359352fe148George Mount        int numStartIds = startItemIds.size();
45130da61d477bcb6cc7718f9516c444359352fe148George Mount        for (int i = 0; i < numStartIds; i++) {
45230da61d477bcb6cc7718f9516c444359352fe148George Mount            View startView = startItemIds.valueAt(i);
45330da61d477bcb6cc7718f9516c444359352fe148George Mount            if (startView != null) {
45430da61d477bcb6cc7718f9516c444359352fe148George Mount                View endView = endItemIds.get(startItemIds.keyAt(i));
45530da61d477bcb6cc7718f9516c444359352fe148George Mount                if (endView != null) {
45630da61d477bcb6cc7718f9516c444359352fe148George Mount                    TransitionValues startValues = unmatchedStart.get(startView);
45730da61d477bcb6cc7718f9516c444359352fe148George Mount                    TransitionValues endValues = unmatchedEnd.get(endView);
45830da61d477bcb6cc7718f9516c444359352fe148George Mount                    if (startValues != null && endValues != null) {
45930da61d477bcb6cc7718f9516c444359352fe148George Mount                        startValuesList.add(startValues);
46030da61d477bcb6cc7718f9516c444359352fe148George Mount                        endValuesList.add(endValues);
46130da61d477bcb6cc7718f9516c444359352fe148George Mount                        unmatchedStart.remove(startView);
46230da61d477bcb6cc7718f9516c444359352fe148George Mount                        unmatchedEnd.remove(endView);
46330da61d477bcb6cc7718f9516c444359352fe148George Mount                    }
46430da61d477bcb6cc7718f9516c444359352fe148George Mount                }
46530da61d477bcb6cc7718f9516c444359352fe148George Mount            }
46630da61d477bcb6cc7718f9516c444359352fe148George Mount        }
46730da61d477bcb6cc7718f9516c444359352fe148George Mount    }
46830da61d477bcb6cc7718f9516c444359352fe148George Mount
46930da61d477bcb6cc7718f9516c444359352fe148George Mount    /**
47030da61d477bcb6cc7718f9516c444359352fe148George Mount     * Match start/end values by Adapter view ID. Adds matched values to startValuesList
47130da61d477bcb6cc7718f9516c444359352fe148George Mount     * and endValuesList and removes them from unmatchedStart and unmatchedEnd, using
47230da61d477bcb6cc7718f9516c444359352fe148George Mount     * startIds and endIds as a guide for which Views have unique IDs.
47330da61d477bcb6cc7718f9516c444359352fe148George Mount     */
47430da61d477bcb6cc7718f9516c444359352fe148George Mount    private void matchIds(ArrayList<TransitionValues> startValuesList,
47530da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayList<TransitionValues> endValuesList,
47630da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayMap<View, TransitionValues> unmatchedStart,
47730da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayMap<View, TransitionValues> unmatchedEnd,
47830da61d477bcb6cc7718f9516c444359352fe148George Mount            SparseArray<View> startIds, SparseArray<View> endIds) {
47930da61d477bcb6cc7718f9516c444359352fe148George Mount        int numStartIds = startIds.size();
48030da61d477bcb6cc7718f9516c444359352fe148George Mount        for (int i = 0; i < numStartIds; i++) {
48130da61d477bcb6cc7718f9516c444359352fe148George Mount            View startView = startIds.valueAt(i);
48230da61d477bcb6cc7718f9516c444359352fe148George Mount            if (startView != null && isValidTarget(startView)) {
48330da61d477bcb6cc7718f9516c444359352fe148George Mount                View endView = endIds.get(startIds.keyAt(i));
48430da61d477bcb6cc7718f9516c444359352fe148George Mount                if (endView != null && isValidTarget(endView)) {
48530da61d477bcb6cc7718f9516c444359352fe148George Mount                    TransitionValues startValues = unmatchedStart.get(startView);
48630da61d477bcb6cc7718f9516c444359352fe148George Mount                    TransitionValues endValues = unmatchedEnd.get(endView);
48730da61d477bcb6cc7718f9516c444359352fe148George Mount                    if (startValues != null && endValues != null) {
48830da61d477bcb6cc7718f9516c444359352fe148George Mount                        startValuesList.add(startValues);
48930da61d477bcb6cc7718f9516c444359352fe148George Mount                        endValuesList.add(endValues);
49030da61d477bcb6cc7718f9516c444359352fe148George Mount                        unmatchedStart.remove(startView);
49130da61d477bcb6cc7718f9516c444359352fe148George Mount                        unmatchedEnd.remove(endView);
49230da61d477bcb6cc7718f9516c444359352fe148George Mount                    }
49330da61d477bcb6cc7718f9516c444359352fe148George Mount                }
49430da61d477bcb6cc7718f9516c444359352fe148George Mount            }
49530da61d477bcb6cc7718f9516c444359352fe148George Mount        }
49630da61d477bcb6cc7718f9516c444359352fe148George Mount    }
49730da61d477bcb6cc7718f9516c444359352fe148George Mount
49830da61d477bcb6cc7718f9516c444359352fe148George Mount    /**
49930da61d477bcb6cc7718f9516c444359352fe148George Mount     * Match start/end values by Adapter viewName. Adds matched values to startValuesList
50030da61d477bcb6cc7718f9516c444359352fe148George Mount     * and endValuesList and removes them from unmatchedStart and unmatchedEnd, using
50130da61d477bcb6cc7718f9516c444359352fe148George Mount     * startNames and endNames as a guide for which Views have unique viewNames.
50230da61d477bcb6cc7718f9516c444359352fe148George Mount     */
50330da61d477bcb6cc7718f9516c444359352fe148George Mount    private void matchNames(ArrayList<TransitionValues> startValuesList,
50430da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayList<TransitionValues> endValuesList,
50530da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayMap<View, TransitionValues> unmatchedStart,
50630da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayMap<View, TransitionValues> unmatchedEnd,
50730da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayMap<String, View> startNames, ArrayMap<String, View> endNames) {
50830da61d477bcb6cc7718f9516c444359352fe148George Mount        int numStartNames = startNames.size();
50930da61d477bcb6cc7718f9516c444359352fe148George Mount        for (int i = 0; i < numStartNames; i++) {
51030da61d477bcb6cc7718f9516c444359352fe148George Mount            View startView = startNames.valueAt(i);
51130da61d477bcb6cc7718f9516c444359352fe148George Mount            if (startView != null && isValidTarget(startView)) {
51230da61d477bcb6cc7718f9516c444359352fe148George Mount                View endView = endNames.get(startNames.keyAt(i));
51330da61d477bcb6cc7718f9516c444359352fe148George Mount                if (endView != null && isValidTarget(endView)) {
51430da61d477bcb6cc7718f9516c444359352fe148George Mount                    TransitionValues startValues = unmatchedStart.get(startView);
51530da61d477bcb6cc7718f9516c444359352fe148George Mount                    TransitionValues endValues = unmatchedEnd.get(endView);
51630da61d477bcb6cc7718f9516c444359352fe148George Mount                    if (startValues != null && endValues != null) {
51730da61d477bcb6cc7718f9516c444359352fe148George Mount                        startValuesList.add(startValues);
51830da61d477bcb6cc7718f9516c444359352fe148George Mount                        endValuesList.add(endValues);
51930da61d477bcb6cc7718f9516c444359352fe148George Mount                        unmatchedStart.remove(startView);
52030da61d477bcb6cc7718f9516c444359352fe148George Mount                        unmatchedEnd.remove(endView);
52130da61d477bcb6cc7718f9516c444359352fe148George Mount                    }
52230da61d477bcb6cc7718f9516c444359352fe148George Mount                }
52330da61d477bcb6cc7718f9516c444359352fe148George Mount            }
52430da61d477bcb6cc7718f9516c444359352fe148George Mount        }
52530da61d477bcb6cc7718f9516c444359352fe148George Mount    }
52630da61d477bcb6cc7718f9516c444359352fe148George Mount
52730da61d477bcb6cc7718f9516c444359352fe148George Mount    /**
52830da61d477bcb6cc7718f9516c444359352fe148George Mount     * Adds all values from unmatchedStart and unmatchedEnd to startValuesList and endValuesList,
52930da61d477bcb6cc7718f9516c444359352fe148George Mount     * assuming that there is no match between values in the list.
53030da61d477bcb6cc7718f9516c444359352fe148George Mount     */
53130da61d477bcb6cc7718f9516c444359352fe148George Mount    private void addUnmatched(ArrayList<TransitionValues> startValuesList,
53230da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayList<TransitionValues> endValuesList,
53330da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayMap<View, TransitionValues> unmatchedStart,
53430da61d477bcb6cc7718f9516c444359352fe148George Mount            ArrayMap<View, TransitionValues> unmatchedEnd) {
53530da61d477bcb6cc7718f9516c444359352fe148George Mount        // Views that only exist in the start Scene
53630da61d477bcb6cc7718f9516c444359352fe148George Mount        for (int i = 0; i < unmatchedStart.size(); i++) {
53730da61d477bcb6cc7718f9516c444359352fe148George Mount            startValuesList.add(unmatchedStart.valueAt(i));
53830da61d477bcb6cc7718f9516c444359352fe148George Mount            endValuesList.add(null);
53930da61d477bcb6cc7718f9516c444359352fe148George Mount        }
54030da61d477bcb6cc7718f9516c444359352fe148George Mount
54130da61d477bcb6cc7718f9516c444359352fe148George Mount        // Views that only exist in the end Scene
54230da61d477bcb6cc7718f9516c444359352fe148George Mount        for (int i = 0; i < unmatchedEnd.size(); i++) {
54330da61d477bcb6cc7718f9516c444359352fe148George Mount            endValuesList.add(unmatchedEnd.valueAt(i));
54430da61d477bcb6cc7718f9516c444359352fe148George Mount            startValuesList.add(null);
54530da61d477bcb6cc7718f9516c444359352fe148George Mount        }
54630da61d477bcb6cc7718f9516c444359352fe148George Mount    }
54730da61d477bcb6cc7718f9516c444359352fe148George Mount
5487b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    private void matchStartAndEnd(TransitionValuesMaps startValues,
5497b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount            TransitionValuesMaps endValues,
5507b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount            ArrayList<TransitionValues> startValuesList,
5517b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount            ArrayList<TransitionValues> endValuesList) {
5527b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        ArrayMap<View, TransitionValues> unmatchedStart =
5537b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                new ArrayMap<View, TransitionValues>(startValues.viewValues);
5547b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        ArrayMap<View, TransitionValues> unmatchedEnd =
5557b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                new ArrayMap<View, TransitionValues>(endValues.viewValues);
5567b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount
5577b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        for (int i = 0; i < mMatchOrder.length; i++) {
5587b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount            switch (mMatchOrder[i]) {
5597b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                case MATCH_INSTANCE:
5607b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                    matchInstances(startValuesList, endValuesList, unmatchedStart, unmatchedEnd);
5617b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                    break;
5627b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                case MATCH_VIEW_NAME:
5637b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                    matchNames(startValuesList, endValuesList, unmatchedStart, unmatchedEnd,
5647b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                            startValues.nameValues, endValues.nameValues);
5657b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                    break;
5667b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                case MATCH_ID:
5677b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                    matchIds(startValuesList, endValuesList, unmatchedStart, unmatchedEnd,
5687b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                            startValues.idValues, endValues.idValues);
5697b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                    break;
5707b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                case MATCH_ITEM_ID:
5717b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                    matchItemIds(startValuesList, endValuesList, unmatchedStart, unmatchedEnd,
5727b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                            startValues.itemIdValues, endValues.itemIdValues);
5737b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount                    break;
5747b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount            }
5757b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        }
5767b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        addUnmatched(startValuesList, endValuesList, unmatchedStart, unmatchedEnd);
5777b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount    }
5787b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount
57930da61d477bcb6cc7718f9516c444359352fe148George Mount    /**
580d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * This method, essentially a wrapper around all calls to createAnimator for all
581d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * possible target views, is called with the entire set of start/end
582faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * values. The implementation in Transition iterates through these lists
583d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * and calls {@link #createAnimator(ViewGroup, TransitionValues, TransitionValues)}
584faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * with each set of start/end values on this transition. The
585d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * TransitionSet subclass overrides this method and delegates it to
5862ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * each of its children in succession.
587faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
588faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @hide
589faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
590d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    protected void createAnimators(ViewGroup sceneRoot, TransitionValuesMaps startValues,
5916ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase            TransitionValuesMaps endValues) {
592c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase        if (DBG) {
593d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase            Log.d(LOG_TAG, "createAnimators() for " + this);
594c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase        }
595faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        ArrayList<TransitionValues> startValuesList = new ArrayList<TransitionValues>();
596faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        ArrayList<TransitionValues> endValuesList = new ArrayList<TransitionValues>();
5977b75062fb05a9981faf3c0c9f840dbdb9e97e7f7George Mount        matchStartAndEnd(startValues, endValues, startValuesList, endValuesList);
59830da61d477bcb6cc7718f9516c444359352fe148George Mount
599199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
600d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        long minStartDelay = Long.MAX_VALUE;
601d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        int minAnimator = mAnimators.size();
602d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        SparseLongArray startDelays = new SparseLongArray();
603faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        for (int i = 0; i < startValuesList.size(); ++i) {
604faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            TransitionValues start = startValuesList.get(i);
605faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            TransitionValues end = endValuesList.get(i);
606c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase            // Only bother trying to animate with values that differ between start/end
607c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase            if (start != null || end != null) {
608c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                if (start == null || !start.equals(end)) {
609c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                    if (DBG) {
610c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                        View view = (end != null) ? end.view : start.view;
611c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                        Log.d(LOG_TAG, "  differing start/end values for view " +
612c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                                view);
613c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                        if (start == null || end == null) {
614ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                            Log.d(LOG_TAG, "    " + ((start == null) ?
615ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                                    "start null, end non-null" : "start non-null, end null"));
616c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                        } else {
617c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                            for (String key : start.values.keySet()) {
618c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                                Object startValue = start.values.get(key);
619c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                                Object endValue = end.values.get(key);
620c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                                if (startValue != endValue && !startValue.equals(endValue)) {
621c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                                    Log.d(LOG_TAG, "    " + key + ": start(" + startValue +
622c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                                            "), end(" + endValue +")");
623c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                                }
624c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                            }
625c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                        }
626c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                    }
627c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                    // TODO: what to do about targetIds and itemIds?
628d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase                    Animator animator = createAnimator(sceneRoot, start, end);
629c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                    if (animator != null) {
630199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                        // Save animation info for future cancellation purposes
631199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                        View view = null;
632199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                        TransitionValues infoValues = null;
633199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                        if (end != null) {
634199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                            view = end.view;
635199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                            String[] properties = getTransitionProperties();
636199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                            if (view != null && properties != null && properties.length > 0) {
637199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                infoValues = new TransitionValues();
638199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                infoValues.view = view;
639199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                TransitionValues newValues = endValues.viewValues.get(view);
640199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                if (newValues != null) {
641199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                    for (int j = 0; j < properties.length; ++j) {
642199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                        infoValues.values.put(properties[j],
643199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                                newValues.values.get(properties[j]));
644199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                    }
645199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                }
646199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                int numExistingAnims = runningAnimators.size();
647199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                for (int j = 0; j < numExistingAnims; ++j) {
648199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                    Animator anim = runningAnimators.keyAt(j);
649199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                    AnimationInfo info = runningAnimators.get(anim);
650199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                    if (info.values != null && info.view == view &&
651199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                            ((info.name == null && getName() == null) ||
652199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                            info.name.equals(getName()))) {
653199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                        if (info.values.equals(infoValues)) {
654199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                            // Favor the old animator
655199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                            animator = null;
656199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                            break;
657199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                        }
658199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                    }
659199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                }
660199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                            }
661199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                        } else {
662199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                            view = (start != null) ? start.view : null;
663199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                        }
664199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                        if (animator != null) {
665d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                            if (mPropagation != null) {
666d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                                long delay = mPropagation
667d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                                        .getStartDelay(sceneRoot, this, start, end);
668d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                                startDelays.put(mAnimators.size(), delay);
669d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                                minStartDelay = Math.min(delay, minStartDelay);
670d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                            }
671cf68aad3164303df59b2a669d186a94533c9c743George Mount                            AnimationInfo info = new AnimationInfo(view, getName(),
672cf68aad3164303df59b2a669d186a94533c9c743George Mount                                    sceneRoot.getWindowId(), infoValues);
673199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                            runningAnimators.put(animator, info);
674199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                            mAnimators.add(animator);
675199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                        }
676c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                    }
677c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                }
678faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
679faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
680d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        if (minStartDelay != 0) {
681d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount            for (int i = 0; i < startDelays.size(); i++) {
682d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                int index = startDelays.keyAt(i);
683d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                Animator animator = mAnimators.get(index);
684d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                long delay = startDelays.valueAt(i) - minStartDelay + animator.getStartDelay();
685d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                animator.setStartDelay(delay);
686d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount            }
687d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        }
688faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
689faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
690faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
691faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Internal utility method for checking whether a given view/id
692faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * is valid for this transition, where "valid" means that either
693faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * the Transition has no target/targetId list (the default, in which
694faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * cause the transition should act on all views in the hiearchy), or
695faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * the given view is in the target list or the view id is in the
696faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * targetId list. If the target parameter is null, then the target list
697faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * is not checked (this is in the case of ListView items, where the
698faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * views are ignored and only the ids are used).
699faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
70030da61d477bcb6cc7718f9516c444359352fe148George Mount    boolean isValidTarget(View target) {
70130da61d477bcb6cc7718f9516c444359352fe148George Mount        int targetId = target.getId();
702ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        if (mTargetIdExcludes != null && mTargetIdExcludes.contains(targetId)) {
703ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            return false;
704ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        }
705ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        if (mTargetExcludes != null && mTargetExcludes.contains(target)) {
706ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            return false;
707ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        }
708ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        if (mTargetTypeExcludes != null && target != null) {
709ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            int numTypes = mTargetTypeExcludes.size();
710ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            for (int i = 0; i < numTypes; ++i) {
711ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                Class type = mTargetTypeExcludes.get(i);
712ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                if (type.isInstance(target)) {
713ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                    return false;
714ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                }
715ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            }
716ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        }
71730da61d477bcb6cc7718f9516c444359352fe148George Mount        if (mTargetNameExcludes != null && target != null && target.getViewName() != null) {
71830da61d477bcb6cc7718f9516c444359352fe148George Mount            if (mTargetNameExcludes.contains(target.getViewName())) {
71930da61d477bcb6cc7718f9516c444359352fe148George Mount                return false;
72030da61d477bcb6cc7718f9516c444359352fe148George Mount            }
72130da61d477bcb6cc7718f9516c444359352fe148George Mount        }
72230da61d477bcb6cc7718f9516c444359352fe148George Mount        if (mTargetIds.size() == 0 && mTargets.size() == 0 &&
72330da61d477bcb6cc7718f9516c444359352fe148George Mount                (mTargetTypes == null || mTargetTypes.isEmpty() &&
72430da61d477bcb6cc7718f9516c444359352fe148George Mount                (mTargetNames == null || mTargetNames.isEmpty()))) {
72530da61d477bcb6cc7718f9516c444359352fe148George Mount            return true;
72630da61d477bcb6cc7718f9516c444359352fe148George Mount        }
72730da61d477bcb6cc7718f9516c444359352fe148George Mount        if (mTargetIds.contains(targetId) || mTargets.contains(target)) {
728faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            return true;
729faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
73030da61d477bcb6cc7718f9516c444359352fe148George Mount        if (mTargetNames != null && mTargetNames.contains(target.getViewName())) {
731a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount            return true;
732faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
733a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount        if (mTargetTypes != null) {
734a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount            for (int i = 0; i < mTargetTypes.size(); ++i) {
735a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount                if (mTargetTypes.get(i).isInstance(target)) {
736faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                    return true;
737faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                }
738faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
739faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
740faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        return false;
741faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
742faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
743e180337ee99b9155fe441ea55451f4d2167b5d9aGeorge Mount    private static ArrayMap<Animator, AnimationInfo> getRunningAnimators() {
744199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        ArrayMap<Animator, AnimationInfo> runningAnimators = sRunningAnimators.get();
745199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        if (runningAnimators == null) {
746199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            runningAnimators = new ArrayMap<Animator, AnimationInfo>();
747199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            sRunningAnimators.set(runningAnimators);
748199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        }
749199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        return runningAnimators;
750199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    }
751199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase
752faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
7532ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * This is called internally once all animations have been set up by the
754d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * transition hierarchy.
755faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
756faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @hide
757faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
758d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    protected void runAnimators() {
759199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        if (DBG) {
760d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase            Log.d(LOG_TAG, "runAnimators() on " + this);
761199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        }
762199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        start();
763199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
764d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        // Now start every Animator that was previously created for this transition
765199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        for (Animator anim : mAnimators) {
766c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase            if (DBG) {
767c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                Log.d(LOG_TAG, "  anim: " + anim);
768c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase            }
769199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            if (runningAnimators.containsKey(anim)) {
770199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                start();
771199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                runAnimator(anim, runningAnimators);
772199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            }
773faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
774199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        mAnimators.clear();
775199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        end();
776faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
777faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
778199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    private void runAnimator(Animator animator,
779199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            final ArrayMap<Animator, AnimationInfo> runningAnimators) {
780e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase        if (animator != null) {
781e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase            // TODO: could be a single listener instance for all of them since it uses the param
782e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase            animator.addListener(new AnimatorListenerAdapter() {
783e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase                @Override
784e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase                public void onAnimationStart(Animator animation) {
785e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase                    mCurrentAnimators.add(animation);
786e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase                }
787e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase                @Override
788e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase                public void onAnimationEnd(Animator animation) {
789199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                    runningAnimators.remove(animation);
790e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase                    mCurrentAnimators.remove(animation);
791e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase                }
792e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase            });
793e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase            animate(animator);
794e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase        }
795e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase    }
796e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase
797faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
798d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * Captures the values in the start scene for the properties that this
799d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * transition monitors. These values are then passed as the startValues
800d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * structure in a later call to
801d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * {@link #createAnimator(ViewGroup, TransitionValues, TransitionValues)}.
802d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * The main concern for an implementation is what the
803d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * properties are that the transition cares about and what the values are
804d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * for all of those properties. The start and end values will be compared
805d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * later during the
806d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * {@link #createAnimator(android.view.ViewGroup, TransitionValues, TransitionValues)}
807d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * method to determine what, if any, animations, should be run.
808d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     *
809d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * <p>Subclasses must implement this method. The method should only be called by the
810d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * transition system; it is not intended to be called from external classes.</p>
811d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     *
812d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @param transitionValues The holder for any values that the Transition
813d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * wishes to store. Values are stored in the <code>values</code> field
814d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * of this TransitionValues object and are keyed from
815d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * a String value. For example, to store a view's rotation value,
816d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * a transition might call
817d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * <code>transitionValues.values.put("appname:transitionname:rotation",
818d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * view.getRotation())</code>. The target view will already be stored in
819d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * the transitionValues structure when this method is called.
820d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     *
821d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @see #captureEndValues(TransitionValues)
822d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @see #createAnimator(ViewGroup, TransitionValues, TransitionValues)
823d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     */
824d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    public abstract void captureStartValues(TransitionValues transitionValues);
825d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase
826d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    /**
827d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * Captures the values in the end scene for the properties that this
828d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * transition monitors. These values are then passed as the endValues
829d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * structure in a later call to
830d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * {@link #createAnimator(ViewGroup, TransitionValues, TransitionValues)}.
831d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * The main concern for an implementation is what the
832faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * properties are that the transition cares about and what the values are
833faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * for all of those properties. The start and end values will be compared
8342ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * later during the
835d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * {@link #createAnimator(android.view.ViewGroup, TransitionValues, TransitionValues)}
8362ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * method to determine what, if any, animations, should be run.
837faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
838d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * <p>Subclasses must implement this method. The method should only be called by the
839d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * transition system; it is not intended to be called from external classes.</p>
840d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     *
8412ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * @param transitionValues The holder for any values that the Transition
8422ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * wishes to store. Values are stored in the <code>values</code> field
8432ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * of this TransitionValues object and are keyed from
8442ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * a String value. For example, to store a view's rotation value,
8452ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * a transition might call
8462ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * <code>transitionValues.values.put("appname:transitionname:rotation",
8472ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * view.getRotation())</code>. The target view will already be stored in
8482ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * the transitionValues structure when this method is called.
849d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     *
850d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @see #captureStartValues(TransitionValues)
851d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @see #createAnimator(ViewGroup, TransitionValues, TransitionValues)
852faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
853d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    public abstract void captureEndValues(TransitionValues transitionValues);
854faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
855faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
856d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * Adds the id of a target view that this Transition is interested in
857faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * animating. By default, there are no targetIds, and a Transition will
858faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * listen for changes on every view in the hierarchy below the sceneRoot
859d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * of the Scene being transitioned into. Setting targetIds constrains
860faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * the Transition to only listen for, and act on, views with these IDs.
861faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Views with different IDs, or no IDs whatsoever, will be ignored.
862faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
863d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * <p>Note that using ids to specify targets implies that ids should be unique
864d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * within the view hierarchy underneat the scene root.</p>
865d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     *
866faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @see View#getId()
867d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @param targetId The id of a target view, must be a positive number.
868d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @return The Transition to which the targetId is added.
869d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * Returning the same object makes it easier to chain calls during
870d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * construction, such as
871ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * <code>transitionSet.addTransitions(new Fade()).addTarget(someId);</code>
872d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     */
873ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    public Transition addTarget(int targetId) {
874d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        if (targetId > 0) {
875d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase            mTargetIds.add(targetId);
876d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        }
877d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        return this;
878d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    }
879d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase
880d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    /**
88130da61d477bcb6cc7718f9516c444359352fe148George Mount     * Adds the viewName of a target view that this Transition is interested in
88230da61d477bcb6cc7718f9516c444359352fe148George Mount     * animating. By default, there are no targetNames, and a Transition will
88330da61d477bcb6cc7718f9516c444359352fe148George Mount     * listen for changes on every view in the hierarchy below the sceneRoot
88430da61d477bcb6cc7718f9516c444359352fe148George Mount     * of the Scene being transitioned into. Setting targetNames constrains
88530da61d477bcb6cc7718f9516c444359352fe148George Mount     * the Transition to only listen for, and act on, views with these viewNames.
88630da61d477bcb6cc7718f9516c444359352fe148George Mount     * Views with different viewNames, or no viewName whatsoever, will be ignored.
88730da61d477bcb6cc7718f9516c444359352fe148George Mount     *
88830da61d477bcb6cc7718f9516c444359352fe148George Mount     * <p>Note that viewNames should be unique within the view hierarchy.</p>
88930da61d477bcb6cc7718f9516c444359352fe148George Mount     *
89030da61d477bcb6cc7718f9516c444359352fe148George Mount     * @see android.view.View#getViewName()
89130da61d477bcb6cc7718f9516c444359352fe148George Mount     * @param targetName The viewName of a target view, must be non-null.
89230da61d477bcb6cc7718f9516c444359352fe148George Mount     * @return The Transition to which the target viewName is added.
89330da61d477bcb6cc7718f9516c444359352fe148George Mount     * Returning the same object makes it easier to chain calls during
89430da61d477bcb6cc7718f9516c444359352fe148George Mount     * construction, such as
89530da61d477bcb6cc7718f9516c444359352fe148George Mount     * <code>transitionSet.addTransitions(new Fade()).addTarget(someName);</code>
89630da61d477bcb6cc7718f9516c444359352fe148George Mount     */
89730da61d477bcb6cc7718f9516c444359352fe148George Mount    public Transition addTarget(String targetName) {
89830da61d477bcb6cc7718f9516c444359352fe148George Mount        if (targetName != null) {
89930da61d477bcb6cc7718f9516c444359352fe148George Mount            if (mTargetNames != null) {
90030da61d477bcb6cc7718f9516c444359352fe148George Mount                mTargetNames = new ArrayList<String>();
90130da61d477bcb6cc7718f9516c444359352fe148George Mount            }
90230da61d477bcb6cc7718f9516c444359352fe148George Mount            mTargetNames.add(targetName);
90330da61d477bcb6cc7718f9516c444359352fe148George Mount        }
90430da61d477bcb6cc7718f9516c444359352fe148George Mount        return this;
90530da61d477bcb6cc7718f9516c444359352fe148George Mount    }
90630da61d477bcb6cc7718f9516c444359352fe148George Mount
90730da61d477bcb6cc7718f9516c444359352fe148George Mount    /**
908a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * Adds the Class of a target view that this Transition is interested in
909a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * animating. By default, there are no targetTypes, and a Transition will
910a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * listen for changes on every view in the hierarchy below the sceneRoot
911a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * of the Scene being transitioned into. Setting targetTypes constrains
912a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * the Transition to only listen for, and act on, views with these classes.
913a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * Views with different classes will be ignored.
914a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     *
915a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * <p>Note that any View that can be cast to targetType will be included, so
916a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * if targetType is <code>View.class</code>, all Views will be included.</p>
917a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     *
918a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * @see #addTarget(int)
919a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * @see #addTarget(android.view.View)
920a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * @see #excludeTarget(Class, boolean)
921a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * @see #excludeChildren(Class, boolean)
922a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     *
923a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * @param targetType The type to include when running this transition.
924a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * @return The Transition to which the target class was added.
925a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * Returning the same object makes it easier to chain calls during
926a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * construction, such as
927a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     * <code>transitionSet.addTransitions(new Fade()).addTarget(ImageView.class);</code>
928a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount     */
929a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount    public Transition addTarget(Class targetType) {
93030da61d477bcb6cc7718f9516c444359352fe148George Mount        if (targetType != null) {
93130da61d477bcb6cc7718f9516c444359352fe148George Mount            if (mTargetTypes == null) {
93230da61d477bcb6cc7718f9516c444359352fe148George Mount                mTargetTypes = new ArrayList<Class>();
93330da61d477bcb6cc7718f9516c444359352fe148George Mount            }
93430da61d477bcb6cc7718f9516c444359352fe148George Mount            mTargetTypes.add(targetType);
935a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount        }
936a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount        return this;
937a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount    }
938a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount
939a98fb7ab6a17d27395cf2c8e86060af49b861be6George Mount    /**
940d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * Removes the given targetId from the list of ids that this Transition
941d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * is interested in animating.
942d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     *
943d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @param targetId The id of a target view, must be a positive number.
944d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @return The Transition from which the targetId is removed.
945faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Returning the same object makes it easier to chain calls during
946faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * construction, such as
947d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * <code>transitionSet.addTransitions(new Fade()).removeTargetId(someId);</code>
948faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
949ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    public Transition removeTarget(int targetId) {
950d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        if (targetId > 0) {
951d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase            mTargetIds.remove(targetId);
952d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        }
953faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        return this;
954faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
955faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
956faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
95730da61d477bcb6cc7718f9516c444359352fe148George Mount     * Removes the given targetName from the list of viewNames that this Transition
95830da61d477bcb6cc7718f9516c444359352fe148George Mount     * is interested in animating.
95930da61d477bcb6cc7718f9516c444359352fe148George Mount     *
96030da61d477bcb6cc7718f9516c444359352fe148George Mount     * @param targetName The viewName of a target view, must not be null.
96130da61d477bcb6cc7718f9516c444359352fe148George Mount     * @return The Transition from which the targetName is removed.
96230da61d477bcb6cc7718f9516c444359352fe148George Mount     * Returning the same object makes it easier to chain calls during
96330da61d477bcb6cc7718f9516c444359352fe148George Mount     * construction, such as
96430da61d477bcb6cc7718f9516c444359352fe148George Mount     * <code>transitionSet.addTransitions(new Fade()).removeTargetName(someName);</code>
96530da61d477bcb6cc7718f9516c444359352fe148George Mount     */
96630da61d477bcb6cc7718f9516c444359352fe148George Mount    public Transition removeTarget(String targetName) {
96730da61d477bcb6cc7718f9516c444359352fe148George Mount        if (targetName != null && mTargetNames != null) {
96830da61d477bcb6cc7718f9516c444359352fe148George Mount            mTargetNames.remove(targetName);
96930da61d477bcb6cc7718f9516c444359352fe148George Mount        }
97030da61d477bcb6cc7718f9516c444359352fe148George Mount        return this;
97130da61d477bcb6cc7718f9516c444359352fe148George Mount    }
97230da61d477bcb6cc7718f9516c444359352fe148George Mount
97330da61d477bcb6cc7718f9516c444359352fe148George Mount    /**
974ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * Whether to add the given id to the list of target ids to exclude from this
975ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * transition. The <code>exclude</code> parameter specifies whether the target
976ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * should be added to or removed from the excluded list.
977ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
978ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * <p>Excluding targets is a general mechanism for allowing transitions to run on
979ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * a view hierarchy while skipping target views that should not be part of
980ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * the transition. For example, you may want to avoid animating children
981ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * of a specific ListView or Spinner. Views can be excluded either by their
982ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * id, or by their instance reference, or by the Class of that view
983ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * (eg, {@link Spinner}).</p>
984ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
985ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeChildren(int, boolean)
986ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeTarget(View, boolean)
987ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeTarget(Class, boolean)
988ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
989ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @param targetId The id of a target to ignore when running this transition.
990ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @param exclude Whether to add the target to or remove the target from the
991ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * current list of excluded targets.
992ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @return This transition object.
993ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     */
994ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    public Transition excludeTarget(int targetId, boolean exclude) {
99530da61d477bcb6cc7718f9516c444359352fe148George Mount        if (targetId >= 0) {
99630da61d477bcb6cc7718f9516c444359352fe148George Mount            mTargetIdExcludes = excludeObject(mTargetIdExcludes, targetId, exclude);
99730da61d477bcb6cc7718f9516c444359352fe148George Mount        }
99830da61d477bcb6cc7718f9516c444359352fe148George Mount        return this;
99930da61d477bcb6cc7718f9516c444359352fe148George Mount    }
100030da61d477bcb6cc7718f9516c444359352fe148George Mount
100130da61d477bcb6cc7718f9516c444359352fe148George Mount    /**
100230da61d477bcb6cc7718f9516c444359352fe148George Mount     * Whether to add the given viewName to the list of target viewNames to exclude from this
100330da61d477bcb6cc7718f9516c444359352fe148George Mount     * transition. The <code>exclude</code> parameter specifies whether the target
100430da61d477bcb6cc7718f9516c444359352fe148George Mount     * should be added to or removed from the excluded list.
100530da61d477bcb6cc7718f9516c444359352fe148George Mount     *
100630da61d477bcb6cc7718f9516c444359352fe148George Mount     * <p>Excluding targets is a general mechanism for allowing transitions to run on
100730da61d477bcb6cc7718f9516c444359352fe148George Mount     * a view hierarchy while skipping target views that should not be part of
100830da61d477bcb6cc7718f9516c444359352fe148George Mount     * the transition. For example, you may want to avoid animating children
100930da61d477bcb6cc7718f9516c444359352fe148George Mount     * of a specific ListView or Spinner. Views can be excluded by their
101030da61d477bcb6cc7718f9516c444359352fe148George Mount     * id, their instance reference, their viewName, or by the Class of that view
101130da61d477bcb6cc7718f9516c444359352fe148George Mount     * (eg, {@link Spinner}).</p>
101230da61d477bcb6cc7718f9516c444359352fe148George Mount     *
101330da61d477bcb6cc7718f9516c444359352fe148George Mount     * @see #excludeTarget(View, boolean)
101430da61d477bcb6cc7718f9516c444359352fe148George Mount     * @see #excludeTarget(int, boolean)
101530da61d477bcb6cc7718f9516c444359352fe148George Mount     * @see #excludeTarget(Class, boolean)
101630da61d477bcb6cc7718f9516c444359352fe148George Mount     *
101730da61d477bcb6cc7718f9516c444359352fe148George Mount     * @param targetViewName The name of a target to ignore when running this transition.
101830da61d477bcb6cc7718f9516c444359352fe148George Mount     * @param exclude Whether to add the target to or remove the target from the
101930da61d477bcb6cc7718f9516c444359352fe148George Mount     * current list of excluded targets.
102030da61d477bcb6cc7718f9516c444359352fe148George Mount     * @return This transition object.
102130da61d477bcb6cc7718f9516c444359352fe148George Mount     */
102230da61d477bcb6cc7718f9516c444359352fe148George Mount    public Transition excludeTarget(String targetViewName, boolean exclude) {
102330da61d477bcb6cc7718f9516c444359352fe148George Mount        mTargetNameExcludes = excludeObject(mTargetNameExcludes, targetViewName, exclude);
1024ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        return this;
1025ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    }
1026ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase
1027ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    /**
1028ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * Whether to add the children of the given id to the list of targets to exclude
1029ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * from this transition. The <code>exclude</code> parameter specifies whether
1030ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * the children of the target should be added to or removed from the excluded list.
1031ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * Excluding children in this way provides a simple mechanism for excluding all
1032ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * children of specific targets, rather than individually excluding each
1033ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * child individually.
1034ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1035ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * <p>Excluding targets is a general mechanism for allowing transitions to run on
1036ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * a view hierarchy while skipping target views that should not be part of
1037ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * the transition. For example, you may want to avoid animating children
1038ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * of a specific ListView or Spinner. Views can be excluded either by their
1039ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * id, or by their instance reference, or by the Class of that view
1040ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * (eg, {@link Spinner}).</p>
1041ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1042ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeTarget(int, boolean)
1043ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeChildren(View, boolean)
1044ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeChildren(Class, boolean)
1045ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1046ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @param targetId The id of a target whose children should be ignored when running
1047ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * this transition.
1048ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @param exclude Whether to add the target to or remove the target from the
1049ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * current list of excluded-child targets.
1050ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @return This transition object.
1051ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     */
1052ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    public Transition excludeChildren(int targetId, boolean exclude) {
105330da61d477bcb6cc7718f9516c444359352fe148George Mount        if (targetId >= 0) {
105430da61d477bcb6cc7718f9516c444359352fe148George Mount            mTargetIdChildExcludes = excludeObject(mTargetIdChildExcludes, targetId, exclude);
1055ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        }
105630da61d477bcb6cc7718f9516c444359352fe148George Mount        return this;
1057ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    }
1058ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase
1059ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    /**
1060ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * Whether to add the given target to the list of targets to exclude from this
1061ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * transition. The <code>exclude</code> parameter specifies whether the target
1062ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * should be added to or removed from the excluded list.
1063ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1064ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * <p>Excluding targets is a general mechanism for allowing transitions to run on
1065ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * a view hierarchy while skipping target views that should not be part of
1066ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * the transition. For example, you may want to avoid animating children
1067ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * of a specific ListView or Spinner. Views can be excluded either by their
1068ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * id, or by their instance reference, or by the Class of that view
1069ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * (eg, {@link Spinner}).</p>
1070ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1071ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeChildren(View, boolean)
1072ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeTarget(int, boolean)
1073ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeTarget(Class, boolean)
1074ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1075ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @param target The target to ignore when running this transition.
1076ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @param exclude Whether to add the target to or remove the target from the
1077ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * current list of excluded targets.
1078ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @return This transition object.
1079ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     */
1080ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    public Transition excludeTarget(View target, boolean exclude) {
108130da61d477bcb6cc7718f9516c444359352fe148George Mount        mTargetExcludes = excludeObject(mTargetExcludes, target, exclude);
1082ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        return this;
1083ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    }
1084ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase
1085ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    /**
1086ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * Whether to add the children of given target to the list of target children
1087ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * to exclude from this transition. The <code>exclude</code> parameter specifies
1088ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * whether the target should be added to or removed from the excluded list.
1089ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1090ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * <p>Excluding targets is a general mechanism for allowing transitions to run on
1091ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * a view hierarchy while skipping target views that should not be part of
1092ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * the transition. For example, you may want to avoid animating children
1093ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * of a specific ListView or Spinner. Views can be excluded either by their
1094ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * id, or by their instance reference, or by the Class of that view
1095ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * (eg, {@link Spinner}).</p>
1096ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1097ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeTarget(View, boolean)
1098ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeChildren(int, boolean)
1099ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeChildren(Class, boolean)
1100ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1101ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @param target The target to ignore when running this transition.
1102ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @param exclude Whether to add the target to or remove the target from the
1103ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * current list of excluded targets.
1104ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @return This transition object.
1105ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     */
1106ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    public Transition excludeChildren(View target, boolean exclude) {
110730da61d477bcb6cc7718f9516c444359352fe148George Mount        mTargetChildExcludes = excludeObject(mTargetChildExcludes, target, exclude);
1108ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        return this;
1109ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    }
1110ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase
1111ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    /**
1112ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * Utility method to manage the boilerplate code that is the same whether we
1113ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * are excluding targets or their children.
1114ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     */
111530da61d477bcb6cc7718f9516c444359352fe148George Mount    private static <T> ArrayList<T> excludeObject(ArrayList<T> list, T target, boolean exclude) {
1116ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        if (target != null) {
1117ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            if (exclude) {
1118ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                list = ArrayListManager.add(list, target);
1119ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            } else {
1120ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                list = ArrayListManager.remove(list, target);
1121ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            }
1122ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        }
1123ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        return list;
1124ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    }
1125ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase
1126ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    /**
1127ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * Whether to add the given type to the list of types to exclude from this
1128ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * transition. The <code>exclude</code> parameter specifies whether the target
1129ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * type should be added to or removed from the excluded list.
1130ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1131ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * <p>Excluding targets is a general mechanism for allowing transitions to run on
1132ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * a view hierarchy while skipping target views that should not be part of
1133ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * the transition. For example, you may want to avoid animating children
1134ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * of a specific ListView or Spinner. Views can be excluded either by their
1135ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * id, or by their instance reference, or by the Class of that view
1136ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * (eg, {@link Spinner}).</p>
1137ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1138ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeChildren(Class, boolean)
1139ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeTarget(int, boolean)
1140ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeTarget(View, boolean)
1141ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1142ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @param type The type to ignore when running this transition.
1143ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @param exclude Whether to add the target type to or remove it from the
1144ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * current list of excluded target types.
1145ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @return This transition object.
1146ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     */
1147ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    public Transition excludeTarget(Class type, boolean exclude) {
114830da61d477bcb6cc7718f9516c444359352fe148George Mount        mTargetTypeExcludes = excludeObject(mTargetTypeExcludes, type, exclude);
1149ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        return this;
1150ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    }
1151ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase
1152ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    /**
1153ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * Whether to add the given type to the list of types whose children should
1154ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * be excluded from this transition. The <code>exclude</code> parameter
1155ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * specifies whether the target type should be added to or removed from
1156ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * the excluded list.
1157ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1158ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * <p>Excluding targets is a general mechanism for allowing transitions to run on
1159ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * a view hierarchy while skipping target views that should not be part of
1160ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * the transition. For example, you may want to avoid animating children
1161ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * of a specific ListView or Spinner. Views can be excluded either by their
1162ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * id, or by their instance reference, or by the Class of that view
1163ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * (eg, {@link Spinner}).</p>
1164ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1165ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeTarget(Class, boolean)
1166ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeChildren(int, boolean)
1167ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #excludeChildren(View, boolean)
1168ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     *
1169ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @param type The type to ignore when running this transition.
1170ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @param exclude Whether to add the target type to or remove it from the
1171ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * current list of excluded target types.
1172ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @return This transition object.
1173ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     */
1174ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    public Transition excludeChildren(Class type, boolean exclude) {
117530da61d477bcb6cc7718f9516c444359352fe148George Mount        mTargetTypeChildExcludes = excludeObject(mTargetTypeChildExcludes, type, exclude);
1176ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        return this;
1177ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    }
1178ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase
1179ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    /**
1180faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Sets the target view instances that this Transition is interested in
1181faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * animating. By default, there are no targets, and a Transition will
1182faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * listen for changes on every view in the hierarchy below the sceneRoot
1183faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * of the Scene being transitioned into. Setting targets constrains
1184faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * the Transition to only listen for, and act on, these views.
1185faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * All other views will be ignored.
1186faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
1187ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * <p>The target list is like the {@link #addTarget(int) targetId}
1188faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * list except this list specifies the actual View instances, not the ids
1189faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * of the views. This is an important distinction when scene changes involve
1190faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * view hierarchies which have been inflated separately; different views may
1191faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * share the same id but not actually be the same instance. If the transition
1192ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * should treat those views as the same, then {@link #addTarget(int)} should be used
1193d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * instead of {@link #addTarget(View)}. If, on the other hand, scene changes involve
1194faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * changes all within the same view hierarchy, among views which do not
1195d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * necessarily have ids set on them, then the target list of views may be more
1196faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * convenient.</p>
1197faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
1198ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * @see #addTarget(int)
1199d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @param target A View on which the Transition will act, must be non-null.
1200d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @return The Transition to which the target is added.
1201d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * Returning the same object makes it easier to chain calls during
1202d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * construction, such as
1203d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * <code>transitionSet.addTransitions(new Fade()).addTarget(someView);</code>
1204d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     */
1205d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    public Transition addTarget(View target) {
1206d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        mTargets.add(target);
1207d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        return this;
1208d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    }
1209d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase
1210d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    /**
1211d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * Removes the given target from the list of targets that this Transition
1212d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * is interested in animating.
1213d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     *
1214d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @param target The target view, must be non-null.
1215d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @return Transition The Transition from which the target is removed.
1216faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Returning the same object makes it easier to chain calls during
1217faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * construction, such as
1218d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * <code>transitionSet.addTransitions(new Fade()).removeTarget(someView);</code>
1219faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
1220d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    public Transition removeTarget(View target) {
1221d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        if (target != null) {
1222d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase            mTargets.remove(target);
1223d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        }
1224faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        return this;
1225faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1226faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1227faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
122830da61d477bcb6cc7718f9516c444359352fe148George Mount     * Removes the given target from the list of targets that this Transition
122930da61d477bcb6cc7718f9516c444359352fe148George Mount     * is interested in animating.
123030da61d477bcb6cc7718f9516c444359352fe148George Mount     *
123130da61d477bcb6cc7718f9516c444359352fe148George Mount     * @param target The type of the target view, must be non-null.
123230da61d477bcb6cc7718f9516c444359352fe148George Mount     * @return Transition The Transition from which the target is removed.
123330da61d477bcb6cc7718f9516c444359352fe148George Mount     * Returning the same object makes it easier to chain calls during
123430da61d477bcb6cc7718f9516c444359352fe148George Mount     * construction, such as
123530da61d477bcb6cc7718f9516c444359352fe148George Mount     * <code>transitionSet.addTransitions(new Fade()).removeTarget(someType);</code>
123630da61d477bcb6cc7718f9516c444359352fe148George Mount     */
123730da61d477bcb6cc7718f9516c444359352fe148George Mount    public Transition removeTarget(Class target) {
123830da61d477bcb6cc7718f9516c444359352fe148George Mount        if (target != null) {
123930da61d477bcb6cc7718f9516c444359352fe148George Mount            mTargetTypes.remove(target);
124030da61d477bcb6cc7718f9516c444359352fe148George Mount        }
124130da61d477bcb6cc7718f9516c444359352fe148George Mount        return this;
124230da61d477bcb6cc7718f9516c444359352fe148George Mount    }
124330da61d477bcb6cc7718f9516c444359352fe148George Mount
124430da61d477bcb6cc7718f9516c444359352fe148George Mount    /**
124530da61d477bcb6cc7718f9516c444359352fe148George Mount     * Returns the list of target IDs that this transition limits itself to
124630da61d477bcb6cc7718f9516c444359352fe148George Mount     * tracking and animating. If the list is null or empty for
124730da61d477bcb6cc7718f9516c444359352fe148George Mount     * {@link #getTargetIds()}, {@link #getTargets()}, {@link #getTargetViewNames()}, and
124830da61d477bcb6cc7718f9516c444359352fe148George Mount     * {@link #getTargetTypes()} then this transition is
1249faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * not limited to specific views, and will handle changes to any views
1250faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * in the hierarchy of a scene change.
1251faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
1252faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @return the list of target IDs
1253faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
1254d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    public List<Integer> getTargetIds() {
1255faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        return mTargetIds;
1256faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1257faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1258faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
125930da61d477bcb6cc7718f9516c444359352fe148George Mount     * Returns the list of target views that this transition limits itself to
126030da61d477bcb6cc7718f9516c444359352fe148George Mount     * tracking and animating. If the list is null or empty for
126130da61d477bcb6cc7718f9516c444359352fe148George Mount     * {@link #getTargetIds()}, {@link #getTargets()}, {@link #getTargetViewNames()}, and
126230da61d477bcb6cc7718f9516c444359352fe148George Mount     * {@link #getTargetTypes()} then this transition is
1263faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * not limited to specific views, and will handle changes to any views
1264faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * in the hierarchy of a scene change.
1265faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
1266faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @return the list of target views
1267faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
1268d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    public List<View> getTargets() {
1269faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        return mTargets;
1270faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1271faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1272faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
127330da61d477bcb6cc7718f9516c444359352fe148George Mount     * Returns the list of target viewNames that this transition limits itself to
127430da61d477bcb6cc7718f9516c444359352fe148George Mount     * tracking and animating. If the list is null or empty for
127530da61d477bcb6cc7718f9516c444359352fe148George Mount     * {@link #getTargetIds()}, {@link #getTargets()}, {@link #getTargetViewNames()}, and
127630da61d477bcb6cc7718f9516c444359352fe148George Mount     * {@link #getTargetTypes()} then this transition is
127730da61d477bcb6cc7718f9516c444359352fe148George Mount     * not limited to specific views, and will handle changes to any views
127830da61d477bcb6cc7718f9516c444359352fe148George Mount     * in the hierarchy of a scene change.
127930da61d477bcb6cc7718f9516c444359352fe148George Mount     *
128030da61d477bcb6cc7718f9516c444359352fe148George Mount     * @return the list of target viewNames
128130da61d477bcb6cc7718f9516c444359352fe148George Mount     */
128230da61d477bcb6cc7718f9516c444359352fe148George Mount    public List<String> getTargetViewNames() {
128330da61d477bcb6cc7718f9516c444359352fe148George Mount        return mTargetNames;
128430da61d477bcb6cc7718f9516c444359352fe148George Mount    }
128530da61d477bcb6cc7718f9516c444359352fe148George Mount
128630da61d477bcb6cc7718f9516c444359352fe148George Mount    /**
128730da61d477bcb6cc7718f9516c444359352fe148George Mount     * Returns the list of target viewNames that this transition limits itself to
128830da61d477bcb6cc7718f9516c444359352fe148George Mount     * tracking and animating. If the list is null or empty for
128930da61d477bcb6cc7718f9516c444359352fe148George Mount     * {@link #getTargetIds()}, {@link #getTargets()}, {@link #getTargetViewNames()}, and
129030da61d477bcb6cc7718f9516c444359352fe148George Mount     * {@link #getTargetTypes()} then this transition is
129130da61d477bcb6cc7718f9516c444359352fe148George Mount     * not limited to specific views, and will handle changes to any views
129230da61d477bcb6cc7718f9516c444359352fe148George Mount     * in the hierarchy of a scene change.
129330da61d477bcb6cc7718f9516c444359352fe148George Mount     *
129430da61d477bcb6cc7718f9516c444359352fe148George Mount     * @return the list of target Types
129530da61d477bcb6cc7718f9516c444359352fe148George Mount     */
129630da61d477bcb6cc7718f9516c444359352fe148George Mount    public List<Class> getTargetTypes() {
129730da61d477bcb6cc7718f9516c444359352fe148George Mount        return mTargetTypes;
129830da61d477bcb6cc7718f9516c444359352fe148George Mount    }
129930da61d477bcb6cc7718f9516c444359352fe148George Mount
130030da61d477bcb6cc7718f9516c444359352fe148George Mount    /**
1301faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Recursive method that captures values for the given view and the
1302faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * hierarchy underneath it.
1303faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @param sceneRoot The root of the view hierarchy being captured
1304faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @param start true if this capture is happening before the scene change,
1305faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * false otherwise
1306faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
1307faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    void captureValues(ViewGroup sceneRoot, boolean start) {
1308df32aa87150768795816852c6393306893467ecaChet Haase        clearValues(start);
130930da61d477bcb6cc7718f9516c444359352fe148George Mount        if ((mTargetIds.size() > 0 || mTargets.size() > 0)
131030da61d477bcb6cc7718f9516c444359352fe148George Mount                && (mTargetNames == null || mTargetNames.isEmpty())
131130da61d477bcb6cc7718f9516c444359352fe148George Mount                && (mTargetTypes == null || mTargetTypes.isEmpty())) {
131230da61d477bcb6cc7718f9516c444359352fe148George Mount            for (int i = 0; i < mTargetIds.size(); ++i) {
131330da61d477bcb6cc7718f9516c444359352fe148George Mount                int id = mTargetIds.get(i);
131430da61d477bcb6cc7718f9516c444359352fe148George Mount                View view = sceneRoot.findViewById(id);
131530da61d477bcb6cc7718f9516c444359352fe148George Mount                if (view != null) {
131630da61d477bcb6cc7718f9516c444359352fe148George Mount                    TransitionValues values = new TransitionValues();
131730da61d477bcb6cc7718f9516c444359352fe148George Mount                    values.view = view;
131830da61d477bcb6cc7718f9516c444359352fe148George Mount                    if (start) {
131930da61d477bcb6cc7718f9516c444359352fe148George Mount                        captureStartValues(values);
132030da61d477bcb6cc7718f9516c444359352fe148George Mount                    } else {
132130da61d477bcb6cc7718f9516c444359352fe148George Mount                        captureEndValues(values);
132230da61d477bcb6cc7718f9516c444359352fe148George Mount                    }
132330da61d477bcb6cc7718f9516c444359352fe148George Mount                    capturePropagationValues(values);
132430da61d477bcb6cc7718f9516c444359352fe148George Mount                    if (start) {
132530da61d477bcb6cc7718f9516c444359352fe148George Mount                        addViewValues(mStartValues, view, values);
132630da61d477bcb6cc7718f9516c444359352fe148George Mount                    } else {
132730da61d477bcb6cc7718f9516c444359352fe148George Mount                        addViewValues(mEndValues, view, values);
1328faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                    }
1329faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                }
1330faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
133130da61d477bcb6cc7718f9516c444359352fe148George Mount            for (int i = 0; i < mTargets.size(); ++i) {
133230da61d477bcb6cc7718f9516c444359352fe148George Mount                View view = mTargets.get(i);
133330da61d477bcb6cc7718f9516c444359352fe148George Mount                TransitionValues values = new TransitionValues();
133430da61d477bcb6cc7718f9516c444359352fe148George Mount                values.view = view;
133530da61d477bcb6cc7718f9516c444359352fe148George Mount                if (start) {
133630da61d477bcb6cc7718f9516c444359352fe148George Mount                    captureStartValues(values);
133730da61d477bcb6cc7718f9516c444359352fe148George Mount                } else {
133830da61d477bcb6cc7718f9516c444359352fe148George Mount                    captureEndValues(values);
133930da61d477bcb6cc7718f9516c444359352fe148George Mount                }
134030da61d477bcb6cc7718f9516c444359352fe148George Mount                capturePropagationValues(values);
134130da61d477bcb6cc7718f9516c444359352fe148George Mount                if (start) {
134230da61d477bcb6cc7718f9516c444359352fe148George Mount                    mStartValues.viewValues.put(view, values);
134330da61d477bcb6cc7718f9516c444359352fe148George Mount                } else {
134430da61d477bcb6cc7718f9516c444359352fe148George Mount                    mEndValues.viewValues.put(view, values);
1345faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                }
1346faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
1347faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        } else {
1348faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            captureHierarchy(sceneRoot, start);
1349faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
1350faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1351faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
135230da61d477bcb6cc7718f9516c444359352fe148George Mount    static void addViewValues(TransitionValuesMaps transitionValuesMaps,
135330da61d477bcb6cc7718f9516c444359352fe148George Mount            View view, TransitionValues transitionValues) {
135430da61d477bcb6cc7718f9516c444359352fe148George Mount        transitionValuesMaps.viewValues.put(view, transitionValues);
135530da61d477bcb6cc7718f9516c444359352fe148George Mount        int id = view.getId();
135630da61d477bcb6cc7718f9516c444359352fe148George Mount        if (id >= 0) {
135730da61d477bcb6cc7718f9516c444359352fe148George Mount            if (transitionValuesMaps.idValues.indexOfKey(id) >= 0) {
135830da61d477bcb6cc7718f9516c444359352fe148George Mount                // Duplicate IDs cannot match by ID.
135930da61d477bcb6cc7718f9516c444359352fe148George Mount                transitionValuesMaps.idValues.put(id, null);
136030da61d477bcb6cc7718f9516c444359352fe148George Mount            } else {
136130da61d477bcb6cc7718f9516c444359352fe148George Mount                transitionValuesMaps.idValues.put(id, view);
136230da61d477bcb6cc7718f9516c444359352fe148George Mount            }
136330da61d477bcb6cc7718f9516c444359352fe148George Mount        }
136430da61d477bcb6cc7718f9516c444359352fe148George Mount        String name = view.getViewName();
136530da61d477bcb6cc7718f9516c444359352fe148George Mount        if (name != null) {
136630da61d477bcb6cc7718f9516c444359352fe148George Mount            if (transitionValuesMaps.nameValues.containsKey(name)) {
136730da61d477bcb6cc7718f9516c444359352fe148George Mount                // Duplicate viewNames: cannot match by viewName.
136830da61d477bcb6cc7718f9516c444359352fe148George Mount                transitionValuesMaps.nameValues.put(name, null);
136930da61d477bcb6cc7718f9516c444359352fe148George Mount            } else {
137030da61d477bcb6cc7718f9516c444359352fe148George Mount                transitionValuesMaps.nameValues.put(name, view);
137130da61d477bcb6cc7718f9516c444359352fe148George Mount            }
137230da61d477bcb6cc7718f9516c444359352fe148George Mount        }
137330da61d477bcb6cc7718f9516c444359352fe148George Mount        if (view.getParent() instanceof ListView) {
137430da61d477bcb6cc7718f9516c444359352fe148George Mount            ListView listview = (ListView) view.getParent();
137530da61d477bcb6cc7718f9516c444359352fe148George Mount            if (listview.getAdapter().hasStableIds()) {
137630da61d477bcb6cc7718f9516c444359352fe148George Mount                int position = listview.getPositionForView(view);
137730da61d477bcb6cc7718f9516c444359352fe148George Mount                long itemId = listview.getItemIdAtPosition(position);
137830da61d477bcb6cc7718f9516c444359352fe148George Mount                if (transitionValuesMaps.itemIdValues.indexOfKey(itemId) >= 0) {
137930da61d477bcb6cc7718f9516c444359352fe148George Mount                    // Duplicate item IDs: cannot match by item ID.
138030da61d477bcb6cc7718f9516c444359352fe148George Mount                    View alreadyMatched = transitionValuesMaps.itemIdValues.get(itemId);
138130da61d477bcb6cc7718f9516c444359352fe148George Mount                    if (alreadyMatched != null) {
138230da61d477bcb6cc7718f9516c444359352fe148George Mount                        alreadyMatched.setHasTransientState(false);
138330da61d477bcb6cc7718f9516c444359352fe148George Mount                        transitionValuesMaps.itemIdValues.put(itemId, null);
138430da61d477bcb6cc7718f9516c444359352fe148George Mount                    }
138530da61d477bcb6cc7718f9516c444359352fe148George Mount                } else {
138630da61d477bcb6cc7718f9516c444359352fe148George Mount                    view.setHasTransientState(true);
138730da61d477bcb6cc7718f9516c444359352fe148George Mount                    transitionValuesMaps.itemIdValues.put(itemId, view);
138830da61d477bcb6cc7718f9516c444359352fe148George Mount                }
138930da61d477bcb6cc7718f9516c444359352fe148George Mount            }
139030da61d477bcb6cc7718f9516c444359352fe148George Mount        }
139130da61d477bcb6cc7718f9516c444359352fe148George Mount    }
139230da61d477bcb6cc7718f9516c444359352fe148George Mount
1393faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
1394df32aa87150768795816852c6393306893467ecaChet Haase     * Clear valuesMaps for specified start/end state
1395df32aa87150768795816852c6393306893467ecaChet Haase     *
1396df32aa87150768795816852c6393306893467ecaChet Haase     * @param start true if the start values should be cleared, false otherwise
1397df32aa87150768795816852c6393306893467ecaChet Haase     */
1398df32aa87150768795816852c6393306893467ecaChet Haase    void clearValues(boolean start) {
1399df32aa87150768795816852c6393306893467ecaChet Haase        if (start) {
1400df32aa87150768795816852c6393306893467ecaChet Haase            mStartValues.viewValues.clear();
1401df32aa87150768795816852c6393306893467ecaChet Haase            mStartValues.idValues.clear();
1402df32aa87150768795816852c6393306893467ecaChet Haase            mStartValues.itemIdValues.clear();
1403df32aa87150768795816852c6393306893467ecaChet Haase        } else {
1404df32aa87150768795816852c6393306893467ecaChet Haase            mEndValues.viewValues.clear();
1405df32aa87150768795816852c6393306893467ecaChet Haase            mEndValues.idValues.clear();
1406df32aa87150768795816852c6393306893467ecaChet Haase            mEndValues.itemIdValues.clear();
1407df32aa87150768795816852c6393306893467ecaChet Haase        }
1408df32aa87150768795816852c6393306893467ecaChet Haase    }
1409df32aa87150768795816852c6393306893467ecaChet Haase
1410df32aa87150768795816852c6393306893467ecaChet Haase    /**
1411faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Recursive method which captures values for an entire view hierarchy,
1412faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * starting at some root view. Transitions without targetIDs will use this
1413faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * method to capture values for all possible views.
1414faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
1415faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @param view The view for which to capture values. Children of this View
1416faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * will also be captured, recursively down to the leaf nodes.
1417faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @param start true if values are being captured in the start scene, false
1418faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * otherwise.
1419faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
1420faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    private void captureHierarchy(View view, boolean start) {
1421faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        if (view == null) {
1422faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            return;
1423faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
142430da61d477bcb6cc7718f9516c444359352fe148George Mount        int id = view.getId();
1425ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        if (mTargetIdExcludes != null && mTargetIdExcludes.contains(id)) {
1426ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            return;
1427ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        }
1428ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        if (mTargetExcludes != null && mTargetExcludes.contains(view)) {
1429ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            return;
1430ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        }
1431ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        if (mTargetTypeExcludes != null && view != null) {
1432ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            int numTypes = mTargetTypeExcludes.size();
1433ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            for (int i = 0; i < numTypes; ++i) {
1434ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                if (mTargetTypeExcludes.get(i).isInstance(view)) {
1435ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                    return;
1436ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                }
1437ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            }
1438ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        }
1439e180337ee99b9155fe441ea55451f4d2167b5d9aGeorge Mount        if (view.getParent() instanceof ViewGroup) {
1440e180337ee99b9155fe441ea55451f4d2167b5d9aGeorge Mount            TransitionValues values = new TransitionValues();
1441e180337ee99b9155fe441ea55451f4d2167b5d9aGeorge Mount            values.view = view;
1442e180337ee99b9155fe441ea55451f4d2167b5d9aGeorge Mount            if (start) {
1443e180337ee99b9155fe441ea55451f4d2167b5d9aGeorge Mount                captureStartValues(values);
1444faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            } else {
1445e180337ee99b9155fe441ea55451f4d2167b5d9aGeorge Mount                captureEndValues(values);
1446faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
1447d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount            capturePropagationValues(values);
1448e180337ee99b9155fe441ea55451f4d2167b5d9aGeorge Mount            if (start) {
144930da61d477bcb6cc7718f9516c444359352fe148George Mount                addViewValues(mStartValues, view, values);
1450faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            } else {
145130da61d477bcb6cc7718f9516c444359352fe148George Mount                addViewValues(mEndValues, view, values);
1452faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
1453faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
1454faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        if (view instanceof ViewGroup) {
1455ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            // Don't traverse child hierarchy if there are any child-excludes on this view
1456ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            if (mTargetIdChildExcludes != null && mTargetIdChildExcludes.contains(id)) {
1457ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                return;
1458ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            }
1459ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            if (mTargetChildExcludes != null && mTargetChildExcludes.contains(view)) {
1460ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                return;
1461ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            }
146230da61d477bcb6cc7718f9516c444359352fe148George Mount            if (mTargetTypeChildExcludes != null) {
1463ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                int numTypes = mTargetTypeChildExcludes.size();
1464ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                for (int i = 0; i < numTypes; ++i) {
1465ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                    if (mTargetTypeChildExcludes.get(i).isInstance(view)) {
1466ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                        return;
1467ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                    }
1468ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                }
1469ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            }
1470faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            ViewGroup parent = (ViewGroup) view;
1471faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            for (int i = 0; i < parent.getChildCount(); ++i) {
1472faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                captureHierarchy(parent.getChildAt(i), start);
1473faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
1474faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
1475faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1476faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1477faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
14786ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase     * This method can be called by transitions to get the TransitionValues for
14796ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase     * any particular view during the transition-playing process. This might be
14806ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase     * necessary, for example, to query the before/after state of related views
14816ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase     * for a given transition.
14826ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase     */
1483d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    public TransitionValues getTransitionValues(View view, boolean start) {
14846ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase        if (mParent != null) {
14856ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase            return mParent.getTransitionValues(view, start);
14866ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase        }
14876ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase        TransitionValuesMaps valuesMaps = start ? mStartValues : mEndValues;
148830da61d477bcb6cc7718f9516c444359352fe148George Mount        return valuesMaps.viewValues.get(view);
14896ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase    }
14906ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase
14916ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase    /**
1492199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * Pauses this transition, sending out calls to {@link
1493199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * TransitionListener#onTransitionPause(Transition)} to all listeners
1494199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * and pausing all running animators started by this transition.
1495199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     *
1496199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * @hide
1497199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     */
1498cf68aad3164303df59b2a669d186a94533c9c743George Mount    public void pause(View sceneRoot) {
1499a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase        if (!mEnded) {
1500a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase            ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
1501a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase            int numOldAnims = runningAnimators.size();
1502cf68aad3164303df59b2a669d186a94533c9c743George Mount            WindowId windowId = sceneRoot.getWindowId();
1503a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase            for (int i = numOldAnims - 1; i >= 0; i--) {
1504cf68aad3164303df59b2a669d186a94533c9c743George Mount                AnimationInfo info = runningAnimators.valueAt(i);
1505cf68aad3164303df59b2a669d186a94533c9c743George Mount                if (info.view != null && windowId.equals(info.windowId)) {
1506cf68aad3164303df59b2a669d186a94533c9c743George Mount                    Animator anim = runningAnimators.keyAt(i);
1507cf68aad3164303df59b2a669d186a94533c9c743George Mount                    anim.pause();
1508cf68aad3164303df59b2a669d186a94533c9c743George Mount                }
1509a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase            }
1510a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase            if (mListeners != null && mListeners.size() > 0) {
1511a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                ArrayList<TransitionListener> tmpListeners =
1512a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                        (ArrayList<TransitionListener>) mListeners.clone();
1513a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                int numListeners = tmpListeners.size();
1514a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                for (int i = 0; i < numListeners; ++i) {
1515a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                    tmpListeners.get(i).onTransitionPause(this);
1516a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                }
1517199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            }
1518a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase            mPaused = true;
1519199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        }
1520199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    }
1521199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase
1522199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    /**
1523199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * Resumes this transition, sending out calls to {@link
1524199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * TransitionListener#onTransitionPause(Transition)} to all listeners
1525199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * and pausing all running animators started by this transition.
1526199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     *
1527199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * @hide
1528199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     */
1529cf68aad3164303df59b2a669d186a94533c9c743George Mount    public void resume(View sceneRoot) {
1530199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        if (mPaused) {
1531a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase            if (!mEnded) {
1532a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
1533a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                int numOldAnims = runningAnimators.size();
1534cf68aad3164303df59b2a669d186a94533c9c743George Mount                WindowId windowId = sceneRoot.getWindowId();
1535a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                for (int i = numOldAnims - 1; i >= 0; i--) {
1536cf68aad3164303df59b2a669d186a94533c9c743George Mount                    AnimationInfo info = runningAnimators.valueAt(i);
1537cf68aad3164303df59b2a669d186a94533c9c743George Mount                    if (info.view != null && windowId.equals(info.windowId)) {
1538cf68aad3164303df59b2a669d186a94533c9c743George Mount                        Animator anim = runningAnimators.keyAt(i);
1539cf68aad3164303df59b2a669d186a94533c9c743George Mount                        anim.resume();
1540cf68aad3164303df59b2a669d186a94533c9c743George Mount                    }
1541a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                }
1542a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                if (mListeners != null && mListeners.size() > 0) {
1543a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                    ArrayList<TransitionListener> tmpListeners =
1544a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                            (ArrayList<TransitionListener>) mListeners.clone();
1545a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                    int numListeners = tmpListeners.size();
1546a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                    for (int i = 0; i < numListeners; ++i) {
1547a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                        tmpListeners.get(i).onTransitionResume(this);
1548a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase                    }
1549199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                }
1550199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            }
1551199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            mPaused = false;
1552199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        }
1553199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    }
1554199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase
1555199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    /**
1556faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Called by TransitionManager to play the transition. This calls
1557d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * createAnimators() to set things up and create all of the animations and then
15582ea7f8b9c5f903050d42c1af57406bf528979f45Chet Haase     * runAnimations() to actually start the animations.
1559faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
15606ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase    void playTransition(ViewGroup sceneRoot) {
1561199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
1562199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        int numOldAnims = runningAnimators.size();
1563199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        for (int i = numOldAnims - 1; i >= 0; i--) {
1564199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            Animator anim = runningAnimators.keyAt(i);
1565199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            if (anim != null) {
1566199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                AnimationInfo oldInfo = runningAnimators.get(anim);
156758ad12208afcf9fdce735dead8449c4db375344dChet Haase                if (oldInfo != null && oldInfo.view != null &&
156858ad12208afcf9fdce735dead8449c4db375344dChet Haase                        oldInfo.view.getContext() == sceneRoot.getContext()) {
1569199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                    boolean cancel = false;
1570199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                    TransitionValues oldValues = oldInfo.values;
1571199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                    View oldView = oldInfo.view;
157230da61d477bcb6cc7718f9516c444359352fe148George Mount                    TransitionValues newValues = mEndValues.viewValues.get(oldView);
1573af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                    if (oldValues != null) {
1574af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                        // if oldValues null, then transition didn't care to stash values,
1575af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                        // and won't get canceled
157623c61f6bc57a611d97d333bce0d8fe00ab81af4cChet Haase                        if (newValues != null) {
1577af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                            for (String key : oldValues.values.keySet()) {
1578af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                                Object oldValue = oldValues.values.get(key);
1579af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                                Object newValue = newValues.values.get(key);
1580af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                                if (oldValue != null && newValue != null &&
1581af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                                        !oldValue.equals(newValue)) {
1582af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                                    cancel = true;
1583af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                                    if (DBG) {
1584af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                                        Log.d(LOG_TAG, "Transition.playTransition: " +
1585af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                                                "oldValue != newValue for " + key +
1586af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                                                ": old, new = " + oldValue + ", " + newValue);
1587af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                                    }
1588af78bdd615ecd5ce9d41a6160ce9f53fa269b119Chet Haase                                    break;
1589199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                }
1590199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                            }
1591199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                        }
1592199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                    }
1593199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                    if (cancel) {
1594199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                        if (anim.isRunning() || anim.isStarted()) {
1595199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                            if (DBG) {
1596199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                Log.d(LOG_TAG, "Canceling anim " + anim);
1597199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                            }
1598199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                            anim.cancel();
1599199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                        } else {
1600199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                            if (DBG) {
1601199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                                Log.d(LOG_TAG, "removing anim from info list: " + anim);
1602199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                            }
1603199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                            runningAnimators.remove(anim);
1604199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                        }
1605199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                    }
1606199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                }
1607199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            }
1608199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        }
1609199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase
1610d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        createAnimators(sceneRoot, mStartValues, mEndValues);
1611d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        runAnimators();
1612faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1613faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1614faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
1615faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * This is a utility method used by subclasses to handle standard parts of
1616faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * setting up and running an Animator: it sets the {@link #getDuration()
1617faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * duration} and the {@link #getStartDelay() startDelay}, starts the
1618199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * animation, and, when the animator ends, calls {@link #end()}.
1619faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
1620faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @param animator The Animator to be run during this transition.
1621faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
1622faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @hide
1623faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
1624faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    protected void animate(Animator animator) {
1625faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        // TODO: maybe pass auto-end as a boolean parameter?
1626faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        if (animator == null) {
1627199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            end();
1628faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        } else {
1629faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            if (getDuration() >= 0) {
1630faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                animator.setDuration(getDuration());
1631faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
1632faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            if (getStartDelay() >= 0) {
1633d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                animator.setStartDelay(getStartDelay() + animator.getStartDelay());
1634faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
1635faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            if (getInterpolator() != null) {
1636faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                animator.setInterpolator(getInterpolator());
1637faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
1638faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            animator.addListener(new AnimatorListenerAdapter() {
1639faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                @Override
1640faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                public void onAnimationEnd(Animator animation) {
1641199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase                    end();
1642faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                    animation.removeListener(this);
1643faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                }
1644faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            });
1645faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            animator.start();
1646faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
1647faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1648faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1649faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
1650faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * This method is called automatically by the transition and
1651d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * TransitionSet classes prior to a Transition subclass starting;
1652faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * subclasses should not need to call it directly.
1653faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
1654faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @hide
1655faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
1656199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    protected void start() {
1657faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        if (mNumInstances == 0) {
1658faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            if (mListeners != null && mListeners.size() > 0) {
1659faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                ArrayList<TransitionListener> tmpListeners =
1660faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                        (ArrayList<TransitionListener>) mListeners.clone();
1661faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                int numListeners = tmpListeners.size();
1662faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                for (int i = 0; i < numListeners; ++i) {
1663faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                    tmpListeners.get(i).onTransitionStart(this);
1664faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                }
1665faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
1666a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase            mEnded = false;
1667faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
1668faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        mNumInstances++;
1669faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1670faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1671faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
1672faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * This method is called automatically by the Transition and
1673d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * TransitionSet classes when a transition finishes, either because
1674faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * a transition did nothing (returned a null Animator from
1675d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * {@link Transition#createAnimator(ViewGroup, TransitionValues,
1676faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * TransitionValues)}) or because the transition returned a valid
1677199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * Animator and end() was called in the onAnimationEnd()
1678faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * callback of the AnimatorListener.
1679faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
1680faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @hide
1681faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
1682199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    protected void end() {
1683faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        --mNumInstances;
1684faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        if (mNumInstances == 0) {
1685faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            if (mListeners != null && mListeners.size() > 0) {
1686faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                ArrayList<TransitionListener> tmpListeners =
1687faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                        (ArrayList<TransitionListener>) mListeners.clone();
1688faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                int numListeners = tmpListeners.size();
1689faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                for (int i = 0; i < numListeners; ++i) {
1690faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                    tmpListeners.get(i).onTransitionEnd(this);
1691faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                }
1692faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
16936ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase            for (int i = 0; i < mStartValues.itemIdValues.size(); ++i) {
169430da61d477bcb6cc7718f9516c444359352fe148George Mount                View view = mStartValues.itemIdValues.valueAt(i);
169530da61d477bcb6cc7718f9516c444359352fe148George Mount                if (view != null) {
169630da61d477bcb6cc7718f9516c444359352fe148George Mount                    view.setHasTransientState(false);
1697faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                }
1698faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
16996ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase            for (int i = 0; i < mEndValues.itemIdValues.size(); ++i) {
170030da61d477bcb6cc7718f9516c444359352fe148George Mount                View view = mEndValues.itemIdValues.valueAt(i);
170130da61d477bcb6cc7718f9516c444359352fe148George Mount                if (view != null) {
170230da61d477bcb6cc7718f9516c444359352fe148George Mount                    view.setHasTransientState(false);
1703faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                }
1704faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
1705a56205c485deb5a95c1e4f79ef2b09d14cbc9524Chet Haase            mEnded = true;
1706faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
1707faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1708faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1709faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
1710faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * This method cancels a transition that is currently running.
1711d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     *
1712d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @hide
1713faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
1714199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    protected void cancel() {
1715e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase        int numAnimators = mCurrentAnimators.size();
171625a738fb257aacfc87d3363a834ed6e0b050c3b1Chet Haase        for (int i = numAnimators - 1; i >= 0; i--) {
1717e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase            Animator animator = mCurrentAnimators.get(i);
1718e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase            animator.cancel();
1719e9d32ea13ee14fc0eb4e45ca627ca77729d38bfeChet Haase        }
1720faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        if (mListeners != null && mListeners.size() > 0) {
1721faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            ArrayList<TransitionListener> tmpListeners =
1722faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                    (ArrayList<TransitionListener>) mListeners.clone();
1723faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            int numListeners = tmpListeners.size();
1724faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            for (int i = 0; i < numListeners; ++i) {
1725faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                tmpListeners.get(i).onTransitionCancel(this);
1726faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
1727faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
1728faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1729faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1730faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
1731faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Adds a listener to the set of listeners that are sent events through the
1732faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * life of an animation, such as start, repeat, and end.
1733faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
1734faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @param listener the listener to be added to the current set of listeners
1735faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * for this animation.
1736d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @return This transition object.
1737faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
1738d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    public Transition addListener(TransitionListener listener) {
1739faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        if (mListeners == null) {
1740faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            mListeners = new ArrayList<TransitionListener>();
1741faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
1742faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        mListeners.add(listener);
1743d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        return this;
1744faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1745faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1746faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
1747faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Removes a listener from the set listening to this animation.
1748faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
1749faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @param listener the listener to be removed from the current set of
1750faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * listeners for this transition.
1751d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * @return This transition object.
1752faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
1753d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    public Transition removeListener(TransitionListener listener) {
1754faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        if (mListeners == null) {
1755d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase            return this;
1756faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
1757faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        mListeners.remove(listener);
1758faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        if (mListeners.size() == 0) {
1759faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            mListeners = null;
1760faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
1761d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        return this;
1762faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1763faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1764d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    /**
1765d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * Sets the callback to use to find the epicenter of a Transition. A null value indicates
1766d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * that there is no epicenter in the Transition and getEpicenter() will return null.
1767d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * Transitions like {@link android.transition.Explode} use a point or Rect to orient
1768d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * the direction of travel. This is called the epicenter of the Transition and is
1769d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * typically centered on a touched View. The
1770d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * {@link android.transition.Transition.EpicenterCallback} allows a Transition to
1771d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * dynamically retrieve the epicenter during a Transition.
1772d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * @param epicenterCallback The callback to use to find the epicenter of the Transition.
1773d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     */
1774d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    public void setEpicenterCallback(EpicenterCallback epicenterCallback) {
1775d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        mEpicenterCallback = epicenterCallback;
1776d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    }
1777d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount
1778d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    /**
1779d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * Returns the callback used to find the epicenter of the Transition.
1780d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * Transitions like {@link android.transition.Explode} use a point or Rect to orient
1781d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * the direction of travel. This is called the epicenter of the Transition and is
1782d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * typically centered on a touched View. The
1783d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * {@link android.transition.Transition.EpicenterCallback} allows a Transition to
1784d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * dynamically retrieve the epicenter during a Transition.
1785d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * @return the callback used to find the epicenter of the Transition.
1786d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     */
1787d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    public EpicenterCallback getEpicenterCallback() {
1788d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        return mEpicenterCallback;
1789d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    }
1790d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount
1791d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    /**
1792d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * Returns the epicenter as specified by the
1793d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * {@link android.transition.Transition.EpicenterCallback} or null if no callback exists.
1794d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * @return the epicenter as specified by the
1795d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * {@link android.transition.Transition.EpicenterCallback} or null if no callback exists.
1796d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * @see #setEpicenterCallback(android.transition.Transition.EpicenterCallback)
1797d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     */
1798d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    public Rect getEpicenter() {
1799d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        if (mEpicenterCallback == null) {
1800d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount            return null;
1801d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        }
1802d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        return mEpicenterCallback.getEpicenter(this);
1803d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    }
1804d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount
1805d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    /**
1806d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * Sets the method for determining Animator start delays.
1807d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * When a Transition affects several Views like {@link android.transition.Explode} or
1808d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * {@link android.transition.Slide}, there may be a desire to have a "wave-front" effect
1809d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * such that the Animator start delay depends on position of the View. The
1810d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * TransitionPropagation specifies how the start delays are calculated.
1811d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * @param transitionPropagation The class used to determine the start delay of
1812d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     *                              Animators created by this Transition. A null value
1813d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     *                              indicates that no delay should be used.
1814d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     */
1815d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    public void setPropagation(TransitionPropagation transitionPropagation) {
1816d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        mPropagation = transitionPropagation;
1817d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    }
1818d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount
1819d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    /**
1820d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * Returns the {@link android.transition.TransitionPropagation} used to calculate Animator start
1821d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * delays.
1822d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * When a Transition affects several Views like {@link android.transition.Explode} or
1823d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * {@link android.transition.Slide}, there may be a desire to have a "wave-front" effect
1824d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * such that the Animator start delay depends on position of the View. The
1825d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * TransitionPropagation specifies how the start delays are calculated.
1826d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * @return the {@link android.transition.TransitionPropagation} used to calculate Animator start
1827d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * delays. This is null by default.
1828d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     */
1829d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    public TransitionPropagation getPropagation() {
1830d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        return mPropagation;
1831d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    }
1832d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount
1833d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    /**
1834d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * Captures TransitionPropagation values for the given view and the
1835d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * hierarchy underneath it.
1836d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     */
1837d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    void capturePropagationValues(TransitionValues transitionValues) {
183831a217290cf376d0573fc36e21c8940987485019George Mount        if (mPropagation != null && !transitionValues.values.isEmpty()) {
1839d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount            String[] propertyNames = mPropagation.getPropagationProperties();
1840d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount            if (propertyNames == null) {
1841d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                return;
1842d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount            }
1843d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount            boolean containsAll = true;
1844d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount            for (int i = 0; i < propertyNames.length; i++) {
1845d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                if (!transitionValues.values.containsKey(propertyNames[i])) {
1846d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                    containsAll = false;
1847d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                    break;
1848d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                }
1849d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount            }
1850d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount            if (!containsAll) {
1851d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount                mPropagation.captureValues(transitionValues);
1852d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount            }
1853d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        }
1854d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    }
1855d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount
1856d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase    Transition setSceneRoot(ViewGroup sceneRoot) {
18576ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase        mSceneRoot = sceneRoot;
1858d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        return this;
18596ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase    }
18606ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase
1861b7a7fc9d233bad507ce893882352618b13647058Chet Haase    void setCanRemoveViews(boolean canRemoveViews) {
1862b7a7fc9d233bad507ce893882352618b13647058Chet Haase        mCanRemoveViews = canRemoveViews;
1863b7a7fc9d233bad507ce893882352618b13647058Chet Haase    }
1864b7a7fc9d233bad507ce893882352618b13647058Chet Haase
18650a778eda690a66173733a63622886e888d405c45George Mount    public boolean canRemoveViews() {
18660a778eda690a66173733a63622886e888d405c45George Mount        return mCanRemoveViews;
18670a778eda690a66173733a63622886e888d405c45George Mount    }
18680a778eda690a66173733a63622886e888d405c45George Mount
1869faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    @Override
1870faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    public String toString() {
1871faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        return toString("");
1872faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1873faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
18746ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase    @Override
18756ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase    public Transition clone() {
18766ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase        Transition clone = null;
18776ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase        try {
18786ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase            clone = (Transition) super.clone();
1879199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            clone.mAnimators = new ArrayList<Animator>();
18807660d121b2ef21164ed33e6091e5dd50f5d0f939Chet Haase            clone.mStartValues = new TransitionValuesMaps();
18817660d121b2ef21164ed33e6091e5dd50f5d0f939Chet Haase            clone.mEndValues = new TransitionValuesMaps();
18826ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase        } catch (CloneNotSupportedException e) {}
18836ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase
18846ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase        return clone;
18856ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase    }
18866ebe3de331efd00ba23bc4191d4a82cfa4c39160Chet Haase
1887199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    /**
1888199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * Returns the name of this Transition. This name is used internally to distinguish
1889199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * between different transitions to determine when interrupting transitions overlap.
1890d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * For example, a ChangeBounds running on the same target view as another ChangeBounds
1891d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * should determine whether the old transition is animating to different end values
1892d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase     * and should be canceled in favor of the new transition.
1893199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     *
1894199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * <p>By default, a Transition's name is simply the value of {@link Class#getName()},
1895199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * but subclasses are free to override and return something different.</p>
1896199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     *
1897199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * @return The name of this transition.
1898199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     */
1899199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    public String getName() {
1900199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        return mName;
1901199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    }
1902199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase
1903faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    String toString(String indent) {
1904faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        String result = indent + getClass().getSimpleName() + "@" +
1905faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                Integer.toHexString(hashCode()) + ": ";
1906c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase        if (mDuration != -1) {
1907c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase            result += "dur(" + mDuration + ") ";
1908c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase        }
1909c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase        if (mStartDelay != -1) {
1910c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase            result += "dly(" + mStartDelay + ") ";
1911c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase        }
1912c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase        if (mInterpolator != null) {
1913c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase            result += "interp(" + mInterpolator + ") ";
1914c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase        }
1915d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase        if (mTargetIds.size() > 0 || mTargets.size() > 0) {
1916c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase            result += "tgts(";
1917d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase            if (mTargetIds.size() > 0) {
1918d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase                for (int i = 0; i < mTargetIds.size(); ++i) {
1919c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                    if (i > 0) {
1920c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                        result += ", ";
1921c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                    }
1922d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase                    result += mTargetIds.get(i);
1923faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                }
1924faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
1925d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase            if (mTargets.size() > 0) {
1926d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase                for (int i = 0; i < mTargets.size(); ++i) {
1927c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                    if (i > 0) {
1928c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                        result += ", ";
1929c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase                    }
1930d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase                    result += mTargets.get(i);
1931faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase                }
1932faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase            }
1933c43524f3869cc0d36974fce61986017093f2ecd2Chet Haase            result += ")";
1934faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
1935faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        return result;
1936faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1937faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1938faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
1939faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * A transition listener receives notifications from a transition.
1940199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * Notifications indicate transition lifecycle events.
1941faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     */
1942faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    public static interface TransitionListener {
1943faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        /**
1944faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         * Notification about the start of the transition.
1945faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         *
1946faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         * @param transition The started transition.
1947faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         */
1948faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        void onTransitionStart(Transition transition);
1949faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1950faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        /**
1951faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         * Notification about the end of the transition. Canceled transitions
1952faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         * will always notify listeners of both the cancellation and end
1953199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         * events. That is, {@link #onTransitionEnd(Transition)} is always called,
1954faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         * regardless of whether the transition was canceled or played
1955faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         * through to completion.
1956faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         *
1957faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         * @param transition The transition which reached its end.
1958faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         */
1959faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        void onTransitionEnd(Transition transition);
1960faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1961faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        /**
1962faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         * Notification about the cancellation of the transition.
1963d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase         * Note that cancel may be called by a parent {@link TransitionSet} on
1964199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         * a child transition which has not yet started. This allows the child
1965199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         * transition to restore state on target objects which was set at
1966d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase         * {@link #createAnimator(android.view.ViewGroup, TransitionValues, TransitionValues)
1967d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase         * createAnimator()} time.
1968faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         *
1969faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         * @param transition The transition which was canceled.
1970faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase         */
1971faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        void onTransitionCancel(Transition transition);
1972199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase
1973199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        /**
1974199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         * Notification when a transition is paused.
1975d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase         * Note that createAnimator() may be called by a parent {@link TransitionSet} on
1976199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         * a child transition which has not yet started. This allows the child
1977199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         * transition to restore state on target objects which was set at
1978d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase         * {@link #createAnimator(android.view.ViewGroup, TransitionValues, TransitionValues)
1979d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase         * createAnimator()} time.
1980199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         *
1981199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         * @param transition The transition which was paused.
1982199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         */
1983199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        void onTransitionPause(Transition transition);
1984199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase
1985199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        /**
1986199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         * Notification when a transition is resumed.
1987d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase         * Note that resume() may be called by a parent {@link TransitionSet} on
1988199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         * a child transition which has not yet started. This allows the child
1989199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         * transition to restore state which may have changed in an earlier call
1990199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         * to {@link #onTransitionPause(Transition)}.
1991199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         *
1992199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         * @param transition The transition which was resumed.
1993199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase         */
1994199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        void onTransitionResume(Transition transition);
1995faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
1996faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
1997faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    /**
1998faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * Utility adapter class to avoid having to override all three methods
1999faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * whenever someone just wants to listen for a single event.
2000faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     *
2001faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * @hide
2002faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase     * */
2003faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    public static class TransitionListenerAdapter implements TransitionListener {
2004faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        @Override
2005faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        public void onTransitionStart(Transition transition) {
2006faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
2007faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
2008faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        @Override
2009faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        public void onTransitionEnd(Transition transition) {
2010faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
2011faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
2012faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        @Override
2013faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        public void onTransitionCancel(Transition transition) {
2014faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase        }
2015199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase
2016199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        @Override
2017199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        public void onTransitionPause(Transition transition) {
2018199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        }
2019199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase
2020199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        @Override
2021199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        public void onTransitionResume(Transition transition) {
2022199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        }
2023faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase    }
2024faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase
2025199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    /**
2026199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * Holds information about each animator used when a new transition starts
2027199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * while other transitions are still running to determine whether a running
2028199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * animation should be canceled or a new animation noop'd. The structure holds
2029199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * information about the state that an animation is going to, to be compared to
2030199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     * end state of a new animation.
20310a778eda690a66173733a63622886e888d405c45George Mount     * @hide
2032199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase     */
20330a778eda690a66173733a63622886e888d405c45George Mount    public static class AnimationInfo {
20340a778eda690a66173733a63622886e888d405c45George Mount        public View view;
2035199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        String name;
2036199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        TransitionValues values;
2037cf68aad3164303df59b2a669d186a94533c9c743George Mount        WindowId windowId;
2038199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase
2039cf68aad3164303df59b2a669d186a94533c9c743George Mount        AnimationInfo(View view, String name, WindowId windowId, TransitionValues values) {
2040199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            this.view = view;
2041199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            this.name = name;
2042199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase            this.values = values;
2043cf68aad3164303df59b2a669d186a94533c9c743George Mount            this.windowId = windowId;
2044199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase        }
2045199acdfcc98e852975dd7edfbcb822ba5e73146fChet Haase    }
2046ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase
2047ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    /**
2048ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * Utility class for managing typed ArrayLists efficiently. In particular, this
2049ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * can be useful for lists that we don't expect to be used often (eg, the exclude
2050ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * lists), so we'd like to keep them nulled out by default. This causes the code to
2051ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * become tedious, with constant null checks, code to allocate when necessary,
2052ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * and code to null out the reference when the list is empty. This class encapsulates
2053ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * all of that functionality into simple add()/remove() methods which perform the
2054ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * necessary checks, allocation/null-out as appropriate, and return the
2055ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     * resulting list.
2056ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase     */
2057ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    private static class ArrayListManager {
2058ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase
2059ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        /**
2060ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase         * Add the specified item to the list, returning the resulting list.
2061ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase         * The returned list can either the be same list passed in or, if that
2062ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase         * list was null, the new list that was created.
2063ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase         *
2064ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase         * Note that the list holds unique items; if the item already exists in the
2065ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase         * list, the list is not modified.
2066ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase         */
2067ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        static <T> ArrayList<T> add(ArrayList<T> list, T item) {
2068ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            if (list == null) {
2069ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                list = new ArrayList<T>();
2070ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            }
2071ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            if (!list.contains(item)) {
2072ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                list.add(item);
2073ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            }
2074ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            return list;
2075ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        }
2076ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase
2077ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        /**
2078ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase         * Remove the specified item from the list, returning the resulting list.
2079ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase         * The returned list can either the be same list passed in or, if that
2080ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase         * list becomes empty as a result of the remove(), the new list was created.
2081ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase         */
2082ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        static <T> ArrayList<T> remove(ArrayList<T> list, T item) {
2083ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            if (list != null) {
2084ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                list.remove(item);
2085ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                if (list.isEmpty()) {
2086ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                    list = null;
2087ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase                }
2088ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            }
2089ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase            return list;
2090ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase        }
2091ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase    }
2092ff58f92a0a77ad849ba714b5adac96790eca0048Chet Haase
2093d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    /**
2094d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * Class to get the epicenter of Transition. Use
2095d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * {@link #setEpicenterCallback(android.transition.Transition.EpicenterCallback)} to
2096d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * set the callback used to calculate the epicenter of the Transition. Override
2097d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * {@link #getEpicenter()} to return the rectangular region in screen coordinates of
2098d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * the epicenter of the transition.
2099d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     * @see #setEpicenterCallback(android.transition.Transition.EpicenterCallback)
2100d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount     */
2101d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    public static abstract class EpicenterCallback {
2102d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount
2103d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        /**
2104d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount         * Implementers must override to return the epicenter of the Transition in screen
2105d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount         * coordinates. Transitions like {@link android.transition.Explode} depend upon
2106d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount         * an epicenter for the Transition. In Explode, Views move toward or away from the
2107d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount         * center of the epicenter Rect along the vector between the epicenter and the center
2108d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount         * of the View appearing and disappearing. Some Transitions, such as
2109d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount         * {@link android.transition.Fade} pay no attention to the epicenter.
2110d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount         *
2111d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount         * @param transition The transition for which the epicenter applies.
2112d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount         * @return The Rect region of the epicenter of <code>transition</code> or null if
2113d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount         * there is no epicenter.
2114d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount         */
2115d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount        public abstract Rect getEpicenter(Transition transition);
2116d6107a3170df61d9e776fcd5666acfc9135c6f16George Mount    }
2117faebd8f0795b7d275fb4e503533c8c0c4a9acc21Chet Haase}
2118