grishka / appkit

Android app boilerplate + image loader
50 stars 17 forks source link

InsetDrawable becoming weirdly small after Android 14 march (or was it april?) update #17

Open LucasGGamerM opened 2 months ago

LucasGGamerM commented 2 months ago

Here we have the following screenshot, which showcases this piece of code:

public static void insetPopupMenuIcon(MenuItem item, ColorStateList iconTint, int addWidth) {
        Drawable icon=item.getIcon().mutate();
        if(Build.VERSION.SDK_INT>=26) item.setIconTintList(iconTint);
        else icon.setTintList(iconTint);
        int pad=V.dp(8);
        boolean rtl=icon.getLayoutDirection()==View.LAYOUT_DIRECTION_RTL;
        icon=new InsetDrawable(icon, rtl ? pad+addWidth : pad, 0, rtl ? pad : addWidth+pad, 0);
        item.setIcon(icon);
        SpannableStringBuilder ssb = new SpannableStringBuilder(item.getTitle());
        item.setTitle(ssb);
    }

Captura de tela de 2024-04-19 15-01-17

And this one showcases the same piece of code, but without the InsetDrawable:

public static void insetPopupMenuIcon(MenuItem item, ColorStateList iconTint, int addWidth) {
        Drawable icon=item.getIcon().mutate();
        if(Build.VERSION.SDK_INT>=26) item.setIconTintList(iconTint);
        else icon.setTintList(iconTint);
        int pad=V.dp(8);
        boolean rtl=icon.getLayoutDirection()==View.LAYOUT_DIRECTION_RTL;
        // icon=new InsetDrawable(icon, rtl ? pad+addWidth : pad, 0, rtl ? pad : addWidth+pad, 0);
        item.setIcon(icon);
        SpannableStringBuilder ssb = new SpannableStringBuilder(item.getTitle());
        item.setTitle(ssb);
    }

Captura de tela de 2024-04-19 15-01-37

And here is the same code as the first piece, but instead being on an earlier build of Android 14:

image

grishka commented 2 months ago

Where does this code come from? How is this related to Appkit?

LucasGGamerM commented 2 months ago

Where does this code come from? How is this related to Appkit?

This code comes from https://github.com/LucasGGamerM/moshidon/blob/d5cd016776a8717be7bb1a26c3ceb993c77341da/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java#L1028, and I thought maybe it had something to do with appkit, but after taking a closer look, it seems to be related to the Android.jar class, which means appkit plays no role here.

I filed this issue just in case you knew what could have gone wrong inside appkit, but after a closer look, this issue isn't caused by appkit, but by the Android.jar changes that happened in AOSP lately...

grishka commented 2 months ago

You may want to set the bounds on the icon. It's always a good idea, some places that use drawables in text (e.g. compound drawables in a TextView) won't set them for you.

LucasGGamerM commented 2 months ago

Strangely enough, settings bounds didn't work on the newer build of android 14, but it worked on the older one. It's a weird issue. (They looked like the one with the commented out InsetDrawable call)

grishka commented 2 months ago

(I wish GitHub had đŸ¤” reaction)

LucasGGamerM commented 2 months ago

(I wish GitHub had đŸ¤” reaction)

Worry not! The set bounds thing may help me (hopefully), and maybe I will get this working soon