diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/documentsui/IconUtils.java | 49 | ||||
-rw-r--r-- | src/com/android/documentsui/loaders/BaseFileLoader.kt | 12 | ||||
-rw-r--r-- | src/com/android/documentsui/loaders/FolderLoader.kt | 2 |
3 files changed, 55 insertions, 8 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) { diff --git a/src/com/android/documentsui/loaders/BaseFileLoader.kt b/src/com/android/documentsui/loaders/BaseFileLoader.kt index dd76217ac..fcb1d4cb0 100644 --- a/src/com/android/documentsui/loaders/BaseFileLoader.kt +++ b/src/com/android/documentsui/loaders/BaseFileLoader.kt @@ -77,7 +77,7 @@ abstract class BaseFileLoader( private var mResult: DirectoryResult? = null override fun cancelLoadInBackground() { - Log.d(TAG, "BasedFileLoader.cancelLoadInBackground") + Log.d(TAG, "${this::class.simpleName}.cancelLoadInBackground") super.cancelLoadInBackground() synchronized(this) { @@ -86,7 +86,7 @@ abstract class BaseFileLoader( } override fun deliverResult(result: DirectoryResult?) { - Log.d(TAG, "BasedFileLoader.deliverResult") + Log.d(TAG, "${this::class.simpleName}.deliverResult") if (isReset) { closeResult(result) return @@ -104,7 +104,7 @@ abstract class BaseFileLoader( } override fun onStartLoading() { - Log.d(TAG, "BasedFileLoader.onStartLoading") + Log.d(TAG, "${this::class.simpleName}.onStartLoading") val isCursorStale: Boolean = checkIfCursorStale(mResult) if (mResult != null && !isCursorStale) { deliverResult(mResult) @@ -115,17 +115,17 @@ abstract class BaseFileLoader( } override fun onStopLoading() { - Log.d(TAG, "BasedFileLoader.onStopLoading") + Log.d(TAG, "${this::class.simpleName}.onStopLoading") cancelLoad() } override fun onCanceled(result: DirectoryResult?) { - Log.d(TAG, "BasedFileLoader.onCanceled") + Log.d(TAG, "${this::class.simpleName}.onCanceled") closeResult(result) } override fun onReset() { - Log.d(TAG, "BasedFileLoader.onReset") + Log.d(TAG, "${this::class.simpleName}.onReset") super.onReset() // Ensure the loader is stopped diff --git a/src/com/android/documentsui/loaders/FolderLoader.kt b/src/com/android/documentsui/loaders/FolderLoader.kt index a166ca752..40c15dfe1 100644 --- a/src/com/android/documentsui/loaders/FolderLoader.kt +++ b/src/com/android/documentsui/loaders/FolderLoader.kt @@ -60,7 +60,7 @@ class FolderLoader( mListedDir.authority, mListedDir.documentId ) - var cursor = + val cursor = queryLocation(mRoot.rootId, folderChildrenUri, mOptions.otherQueryArgs, ALL_RESULTS) ?: emptyCursor() cursor.registerContentObserver(mObserver) |