Add Utility method in userCache to get badgeDrawables

- In userCache, create a utility method to get badgeDrawables via userHandle. As of this moment, this is used in Toast.

Bug: 312898415
Test: Manual photos:
before 0-state: https://drive.google.com/file/d/15OUcd8i1IoUU0BgMlZj-8e0YWsmtzY4E/view?usp=sharing
after 0-state: https://drive.google.com/file/d/15SH19xvdLzQt1QbHY2oAxPAFVXPZDchF/view?usp=sharing
before textHeader: https://drive.google.com/file/d/15OLpN2SNF9QNWMrs0Aos5fS-l39Op-wo/view?usp=sharing
after textHeader: https://drive.google.com/file/d/15PIi-K6FfdCtPwWg2GEP9SUE5ow2YXJ5/view?usp=sharing
Flags: None

Change-Id: Ia6f89e634cc0af47cae91add6ea62d3af452c441
This commit is contained in:
Brandon Dayauon
2024-01-16 09:27:53 -08:00
parent 99cfd0905b
commit 72542b6058

View File

@@ -28,9 +28,13 @@ import android.os.UserManager;
import androidx.annotation.AnyThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;
import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.icons.UserBadgeDrawable;
import com.android.launcher3.util.FlagOp;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.SafeCloseable;
import com.android.launcher3.util.SimpleBroadcastReceiver;
@@ -166,4 +170,14 @@ public class UserCache implements SafeCloseable {
public List<UserHandle> getUserProfiles() {
return List.copyOf(mUserToSerialMap.keySet());
}
/**
* Get a non-themed {@link UserBadgeDrawable} based on the provided {@link UserHandle}.
*/
@Nullable
public static UserBadgeDrawable getBadgeDrawable(Context context, UserHandle userHandle) {
return (UserBadgeDrawable) BitmapInfo.LOW_RES_INFO.withFlags(UserCache.getInstance(context)
.getUserInfo(userHandle).applyBitmapInfoFlags(FlagOp.NO_OP))
.getBadgeDrawable(context, false /* isThemed */);
}
}