Can't Repro
Status Update
Comments
al...@android.com <al...@android.com>
ch...@google.com <ch...@google.com>
ki...@google.com <ki...@google.com> #2
The issue is reproducible with core-ktx 1.2.0 and 1.3.0-rc01.
ki...@google.com <ki...@google.com> #3
The Typeface.weight is not a weight of the underlying font file. It is a display style. On older APIs, the display style is adjusted if the Typeface is created from single font. However, after moving to CustomFallbackBuilder, that adjustment is removed since it can crate Typeface from multiple style font files.
Looks like it is good to set display style by ResourcesCompat.getFont for backward compatibility.
ki...@google.com <ki...@google.com> #4
Hi Nona,
Can you please schedule a release after you merge the fix?
Description
In the end i have found that the strange behaviour is caused by the mutate issue of Transition/LayerDrawable that has been fixed on api level 18.
This is the code that i'm using to solve the problem:
private static Drawable getDrawableCompat(Resources res, int id) {
Drawable d = ResourcesCompat.getDrawable(res, id, null);
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) {
// fix for "TransitionDrawable should not become a LayerDrawable"
//
// issue fixed on api 18+ (mr2) and that happens only on api 17 (mr1) because of the different
// drawable constantstate/mutate handling added on api 17
// "The drawables cache strikes again"
//
if (hasLayerDrawable(d)) {
d = d.getConstantState().newDrawable();
}
}
return d;
}
public static boolean hasLayerDrawable(Drawable d) {
if (d instanceof LayerDrawable) {
return true;
} else if (d instanceof DrawableContainer) {
final DrawableContainer.DrawableContainerState cs = (DrawableContainer.DrawableContainerState)d.getConstantState();
final Drawable[] children = cs.getChildren();
if (children != null) {
for (Drawable child : cs.getChildren()) {
if (child != null) {
if (hasLayerDrawable(child)) return true;
}
}
}
}
return false;
}