diff options
author | 2025-03-17 04:33:31 +0000 | |
---|---|---|
committer | 2025-03-18 06:27:36 +0000 | |
commit | 47cd74f7fd16a5d857b0e5e6a8c51abf90280078 (patch) | |
tree | 654acf1198a1dc5ba9af8b5f4b407df39b370292 /src/com | |
parent | 5d4b99a40e85da7260b2cf034b715ca8ba903ab8 (diff) |
[DocsUI M3] Use dynamic color for Mime type icons
Since dynamic color in RRO Mime type icons is not supported
currently, as a workaround, we define a map in our app code to
achieve this custom color mapping for certain Mime type icons.
Check the attached bug for the before/after comparison.
Bug: 380746671
Test: m DocumentsUIGoogle && manual inspection
Flag: com.android.documentsui.flags.use_material3
Change-Id: Ibdfa3cc25763b6910be8cee158cc4ec912581683
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/documentsui/IconUtils.java | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/com/android/documentsui/IconUtils.java b/src/com/android/documentsui/IconUtils.java index ece38bb64..477209150 100644 --- a/src/com/android/documentsui/IconUtils.java +++ b/src/com/android/documentsui/IconUtils.java @@ -16,19 +16,56 @@ package com.android.documentsui; +import static com.android.documentsui.util.FlagUtils.isUseMaterial3FlagEnabled; + import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; +import android.content.res.Resources; import android.graphics.Outline; import android.graphics.drawable.Drawable; +import android.graphics.drawable.Icon; import android.util.TypedValue; import android.view.View; import android.view.ViewOutlineProvider; import android.widget.ImageView; import com.android.documentsui.base.UserId; +import com.android.documentsui.util.ColorUtils; + +import java.util.HashMap; +import java.util.Map; public class IconUtils { + // key: drawable resource id, value: color attribute id + private static final Map<Integer, Integer> sCustomIconColorMap = new HashMap<>(); + + static { + if (isUseMaterial3FlagEnabled()) { + // Use Resources.getSystem().getIdentifier() here instead of R.drawable.ic_doc_folder + // because com.android.internal.R is not public. + sCustomIconColorMap.put( + Resources.getSystem().getIdentifier("ic_doc_folder", "drawable", "android"), + com.google.android.material.R.attr.colorPrimaryFixedDim); + sCustomIconColorMap.put( + Resources.getSystem().getIdentifier("ic_doc_generic", "drawable", "android"), + com.google.android.material.R.attr.colorOutline); + sCustomIconColorMap.put( + Resources.getSystem() + .getIdentifier("ic_doc_certificate", "drawable", "android"), + com.google.android.material.R.attr.colorOutline); + sCustomIconColorMap.put( + Resources.getSystem().getIdentifier("ic_doc_codes", "drawable", "android"), + com.google.android.material.R.attr.colorOutline); + sCustomIconColorMap.put( + Resources.getSystem().getIdentifier("ic_doc_contact", "drawable", "android"), + com.google.android.material.R.attr.colorOutline); + sCustomIconColorMap.put( + Resources.getSystem().getIdentifier("ic_doc_font", "drawable", "android"), + com.google.android.material.R.attr.colorOutline); + } + } + public static Drawable loadPackageIcon(Context context, UserId userId, String authority, int icon, boolean maybeShowBadge) { if (icon != 0) { @@ -65,7 +102,17 @@ public class IconUtils { */ public static Drawable loadMimeIcon(Context context, String mimeType) { if (mimeType == null) return null; - return context.getContentResolver().getTypeInfo(mimeType).getIcon().loadDrawable(context); + Icon icon = context.getContentResolver().getTypeInfo(mimeType).getIcon(); + Drawable drawable = icon.loadDrawable(context); + // TODO(b/400263417): Remove this once RRO mime icons support dynamic colors. + if (isUseMaterial3FlagEnabled() + && drawable != null + && sCustomIconColorMap.containsKey(icon.getResId())) { + drawable.setTint( + ColorUtils.resolveMaterialColorAttribute( + context, sCustomIconColorMap.get(icon.getResId()))); + } + return drawable; } public static Drawable applyTintColor(Context context, int drawableId, int tintColorId) { |