From 6de56bb07ec58480983932cb055aa9ed2ddfcc99 Mon Sep 17 00:00:00 2001 From: George Mount Date: Tue, 6 May 2014 17:19:14 -0700 Subject: Fix mismatch in Transition ID/instances Bug 14597573 In a Transition, when a View is removed from a Scene and that View has an ID in common with another View in the end Scene, it will be matched, even if the View in the start Scene already had a matching View by instance. This CL prevents a match by ID when an instance match is available. Future: disable matching when two views have the same ID. Change-Id: I0e51d1f2d0a2d05d09e8e135f090d0e1b2a67efc --- core/java/android/transition/Transition.java | 60 ++++++---------------------- 1 file changed, 13 insertions(+), 47 deletions(-) (limited to 'core/java/android/transition/Transition.java') diff --git a/core/java/android/transition/Transition.java b/core/java/android/transition/Transition.java index 2549fde62634..49a0138734bb 100644 --- a/core/java/android/transition/Transition.java +++ b/core/java/android/transition/Transition.java @@ -351,18 +351,8 @@ public abstract class Transition implements Cloneable { } ArrayMap endCopy = new ArrayMap(endValues.viewValues); - SparseArray endIdCopy = - new SparseArray(endValues.idValues.size()); - for (int i = 0; i < endValues.idValues.size(); ++i) { - int id = endValues.idValues.keyAt(i); - endIdCopy.put(id, endValues.idValues.valueAt(i)); - } - LongSparseArray endItemIdCopy = - new LongSparseArray(endValues.itemIdValues.size()); - for (int i = 0; i < endValues.itemIdValues.size(); ++i) { - long id = endValues.itemIdValues.keyAt(i); - endItemIdCopy.put(id, endValues.itemIdValues.valueAt(i)); - } + SparseArray endIdCopy = endValues.idValues.clone(); + LongSparseArray endItemIdCopy = endValues.itemIdValues.clone(); // Walk through the start values, playing everything we find // Remove from the end set as we go ArrayList startValuesList = new ArrayList(); @@ -376,21 +366,17 @@ public abstract class Transition implements Cloneable { } if (!isInListView) { int id = view.getId(); - start = startValues.viewValues.get(view) != null ? - startValues.viewValues.get(view) : startValues.idValues.get(id); - if (endValues.viewValues.get(view) != null) { - end = endValues.viewValues.get(view); + start = startValues.viewValues.get(view); + end = endValues.viewValues.get(view); + if (end != null) { endCopy.remove(view); } else if (id != View.NO_ID) { - end = endValues.idValues.get(id); - View removeView = null; - for (View viewToRemove : endCopy.keySet()) { - if (viewToRemove.getId() == id) { - removeView = viewToRemove; - } - } - if (removeView != null) { - endCopy.remove(removeView); + end = endIdCopy.get(id); + if (end == null || startValues.viewValues.containsKey(end.view)) { + end = null; + id = View.NO_ID; + } else { + endCopy.remove(end.view); } } endIdCopy.remove(id); @@ -423,36 +409,16 @@ public abstract class Transition implements Cloneable { } } // Now walk through the remains of the end set + // We've already matched everything from start to end, everything else doesn't match. for (View view : endCopy.keySet()) { int id = view.getId(); if (isValidTarget(view, id)) { - TransitionValues start = startValues.viewValues.get(view) != null ? - startValues.viewValues.get(view) : startValues.idValues.get(id); + TransitionValues start = null; TransitionValues end = endCopy.get(view); - endIdCopy.remove(id); startValuesList.add(start); endValuesList.add(end); } } - int endIdCopySize = endIdCopy.size(); - for (int i = 0; i < endIdCopySize; ++i) { - int id = endIdCopy.keyAt(i); - if (isValidTarget(null, id)) { - TransitionValues start = startValues.idValues.get(id); - TransitionValues end = endIdCopy.get(id); - startValuesList.add(start); - endValuesList.add(end); - } - } - int endItemIdCopySize = endItemIdCopy.size(); - for (int i = 0; i < endItemIdCopySize; ++i) { - long id = endItemIdCopy.keyAt(i); - // TODO: Deal with targetIDs and itemIDs - TransitionValues start = startValues.itemIdValues.get(id); - TransitionValues end = endItemIdCopy.get(id); - startValuesList.add(start); - endValuesList.add(end); - } ArrayMap runningAnimators = getRunningAnimators(); long minStartDelay = Long.MAX_VALUE; int minAnimator = mAnimators.size(); -- cgit v1.2.3