Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.transition; |
| 18 | |
| 19 | import android.animation.TimeInterpolator; |
George Mount | ecd857b | 2014-06-19 07:51:08 -0700 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.res.TypedArray; |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 22 | import android.util.AndroidRuntimeException; |
George Mount | ecd857b | 2014-06-19 07:51:08 -0700 | [diff] [blame] | 23 | import android.util.AttributeSet; |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 24 | import android.view.View; |
| 25 | import android.view.ViewGroup; |
| 26 | |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 27 | import com.android.internal.R; |
| 28 | |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 29 | import java.util.ArrayList; |
| 30 | |
| 31 | /** |
| 32 | * A TransitionSet is a parent of child transitions (including other |
| 33 | * TransitionSets). Using TransitionSets enables more complex |
| 34 | * choreography of transitions, where some sets play {@link #ORDERING_TOGETHER} and |
| 35 | * others play {@link #ORDERING_SEQUENTIAL}. For example, {@link AutoTransition} |
| 36 | * uses a TransitionSet to sequentially play a Fade(Fade.OUT), followed by |
| 37 | * a {@link ChangeBounds}, followed by a Fade(Fade.OUT) transition. |
Chet Haase | aafc91c | 2013-10-06 12:10:12 -0700 | [diff] [blame] | 38 | * |
| 39 | * <p>A TransitionSet can be described in a resource file by using the |
| 40 | * tag <code>transitionSet</code>, along with the standard |
| 41 | * attributes of {@link android.R.styleable#TransitionSet} and |
| 42 | * {@link android.R.styleable#Transition}. Child transitions of the |
| 43 | * TransitionSet object can be loaded by adding those child tags inside the |
| 44 | * enclosing <code>transitionSet</code> tag. For example, the following xml |
| 45 | * describes a TransitionSet that plays a Fade and then a ChangeBounds |
| 46 | * transition on the affected view targets:</p> |
| 47 | * <pre> |
| 48 | * <transitionSet xmlns:android="http://schemas.android.com/apk/res/android" |
George Mount | 93aaab0 | 2016-02-10 15:39:17 -0800 | [diff] [blame] | 49 | * android:transitionOrdering="sequential"> |
Chet Haase | aafc91c | 2013-10-06 12:10:12 -0700 | [diff] [blame] | 50 | * <fade/> |
| 51 | * <changeBounds/> |
| 52 | * </transitionSet> |
| 53 | * </pre> |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 54 | */ |
| 55 | public class TransitionSet extends Transition { |
George Mount | a69609e | 2018-03-15 16:37:37 -0700 | [diff] [blame] | 56 | /** |
| 57 | * Flag indicating the the interpolator changed. |
| 58 | */ |
| 59 | private static final int FLAG_CHANGE_INTERPOLATOR = 0x01; |
| 60 | /** |
| 61 | * Flag indicating the the propagation changed. |
| 62 | */ |
| 63 | private static final int FLAG_CHANGE_PROPAGATION = 0x02; |
| 64 | /** |
| 65 | * Flag indicating the the path motion changed. |
| 66 | */ |
| 67 | private static final int FLAG_CHANGE_PATH_MOTION = 0x04; |
| 68 | /** |
| 69 | * Flag indicating the the epicentera callback changed. |
| 70 | */ |
| 71 | static final int FLAG_CHANGE_EPICENTER = 0x08; |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 72 | |
| 73 | ArrayList<Transition> mTransitions = new ArrayList<Transition>(); |
| 74 | private boolean mPlayTogether = true; |
| 75 | int mCurrentListeners; |
| 76 | boolean mStarted = false; |
George Mount | a69609e | 2018-03-15 16:37:37 -0700 | [diff] [blame] | 77 | // Flags to know whether or not the interpolator, path motion, epicenter, propagation |
| 78 | // have changed |
| 79 | private int mChangeFlags = 0; |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * A flag used to indicate that the child transitions of this set |
| 83 | * should all start at the same time. |
| 84 | */ |
| 85 | public static final int ORDERING_TOGETHER = 0; |
| 86 | /** |
| 87 | * A flag used to indicate that the child transitions of this set should |
| 88 | * play in sequence; when one child transition ends, the next child |
| 89 | * transition begins. Note that a transition does not end until all |
| 90 | * instances of it (which are playing on all applicable targets of the |
| 91 | * transition) end. |
| 92 | */ |
| 93 | public static final int ORDERING_SEQUENTIAL = 1; |
| 94 | |
| 95 | /** |
| 96 | * Constructs an empty transition set. Add child transitions to the |
| 97 | * set by calling {@link #addTransition(Transition)} )}. By default, |
| 98 | * child transitions will play {@link #ORDERING_TOGETHER together}. |
| 99 | */ |
| 100 | public TransitionSet() { |
| 101 | } |
| 102 | |
George Mount | ecd857b | 2014-06-19 07:51:08 -0700 | [diff] [blame] | 103 | public TransitionSet(Context context, AttributeSet attrs) { |
| 104 | super(context, attrs); |
| 105 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TransitionSet); |
| 106 | int ordering = a.getInt(R.styleable.TransitionSet_transitionOrdering, |
| 107 | TransitionSet.ORDERING_TOGETHER); |
| 108 | setOrdering(ordering); |
| 109 | a.recycle(); |
| 110 | } |
| 111 | |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 112 | /** |
| 113 | * Sets the play order of this set's child transitions. |
| 114 | * |
| 115 | * @param ordering {@link #ORDERING_TOGETHER} to play this set's child |
| 116 | * transitions together, {@link #ORDERING_SEQUENTIAL} to play the child |
| 117 | * transitions in sequence. |
| 118 | * @return This transitionSet object. |
| 119 | */ |
| 120 | public TransitionSet setOrdering(int ordering) { |
| 121 | switch (ordering) { |
| 122 | case ORDERING_SEQUENTIAL: |
| 123 | mPlayTogether = false; |
| 124 | break; |
| 125 | case ORDERING_TOGETHER: |
| 126 | mPlayTogether = true; |
| 127 | break; |
| 128 | default: |
| 129 | throw new AndroidRuntimeException("Invalid parameter for TransitionSet " + |
| 130 | "ordering: " + ordering); |
| 131 | } |
| 132 | return this; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Returns the ordering of this TransitionSet. By default, the value is |
| 137 | * {@link #ORDERING_TOGETHER}. |
| 138 | * |
| 139 | * @return {@link #ORDERING_TOGETHER} if child transitions will play at the same |
| 140 | * time, {@link #ORDERING_SEQUENTIAL} if they will play in sequence. |
| 141 | * |
| 142 | * @see #setOrdering(int) |
| 143 | */ |
| 144 | public int getOrdering() { |
| 145 | return mPlayTogether ? ORDERING_TOGETHER : ORDERING_SEQUENTIAL; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Adds child transition to this set. The order in which this child transition |
| 150 | * is added relative to other child transitions that are added, in addition to |
| 151 | * the {@link #getOrdering() ordering} property, determines the |
| 152 | * order in which the transitions are started. |
| 153 | * |
George Mount | a69609e | 2018-03-15 16:37:37 -0700 | [diff] [blame] | 154 | * <p>If this transitionSet has a {@link #getDuration() duration}, |
| 155 | * {@link #getInterpolator() interpolator}, {@link #getPropagation() propagation delay}, |
| 156 | * {@link #getPathMotion() path motion}, or |
| 157 | * {@link #setEpicenterCallback(EpicenterCallback) epicenter callback} |
| 158 | * set on it, the child transition will inherit the values that are set. |
| 159 | * Transitions are assumed to have a maximum of one transitionSet parent.</p> |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 160 | * |
| 161 | * @param transition A non-null child transition to be added to this set. |
| 162 | * @return This transitionSet object. |
| 163 | */ |
| 164 | public TransitionSet addTransition(Transition transition) { |
| 165 | if (transition != null) { |
| 166 | mTransitions.add(transition); |
| 167 | transition.mParent = this; |
| 168 | if (mDuration >= 0) { |
| 169 | transition.setDuration(mDuration); |
| 170 | } |
George Mount | a69609e | 2018-03-15 16:37:37 -0700 | [diff] [blame] | 171 | if ((mChangeFlags & FLAG_CHANGE_INTERPOLATOR) != 0) { |
| 172 | transition.setInterpolator(getInterpolator()); |
| 173 | } |
| 174 | if ((mChangeFlags & FLAG_CHANGE_PROPAGATION) != 0) { |
| 175 | transition.setPropagation(getPropagation()); |
| 176 | } |
| 177 | if ((mChangeFlags & FLAG_CHANGE_PATH_MOTION) != 0) { |
| 178 | transition.setPathMotion(getPathMotion()); |
| 179 | } |
| 180 | if ((mChangeFlags & FLAG_CHANGE_EPICENTER) != 0) { |
| 181 | transition.setEpicenterCallback(getEpicenterCallback()); |
| 182 | } |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 183 | } |
| 184 | return this; |
| 185 | } |
| 186 | |
| 187 | /** |
George Mount | 7f15164 | 2014-08-18 16:24:21 -0700 | [diff] [blame] | 188 | * Returns the number of child transitions in the TransitionSet. |
| 189 | * |
| 190 | * @return The number of child transitions in the TransitionSet. |
| 191 | * @see #addTransition(Transition) |
| 192 | * @see #getTransitionAt(int) |
| 193 | */ |
| 194 | public int getTransitionCount() { |
| 195 | return mTransitions.size(); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Returns the child Transition at the specified position in the TransitionSet. |
| 200 | * |
| 201 | * @param index The position of the Transition to retrieve. |
| 202 | * @see #addTransition(Transition) |
| 203 | * @see #getTransitionCount() |
| 204 | */ |
| 205 | public Transition getTransitionAt(int index) { |
| 206 | if (index < 0 || index >= mTransitions.size()) { |
| 207 | return null; |
| 208 | } |
| 209 | return mTransitions.get(index); |
| 210 | } |
| 211 | |
| 212 | /** |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 213 | * Setting a non-negative duration on a TransitionSet causes all of the child |
| 214 | * transitions (current and future) to inherit this duration. |
| 215 | * |
| 216 | * @param duration The length of the animation, in milliseconds. |
| 217 | * @return This transitionSet object. |
| 218 | */ |
| 219 | @Override |
| 220 | public TransitionSet setDuration(long duration) { |
| 221 | super.setDuration(duration); |
George Mount | e3b50ae | 2014-07-15 10:41:50 -0700 | [diff] [blame] | 222 | if (mDuration >= 0 && mTransitions != null) { |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 223 | int numTransitions = mTransitions.size(); |
| 224 | for (int i = 0; i < numTransitions; ++i) { |
| 225 | mTransitions.get(i).setDuration(duration); |
| 226 | } |
| 227 | } |
| 228 | return this; |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public TransitionSet setStartDelay(long startDelay) { |
| 233 | return (TransitionSet) super.setStartDelay(startDelay); |
| 234 | } |
| 235 | |
| 236 | @Override |
| 237 | public TransitionSet setInterpolator(TimeInterpolator interpolator) { |
George Mount | a69609e | 2018-03-15 16:37:37 -0700 | [diff] [blame] | 238 | mChangeFlags |= FLAG_CHANGE_INTERPOLATOR; |
| 239 | if (mTransitions != null) { |
| 240 | int numTransitions = mTransitions.size(); |
| 241 | for (int i = 0; i < numTransitions; ++i) { |
| 242 | mTransitions.get(i).setInterpolator(interpolator); |
| 243 | } |
| 244 | } |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 245 | return (TransitionSet) super.setInterpolator(interpolator); |
| 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public TransitionSet addTarget(View target) { |
George Mount | d4c3c91 | 2014-06-09 12:31:34 -0700 | [diff] [blame] | 250 | for (int i = 0; i < mTransitions.size(); i++) { |
| 251 | mTransitions.get(i).addTarget(target); |
| 252 | } |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 253 | return (TransitionSet) super.addTarget(target); |
| 254 | } |
| 255 | |
| 256 | @Override |
Chet Haase | ff58f92 | 2013-09-11 13:08:18 -0700 | [diff] [blame] | 257 | public TransitionSet addTarget(int targetId) { |
George Mount | d4c3c91 | 2014-06-09 12:31:34 -0700 | [diff] [blame] | 258 | for (int i = 0; i < mTransitions.size(); i++) { |
| 259 | mTransitions.get(i).addTarget(targetId); |
| 260 | } |
Chet Haase | ff58f92 | 2013-09-11 13:08:18 -0700 | [diff] [blame] | 261 | return (TransitionSet) super.addTarget(targetId); |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | @Override |
George Mount | d4c3c91 | 2014-06-09 12:31:34 -0700 | [diff] [blame] | 265 | public TransitionSet addTarget(String targetName) { |
| 266 | for (int i = 0; i < mTransitions.size(); i++) { |
| 267 | mTransitions.get(i).addTarget(targetName); |
| 268 | } |
| 269 | return (TransitionSet) super.addTarget(targetName); |
| 270 | } |
| 271 | |
| 272 | @Override |
| 273 | public TransitionSet addTarget(Class targetType) { |
| 274 | for (int i = 0; i < mTransitions.size(); i++) { |
| 275 | mTransitions.get(i).addTarget(targetType); |
| 276 | } |
| 277 | return (TransitionSet) super.addTarget(targetType); |
| 278 | } |
| 279 | |
| 280 | @Override |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 281 | public TransitionSet addListener(TransitionListener listener) { |
| 282 | return (TransitionSet) super.addListener(listener); |
| 283 | } |
| 284 | |
| 285 | @Override |
Chet Haase | ff58f92 | 2013-09-11 13:08:18 -0700 | [diff] [blame] | 286 | public TransitionSet removeTarget(int targetId) { |
George Mount | d4c3c91 | 2014-06-09 12:31:34 -0700 | [diff] [blame] | 287 | for (int i = 0; i < mTransitions.size(); i++) { |
| 288 | mTransitions.get(i).removeTarget(targetId); |
| 289 | } |
Chet Haase | ff58f92 | 2013-09-11 13:08:18 -0700 | [diff] [blame] | 290 | return (TransitionSet) super.removeTarget(targetId); |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | @Override |
| 294 | public TransitionSet removeTarget(View target) { |
George Mount | d4c3c91 | 2014-06-09 12:31:34 -0700 | [diff] [blame] | 295 | for (int i = 0; i < mTransitions.size(); i++) { |
| 296 | mTransitions.get(i).removeTarget(target); |
| 297 | } |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 298 | return (TransitionSet) super.removeTarget(target); |
| 299 | } |
| 300 | |
| 301 | @Override |
George Mount | d4c3c91 | 2014-06-09 12:31:34 -0700 | [diff] [blame] | 302 | public TransitionSet removeTarget(Class target) { |
| 303 | for (int i = 0; i < mTransitions.size(); i++) { |
| 304 | mTransitions.get(i).removeTarget(target); |
| 305 | } |
| 306 | return (TransitionSet) super.removeTarget(target); |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public TransitionSet removeTarget(String target) { |
| 311 | for (int i = 0; i < mTransitions.size(); i++) { |
| 312 | mTransitions.get(i).removeTarget(target); |
| 313 | } |
| 314 | return (TransitionSet) super.removeTarget(target); |
| 315 | } |
| 316 | |
| 317 | @Override |
| 318 | public Transition excludeTarget(View target, boolean exclude) { |
| 319 | for (int i = 0; i < mTransitions.size(); i++) { |
| 320 | mTransitions.get(i).excludeTarget(target, exclude); |
| 321 | } |
| 322 | return super.excludeTarget(target, exclude); |
| 323 | } |
| 324 | |
| 325 | @Override |
George Mount | 0a2ae00 | 2014-06-23 14:57:27 +0000 | [diff] [blame] | 326 | public Transition excludeTarget(String targetName, boolean exclude) { |
George Mount | d4c3c91 | 2014-06-09 12:31:34 -0700 | [diff] [blame] | 327 | for (int i = 0; i < mTransitions.size(); i++) { |
George Mount | 0a2ae00 | 2014-06-23 14:57:27 +0000 | [diff] [blame] | 328 | mTransitions.get(i).excludeTarget(targetName, exclude); |
George Mount | d4c3c91 | 2014-06-09 12:31:34 -0700 | [diff] [blame] | 329 | } |
George Mount | 0a2ae00 | 2014-06-23 14:57:27 +0000 | [diff] [blame] | 330 | return super.excludeTarget(targetName, exclude); |
George Mount | d4c3c91 | 2014-06-09 12:31:34 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | @Override |
| 334 | public Transition excludeTarget(int targetId, boolean exclude) { |
| 335 | for (int i = 0; i < mTransitions.size(); i++) { |
| 336 | mTransitions.get(i).excludeTarget(targetId, exclude); |
| 337 | } |
| 338 | return super.excludeTarget(targetId, exclude); |
| 339 | } |
| 340 | |
| 341 | @Override |
| 342 | public Transition excludeTarget(Class type, boolean exclude) { |
| 343 | for (int i = 0; i < mTransitions.size(); i++) { |
| 344 | mTransitions.get(i).excludeTarget(type, exclude); |
| 345 | } |
| 346 | return super.excludeTarget(type, exclude); |
| 347 | } |
| 348 | |
| 349 | @Override |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 350 | public TransitionSet removeListener(TransitionListener listener) { |
| 351 | return (TransitionSet) super.removeListener(listener); |
| 352 | } |
| 353 | |
George Mount | ecd857b | 2014-06-19 07:51:08 -0700 | [diff] [blame] | 354 | @Override |
| 355 | public void setPathMotion(PathMotion pathMotion) { |
| 356 | super.setPathMotion(pathMotion); |
George Mount | a69609e | 2018-03-15 16:37:37 -0700 | [diff] [blame] | 357 | mChangeFlags |= FLAG_CHANGE_PATH_MOTION; |
George Mount | ecd857b | 2014-06-19 07:51:08 -0700 | [diff] [blame] | 358 | for (int i = 0; i < mTransitions.size(); i++) { |
| 359 | mTransitions.get(i).setPathMotion(pathMotion); |
| 360 | } |
| 361 | } |
| 362 | |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 363 | /** |
| 364 | * Removes the specified child transition from this set. |
| 365 | * |
| 366 | * @param transition The transition to be removed. |
| 367 | * @return This transitionSet object. |
| 368 | */ |
| 369 | public TransitionSet removeTransition(Transition transition) { |
| 370 | mTransitions.remove(transition); |
| 371 | transition.mParent = null; |
| 372 | return this; |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Sets up listeners for each of the child transitions. This is used to |
| 377 | * determine when this transition set is finished (all child transitions |
| 378 | * must finish first). |
| 379 | */ |
| 380 | private void setupStartEndListeners() { |
| 381 | TransitionSetListener listener = new TransitionSetListener(this); |
| 382 | for (Transition childTransition : mTransitions) { |
| 383 | childTransition.addListener(listener); |
| 384 | } |
| 385 | mCurrentListeners = mTransitions.size(); |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * This listener is used to detect when all child transitions are done, at |
| 390 | * which point this transition set is also done. |
| 391 | */ |
| 392 | static class TransitionSetListener extends TransitionListenerAdapter { |
| 393 | TransitionSet mTransitionSet; |
| 394 | TransitionSetListener(TransitionSet transitionSet) { |
| 395 | mTransitionSet = transitionSet; |
| 396 | } |
| 397 | @Override |
| 398 | public void onTransitionStart(Transition transition) { |
| 399 | if (!mTransitionSet.mStarted) { |
| 400 | mTransitionSet.start(); |
| 401 | mTransitionSet.mStarted = true; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | @Override |
| 406 | public void onTransitionEnd(Transition transition) { |
| 407 | --mTransitionSet.mCurrentListeners; |
| 408 | if (mTransitionSet.mCurrentListeners == 0) { |
| 409 | // All child trans |
| 410 | mTransitionSet.mStarted = false; |
| 411 | mTransitionSet.end(); |
| 412 | } |
| 413 | transition.removeListener(this); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * @hide |
| 419 | */ |
| 420 | @Override |
| 421 | protected void createAnimators(ViewGroup sceneRoot, TransitionValuesMaps startValues, |
George Mount | 4d1ecf5 | 2014-07-29 11:15:54 -0700 | [diff] [blame] | 422 | TransitionValuesMaps endValues, ArrayList<TransitionValues> startValuesList, |
| 423 | ArrayList<TransitionValues> endValuesList) { |
George Mount | 0460002 | 2014-09-10 10:58:08 -0700 | [diff] [blame] | 424 | long startDelay = getStartDelay(); |
| 425 | int numTransitions = mTransitions.size(); |
| 426 | for (int i = 0; i < numTransitions; i++) { |
| 427 | Transition childTransition = mTransitions.get(i); |
| 428 | // We only set the start delay on the first transition if we are playing |
| 429 | // the transitions sequentially. |
| 430 | if (startDelay > 0 && (mPlayTogether || i == 0)) { |
| 431 | long childStartDelay = childTransition.getStartDelay(); |
| 432 | if (childStartDelay > 0) { |
| 433 | childTransition.setStartDelay(startDelay + childStartDelay); |
| 434 | } else { |
| 435 | childTransition.setStartDelay(startDelay); |
| 436 | } |
| 437 | } |
George Mount | 4d1ecf5 | 2014-07-29 11:15:54 -0700 | [diff] [blame] | 438 | childTransition.createAnimators(sceneRoot, startValues, endValues, startValuesList, |
| 439 | endValuesList); |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * @hide |
| 445 | */ |
| 446 | @Override |
| 447 | protected void runAnimators() { |
George Mount | 38a6649 | 2014-09-10 10:58:08 -0700 | [diff] [blame] | 448 | if (mTransitions.isEmpty()) { |
| 449 | start(); |
| 450 | end(); |
| 451 | return; |
| 452 | } |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 453 | setupStartEndListeners(); |
George Mount | 38a6649 | 2014-09-10 10:58:08 -0700 | [diff] [blame] | 454 | int numTransitions = mTransitions.size(); |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 455 | if (!mPlayTogether) { |
| 456 | // Setup sequence with listeners |
| 457 | // TODO: Need to add listeners in such a way that we can remove them later if canceled |
George Mount | 38a6649 | 2014-09-10 10:58:08 -0700 | [diff] [blame] | 458 | for (int i = 1; i < numTransitions; ++i) { |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 459 | Transition previousTransition = mTransitions.get(i - 1); |
| 460 | final Transition nextTransition = mTransitions.get(i); |
| 461 | previousTransition.addListener(new TransitionListenerAdapter() { |
| 462 | @Override |
| 463 | public void onTransitionEnd(Transition transition) { |
| 464 | nextTransition.runAnimators(); |
| 465 | transition.removeListener(this); |
| 466 | } |
| 467 | }); |
| 468 | } |
| 469 | Transition firstTransition = mTransitions.get(0); |
| 470 | if (firstTransition != null) { |
| 471 | firstTransition.runAnimators(); |
| 472 | } |
| 473 | } else { |
George Mount | 38a6649 | 2014-09-10 10:58:08 -0700 | [diff] [blame] | 474 | for (int i = 0; i < numTransitions; ++i) { |
| 475 | mTransitions.get(i).runAnimators(); |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | @Override |
| 481 | public void captureStartValues(TransitionValues transitionValues) { |
George Mount | 30da61d | 2014-05-09 13:17:52 -0700 | [diff] [blame] | 482 | if (isValidTarget(transitionValues.view)) { |
Chet Haase | ff58f92 | 2013-09-11 13:08:18 -0700 | [diff] [blame] | 483 | for (Transition childTransition : mTransitions) { |
George Mount | 30da61d | 2014-05-09 13:17:52 -0700 | [diff] [blame] | 484 | if (childTransition.isValidTarget(transitionValues.view)) { |
Chet Haase | ff58f92 | 2013-09-11 13:08:18 -0700 | [diff] [blame] | 485 | childTransition.captureStartValues(transitionValues); |
George Mount | 5030c7f | 2014-09-10 10:58:08 -0700 | [diff] [blame] | 486 | transitionValues.targetedTransitions.add(childTransition); |
Chet Haase | ff58f92 | 2013-09-11 13:08:18 -0700 | [diff] [blame] | 487 | } |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 488 | } |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | @Override |
| 493 | public void captureEndValues(TransitionValues transitionValues) { |
George Mount | 30da61d | 2014-05-09 13:17:52 -0700 | [diff] [blame] | 494 | if (isValidTarget(transitionValues.view)) { |
Chet Haase | ff58f92 | 2013-09-11 13:08:18 -0700 | [diff] [blame] | 495 | for (Transition childTransition : mTransitions) { |
George Mount | 30da61d | 2014-05-09 13:17:52 -0700 | [diff] [blame] | 496 | if (childTransition.isValidTarget(transitionValues.view)) { |
Chet Haase | ff58f92 | 2013-09-11 13:08:18 -0700 | [diff] [blame] | 497 | childTransition.captureEndValues(transitionValues); |
George Mount | 5030c7f | 2014-09-10 10:58:08 -0700 | [diff] [blame] | 498 | transitionValues.targetedTransitions.add(childTransition); |
Chet Haase | ff58f92 | 2013-09-11 13:08:18 -0700 | [diff] [blame] | 499 | } |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | } |
| 503 | |
George Mount | d6107a3 | 2014-03-10 16:51:16 -0700 | [diff] [blame] | 504 | @Override |
| 505 | void capturePropagationValues(TransitionValues transitionValues) { |
| 506 | super.capturePropagationValues(transitionValues); |
| 507 | int numTransitions = mTransitions.size(); |
| 508 | for (int i = 0; i < numTransitions; ++i) { |
| 509 | mTransitions.get(i).capturePropagationValues(transitionValues); |
| 510 | } |
| 511 | } |
| 512 | |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 513 | /** @hide */ |
| 514 | @Override |
George Mount | cf68aad | 2014-03-06 14:17:46 -0800 | [diff] [blame] | 515 | public void pause(View sceneRoot) { |
| 516 | super.pause(sceneRoot); |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 517 | int numTransitions = mTransitions.size(); |
| 518 | for (int i = 0; i < numTransitions; ++i) { |
George Mount | cf68aad | 2014-03-06 14:17:46 -0800 | [diff] [blame] | 519 | mTransitions.get(i).pause(sceneRoot); |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | |
| 523 | /** @hide */ |
| 524 | @Override |
George Mount | cf68aad | 2014-03-06 14:17:46 -0800 | [diff] [blame] | 525 | public void resume(View sceneRoot) { |
| 526 | super.resume(sceneRoot); |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 527 | int numTransitions = mTransitions.size(); |
| 528 | for (int i = 0; i < numTransitions; ++i) { |
George Mount | cf68aad | 2014-03-06 14:17:46 -0800 | [diff] [blame] | 529 | mTransitions.get(i).resume(sceneRoot); |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
| 533 | /** @hide */ |
| 534 | @Override |
| 535 | protected void cancel() { |
| 536 | super.cancel(); |
| 537 | int numTransitions = mTransitions.size(); |
| 538 | for (int i = 0; i < numTransitions; ++i) { |
| 539 | mTransitions.get(i).cancel(); |
| 540 | } |
| 541 | } |
| 542 | |
George Mount | 413739e | 2016-06-08 07:13:37 -0700 | [diff] [blame] | 543 | /** @hide */ |
| 544 | @Override |
| 545 | void forceToEnd(ViewGroup sceneRoot) { |
| 546 | super.forceToEnd(sceneRoot); |
| 547 | int numTransitions = mTransitions.size(); |
| 548 | for (int i = 0; i < numTransitions; ++i) { |
| 549 | mTransitions.get(i).forceToEnd(sceneRoot); |
| 550 | } |
| 551 | } |
| 552 | |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 553 | @Override |
| 554 | TransitionSet setSceneRoot(ViewGroup sceneRoot) { |
| 555 | super.setSceneRoot(sceneRoot); |
| 556 | int numTransitions = mTransitions.size(); |
| 557 | for (int i = 0; i < numTransitions; ++i) { |
| 558 | mTransitions.get(i).setSceneRoot(sceneRoot); |
| 559 | } |
| 560 | return (TransitionSet) this; |
| 561 | } |
| 562 | |
| 563 | @Override |
Chet Haase | b7a7fc9 | 2013-09-20 16:33:08 -0700 | [diff] [blame] | 564 | void setCanRemoveViews(boolean canRemoveViews) { |
| 565 | super.setCanRemoveViews(canRemoveViews); |
| 566 | int numTransitions = mTransitions.size(); |
| 567 | for (int i = 0; i < numTransitions; ++i) { |
| 568 | mTransitions.get(i).setCanRemoveViews(canRemoveViews); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | @Override |
George Mount | d6107a3 | 2014-03-10 16:51:16 -0700 | [diff] [blame] | 573 | public void setPropagation(TransitionPropagation propagation) { |
| 574 | super.setPropagation(propagation); |
George Mount | a69609e | 2018-03-15 16:37:37 -0700 | [diff] [blame] | 575 | mChangeFlags |= FLAG_CHANGE_PROPAGATION; |
George Mount | d6107a3 | 2014-03-10 16:51:16 -0700 | [diff] [blame] | 576 | int numTransitions = mTransitions.size(); |
| 577 | for (int i = 0; i < numTransitions; ++i) { |
| 578 | mTransitions.get(i).setPropagation(propagation); |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | @Override |
| 583 | public void setEpicenterCallback(EpicenterCallback epicenterCallback) { |
| 584 | super.setEpicenterCallback(epicenterCallback); |
George Mount | a69609e | 2018-03-15 16:37:37 -0700 | [diff] [blame] | 585 | mChangeFlags |= FLAG_CHANGE_EPICENTER; |
George Mount | d6107a3 | 2014-03-10 16:51:16 -0700 | [diff] [blame] | 586 | int numTransitions = mTransitions.size(); |
| 587 | for (int i = 0; i < numTransitions; ++i) { |
| 588 | mTransitions.get(i).setEpicenterCallback(epicenterCallback); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | @Override |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 593 | String toString(String indent) { |
| 594 | String result = super.toString(indent); |
| 595 | for (int i = 0; i < mTransitions.size(); ++i) { |
| 596 | result += "\n" + mTransitions.get(i).toString(indent + " "); |
| 597 | } |
| 598 | return result; |
| 599 | } |
| 600 | |
| 601 | @Override |
| 602 | public TransitionSet clone() { |
| 603 | TransitionSet clone = (TransitionSet) super.clone(); |
| 604 | clone.mTransitions = new ArrayList<Transition>(); |
| 605 | int numTransitions = mTransitions.size(); |
| 606 | for (int i = 0; i < numTransitions; ++i) { |
Chet Haase | c46181a | 2013-09-16 13:56:21 -0700 | [diff] [blame] | 607 | clone.addTransition((Transition) mTransitions.get(i).clone()); |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 608 | } |
| 609 | return clone; |
| 610 | } |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 611 | } |