From f81c6af10ef3041eeddb4a4560611a17dd3d399b Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Mon, 20 Oct 2014 14:42:53 -0700 Subject: Propagate state changes even when we don't change drawable index Previously we could miss the state change if we were simply reversing the current transition. BUG: 17967405 Change-Id: I2cb396dedbff61b980741ef8c0d931be6abe129c --- .../drawable/AnimatedStateListDrawable.java | 30 +++++++--------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'graphics') diff --git a/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java b/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java index 9bcad3e..849faec 100644 --- a/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedStateListDrawable.java @@ -139,27 +139,15 @@ public class AnimatedStateListDrawable extends StateListDrawable { @Override protected boolean onStateChange(int[] stateSet) { - final int keyframeIndex = mState.indexOfKeyframe(stateSet); - if (keyframeIndex == getCurrentIndex()) { - // Propagate state change to current keyframe. - final Drawable current = getCurrent(); - if (current != null) { - return current.setState(stateSet); - } - return false; - } - - // Attempt to find a valid transition to the keyframe. - if (selectTransition(keyframeIndex)) { - return true; - } - - // No valid transition, attempt to jump directly to the keyframe. - if (selectDrawable(keyframeIndex)) { - return true; - } - - return super.onStateChange(stateSet); + // If we're not already at the target index, either attempt to find a + // valid transition to it or jump directly there. + final int targetIndex = mState.indexOfKeyframe(stateSet); + final boolean changedIndex = targetIndex != getCurrentIndex() + && (selectTransition(targetIndex) || selectDrawable(targetIndex)); + + // Always call super.onStateChanged() to propagate the state change to + // the current drawable. + return super.onStateChange(stateSet) || changedIndex; } private boolean selectTransition(int toIndex) { -- cgit v1.1