Loading iconloaderlib/res/drawable/ic_clone_app_badge.xml 0 → 100644 +43 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2023 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="@dimen/profile_badge_size" android:height="@dimen/profile_badge_size" android:viewportWidth="24" android:viewportHeight="24"> <path android:fillColor="#11000000" android:pathData="M.5,12.25 A11.5,11.5 0 1,1 23.5,12.25 A11.5,11.5 0 1,1 .5,12.25" /> <path android:fillColor="@android:color/white" android:pathData="M1,12 A11,11 0 1,1 23,12 A11,11 0 1,1 1,12" /> <group android:scaleX=".6" android:scaleY=".6" android:pivotX="12" android:pivotY="12"> <path android:pathData="M22,9.5C22,13.642 18.642,17 14.5,17C10.358,17 7,13.642 7,9.5C7,5.358 10.358,2 14.5,2C18.642,2 22,5.358 22,9.5Z" android:fillColor="#ff3C4043"/> <path android:pathData="M9.5,20.333C12.722,20.333 15.333,17.722 15.333,14.5C15.333,11.278 12.722,8.667 9.5,8.667C6.278,8.667 3.667,11.278 3.667,14.5C3.667,17.722 6.278,20.333 9.5,20.333ZM9.5,22C13.642,22 17,18.642 17,14.5C17,10.358 13.642,7 9.5,7C5.358,7 2,10.358 2,14.5C2,18.642 5.358,22 9.5,22Z" android:fillColor="#ff3C4043" android:fillType="evenOdd"/> </group> </vector> iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java +31 −2 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ import static android.graphics.Paint.DITHER_FLAG; import static android.graphics.Paint.FILTER_BITMAP_FLAG; import static android.graphics.drawable.AdaptiveIconDrawable.getExtraInsetFraction; import static com.android.launcher3.icons.BitmapInfo.FLAG_CLONE; import static com.android.launcher3.icons.BitmapInfo.FLAG_INSTANT; import static com.android.launcher3.icons.BitmapInfo.FLAG_WORK; import static com.android.launcher3.icons.ShadowGenerator.BLUR_FACTOR; Loading Loading @@ -212,7 +213,8 @@ public class BaseIconFactory implements AutoCloseable { boolean shrinkNonAdaptiveIcons = options == null || options.mShrinkNonAdaptiveIcons; float[] scale = new float[1]; icon = normalizeAndWrapToAdaptiveIcon(icon, shrinkNonAdaptiveIcons, null, scale); Bitmap bitmap = createIconBitmap(icon, scale[0], MODE_WITH_SHADOW); Bitmap bitmap = createIconBitmap(icon, scale[0], options == null ? MODE_WITH_SHADOW : options.mGenerationMode); int color = (options != null && options.mExtractedColor != null) ? options.mExtractedColor : mColorExtractor.findDominantColorByHue(bitmap); Loading Loading @@ -265,7 +267,10 @@ public class BaseIconFactory implements AutoCloseable { isBadged = (d != mPm.getUserBadgedIcon(d, options.mUserHandle)); mIsUserBadged.put(key, isBadged); } op = op.setFlag(FLAG_WORK, isBadged); // Set the clone profile badge flag in case it is present. op = op.setFlag(FLAG_CLONE, isBadged && options.mIsCloneProfile); // Set the Work profile badge for all other cases. op = op.setFlag(FLAG_WORK, isBadged && !options.mIsCloneProfile); } } return op; Loading Loading @@ -463,6 +468,11 @@ public class BaseIconFactory implements AutoCloseable { boolean mIsInstantApp; boolean mIsCloneProfile; @BitmapGenerationMode int mGenerationMode = MODE_WITH_SHADOW; @Nullable UserHandle mUserHandle; @ColorInt Loading Loading @@ -503,6 +513,25 @@ public class BaseIconFactory implements AutoCloseable { mExtractedColor = color; return this; } /** * Sets the bitmap generation mode to use for the bitmap info. Note that some generation * modes do not support color extraction, so consider setting a extracted color manually * in those cases. */ public IconOptions setBitmapGenerationMode(@BitmapGenerationMode int generationMode) { mGenerationMode = generationMode; return this; } /** * Used to determine the badge type for this icon. */ @NonNull public IconOptions setIsCloneProfile(boolean isCloneProfile) { mIsCloneProfile = isCloneProfile; return this; } } /** Loading iconloaderlib/src/com/android/launcher3/icons/BitmapInfo.java +4 −0 Original line number Diff line number Diff line Loading @@ -30,9 +30,11 @@ public class BitmapInfo { static final int FLAG_WORK = 1 << 0; static final int FLAG_INSTANT = 1 << 1; static final int FLAG_CLONE = 1 << 2; @IntDef(flag = true, value = { FLAG_WORK, FLAG_INSTANT, FLAG_CLONE }) @interface BitmapInfoFlags {} Loading Loading @@ -155,6 +157,8 @@ public class BitmapInfo { drawable.setBadge(context.getDrawable(R.drawable.ic_instant_app_badge)); } else if ((flags & FLAG_WORK) != 0) { drawable.setBadge(context.getDrawable(R.drawable.ic_work_app_badge)); } else if ((flags & FLAG_CLONE) != 0) { drawable.setBadge(context.getDrawable(R.drawable.ic_clone_app_badge)); } } } Loading iconloaderlib/src/com/android/launcher3/icons/GraphicsUtils.java +19 −1 Original line number Diff line number Diff line Loading @@ -16,9 +16,11 @@ package com.android.launcher3.icons; import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Path; import android.graphics.Rect; import android.graphics.Region; Loading @@ -28,6 +30,8 @@ import android.graphics.drawable.ColorDrawable; import android.util.Log; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.core.graphics.PathParser; import java.io.ByteArrayOutputStream; import java.io.IOException; Loading @@ -35,6 +39,7 @@ import java.io.IOException; public class GraphicsUtils { private static final String TAG = "GraphicsUtils"; private static final float MASK_SIZE = 100f; public static Runnable sOnNewBitmapRunnable = () -> { }; Loading Loading @@ -98,7 +103,20 @@ public class GraphicsUtils { /** * Returns the default path to be used by an icon */ public static Path getShapePath(int size) { public static Path getShapePath(@NonNull Context context, int size) { if (IconProvider.CONFIG_ICON_MASK_RES_ID != Resources.ID_NULL) { Path path = PathParser.createPathFromPathData( context.getString(IconProvider.CONFIG_ICON_MASK_RES_ID)); if (path != null) { if (size != MASK_SIZE) { Matrix m = new Matrix(); float scale = ((float) size) / MASK_SIZE; m.setScale(scale, scale); path.transform(m); } return path; } } AdaptiveIconDrawable drawable = new AdaptiveIconDrawable( new ColorDrawable(Color.BLACK), new ColorDrawable(Color.BLACK)); drawable.setBounds(0, 0, size, size); Loading iconloaderlib/src/com/android/launcher3/icons/IconProvider.java +1 −1 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ import java.util.function.Supplier; public class IconProvider { private final String ACTION_OVERLAY_CHANGED = "android.intent.action.OVERLAY_CHANGED"; private static final int CONFIG_ICON_MASK_RES_ID = Resources.getSystem().getIdentifier( static final int CONFIG_ICON_MASK_RES_ID = Resources.getSystem().getIdentifier( "config_icon_mask", "string", "android"); private static final String TAG = "IconProvider"; Loading Loading
iconloaderlib/res/drawable/ic_clone_app_badge.xml 0 → 100644 +43 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2023 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="@dimen/profile_badge_size" android:height="@dimen/profile_badge_size" android:viewportWidth="24" android:viewportHeight="24"> <path android:fillColor="#11000000" android:pathData="M.5,12.25 A11.5,11.5 0 1,1 23.5,12.25 A11.5,11.5 0 1,1 .5,12.25" /> <path android:fillColor="@android:color/white" android:pathData="M1,12 A11,11 0 1,1 23,12 A11,11 0 1,1 1,12" /> <group android:scaleX=".6" android:scaleY=".6" android:pivotX="12" android:pivotY="12"> <path android:pathData="M22,9.5C22,13.642 18.642,17 14.5,17C10.358,17 7,13.642 7,9.5C7,5.358 10.358,2 14.5,2C18.642,2 22,5.358 22,9.5Z" android:fillColor="#ff3C4043"/> <path android:pathData="M9.5,20.333C12.722,20.333 15.333,17.722 15.333,14.5C15.333,11.278 12.722,8.667 9.5,8.667C6.278,8.667 3.667,11.278 3.667,14.5C3.667,17.722 6.278,20.333 9.5,20.333ZM9.5,22C13.642,22 17,18.642 17,14.5C17,10.358 13.642,7 9.5,7C5.358,7 2,10.358 2,14.5C2,18.642 5.358,22 9.5,22Z" android:fillColor="#ff3C4043" android:fillType="evenOdd"/> </group> </vector>
iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java +31 −2 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ import static android.graphics.Paint.DITHER_FLAG; import static android.graphics.Paint.FILTER_BITMAP_FLAG; import static android.graphics.drawable.AdaptiveIconDrawable.getExtraInsetFraction; import static com.android.launcher3.icons.BitmapInfo.FLAG_CLONE; import static com.android.launcher3.icons.BitmapInfo.FLAG_INSTANT; import static com.android.launcher3.icons.BitmapInfo.FLAG_WORK; import static com.android.launcher3.icons.ShadowGenerator.BLUR_FACTOR; Loading Loading @@ -212,7 +213,8 @@ public class BaseIconFactory implements AutoCloseable { boolean shrinkNonAdaptiveIcons = options == null || options.mShrinkNonAdaptiveIcons; float[] scale = new float[1]; icon = normalizeAndWrapToAdaptiveIcon(icon, shrinkNonAdaptiveIcons, null, scale); Bitmap bitmap = createIconBitmap(icon, scale[0], MODE_WITH_SHADOW); Bitmap bitmap = createIconBitmap(icon, scale[0], options == null ? MODE_WITH_SHADOW : options.mGenerationMode); int color = (options != null && options.mExtractedColor != null) ? options.mExtractedColor : mColorExtractor.findDominantColorByHue(bitmap); Loading Loading @@ -265,7 +267,10 @@ public class BaseIconFactory implements AutoCloseable { isBadged = (d != mPm.getUserBadgedIcon(d, options.mUserHandle)); mIsUserBadged.put(key, isBadged); } op = op.setFlag(FLAG_WORK, isBadged); // Set the clone profile badge flag in case it is present. op = op.setFlag(FLAG_CLONE, isBadged && options.mIsCloneProfile); // Set the Work profile badge for all other cases. op = op.setFlag(FLAG_WORK, isBadged && !options.mIsCloneProfile); } } return op; Loading Loading @@ -463,6 +468,11 @@ public class BaseIconFactory implements AutoCloseable { boolean mIsInstantApp; boolean mIsCloneProfile; @BitmapGenerationMode int mGenerationMode = MODE_WITH_SHADOW; @Nullable UserHandle mUserHandle; @ColorInt Loading Loading @@ -503,6 +513,25 @@ public class BaseIconFactory implements AutoCloseable { mExtractedColor = color; return this; } /** * Sets the bitmap generation mode to use for the bitmap info. Note that some generation * modes do not support color extraction, so consider setting a extracted color manually * in those cases. */ public IconOptions setBitmapGenerationMode(@BitmapGenerationMode int generationMode) { mGenerationMode = generationMode; return this; } /** * Used to determine the badge type for this icon. */ @NonNull public IconOptions setIsCloneProfile(boolean isCloneProfile) { mIsCloneProfile = isCloneProfile; return this; } } /** Loading
iconloaderlib/src/com/android/launcher3/icons/BitmapInfo.java +4 −0 Original line number Diff line number Diff line Loading @@ -30,9 +30,11 @@ public class BitmapInfo { static final int FLAG_WORK = 1 << 0; static final int FLAG_INSTANT = 1 << 1; static final int FLAG_CLONE = 1 << 2; @IntDef(flag = true, value = { FLAG_WORK, FLAG_INSTANT, FLAG_CLONE }) @interface BitmapInfoFlags {} Loading Loading @@ -155,6 +157,8 @@ public class BitmapInfo { drawable.setBadge(context.getDrawable(R.drawable.ic_instant_app_badge)); } else if ((flags & FLAG_WORK) != 0) { drawable.setBadge(context.getDrawable(R.drawable.ic_work_app_badge)); } else if ((flags & FLAG_CLONE) != 0) { drawable.setBadge(context.getDrawable(R.drawable.ic_clone_app_badge)); } } } Loading
iconloaderlib/src/com/android/launcher3/icons/GraphicsUtils.java +19 −1 Original line number Diff line number Diff line Loading @@ -16,9 +16,11 @@ package com.android.launcher3.icons; import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Path; import android.graphics.Rect; import android.graphics.Region; Loading @@ -28,6 +30,8 @@ import android.graphics.drawable.ColorDrawable; import android.util.Log; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.core.graphics.PathParser; import java.io.ByteArrayOutputStream; import java.io.IOException; Loading @@ -35,6 +39,7 @@ import java.io.IOException; public class GraphicsUtils { private static final String TAG = "GraphicsUtils"; private static final float MASK_SIZE = 100f; public static Runnable sOnNewBitmapRunnable = () -> { }; Loading Loading @@ -98,7 +103,20 @@ public class GraphicsUtils { /** * Returns the default path to be used by an icon */ public static Path getShapePath(int size) { public static Path getShapePath(@NonNull Context context, int size) { if (IconProvider.CONFIG_ICON_MASK_RES_ID != Resources.ID_NULL) { Path path = PathParser.createPathFromPathData( context.getString(IconProvider.CONFIG_ICON_MASK_RES_ID)); if (path != null) { if (size != MASK_SIZE) { Matrix m = new Matrix(); float scale = ((float) size) / MASK_SIZE; m.setScale(scale, scale); path.transform(m); } return path; } } AdaptiveIconDrawable drawable = new AdaptiveIconDrawable( new ColorDrawable(Color.BLACK), new ColorDrawable(Color.BLACK)); drawable.setBounds(0, 0, size, size); Loading
iconloaderlib/src/com/android/launcher3/icons/IconProvider.java +1 −1 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ import java.util.function.Supplier; public class IconProvider { private final String ACTION_OVERLAY_CHANGED = "android.intent.action.OVERLAY_CHANGED"; private static final int CONFIG_ICON_MASK_RES_ID = Resources.getSystem().getIdentifier( static final int CONFIG_ICON_MASK_RES_ID = Resources.getSystem().getIdentifier( "config_icon_mask", "string", "android"); private static final String TAG = "IconProvider"; Loading