Use custom adaptive icon class

This commit is contained in:
Suphon Thanakornpakapong
2021-10-13 12:04:04 +07:00
parent 222270e965
commit 97209503ff
9 changed files with 33 additions and 7 deletions

View File

@@ -74,7 +74,7 @@ android {
}
defaultConfig {
minSdkVersion 25
minSdkVersion 26
targetSdkVersion 30
versionCode 7
def versionDisplayName = "12.0 Alpha 6.1"

View File

@@ -2,6 +2,9 @@ package app.lawnchair.icons
import android.content.*
import android.content.Intent.*
import android.content.pm.ActivityInfo
import android.content.pm.LauncherActivityInfo
import android.graphics.drawable.AdaptiveIconDrawable
import android.graphics.drawable.Drawable
import android.os.Handler
import android.os.Process
@@ -46,6 +49,18 @@ class LawnchairIconProvider @JvmOverloads constructor(
return icon ?: super.getIconWithOverrides(packageName, component, user, iconDpi, fallback)
}
override fun getIcon(info: ActivityInfo?): Drawable {
return CustomAdaptiveIconDrawable.wrapNonNull(super.getIcon(info))
}
override fun getIcon(info: ActivityInfo?, iconDpi: Int): Drawable {
return CustomAdaptiveIconDrawable.wrapNonNull(super.getIcon(info, iconDpi))
}
override fun getIcon(info: LauncherActivityInfo?, iconDpi: Int): Drawable {
return CustomAdaptiveIconDrawable.wrapNonNull(super.getIcon(info, iconDpi))
}
override fun getSystemStateForPackage(systemState: String, packageName: String): String {
return super.getSystemStateForPackage(systemState, packageName)
}

View File

@@ -96,6 +96,7 @@ import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import app.lawnchair.icons.CustomAdaptiveIconDrawable;
import app.lawnchair.preferences.PreferenceManager;
/**

View File

@@ -68,6 +68,8 @@ import com.android.launcher3.util.Thunk;
import com.android.launcher3.views.BaseDragLayer;
import com.android.launcher3.widget.LauncherAppWidgetHostView;
import app.lawnchair.icons.CustomAdaptiveIconDrawable;
/** A custom view for rendering an icon, folder, shortcut or widget during drag-n-drop. */
public class DragView extends FrameLayout implements StateListener<LauncherState> {
@@ -245,7 +247,7 @@ public class DragView extends FrameLayout implements StateListener<LauncherState
nDr = dr;
} else {
// Since we just want the scale, avoid heavy drawing operations
nDr = new AdaptiveIconDrawable(new ColorDrawable(Color.BLACK), null);
nDr = new CustomAdaptiveIconDrawable(new ColorDrawable(Color.BLACK), null);
}
Utilities.scaleRectAboutCenter(bounds,
li.getNormalizer().getScale(nDr, null, null, null));

View File

@@ -39,11 +39,13 @@ import com.android.launcher3.graphics.ShiftedBitmapDrawable;
import com.android.launcher3.icons.BitmapRenderer;
import com.android.launcher3.util.Preconditions;
import app.lawnchair.icons.CustomAdaptiveIconDrawable;
/**
* {@link AdaptiveIconDrawable} representation of a {@link FolderIcon}
*/
@TargetApi(Build.VERSION_CODES.O)
public class FolderAdaptiveIcon extends AdaptiveIconDrawable {
public class FolderAdaptiveIcon extends CustomAdaptiveIconDrawable {
private static final String TAG = "FolderAdaptiveIcon";
private final Drawable mBadge;

View File

@@ -54,6 +54,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import app.lawnchair.icons.CustomAdaptiveIconDrawable;
/**
* Abstract representation of the shape of an icon shape
*/
@@ -435,7 +437,7 @@ public abstract class IconShape {
Region full = new Region(0, 0, size, size);
Region iconR = new Region();
AdaptiveIconDrawable drawable = new AdaptiveIconDrawable(
AdaptiveIconDrawable drawable = new CustomAdaptiveIconDrawable(
new ColorDrawable(Color.BLACK), new ColorDrawable(Color.BLACK));
drawable.setBounds(0, 0, size, size);
iconR.setPath(drawable.getIconMask(), full);

View File

@@ -105,6 +105,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import app.lawnchair.font.FontCache;
import app.lawnchair.font.FontManager;
import app.lawnchair.icons.CustomAdaptiveIconDrawable;
import app.lawnchair.icons.IconPackProvider;
import app.lawnchair.preferences.PreferenceManager;
@@ -250,7 +251,7 @@ public class LauncherPreviewRenderer extends ContextWrapper
BaseIconFactory iconFactory =
new BaseIconFactory(context, mIdp.fillResIconDpi, mIdp.iconBitmapSize) { };
BitmapInfo iconInfo = iconFactory.createBadgedIconBitmap(new AdaptiveIconDrawable(
BitmapInfo iconInfo = iconFactory.createBadgedIconBitmap(new CustomAdaptiveIconDrawable(
new ColorDrawable(Color.WHITE), new ColorDrawable(Color.WHITE)),
Process.myUserHandle(),
Build.VERSION.SDK_INT);

View File

@@ -36,6 +36,8 @@ import com.android.launcher3.icons.cache.CachingLogic;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.util.Themes;
import app.lawnchair.icons.CustomAdaptiveIconDrawable;
/**
* Caching logic for shortcuts.
*/
@@ -98,8 +100,9 @@ public class ShortcutCachingLogic implements CachingLogic<ShortcutInfo> {
return null;
}
try {
return context.getSystemService(LauncherApps.class)
Drawable icon = context.getSystemService(LauncherApps.class)
.getShortcutIconDrawable(shortcutInfo, density);
return CustomAdaptiveIconDrawable.wrap(icon);
} catch (SecurityException | IllegalStateException e) {
Log.e(TAG, "Failed to get shortcut icon", e);
return null;