From 45feb95c4a18c5da93da72f448003857b6226082 Mon Sep 17 00:00:00 2001 From: George Mount Date: Wed, 10 Feb 2016 15:14:17 -0800 Subject: [PATCH] Null check for fade start alpha value. Bug 27105186 Fade previously hadn't had any values saved over those captured by Visibility. If a Transition merged two Visibility transitions, it could avoid calling captureStartValues for the Fade transition. This change prevents an NPE in that case. The combined transition won't get the intermediate alpha value, but at least it won't crash. Change-Id: I8e5720caafda56b017dfe1cc0b16ebdf246e90c4 --- core/java/android/transition/Fade.java | 29 +++++++++++++++----------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/core/java/android/transition/Fade.java b/core/java/android/transition/Fade.java index b2e8d3351028c..627183f0cf243 100644 --- a/core/java/android/transition/Fade.java +++ b/core/java/android/transition/Fade.java @@ -16,8 +16,6 @@ package android.transition; -import com.android.internal.R; - import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; @@ -28,6 +26,8 @@ import android.util.Log; import android.view.View; import android.view.ViewGroup; +import com.android.internal.R; + /** * This transition tracks changes to the visibility of target views in the * start and end scenes and fades views in or out when they become visible @@ -144,12 +144,9 @@ public class Fade extends Visibility { Log.d(LOG_TAG, "Fade.onAppear: startView, startVis, endView, endVis = " + startView + ", " + view); } - float startAlpha = 0; - if (startValues != null) { - startAlpha = (Float) startValues.values.get(PROPNAME_TRANSITION_ALPHA); - if (startAlpha == 1) { - startAlpha = 0; - } + float startAlpha = getStartAlpha(startValues, 0); + if (startAlpha == 1) { + startAlpha = 0; } return createAnimation(view, startAlpha, 1); } @@ -157,13 +154,21 @@ public class Fade extends Visibility { @Override public Animator onDisappear(ViewGroup sceneRoot, final View view, TransitionValues startValues, TransitionValues endValues) { - float startAlpha = 1; - if (startValues != null) { - startAlpha = (Float) startValues.values.get(PROPNAME_TRANSITION_ALPHA); - } + float startAlpha = getStartAlpha(startValues, 1); return createAnimation(view, startAlpha, 0); } + private static float getStartAlpha(TransitionValues startValues, float fallbackValue) { + float startAlpha = fallbackValue; + if (startValues != null) { + Float startAlphaFloat = (Float) startValues.values.get(PROPNAME_TRANSITION_ALPHA); + if (startAlphaFloat != null) { + startAlpha = startAlphaFloat; + } + } + return startAlpha; + } + private static class FadeAnimatorListener extends AnimatorListenerAdapter { private final View mView; private boolean mLayerTypeChanged = false;