Loading iconloaderlib/Android.bp +4 −0 Original line number Diff line number Diff line Loading @@ -22,12 +22,14 @@ android_library { min_sdk_version: "26", static_libs: [ "androidx.core_core", "androidx.core_core-ktx", ], resource_dirs: [ "res", ], srcs: [ "src/**/*.java", "src/**/*.kt", ], } Loading @@ -37,6 +39,7 @@ android_library { min_sdk_version: "26", static_libs: [ "androidx.core_core", "androidx.core_core-ktx", ], resource_dirs: [ "res", Loading @@ -44,5 +47,6 @@ android_library { srcs: [ "src/**/*.java", "src_full_lib/**/*.java", "src/**/*.kt", ], } iconloaderlib/src/com/android/launcher3/icons/AdaptiveIconGenerator.kt 0 → 100644 +26 −0 Original line number Diff line number Diff line package com.android.launcher3.icons import android.graphics.Bitmap import android.graphics.drawable.Drawable import androidx.core.graphics.drawable.toBitmap object AdaptiveIconGenerator { private const val ICON_SCALE = 1.46f @JvmStatic fun toBitmap(drawable: Drawable) = drawable.toBitmap() @JvmStatic fun getScale(bitmap: Bitmap, scale: Float): Float { val topRightPx = bitmap.getPixel(0, 0) val topLeftPx = bitmap.getPixel(0, bitmap.height - 1) val bottomRightPx = bitmap.getPixel(bitmap.width - 1, 0) val bottomLeftPx = bitmap.getPixel(bitmap.width - 1, bitmap.height - 1) return if (!(topRightPx != 0 && topLeftPx != 0 && bottomRightPx != 0 && bottomLeftPx != 0)) { scale } else { ICON_SCALE } } } iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java +5 −2 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.os.Process; import android.os.UserHandle; import androidx.annotation.NonNull; import androidx.core.graphics.ColorUtils; import com.android.launcher3.icons.BitmapInfo.Extender; Loading Loading @@ -305,11 +306,13 @@ public class BaseIconFactory implements AutoCloseable { if (!(icon instanceof AdaptiveIconDrawable) && !outShape[0]) { FixedScaleDrawable fsd = ((FixedScaleDrawable) dr.getForeground()); fsd.setDrawable(icon); fsd.setScale(scale); Bitmap bitmap = AdaptiveIconGenerator.toBitmap(icon); fsd.setScale(AdaptiveIconGenerator.getScale(bitmap, scale)); icon = dr; scale = getNormalizer().getScale(icon, outIconBounds, null, null); ((ColorDrawable) dr.getBackground()).setColor(mWrapperBackgroundColor); int color = ColorUtils.setAlphaComponent(new ColorExtractor().findDominantColorByHue(bitmap), 200); ((ColorDrawable) dr.getBackground()).setColor(color); } } else { scale = getNormalizer().getScale(icon, outIconBounds, null, null); Loading Loading
iconloaderlib/Android.bp +4 −0 Original line number Diff line number Diff line Loading @@ -22,12 +22,14 @@ android_library { min_sdk_version: "26", static_libs: [ "androidx.core_core", "androidx.core_core-ktx", ], resource_dirs: [ "res", ], srcs: [ "src/**/*.java", "src/**/*.kt", ], } Loading @@ -37,6 +39,7 @@ android_library { min_sdk_version: "26", static_libs: [ "androidx.core_core", "androidx.core_core-ktx", ], resource_dirs: [ "res", Loading @@ -44,5 +47,6 @@ android_library { srcs: [ "src/**/*.java", "src_full_lib/**/*.java", "src/**/*.kt", ], }
iconloaderlib/src/com/android/launcher3/icons/AdaptiveIconGenerator.kt 0 → 100644 +26 −0 Original line number Diff line number Diff line package com.android.launcher3.icons import android.graphics.Bitmap import android.graphics.drawable.Drawable import androidx.core.graphics.drawable.toBitmap object AdaptiveIconGenerator { private const val ICON_SCALE = 1.46f @JvmStatic fun toBitmap(drawable: Drawable) = drawable.toBitmap() @JvmStatic fun getScale(bitmap: Bitmap, scale: Float): Float { val topRightPx = bitmap.getPixel(0, 0) val topLeftPx = bitmap.getPixel(0, bitmap.height - 1) val bottomRightPx = bitmap.getPixel(bitmap.width - 1, 0) val bottomLeftPx = bitmap.getPixel(bitmap.width - 1, bitmap.height - 1) return if (!(topRightPx != 0 && topLeftPx != 0 && bottomRightPx != 0 && bottomLeftPx != 0)) { scale } else { ICON_SCALE } } }
iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java +5 −2 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.os.Process; import android.os.UserHandle; import androidx.annotation.NonNull; import androidx.core.graphics.ColorUtils; import com.android.launcher3.icons.BitmapInfo.Extender; Loading Loading @@ -305,11 +306,13 @@ public class BaseIconFactory implements AutoCloseable { if (!(icon instanceof AdaptiveIconDrawable) && !outShape[0]) { FixedScaleDrawable fsd = ((FixedScaleDrawable) dr.getForeground()); fsd.setDrawable(icon); fsd.setScale(scale); Bitmap bitmap = AdaptiveIconGenerator.toBitmap(icon); fsd.setScale(AdaptiveIconGenerator.getScale(bitmap, scale)); icon = dr; scale = getNormalizer().getScale(icon, outIconBounds, null, null); ((ColorDrawable) dr.getBackground()).setColor(mWrapperBackgroundColor); int color = ColorUtils.setAlphaComponent(new ColorExtractor().findDominantColorByHue(bitmap), 200); ((ColorDrawable) dr.getBackground()).setColor(color); } } else { scale = getNormalizer().getScale(icon, outIconBounds, null, null); Loading