diff options
author | keyboardr <keyboardr@google.com> | 2017-06-28 11:47:12 -0700 |
---|---|---|
committer | Brandon Maxwell <maxwelb@google.com> | 2017-06-30 14:38:25 -0700 |
commit | 41e5314a578551fc4611ff145d389184184589ea (patch) | |
tree | e5908f5d130537674d35e84033354e2322eebe33 | |
parent | 7f10924e13a030fa82b58d3443af56ba63ba8271 (diff) |
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
-rw-r--r-- | java/com/android/dialershared/bubble/ChangeOnScreenBounds.java | 19 |
1 files changed, 15 insertions, 4 deletions
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<ViewBounds, PointF> TOP_LEFT_PROPERTY = new Property<ViewBounds, PointF>(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; |