summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Martinz <amartinz@shiftphones.com>2018-04-09 15:52:25 (GMT)
committerJoey <joey@lineageos.org>2018-05-21 12:42:22 (GMT)
commit0a000247c9041c1c786e9b2b89217c9abf6fa848 (patch)
treeee3d3c488d9c1957338a3bf4b905ce3eb04a4771
parent4e987baa75d9fa05d38f2a14c9792f384608dd8e (diff)
downloadandroid_packages_apps_Trebuchet-0a000247c9041c1c786e9b2b89217c9abf6fa848.zip
android_packages_apps_Trebuchet-0a000247c9041c1c786e9b2b89217c9abf6fa848.tar.gz
android_packages_apps_Trebuchet-0a000247c9041c1c786e9b2b89217c9abf6fa848.tar.bz2
Icons: fix non-adaptive icon handling
The icon pack support broke this feature, fix it up to make it work again. Change-Id: I22e1ba953fc8cabb0e7633a3c5cf3ce5c07cf762 Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
-rw-r--r--src/com/android/launcher3/graphics/LauncherIcons.java22
-rw-r--r--src/com/android/launcher3/icons/CustomIconsProvider.java7
-rw-r--r--src/com/android/launcher3/icons/IconsHandler.java24
3 files changed, 28 insertions, 25 deletions
diff --git a/src/com/android/launcher3/graphics/LauncherIcons.java b/src/com/android/launcher3/graphics/LauncherIcons.java
index 45b64dd..a1884a7 100644
--- a/src/com/android/launcher3/graphics/LauncherIcons.java
+++ b/src/com/android/launcher3/graphics/LauncherIcons.java
@@ -20,7 +20,6 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.Intent.ShortcutIconResource;
-import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -43,7 +42,6 @@ import com.android.launcher3.FastBitmapDrawable;
import com.android.launcher3.IconCache;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R;
-import com.android.launcher3.SettingsActivity;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.PackageItemInfo;
@@ -76,7 +74,8 @@ public class LauncherIcons {
if (resources != null) {
final int id = resources.getIdentifier(iconRes.resourceName, null, null);
return createIconBitmap(resources.getDrawableForDensity(
- id, LauncherAppState.getIDP(context).fillResIconDpi), context);
+ id, LauncherAppState.getIDP(context).fillResIconDpi, context.getTheme()),
+ context);
}
} catch (Exception e) {
// Icon not found.
@@ -113,8 +112,7 @@ public class LauncherIcons {
context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate();
dr.setBounds(0, 0, 1, 1);
scale = normalizer.getScale(icon, null, dr.getIconMask(), outShape);
- if (FeatureFlags.LEGACY_ICON_TREATMENT &&
- !outShape[0]){
+ if (FeatureFlags.LEGACY_ICON_TREATMENT && !outShape[0]) {
Drawable wrappedIcon = wrapToAdaptiveIconDrawable(context, icon, scale);
if (wrappedIcon != icon) {
icon = wrappedIcon;
@@ -167,8 +165,7 @@ public class LauncherIcons {
context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate();
dr.setBounds(0, 0, 1, 1);
scale = normalizer.getScale(icon, iconBounds, dr.getIconMask(), outShape);
- if (Utilities.ATLEAST_OREO && FeatureFlags.LEGACY_ICON_TREATMENT &&
- !outShape[0]) {
+ if (FeatureFlags.LEGACY_ICON_TREATMENT && !outShape[0]) {
Drawable wrappedIcon = wrapToAdaptiveIconDrawable(context, icon, scale);
if (wrappedIcon != icon) {
icon = wrappedIcon;
@@ -216,6 +213,15 @@ public class LauncherIcons {
*/
public static Bitmap createIconBitmap(Drawable icon, Context context) {
float scale = 1f;
+
+ if (FeatureFlags.LEGACY_ICON_TREATMENT && Utilities.ATLEAST_OREO &&
+ !(icon instanceof AdaptiveIconDrawable)) {
+ Drawable wrappedIcon = wrapToAdaptiveIconDrawable(context, icon, scale);
+ if (wrappedIcon != icon) {
+ icon = wrappedIcon;
+ }
+ }
+
if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.ATLEAST_OREO &&
icon instanceof AdaptiveIconDrawable) {
scale = ShadowGenerator.getScaleForBounds(new RectF(0, 0, 0, 0));
@@ -298,7 +304,7 @@ public class LauncherIcons {
* shrink the legacy icon and set it as foreground. Use color drawable as background to
* create AdaptiveIconDrawable.
*/
- static Drawable wrapToAdaptiveIconDrawable(Context context, Drawable drawable, float scale) {
+ public static Drawable wrapToAdaptiveIconDrawable(Context context, Drawable drawable, float scale) {
if (!(FeatureFlags.LEGACY_ICON_TREATMENT && Utilities.ATLEAST_OREO)) {
return drawable;
}
diff --git a/src/com/android/launcher3/icons/CustomIconsProvider.java b/src/com/android/launcher3/icons/CustomIconsProvider.java
index ed63c07..1490fd9 100644
--- a/src/com/android/launcher3/icons/CustomIconsProvider.java
+++ b/src/com/android/launcher3/icons/CustomIconsProvider.java
@@ -38,12 +38,7 @@ public class CustomIconsProvider extends IconProvider {
@Override
public Drawable getIcon(LauncherActivityInfo info, int iconDpi, boolean flattenDrawable) {
- // if we are not using any icon pack, load application icon directly
- if (Utilities.ATLEAST_OREO && !Utilities.isUsingIconPack(mContext)) {
- return mContext.getPackageManager().getApplicationIcon(info.getApplicationInfo());
- }
-
- Bitmap bm = mHandler.getDrawableIconForPackage(info.getComponentName());
+ final Bitmap bm = mHandler.getDrawableIconForPackage(info.getComponentName());
if (bm == null) {
return info.getIcon(iconDpi);
}
diff --git a/src/com/android/launcher3/icons/IconsHandler.java b/src/com/android/launcher3/icons/IconsHandler.java
index 914d357..04c2dcc 100644
--- a/src/com/android/launcher3/icons/IconsHandler.java
+++ b/src/com/android/launcher3/icons/IconsHandler.java
@@ -34,6 +34,7 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
+import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
@@ -281,11 +282,13 @@ public class IconsHandler {
if (packageName == null) {
packageName = mIconPackPackageName;
}
- int id = getIdentifier(packageName, drawableName, currentIconPack);
- return id > 0 ?
- (!currentIconPack ? mOriginalIconPackRes : mCurrentIconPackRes).getDrawable(id) :
- null;
+ final int id = getIdentifier(packageName, drawableName, currentIconPack);
+ if (id <= 0) {
+ return null;
+ }
+
+ return (!currentIconPack ? mOriginalIconPackRes : mCurrentIconPackRes).getDrawable(id);
}
private Bitmap loadBitmap(String drawableName) {
@@ -296,7 +299,7 @@ public class IconsHandler {
return null;
}
- private Bitmap getDefaultAppDrawable(ComponentName componentName) {
+ private Bitmap getDefaultAppDrawable(ComponentName componentName, boolean isDefaultIconPack) {
Drawable drawable = null;
try {
drawable = mPackageManager.getActivityIcon(componentName);
@@ -306,7 +309,8 @@ public class IconsHandler {
if (drawable == null) {
return null;
}
- if (drawable instanceof BitmapDrawable) {
+
+ if (!isDefaultIconPack && drawable instanceof BitmapDrawable) {
return generateBitmap(((BitmapDrawable) drawable).getBitmap());
}
@@ -350,7 +354,7 @@ public class IconsHandler {
public Bitmap getDrawableIconForPackage(ComponentName componentName) {
if (isDefaultIconPack()) {
- return getDefaultAppDrawable(componentName);
+ return getDefaultAppDrawable(componentName, true);
}
// sth FUKY here
@@ -360,8 +364,6 @@ public class IconsHandler {
if (drawable != null && drawable instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
cacheStoreDrawable(componentName.toString(), bitmap);
- if (bitmap == null) {
- }
return bitmap;
}
@@ -370,7 +372,7 @@ public class IconsHandler {
return cachedIcon;
}
- return getDefaultAppDrawable(componentName);
+ return getDefaultAppDrawable(componentName, false);
}
private Bitmap generateBitmap(Bitmap defaultBitmap) {
@@ -617,4 +619,4 @@ public class IconsHandler {
LauncherAppState.getInstance(mContext).getModel().forceReload();
}
}
-} \ No newline at end of file
+}