1/* 2 * Copyright (C) 2016 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 17package android.support.transition; 18 19import android.animation.Animator; 20import android.os.Build; 21import android.support.annotation.NonNull; 22import android.support.annotation.Nullable; 23import android.view.ViewGroup; 24 25/** 26 * A TransitionSet is a parent of child transitions (including other 27 * TransitionSets). Using TransitionSets enables more complex 28 * choreography of transitions, where some sets play {@link #ORDERING_TOGETHER} and 29 * others play {@link #ORDERING_SEQUENTIAL}. For example, {@link AutoTransition} 30 * uses a TransitionSet to sequentially play a Fade(Fade.OUT), followed by 31 * a {@link ChangeBounds}, followed by a Fade(Fade.OUT) transition. 32 * 33 * <p>Unlike the platform version, this does not support declaration by XML resources.</p> 34 */ 35public class TransitionSet extends Transition { 36 37 /** 38 * A flag used to indicate that the child transitions of this set 39 * should all start at the same time. 40 */ 41 public static final int ORDERING_TOGETHER = 0; 42 43 /** 44 * A flag used to indicate that the child transitions of this set should 45 * play in sequence; when one child transition ends, the next child 46 * transition begins. Note that a transition does not end until all 47 * instances of it (which are playing on all applicable targets of the 48 * transition) end. 49 */ 50 public static final int ORDERING_SEQUENTIAL = 1; 51 52 /** 53 * Constructs an empty transition set. Add child transitions to the 54 * set by calling {@link #addTransition(Transition)} )}. By default, 55 * child transitions will play {@link #ORDERING_TOGETHER together}. 56 */ 57 public TransitionSet() { 58 super(true); 59 if (Build.VERSION.SDK_INT < 19) { 60 mImpl = new TransitionSetIcs(this); 61 } else { 62 mImpl = new TransitionSetKitKat(this); 63 } 64 } 65 66 /** 67 * Returns the ordering of this TransitionSet. By default, the value is 68 * {@link #ORDERING_TOGETHER}. 69 * 70 * @return {@link #ORDERING_TOGETHER} if child transitions will play at the same 71 * time, {@link #ORDERING_SEQUENTIAL} if they will play in sequence. 72 * @see #setOrdering(int) 73 */ 74 public int getOrdering() { 75 return ((TransitionSetImpl) mImpl).getOrdering(); 76 } 77 78 /** 79 * Sets the play order of this set's child transitions. 80 * 81 * @param ordering {@link #ORDERING_TOGETHER} to play this set's child 82 * transitions together, {@link #ORDERING_SEQUENTIAL} to play the child 83 * transitions in sequence. 84 * @return This transitionSet object. 85 */ 86 @NonNull 87 public TransitionSet setOrdering(int ordering) { 88 ((TransitionSetImpl) mImpl).setOrdering(ordering); 89 return this; 90 } 91 92 /** 93 * Adds child transition to this set. The order in which this child transition 94 * is added relative to other child transitions that are added, in addition to 95 * the {@link #getOrdering() ordering} property, determines the 96 * order in which the transitions are started. 97 * 98 * <p>If this transitionSet has a {@link #getDuration() duration} set on it, the 99 * child transition will inherit that duration. Transitions are assumed to have 100 * a maximum of one transitionSet parent.</p> 101 * 102 * @param transition A non-null child transition to be added to this set. 103 * @return This transitionSet object. 104 */ 105 @NonNull 106 public TransitionSet addTransition(@NonNull Transition transition) { 107 ((TransitionSetImpl) mImpl).addTransition(transition.mImpl); 108 return this; 109 } 110 111 /** 112 * Removes the specified child transition from this set. 113 * 114 * @param transition The transition to be removed. 115 * @return This transitionSet object. 116 */ 117 @NonNull 118 public TransitionSet removeTransition(@NonNull Transition transition) { 119 ((TransitionSetImpl) mImpl).removeTransition(transition.mImpl); 120 return this; 121 } 122 123 @Override 124 public void captureEndValues(@NonNull TransitionValues transitionValues) { 125 mImpl.captureEndValues(transitionValues); 126 } 127 128 @Override 129 public void captureStartValues(@NonNull TransitionValues transitionValues) { 130 mImpl.captureStartValues(transitionValues); 131 } 132 133 @Override 134 @Nullable 135 public Animator createAnimator(@NonNull ViewGroup sceneRoot, 136 @NonNull TransitionValues startValues, @NonNull TransitionValues endValues) { 137 return mImpl.createAnimator(sceneRoot, startValues, endValues); 138 } 139 140} 141