From 868a0bfca4070015afdedaba050a5425a0437e00 Mon Sep 17 00:00:00 2001 From: Fahim Date: Tue, 18 Jan 2022 12:20:13 +0600 Subject: [PATCH] 4575-Q-Fix_wrong_accent_color_issue issue: https://gitlab.e.foundation/e/backlog/-/issues/4575 --- .../theme/custom/ColorOptionsProvider.java | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/com/android/customization/model/theme/custom/ColorOptionsProvider.java b/src/com/android/customization/model/theme/custom/ColorOptionsProvider.java index f3b950b51..1107329a2 100644 --- a/src/com/android/customization/model/theme/custom/ColorOptionsProvider.java +++ b/src/com/android/customization/model/theme/custom/ColorOptionsProvider.java @@ -45,7 +45,9 @@ import com.android.customization.model.theme.custom.ThemeComponentOption.ColorOp import com.android.wallpaper.R; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * Implementation of {@link ThemeComponentOptionProvider} that reads {@link ColorOption}s from @@ -91,24 +93,35 @@ public class ColorOptionsProvider extends ThemeComponentOptionProvider previewIcons, Drawable shape) { + Map optionMap = new HashMap<>(); + String skippedPackage = "org.lineageos.overlay.accent.black"; for (String overlayPackage : mOverlayPackages) { - try { - Resources overlayRes = getOverlayResources(overlayPackage); - int lightColor = overlayRes.getColor( - overlayRes.getIdentifier(ACCENT_COLOR_LIGHT_NAME, "color", overlayPackage), - null); - int darkColor = overlayRes.getColor( - overlayRes.getIdentifier(ACCENT_COLOR_DARK_NAME, "color", overlayPackage), - null); - PackageManager pm = mContext.getPackageManager(); - String label = pm.getApplicationInfo(overlayPackage, 0).loadLabel(pm).toString(); - ColorOption option = new ColorOption(overlayPackage, label, lightColor, darkColor); - option.setPreviewIcons(previewIcons); - option.setShapeDrawable(shape); - mOptions.add(option); - } catch (NameNotFoundException | NotFoundException e) { - Log.w(TAG, String.format("Couldn't load color overlay %s, will skip it", - overlayPackage), e); + if (!overlayPackage.equalsIgnoreCase(skippedPackage)) { + try { + PackageManager pm = mContext.getPackageManager(); + String label = pm.getApplicationInfo(overlayPackage, 0).loadLabel(pm).toString(); + if (!optionMap.containsKey(label.toLowerCase())) { + Resources overlayRes = getOverlayResources(overlayPackage); + int lightColor = overlayRes.getColor( + overlayRes.getIdentifier(ACCENT_COLOR_LIGHT_NAME, "color", overlayPackage), + null); + int darkColor = overlayRes.getColor( + overlayRes.getIdentifier(ACCENT_COLOR_DARK_NAME, "color", overlayPackage), + null); + ColorOption option = new ColorOption(overlayPackage, label, lightColor, darkColor); + option.setPreviewIcons(previewIcons); + option.setShapeDrawable(shape); + mOptions.add(option); + optionMap.put(label.toLowerCase(), option); + } + } catch (NameNotFoundException | NotFoundException e) { + Log.w(TAG, String.format("Couldn't load color overlay %s, will skip it", + overlayPackage), e); + } } } } -- GitLab