From 41e5314a578551fc4611ff145d389184184589ea Mon Sep 17 00:00:00 2001 From: keyboardr Date: Wed, 28 Jun 2017 11:47:12 -0700 Subject: Avoid NPE in ChangeOnScreenBounds when the start or end values are not populated. Will just return null in createAnimation() thus not animating (this will likely only happen if the View hasn't laid out yet, so there's nothing to animate from). Bug: 63054791 Test: ChangeOnScreenBoundsTest.java PiperOrigin-RevId: 160433277 Change-Id: Ib87d274fd6f109290ec74f2241e2fb559d6138cd --- .../dialershared/bubble/ChangeOnScreenBounds.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'java/com/android/dialershared') diff --git a/java/com/android/dialershared/bubble/ChangeOnScreenBounds.java b/java/com/android/dialershared/bubble/ChangeOnScreenBounds.java index 4da6a3561..37c820447 100644 --- a/java/com/android/dialershared/bubble/ChangeOnScreenBounds.java +++ b/java/com/android/dialershared/bubble/ChangeOnScreenBounds.java @@ -22,6 +22,7 @@ import android.animation.ObjectAnimator; import android.graphics.Path; import android.graphics.PointF; import android.graphics.Rect; +import android.support.annotation.VisibleForTesting; import android.transition.Transition; import android.transition.TransitionValues; import android.util.Property; @@ -31,9 +32,14 @@ import android.view.ViewGroup; /** Similar to {@link android.transition.ChangeBounds ChangeBounds} but works across windows */ public class ChangeOnScreenBounds extends Transition { - private static final String PROPNAME_BOUNDS = "bubble:changeScreenBounds:bounds"; - private static final String PROPNAME_SCREEN_X = "bubble:changeScreenBounds:screenX"; - private static final String PROPNAME_SCREEN_Y = "bubble:changeScreenBounds:screenY"; + @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) + static final String PROPNAME_BOUNDS = "bubble:changeScreenBounds:bounds"; + + @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) + static final String PROPNAME_SCREEN_X = "bubble:changeScreenBounds:screenX"; + + @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) + static final String PROPNAME_SCREEN_Y = "bubble:changeScreenBounds:screenY"; private static final Property TOP_LEFT_PROPERTY = new Property(PointF.class, "topLeft") { @@ -89,6 +95,12 @@ public class ChangeOnScreenBounds extends Transition { public Animator createAnimator( ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { Rect startBounds = (Rect) startValues.values.get(PROPNAME_BOUNDS); + Rect endBounds = (Rect) endValues.values.get(PROPNAME_BOUNDS); + + if (startBounds == null || endBounds == null) { + // start or end values were not captured, so don't animate. + return null; + } // Offset the startBounds by the difference in screen position int startScreenX = (Integer) startValues.values.get(PROPNAME_SCREEN_X); @@ -97,7 +109,6 @@ public class ChangeOnScreenBounds extends Transition { int endScreenY = (Integer) endValues.values.get(PROPNAME_SCREEN_Y); startBounds.offset(startScreenX - endScreenX, startScreenY - endScreenY); - Rect endBounds = (Rect) endValues.values.get(PROPNAME_BOUNDS); final int startLeft = startBounds.left; final int endLeft = endBounds.left; final int startTop = startBounds.top; -- cgit v1.2.3