Bug 1311842 - Manually set intrinsic bounds on DrawableCompat to ensure visibility r=sebastian
authorAndrzej Hunt <ahunt@mozilla.com>
Thu, 20 Oct 2016 15:49:09 -0700
changeset 346985 9274f4f0ebdca3552c5cf860cfc2b95f86907ccc
parent 346984 a9f1a369aa956e40bca3f7fe5fcbd2138dd6f044
child 346986 b92e6bb8b2c7c43463c7b3f8a83f1b8d4a1df134
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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;
     }
 }