Merge "Merge commit 'e4c7e61dbe94a77c5389eb20952d6b7ed6536caf'"
diff --git a/api/current.txt b/api/current.txt
index 8b9b4e7..5d69d6a 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -1536,6 +1536,8 @@
     method public void captureEndValues(android.support.transition.TransitionValues);
     method public void captureStartValues(android.support.transition.TransitionValues);
     method public int getOrdering();
+    method public android.support.transition.Transition getTransitionAt(int);
+    method public int getTransitionCount();
     method public android.support.transition.TransitionSet removeTransition(android.support.transition.Transition);
     method public android.support.transition.TransitionSet setOrdering(int);
     field public static final int ORDERING_SEQUENTIAL = 1; // 0x1
diff --git a/transition/src/android/support/transition/TransitionSet.java b/transition/src/android/support/transition/TransitionSet.java
index add83c4..66f8109 100644
--- a/transition/src/android/support/transition/TransitionSet.java
+++ b/transition/src/android/support/transition/TransitionSet.java
@@ -129,6 +129,31 @@
     }
 
     /**
+     * Returns the number of child transitions in the TransitionSet.
+     *
+     * @return The number of child transitions in the TransitionSet.
+     * @see #addTransition(Transition)
+     * @see #getTransitionAt(int)
+     */
+    public int getTransitionCount() {
+        return mTransitions.size();
+    }
+
+    /**
+     * Returns the child Transition at the specified position in the TransitionSet.
+     *
+     * @param index The position of the Transition to retrieve.
+     * @see #addTransition(Transition)
+     * @see #getTransitionCount()
+     */
+    public Transition getTransitionAt(int index) {
+        if (index < 0 || index >= mTransitions.size()) {
+            return null;
+        }
+        return mTransitions.get(index);
+    }
+
+    /**
      * Setting a non-negative duration on a TransitionSet causes all of the child
      * transitions (current and future) to inherit this duration.
      *
@@ -180,6 +205,24 @@
 
     @NonNull
     @Override
+    public TransitionSet addTarget(@NonNull String targetName) {
+        for (int i = 0; i < mTransitions.size(); i++) {
+            mTransitions.get(i).addTarget(targetName);
+        }
+        return (TransitionSet) super.addTarget(targetName);
+    }
+
+    @NonNull
+    @Override
+    public TransitionSet addTarget(@NonNull Class targetType) {
+        for (int i = 0; i < mTransitions.size(); i++) {
+            mTransitions.get(i).addTarget(targetType);
+        }
+        return (TransitionSet) super.addTarget(targetType);
+    }
+
+    @NonNull
+    @Override
     public TransitionSet addListener(@NonNull TransitionListener listener) {
         return (TransitionSet) super.addListener(listener);
     }
@@ -204,6 +247,60 @@
 
     @NonNull
     @Override
+    public TransitionSet removeTarget(@NonNull Class target) {
+        for (int i = 0; i < mTransitions.size(); i++) {
+            mTransitions.get(i).removeTarget(target);
+        }
+        return (TransitionSet) super.removeTarget(target);
+    }
+
+    @NonNull
+    @Override
+    public TransitionSet removeTarget(@NonNull String target) {
+        for (int i = 0; i < mTransitions.size(); i++) {
+            mTransitions.get(i).removeTarget(target);
+        }
+        return (TransitionSet) super.removeTarget(target);
+    }
+
+    @NonNull
+    @Override
+    public Transition excludeTarget(@NonNull View target, boolean exclude) {
+        for (int i = 0; i < mTransitions.size(); i++) {
+            mTransitions.get(i).excludeTarget(target, exclude);
+        }
+        return super.excludeTarget(target, exclude);
+    }
+
+    @NonNull
+    @Override
+    public Transition excludeTarget(@NonNull String targetName, boolean exclude) {
+        for (int i = 0; i < mTransitions.size(); i++) {
+            mTransitions.get(i).excludeTarget(targetName, exclude);
+        }
+        return super.excludeTarget(targetName, exclude);
+    }
+
+    @NonNull
+    @Override
+    public Transition excludeTarget(int targetId, boolean exclude) {
+        for (int i = 0; i < mTransitions.size(); i++) {
+            mTransitions.get(i).excludeTarget(targetId, exclude);
+        }
+        return super.excludeTarget(targetId, exclude);
+    }
+
+    @NonNull
+    @Override
+    public Transition excludeTarget(@NonNull Class type, boolean exclude) {
+        for (int i = 0; i < mTransitions.size(); i++) {
+            mTransitions.get(i).excludeTarget(type, exclude);
+        }
+        return super.excludeTarget(type, exclude);
+    }
+
+    @NonNull
+    @Override
     public TransitionSet removeListener(@NonNull TransitionListener listener) {
         return (TransitionSet) super.removeListener(listener);
     }
diff --git a/transition/tests/src/android/support/transition/TransitionSetTest.java b/transition/tests/src/android/support/transition/TransitionSetTest.java
new file mode 100644
index 0000000..aec9ecb
--- /dev/null
+++ b/transition/tests/src/android/support/transition/TransitionSetTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.support.transition;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.sameInstance;
+
+import android.support.test.filters.MediumTest;
+import android.support.transition.test.R;
+import android.view.View;
+
+import org.junit.Before;
+import org.junit.Test;
+
+@MediumTest
+public class TransitionSetTest extends BaseTest {
+
+    private final TransitionSet mTransitionSet = new TransitionSet();
+    private final Transition mTransition = new TransitionTest.EmptyTransition();
+
+    @Before
+    public void setUp() {
+        // mTransitionSet has 1 item from the start
+        mTransitionSet.addTransition(mTransition);
+    }
+
+    @Test
+    public void testOrdering() {
+        assertThat(mTransitionSet.getOrdering(), is(TransitionSet.ORDERING_TOGETHER));
+        assertThat(mTransitionSet.setOrdering(TransitionSet.ORDERING_SEQUENTIAL),
+                is(sameInstance(mTransitionSet)));
+        assertThat(mTransitionSet.getOrdering(), is(TransitionSet.ORDERING_SEQUENTIAL));
+    }
+
+    @Test
+    public void testAddAndRemoveTransition() {
+        assertThat(mTransitionSet.getTransitionCount(), is(1));
+        assertThat(mTransitionSet.getTransitionAt(0), is(sameInstance(mTransition)));
+        Transition anotherTransition = new TransitionTest.EmptyTransition();
+        assertThat(mTransitionSet.addTransition(anotherTransition),
+                is(sameInstance(mTransitionSet)));
+        assertThat(mTransitionSet.getTransitionCount(), is(2));
+        assertThat(mTransitionSet.getTransitionAt(0), is(sameInstance(mTransition)));
+        assertThat(mTransitionSet.getTransitionAt(1), is(sameInstance(anotherTransition)));
+        assertThat(mTransitionSet.removeTransition(mTransition),
+                is(sameInstance(mTransitionSet)));
+        assertThat(mTransitionSet.getTransitionCount(), is(1));
+    }
+
+    @Test
+    public void testSetDuration() {
+        assertThat(mTransitionSet.setDuration(123), is(sameInstance(mTransitionSet)));
+        assertThat(mTransitionSet.getDuration(), is(123L));
+        assertThat(mTransition.getDuration(), is(123L));
+    }
+
+    @Test
+    public void testTargetId() {
+        assertThat(mTransitionSet.addTarget(R.id.view0), is(sameInstance(mTransitionSet)));
+        assertThat(mTransitionSet.getTargetIds(), hasItem(R.id.view0));
+        assertThat(mTransitionSet.getTargetIds(), hasSize(1));
+        assertThat(mTransition.getTargetIds(), hasItem(R.id.view0));
+        assertThat(mTransition.getTargetIds(), hasSize(1));
+        assertThat(mTransitionSet.removeTarget(R.id.view0), is(sameInstance(mTransitionSet)));
+        assertThat(mTransitionSet.getTargetIds(), hasSize(0));
+        assertThat(mTransition.getTargetIds(), hasSize(0));
+    }
+
+    @Test
+    public void testTargetView() {
+        final View view = new View(rule.getActivity());
+        assertThat(mTransitionSet.addTarget(view), is(sameInstance(mTransitionSet)));
+        assertThat(mTransitionSet.getTargets(), hasItem(view));
+        assertThat(mTransitionSet.getTargets(), hasSize(1));
+        assertThat(mTransition.getTargets(), hasItem(view));
+        assertThat(mTransition.getTargets(), hasSize(1));
+        assertThat(mTransitionSet.removeTarget(view), is(sameInstance(mTransitionSet)));
+        assertThat(mTransitionSet.getTargets(), hasSize(0));
+        assertThat(mTransition.getTargets(), hasSize(0));
+    }
+
+    @Test
+    public void testTargetName() {
+        assertThat(mTransitionSet.addTarget("abc"), is(sameInstance(mTransitionSet)));
+        assertThat(mTransitionSet.getTargetNames(), hasItem("abc"));
+        assertThat(mTransitionSet.getTargetNames(), hasSize(1));
+        assertThat(mTransition.getTargetNames(), hasItem("abc"));
+        assertThat(mTransition.getTargetNames(), hasSize(1));
+        assertThat(mTransitionSet.removeTarget("abc"), is(sameInstance(mTransitionSet)));
+        assertThat(mTransitionSet.getTargetNames(), hasSize(0));
+        assertThat(mTransition.getTargetNames(), hasSize(0));
+    }
+
+    @Test
+    public void testTargetClass() {
+        assertThat(mTransitionSet.addTarget(View.class), is(sameInstance(mTransitionSet)));
+        assertThat(mTransitionSet.getTargetTypes(), hasItem(View.class));
+        assertThat(mTransitionSet.getTargetTypes(), hasSize(1));
+        assertThat(mTransition.getTargetTypes(), hasItem(View.class));
+        assertThat(mTransition.getTargetTypes(), hasSize(1));
+        assertThat(mTransitionSet.removeTarget(View.class), is(sameInstance(mTransitionSet)));
+        assertThat(mTransitionSet.getTargetTypes(), hasSize(0));
+        assertThat(mTransition.getTargetTypes(), hasSize(0));
+    }
+
+}