From f4123fd9e54552607c953f053278cf68cd7acfd2 Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Wed, 10 May 2017 16:57:59 -0700 Subject: Gradient drawable bounds Checking if setScreenSize was called before drawing or building paints. This will keep us from making mistakes in the future. Test: manual Change-Id: I380f109e3bb3f75b9bc545de012fa857d13af3de --- .../android/colorextraction/drawable/GradientDrawable.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/colorextraction/src/com/google/android/colorextraction/drawable/GradientDrawable.java b/packages/SystemUI/colorextraction/src/com/google/android/colorextraction/drawable/GradientDrawable.java index e75d95a9226f..38e16f3d5840 100644 --- a/packages/SystemUI/colorextraction/src/com/google/android/colorextraction/drawable/GradientDrawable.java +++ b/packages/SystemUI/colorextraction/src/com/google/android/colorextraction/drawable/GradientDrawable.java @@ -157,7 +157,10 @@ public class GradientDrawable extends Drawable { } private void buildPaints() { - final Rect bounds = mWindowBounds; + Rect bounds = mWindowBounds; + if (bounds.width() == 0) { + return; + } float w = bounds.width(); float h = bounds.height(); @@ -177,7 +180,10 @@ public class GradientDrawable extends Drawable { @Override public void draw(@NonNull Canvas canvas) { - final Rect bounds = mWindowBounds; + Rect bounds = mWindowBounds; + if (bounds.width() == 0) { + throw new IllegalStateException("You need to call setScreenSize before drawing."); + } // Splat each gradient float w = bounds.width(); -- cgit v1.2.3-59-g8ed1b