From c5dede2bcac536580b7cfa14889f3d218bbb7834 Mon Sep 17 00:00:00 2001 From: Andrey Kulikov Date: Wed, 31 Oct 2018 14:32:26 +0000 Subject: [PATCH] Improve platform TransitionSet behavior 1) Allow override values for a children of TransitionSet. For example for usages like this: TransitionSet set = new TransitionSet().setDuration(300); Fade fade = new Fade(); set.addTransition(fade); fade.setDuration(100); The result duration applied for fade transition is still 300. And it breaks all the flexibility of configuring sets. The reason of it is clone() method which will be executed in beginDelayedTransition. And as part of clone() implementation of TransitionSet the children will be re-added to the new cloned set and set's duration will be re-applied again. To fix it I changed how we add transitions into set in clone(). 2) Recently we had a bug about TransitionSet will crash during inflation if we provide duration for it via xml. I fixed similar issue for applying a path motion. Test: added new tests for both issues Change in AndroidX: aosp/803493 Bug: 64644617 Change-Id: If205845a83e29d49f8cced8a53d9f56a4ad740aa --- core/java/android/transition/TransitionSet.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/java/android/transition/TransitionSet.java b/core/java/android/transition/TransitionSet.java index 589ad574dd9b2..b9b2a70d32b19 100644 --- a/core/java/android/transition/TransitionSet.java +++ b/core/java/android/transition/TransitionSet.java @@ -163,8 +163,7 @@ public class TransitionSet extends Transition { */ public TransitionSet addTransition(Transition transition) { if (transition != null) { - mTransitions.add(transition); - transition.mParent = this; + addTransitionInternal(transition); if (mDuration >= 0) { transition.setDuration(mDuration); } @@ -184,6 +183,11 @@ public class TransitionSet extends Transition { return this; } + private void addTransitionInternal(Transition transition) { + mTransitions.add(transition); + transition.mParent = this; + } + /** * Returns the number of child transitions in the TransitionSet. * @@ -355,8 +359,10 @@ public class TransitionSet extends Transition { public void setPathMotion(PathMotion pathMotion) { super.setPathMotion(pathMotion); mChangeFlags |= FLAG_CHANGE_PATH_MOTION; - for (int i = 0; i < mTransitions.size(); i++) { - mTransitions.get(i).setPathMotion(pathMotion); + if (mTransitions != null) { + for (int i = 0; i < mTransitions.size(); i++) { + mTransitions.get(i).setPathMotion(pathMotion); + } } } @@ -604,7 +610,7 @@ public class TransitionSet extends Transition { clone.mTransitions = new ArrayList(); int numTransitions = mTransitions.size(); for (int i = 0; i < numTransitions; ++i) { - clone.addTransition((Transition) mTransitions.get(i).clone()); + clone.addTransitionInternal((Transition) mTransitions.get(i).clone()); } return clone; }