Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b770cf90 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal
Browse files

beautiful icons

parent da0c1266
Loading
Loading
Loading
Loading
+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
        }
    }
}
+5 −2
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import androidx.annotation.ColorInt;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.graphics.ColorUtils;

import com.android.launcher3.icons.BitmapInfo.Extender;
import com.android.launcher3.util.FlagOp;
@@ -323,10 +324,12 @@ public class BaseIconFactory implements AutoCloseable {
            if (!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);