Add badge colors for dark theme

Test: manual
Test: atest UserManagerTest#testProfileTypeInformation
Fixes: 149669756
Change-Id: Ib3fd377a4902bbe936d574dc52bac4eae6e25dd4
This commit is contained in:
Beverly
2020-04-27 16:15:15 -04:00
parent 27f4c791a2
commit 2b4306a8ec
10 changed files with 116 additions and 9 deletions

View File

@@ -1574,7 +1574,7 @@ public class ApplicationPackageManager extends PackageManager {
}
Drawable badge = new LauncherIcons(mContext).getBadgeDrawable(
getUserManager().getUserIconBadgeResId(user.getIdentifier()),
getUserBadgeColor(user));
getUserBadgeColor(user, false));
return getBadgedDrawable(icon, badge, null, true);
}
@@ -1588,8 +1588,16 @@ public class ApplicationPackageManager extends PackageManager {
return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
}
/** Returns the color of the user's actual badge (not the badge's shadow). */
private int getUserBadgeColor(UserHandle user) {
/**
* Returns the color of the user's actual badge (not the badge's shadow).
* @param checkTheme whether to check the theme to determine the badge color. This should be
* true if the background is determined by the theme. Otherwise, if
* checkTheme is false, returns the color assuming a light background.
*/
private int getUserBadgeColor(UserHandle user, boolean checkTheme) {
if (checkTheme && mContext.getResources().getConfiguration().isNightModeActive()) {
return getUserManager().getUserBadgeDarkColor(user.getIdentifier());
}
return getUserManager().getUserBadgeColor(user.getIdentifier());
}
@@ -1603,11 +1611,14 @@ public class ApplicationPackageManager extends PackageManager {
}
Drawable badgeForeground = getDrawableForDensity(
getUserManager().getUserBadgeResId(user.getIdentifier()), density);
badgeForeground.setTint(getUserBadgeColor(user));
badgeForeground.setTint(getUserBadgeColor(user, false));
Drawable badge = new LayerDrawable(new Drawable[] {badgeColor, badgeForeground });
return badge;
}
/**
* Returns the badge color based on whether device has dark theme enabled or not.
*/
@Override
public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) {
if (!hasUserBadge(user.getIdentifier())) {
@@ -1616,7 +1627,7 @@ public class ApplicationPackageManager extends PackageManager {
Drawable badge = getDrawableForDensity(
getUserManager().getUserBadgeNoBackgroundResId(user.getIdentifier()), density);
if (badge != null) {
badge.setTint(getUserBadgeColor(user));
badge.setTint(getUserBadgeColor(user, true));
}
return badge;
}

View File

@@ -108,6 +108,7 @@ interface IUserManager {
int getUserBadgeNoBackgroundResId(int userId);
int getUserBadgeLabelResId(int userId);
int getUserBadgeColorResId(int userId);
int getUserBadgeDarkColorResId(int userId);
boolean hasBadge(int userId);
boolean isUserUnlocked(int userId);
boolean isUserRunning(int userId);

View File

@@ -3662,7 +3662,8 @@ public class UserManager {
}
/**
* Returns the badge color for the given user (generally to color a profile's icon's badge).
* Returns the light theme badge color for the given user (generally to color a profile's
* icon's badge).
*
* <p>To check whether a badge color is expected for the user, first call {@link #hasBadge}.
*
@@ -3681,6 +3682,27 @@ public class UserManager {
}
}
/**
* Returns the dark theme badge color for the given user (generally to color a profile's icon's
* badge).
*
* <p>To check whether a badge color is expected for the user, first call {@link #hasBadge}.
*
* @return the color (not the resource ID) to be used for the user's badge
* @throws Resources.NotFoundException if no valid badge color exists for this user
*
* @see #getBadgedIconForUser more information about badging in general
* @hide
*/
public @ColorInt int getUserBadgeDarkColor(@UserIdInt int userId) {
try {
final int resourceId = mService.getUserBadgeDarkColorResId(userId);
return Resources.getSystem().getColor(resourceId, null);
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
}
}
/**
* Returns the Resource ID of the user's icon badge.
*