From 23c61f6bc57a611d97d333bce0d8fe00ab81af4c Mon Sep 17 00:00:00 2001 From: Chet Haase Date: Sat, 14 Sep 2013 11:28:46 -0700 Subject: [PATCH] Ensure that transitions animating alpha end on a reasonable value The Fade transition sets an initial alpha value of 0 when items are appearing. This makes items invisible to start with, and then they eventually fade in as part of the transition when the transition's animation runs. But if that animation/transition gets interrupted, or not started, then the alpha value would not be restored, and the value would stay 0, making the items invisible indefinitely. This is what was happening in the action bar of the People app when performing a search. The fix is to handle Transition and animation events to restore the alpha to its true value when the transition completes, whether that transition is canceled or not. Issue #10726905 ActionBar weirdness in People app Change-Id: Idb65fd8d471d2ac0a1ddc243fee00ae99f7e72d8 --- core/java/android/transition/Fade.java | 34 ++++++++++++++++++- core/java/android/transition/Transition.java | 7 ++-- .../android/transition/TransitionManager.java | 32 ++++++++--------- 3 files changed, 51 insertions(+), 22 deletions(-) diff --git a/core/java/android/transition/Fade.java b/core/java/android/transition/Fade.java index 12e0d73db3893..4cc2c4280d745 100644 --- a/core/java/android/transition/Fade.java +++ b/core/java/android/transition/Fade.java @@ -91,6 +91,9 @@ public class Fade extends Visibility { return null; } final ObjectAnimator anim = ObjectAnimator.ofFloat(view, "alpha", startAlpha, endAlpha); + if (DBG) { + Log.d(LOG_TAG, "Created animator " + anim); + } if (listener != null) { anim.addListener(listener); anim.addPauseListener(listener); @@ -146,12 +149,41 @@ public class Fade extends Visibility { final View endView = endValues.view; if (DBG) { View startView = (startValues != null) ? startValues.view : null; - Log.d(LOG_TAG, "Fade.onDisappear: startView, startVis, endView, endVis = " + + Log.d(LOG_TAG, "Fade.onAppear: startView, startVis, endView, endVis = " + startView + ", " + startVisibility + ", " + endView + ", " + endVisibility); } // if alpha < 1, just fade it in from the current value if (endView.getAlpha() == 1.0f) { endView.setAlpha(0); + TransitionListener transitionListener = new TransitionListenerAdapter() { + boolean mCanceled = false; + float mPausedAlpha; + + @Override + public void onTransitionCancel(Transition transition) { + endView.setAlpha(1); + mCanceled = true; + } + + @Override + public void onTransitionEnd(Transition transition) { + if (!mCanceled) { + endView.setAlpha(1); + } + } + + @Override + public void onTransitionPause(Transition transition) { + mPausedAlpha = endView.getAlpha(); + endView.setAlpha(1); + } + + @Override + public void onTransitionResume(Transition transition) { + endView.setAlpha(mPausedAlpha); + } + }; + addListener(transitionListener); } return createAnimation(endView, endView.getAlpha(), 1, null); } diff --git a/core/java/android/transition/Transition.java b/core/java/android/transition/Transition.java index 2fb32aafad0ce..60b47087fe44c 100644 --- a/core/java/android/transition/Transition.java +++ b/core/java/android/transition/Transition.java @@ -1240,12 +1240,13 @@ public abstract class Transition implements Cloneable { View oldView = oldInfo.view; TransitionValues newValues = mEndValues.viewValues != null ? mEndValues.viewValues.get(oldView) : null; + if (newValues == null) { + newValues = mEndValues.idValues.get(oldView.getId()); + } if (oldValues != null) { // if oldValues null, then transition didn't care to stash values, // and won't get canceled - if (newValues == null) { - cancel = true; - } else { + if (newValues != null) { for (String key : oldValues.values.keySet()) { Object oldValue = oldValues.values.get(key); Object newValue = newValues.values.get(key); diff --git a/core/java/android/transition/TransitionManager.java b/core/java/android/transition/TransitionManager.java index 727a98dceb9a8..44ca4e58fd946 100644 --- a/core/java/android/transition/TransitionManager.java +++ b/core/java/android/transition/TransitionManager.java @@ -349,23 +349,19 @@ public class TransitionManager { * value of null causes the TransitionManager to use the default transition. */ public static void beginDelayedTransition(final ViewGroup sceneRoot, Transition transition) { - - // TEMPORARY: disabling delayed transitions until a fix for the various ActionBar- - // triggered artifacts is found - -// if (!sPendingTransitions.contains(sceneRoot) && sceneRoot.isLaidOut()) { -// if (Transition.DBG) { -// Log.d(LOG_TAG, "beginDelayedTransition: root, transition = " + -// sceneRoot + ", " + transition); -// } -// sPendingTransitions.add(sceneRoot); -// if (transition == null) { -// transition = sDefaultTransition; -// } -// final Transition transitionClone = transition.clone(); -// sceneChangeSetup(sceneRoot, transitionClone); -// Scene.setCurrentScene(sceneRoot, null); -// sceneChangeRunTransition(sceneRoot, transitionClone); -// } + if (!sPendingTransitions.contains(sceneRoot) && sceneRoot.isLaidOut()) { + if (Transition.DBG) { + Log.d(LOG_TAG, "beginDelayedTransition: root, transition = " + + sceneRoot + ", " + transition); + } + sPendingTransitions.add(sceneRoot); + if (transition == null) { + transition = sDefaultTransition; + } + final Transition transitionClone = transition.clone(); + sceneChangeSetup(sceneRoot, transitionClone); + Scene.setCurrentScene(sceneRoot, null); + sceneChangeRunTransition(sceneRoot, transitionClone); + } } }