Skip to content

Commit a7e88d6

Browse files
chethaaseAndroid (Google) Code Review
authored andcommitted
Merge "Add end functionality to LayoutTransition"
2 parents 65e7815 + d56c695 commit a7e88d6

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

core/java/android/animation/LayoutTransition.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,14 +793,33 @@ public void onAnimationEnd(Animator animator) {
793793
* @hide
794794
*/
795795
public void startChangingAnimations() {
796-
for (Animator anim : currentChangingAnimations.values()) {
796+
LinkedHashMap<View, Animator> currentAnimCopy =
797+
(LinkedHashMap<View, Animator>) currentChangingAnimations.clone();
798+
for (Animator anim : currentAnimCopy.values()) {
797799
if (anim instanceof ObjectAnimator) {
798800
((ObjectAnimator) anim).setCurrentPlayTime(0);
799801
}
800802
anim.start();
801803
}
802804
}
803805

806+
/**
807+
* Ends the animations that are set up for a CHANGING transition. This is a variant of
808+
* startChangingAnimations() which is called when the window the transition is playing in
809+
* is not visible. We need to make sure the animations put their targets in their end states
810+
* and that the transition finishes to remove any mid-process state (such as isRunning()).
811+
*
812+
* @hide
813+
*/
814+
public void endChangingAnimations() {
815+
LinkedHashMap<View, Animator> currentAnimCopy =
816+
(LinkedHashMap<View, Animator>) currentChangingAnimations.clone();
817+
for (Animator anim : currentAnimCopy.values()) {
818+
anim.start();
819+
anim.end();
820+
}
821+
}
822+
804823
/**
805824
* Returns true if animations are running which animate layout-related properties. This
806825
* essentially means that either CHANGE_APPEARING or CHANGE_DISAPPEARING animations

core/java/android/view/ViewRootImpl.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,13 +1575,13 @@ private void performTraversals() {
15751575
boolean cancelDraw = attachInfo.mTreeObserver.dispatchOnPreDraw() ||
15761576
viewVisibility != View.VISIBLE;
15771577

1578-
if (mPendingTransitions != null && mPendingTransitions.size() > 0) {
1579-
for (int i = 0; i < mPendingTransitions.size(); ++i) {
1580-
mPendingTransitions.get(i).startChangingAnimations();
1581-
}
1582-
mPendingTransitions.clear();
1583-
}
15841578
if (!cancelDraw && !newSurface) {
1579+
if (mPendingTransitions != null && mPendingTransitions.size() > 0) {
1580+
for (int i = 0; i < mPendingTransitions.size(); ++i) {
1581+
mPendingTransitions.get(i).startChangingAnimations();
1582+
}
1583+
mPendingTransitions.clear();
1584+
}
15851585
mFullRedrawNeeded = false;
15861586

15871587
final long drawStartTime;
@@ -1619,7 +1619,13 @@ private void performTraversals() {
16191619
}
16201620
}
16211621
} else {
1622-
1622+
// End any pending transitions on this non-visible window
1623+
if (mPendingTransitions != null && mPendingTransitions.size() > 0) {
1624+
for (int i = 0; i < mPendingTransitions.size(); ++i) {
1625+
mPendingTransitions.get(i).endChangingAnimations();
1626+
}
1627+
mPendingTransitions.clear();
1628+
}
16231629
// We were supposed to report when we are done drawing. Since we canceled the
16241630
// draw, remember it here.
16251631
if ((relayoutResult&WindowManagerImpl.RELAYOUT_FIRST_TIME) != 0) {

0 commit comments

Comments
 (0)