diff --git a/quickstep/src/com/android/launcher3/uioverrides/SystemApiWrapper.kt b/quickstep/src/com/android/launcher3/uioverrides/SystemApiWrapper.kt index 2e2d7cc3d3..d097dbaefc 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/SystemApiWrapper.kt +++ b/quickstep/src/com/android/launcher3/uioverrides/SystemApiWrapper.kt @@ -192,4 +192,6 @@ open class SystemApiWrapper @Inject constructor(@ApplicationContext context: Con override fun getApplicationInfoHash(appInfo: ApplicationInfo): String = (appInfo.sourceDir?.hashCode() ?: 0).toString() + " " + appInfo.longVersionCode + + override fun getRoundIconRes(appInfo: ApplicationInfo) = appInfo.roundIconRes } diff --git a/src/com/android/launcher3/graphics/IconShape.kt b/src/com/android/launcher3/graphics/IconShape.kt index 2c4d8e4de3..4f6f4d2eb2 100644 --- a/src/com/android/launcher3/graphics/IconShape.kt +++ b/src/com/android/launcher3/graphics/IconShape.kt @@ -126,7 +126,6 @@ constructor( ): ValueAnimator where T : View, T : ClipPathView } - @VisibleForTesting class Circle : RoundedSquare(1f) { override fun drawShape( diff --git a/src/com/android/launcher3/icons/LauncherIconProvider.java b/src/com/android/launcher3/icons/LauncherIconProvider.java index e40f52638f..482360cb0b 100644 --- a/src/com/android/launcher3/icons/LauncherIconProvider.java +++ b/src/com/android/launcher3/icons/LauncherIconProvider.java @@ -19,14 +19,18 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.res.Resources; import android.content.res.XmlResourceParser; +import android.graphics.drawable.AdaptiveIconDrawable; +import android.graphics.drawable.Drawable; import android.text.TextUtils; import android.util.ArrayMap; import android.util.Log; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.android.launcher3.R; import com.android.launcher3.config.FeatureFlags; +import com.android.launcher3.graphics.IconShape; import com.android.launcher3.graphics.ThemeManager; import com.android.launcher3.util.ApiWrapper; @@ -49,9 +53,14 @@ public class LauncherIconProvider extends IconProvider { private Map mThemedIconMap; + private final ApiWrapper mApiWrapper; + private final IconShape mIconShape; + public LauncherIconProvider(Context context) { super(context); setIconThemeSupported(ThemeManager.INSTANCE.get(context).isMonoThemeEnabled()); + mApiWrapper = ApiWrapper.INSTANCE.get(context); + mIconShape = IconShape.INSTANCE.get(context); } /** @@ -75,7 +84,25 @@ public class LauncherIconProvider extends IconProvider { @Override protected String getApplicationInfoHash(@NonNull ApplicationInfo appInfo) { - return ApiWrapper.INSTANCE.get(mContext).getApplicationInfoHash(appInfo); + return mApiWrapper.getApplicationInfoHash(appInfo); + } + + @Nullable + @Override + protected Drawable loadAppInfoIcon(ApplicationInfo info, Resources resources, int density) { + // Tries to load the round icon res, if the app defines it as an adaptive icon + if (mIconShape.getShape() instanceof IconShape.Circle) { + int roundIconRes = mApiWrapper.getRoundIconRes(info); + if (roundIconRes != 0 && roundIconRes != info.icon) { + try { + Drawable d = resources.getDrawableForDensity(roundIconRes, density); + if (d instanceof AdaptiveIconDrawable) { + return d; + } + } catch (Resources.NotFoundException exc) { } + } + } + return super.loadAppInfoIcon(info, resources, density); } private Map getThemedIconMap() { diff --git a/src/com/android/launcher3/util/ApiWrapper.java b/src/com/android/launcher3/util/ApiWrapper.java index 467a7ec54f..73bf58077f 100644 --- a/src/com/android/launcher3/util/ApiWrapper.java +++ b/src/com/android/launcher3/util/ApiWrapper.java @@ -171,6 +171,13 @@ public class ApiWrapper { return appInfo.sourceDir; } + /** + * Returns the round icon resource Id if defined by the app + */ + public int getRoundIconRes(@NonNull ApplicationInfo appInfo) { + return 0; + } + private static class NoopDrawable extends ColorDrawable { @Override public int getIntrinsicHeight() {