Bug 1311842 - Manually set intrinsic bounds on DrawableCompat to ensure visibility r?sebastian draft
authorAndrzej Hunt <ahunt@mozilla.com>
Thu, 20 Oct 2016 15:49:09 -0700
changeset 428975 d045934911e055ad4982a1f99d188bc58565d0b7
parent 428968 9cdd8ed1733a941de56c4d022400c3e4b2ce0d12
child 534864 35056fec232b434130969b2560901f3485ee46e4
push id33447
push userahunt@mozilla.com
push dateMon, 24 Oct 2016 21:31:49 +0000
reviewerssebastian
bugs1311842
milestone52.0a1
Bug 1311842 - Manually set intrinsic bounds on DrawableCompat to ensure visibility r?sebastian This seems to be a change and/or regression in the 23.4.0 support libraries, which results in the drawable being treated as having no (or infintely small) bounds, and therefore no drawable being shown on screen. This workaround is only needed on Android <= 4.4.4, i.e. pre-Lollipop. MozReview-Commit-ID: LOg3Dd6gtZx
mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/DrawableUtil.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/DrawableUtil.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/DrawableUtil.java
@@ -12,16 +12,18 @@ import android.graphics.drawable.Drawabl
 import android.support.annotation.CheckResult;
 import android.support.annotation.ColorInt;
 import android.support.annotation.ColorRes;
 import android.support.annotation.DrawableRes;
 import android.support.annotation.NonNull;
 import android.support.v4.content.ContextCompat;
 import android.support.v4.graphics.drawable.DrawableCompat;
 
+import org.mozilla.gecko.AppConstants;
+
 public class DrawableUtil {
 
     /**
      * Tints the given drawable with the given color and returns it.
      */
     @CheckResult
     public static Drawable tintDrawable(@NonNull final Context context,
                                         @DrawableRes final int drawableID,
@@ -48,11 +50,18 @@ public class DrawableUtil {
      * on pre-Lollipop devices but is mutated on L+ due to differences in the Support
      * Library implementation (bug 1193950).
      */
     @CheckResult
     public static Drawable tintDrawableWithStateList(@NonNull final Drawable drawable,
             @NonNull final ColorStateList colorList) {
         final Drawable wrappedDrawable = DrawableCompat.wrap(drawable.mutate());
         DrawableCompat.setTintList(wrappedDrawable, colorList);
+
+        // DrawableCompat on pre-L doesn't handle its bounds correctly, and by default therefore won't
+        // be rendered - we need to manually copy the bounds as a workaround:
+        if (AppConstants.Versions.preMarshmallow) {
+            wrappedDrawable.setBounds(0, 0, wrappedDrawable.getIntrinsicHeight(), wrappedDrawable.getIntrinsicHeight());
+        }
+
         return wrappedDrawable;
     }
 }