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
--- 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;
}
}