Loading src/com/android/documentsui/IconUtils.java +13 −5 Original line number Diff line number Diff line Loading @@ -22,21 +22,29 @@ import android.content.pm.ProviderInfo; import android.graphics.drawable.Drawable; import android.util.TypedValue; import com.android.documentsui.base.MimeTypes; import com.android.documentsui.base.UserId; public class IconUtils { public static Drawable loadPackageIcon(Context context, String authority, int icon) { public static Drawable loadPackageIcon(Context context, UserId userId, String authority, int icon, boolean maybeShowBadge) { if (icon != 0) { final PackageManager pm = userId.getPackageManager(context); Drawable packageIcon = null; if (authority != null) { final PackageManager pm = context.getPackageManager(); final ProviderInfo info = pm.resolveContentProvider(authority, 0); if (info != null) { return pm.getDrawable(info.packageName, icon, info.applicationInfo); packageIcon = pm.getDrawable(info.packageName, icon, info.applicationInfo); } } else { return context.getDrawable(icon); packageIcon = userId.getDrawable(context, icon); } if (maybeShowBadge) { return userId.getUserBadgedIcon(context, packageIcon); } else { return packageIcon; } } return null; } Loading src/com/android/documentsui/base/RootInfo.java +5 −4 Original line number Diff line number Diff line Loading @@ -423,24 +423,25 @@ public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> { } } public Drawable loadIcon(Context context) { public Drawable loadIcon(Context context, boolean maybeShowBadge) { if (derivedIcon == LOAD_FROM_CONTENT_RESOLVER) { return loadMimeTypeIcon(context); } else if (derivedIcon != 0) { // derivedIcon is set with the resources of the current user. return context.getDrawable(derivedIcon); } else { return IconUtils.loadPackageIcon(context, authority, icon); return IconUtils.loadPackageIcon(context, userId, authority, icon, maybeShowBadge); } } public Drawable loadDrawerIcon(Context context) { public Drawable loadDrawerIcon(Context context, boolean maybeShowBadge) { if (derivedIcon == LOAD_FROM_CONTENT_RESOLVER) { return IconUtils.applyTintColor(context, loadMimeTypeIcon(context), R.color.item_root_icon); } else if (derivedIcon != 0) { return IconUtils.applyTintColor(context, derivedIcon, R.color.item_root_icon); } else { return IconUtils.loadPackageIcon(context, authority, icon); return IconUtils.loadPackageIcon(context, userId, authority, icon, maybeShowBadge); } } Loading src/com/android/documentsui/base/UserId.java +17 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Process; import android.os.UserHandle; Loading Loading @@ -90,6 +91,7 @@ public final class UserId { } catch (PackageManager.NameNotFoundException e) { throw new IllegalStateException("android package not found."); } } /** Loading @@ -106,6 +108,21 @@ public final class UserId { return asContext(context).getContentResolver(); } /** * Returns a drawable object associated with a particular resource ID in this user. */ public Drawable getDrawable(Context context, int resId) { return asContext(context).getDrawable(resId); } /** * If this target user is a managed profile, then this returns a badged copy of the given icon * to be able to distinguish it from the original icon. */ public Drawable getUserBadgedIcon(Context context, Drawable drawable) { return getPackageManager(context).getUserBadgedIcon(drawable, mUserHandle); } /** * Returns true if this user refers to the system user; false otherwise. */ Loading src/com/android/documentsui/dirlist/AppsRowItemData.java +13 −8 Original line number Diff line number Diff line Loading @@ -36,16 +36,19 @@ import com.android.documentsui.sidebar.RootItem; */ public abstract class AppsRowItemData { private final UserId mUserId; protected final UserId mUserId; private final String mTitle; private final @Nullable String mSummary; protected final ActionHandler mActionHandler; protected final boolean mMaybeShowBadge; public AppsRowItemData(Item item, ActionHandler actionHandler, boolean shouldShowSummary) { public AppsRowItemData(Item item, ActionHandler actionHandler, boolean shouldShowSummary, boolean maybeShowBadge) { mUserId = item.userId; mTitle = item.title; mSummary = shouldShowSummary ? item.getSummary() : null; mActionHandler = actionHandler; mMaybeShowBadge = maybeShowBadge; } public final String getTitle() { Loading @@ -70,14 +73,15 @@ public abstract class AppsRowItemData { private final ResolveInfo mResolveInfo; public AppData(AppItem item, ActionHandler actionHandler, boolean shouldShowSummary) { super(item, actionHandler, shouldShowSummary); public AppData(AppItem item, ActionHandler actionHandler, boolean shouldShowSummary, boolean maybeShowBadge) { super(item, actionHandler, shouldShowSummary, maybeShowBadge); mResolveInfo = item.info; } @Override protected Drawable getIconDrawable(Context context) { return mResolveInfo.loadIcon(context.getPackageManager()); return mResolveInfo.loadIcon(mUserId.getPackageManager(context)); } @Override Loading @@ -90,14 +94,15 @@ public abstract class AppsRowItemData { private final RootInfo mRootInfo; public RootData(RootItem item, ActionHandler actionHandler, boolean shouldShowSummary) { super(item, actionHandler, shouldShowSummary); public RootData(RootItem item, ActionHandler actionHandler, boolean shouldShowSummary, boolean maybeShowBadge) { super(item, actionHandler, shouldShowSummary, maybeShowBadge); mRootInfo = item.root; } @Override protected Drawable getIconDrawable(Context context) { return mRootInfo.loadIcon(context); return mRootInfo.loadIcon(context, mMaybeShowBadge); } @Override Loading src/com/android/documentsui/dirlist/AppsRowManager.java +7 −3 Original line number Diff line number Diff line Loading @@ -46,10 +46,12 @@ public class AppsRowManager { private final ActionHandler mActionHandler; private final List<AppsRowItemData> mDataList; private final boolean mMaybeShowBadge; public AppsRowManager(ActionHandler handler) { public AppsRowManager(ActionHandler handler, boolean maybeShowBadge) { mDataList = new ArrayList<>(); mActionHandler = handler; mMaybeShowBadge = maybeShowBadge; } public List<AppsRowItemData> updateList(List<Item> itemList) { Loading @@ -68,9 +70,11 @@ public class AppsRowManager { for (Item item : itemList) { boolean shouldShowSummary = packageNameCount.get(item.getPackageName()) > 1; if (item instanceof RootItem) { mDataList.add(new RootData((RootItem) item, mActionHandler, shouldShowSummary)); mDataList.add(new RootData((RootItem) item, mActionHandler, shouldShowSummary, mMaybeShowBadge)); } else { mDataList.add(new AppData((AppItem) item, mActionHandler, shouldShowSummary)); mDataList.add(new AppData((AppItem) item, mActionHandler, shouldShowSummary, mMaybeShowBadge)); } } return mDataList; Loading Loading
src/com/android/documentsui/IconUtils.java +13 −5 Original line number Diff line number Diff line Loading @@ -22,21 +22,29 @@ import android.content.pm.ProviderInfo; import android.graphics.drawable.Drawable; import android.util.TypedValue; import com.android.documentsui.base.MimeTypes; import com.android.documentsui.base.UserId; public class IconUtils { public static Drawable loadPackageIcon(Context context, String authority, int icon) { public static Drawable loadPackageIcon(Context context, UserId userId, String authority, int icon, boolean maybeShowBadge) { if (icon != 0) { final PackageManager pm = userId.getPackageManager(context); Drawable packageIcon = null; if (authority != null) { final PackageManager pm = context.getPackageManager(); final ProviderInfo info = pm.resolveContentProvider(authority, 0); if (info != null) { return pm.getDrawable(info.packageName, icon, info.applicationInfo); packageIcon = pm.getDrawable(info.packageName, icon, info.applicationInfo); } } else { return context.getDrawable(icon); packageIcon = userId.getDrawable(context, icon); } if (maybeShowBadge) { return userId.getUserBadgedIcon(context, packageIcon); } else { return packageIcon; } } return null; } Loading
src/com/android/documentsui/base/RootInfo.java +5 −4 Original line number Diff line number Diff line Loading @@ -423,24 +423,25 @@ public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> { } } public Drawable loadIcon(Context context) { public Drawable loadIcon(Context context, boolean maybeShowBadge) { if (derivedIcon == LOAD_FROM_CONTENT_RESOLVER) { return loadMimeTypeIcon(context); } else if (derivedIcon != 0) { // derivedIcon is set with the resources of the current user. return context.getDrawable(derivedIcon); } else { return IconUtils.loadPackageIcon(context, authority, icon); return IconUtils.loadPackageIcon(context, userId, authority, icon, maybeShowBadge); } } public Drawable loadDrawerIcon(Context context) { public Drawable loadDrawerIcon(Context context, boolean maybeShowBadge) { if (derivedIcon == LOAD_FROM_CONTENT_RESOLVER) { return IconUtils.applyTintColor(context, loadMimeTypeIcon(context), R.color.item_root_icon); } else if (derivedIcon != 0) { return IconUtils.applyTintColor(context, derivedIcon, R.color.item_root_icon); } else { return IconUtils.loadPackageIcon(context, authority, icon); return IconUtils.loadPackageIcon(context, userId, authority, icon, maybeShowBadge); } } Loading
src/com/android/documentsui/base/UserId.java +17 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Process; import android.os.UserHandle; Loading Loading @@ -90,6 +91,7 @@ public final class UserId { } catch (PackageManager.NameNotFoundException e) { throw new IllegalStateException("android package not found."); } } /** Loading @@ -106,6 +108,21 @@ public final class UserId { return asContext(context).getContentResolver(); } /** * Returns a drawable object associated with a particular resource ID in this user. */ public Drawable getDrawable(Context context, int resId) { return asContext(context).getDrawable(resId); } /** * If this target user is a managed profile, then this returns a badged copy of the given icon * to be able to distinguish it from the original icon. */ public Drawable getUserBadgedIcon(Context context, Drawable drawable) { return getPackageManager(context).getUserBadgedIcon(drawable, mUserHandle); } /** * Returns true if this user refers to the system user; false otherwise. */ Loading
src/com/android/documentsui/dirlist/AppsRowItemData.java +13 −8 Original line number Diff line number Diff line Loading @@ -36,16 +36,19 @@ import com.android.documentsui.sidebar.RootItem; */ public abstract class AppsRowItemData { private final UserId mUserId; protected final UserId mUserId; private final String mTitle; private final @Nullable String mSummary; protected final ActionHandler mActionHandler; protected final boolean mMaybeShowBadge; public AppsRowItemData(Item item, ActionHandler actionHandler, boolean shouldShowSummary) { public AppsRowItemData(Item item, ActionHandler actionHandler, boolean shouldShowSummary, boolean maybeShowBadge) { mUserId = item.userId; mTitle = item.title; mSummary = shouldShowSummary ? item.getSummary() : null; mActionHandler = actionHandler; mMaybeShowBadge = maybeShowBadge; } public final String getTitle() { Loading @@ -70,14 +73,15 @@ public abstract class AppsRowItemData { private final ResolveInfo mResolveInfo; public AppData(AppItem item, ActionHandler actionHandler, boolean shouldShowSummary) { super(item, actionHandler, shouldShowSummary); public AppData(AppItem item, ActionHandler actionHandler, boolean shouldShowSummary, boolean maybeShowBadge) { super(item, actionHandler, shouldShowSummary, maybeShowBadge); mResolveInfo = item.info; } @Override protected Drawable getIconDrawable(Context context) { return mResolveInfo.loadIcon(context.getPackageManager()); return mResolveInfo.loadIcon(mUserId.getPackageManager(context)); } @Override Loading @@ -90,14 +94,15 @@ public abstract class AppsRowItemData { private final RootInfo mRootInfo; public RootData(RootItem item, ActionHandler actionHandler, boolean shouldShowSummary) { super(item, actionHandler, shouldShowSummary); public RootData(RootItem item, ActionHandler actionHandler, boolean shouldShowSummary, boolean maybeShowBadge) { super(item, actionHandler, shouldShowSummary, maybeShowBadge); mRootInfo = item.root; } @Override protected Drawable getIconDrawable(Context context) { return mRootInfo.loadIcon(context); return mRootInfo.loadIcon(context, mMaybeShowBadge); } @Override Loading
src/com/android/documentsui/dirlist/AppsRowManager.java +7 −3 Original line number Diff line number Diff line Loading @@ -46,10 +46,12 @@ public class AppsRowManager { private final ActionHandler mActionHandler; private final List<AppsRowItemData> mDataList; private final boolean mMaybeShowBadge; public AppsRowManager(ActionHandler handler) { public AppsRowManager(ActionHandler handler, boolean maybeShowBadge) { mDataList = new ArrayList<>(); mActionHandler = handler; mMaybeShowBadge = maybeShowBadge; } public List<AppsRowItemData> updateList(List<Item> itemList) { Loading @@ -68,9 +70,11 @@ public class AppsRowManager { for (Item item : itemList) { boolean shouldShowSummary = packageNameCount.get(item.getPackageName()) > 1; if (item instanceof RootItem) { mDataList.add(new RootData((RootItem) item, mActionHandler, shouldShowSummary)); mDataList.add(new RootData((RootItem) item, mActionHandler, shouldShowSummary, mMaybeShowBadge)); } else { mDataList.add(new AppData((AppItem) item, mActionHandler, shouldShowSummary)); mDataList.add(new AppData((AppItem) item, mActionHandler, shouldShowSummary, mMaybeShowBadge)); } } return mDataList; Loading