Merge "Scaling down the icon before applying the user badge > This also saves memory only create one new bitmap while loading instead of two" into ub-launcher3-burnaby-polish
This commit is contained in:
@@ -179,15 +179,7 @@ public class IconCache {
|
||||
|
||||
private Bitmap makeDefaultIcon(UserHandleCompat user) {
|
||||
Drawable unbadged = getFullResDefaultActivityIcon();
|
||||
Drawable d = mUserManager.getBadgedDrawableForUser(unbadged, user);
|
||||
Bitmap b = Bitmap.createBitmap(Math.max(d.getIntrinsicWidth(), 1),
|
||||
Math.max(d.getIntrinsicHeight(), 1),
|
||||
Bitmap.Config.ARGB_8888);
|
||||
Canvas c = new Canvas(b);
|
||||
d.setBounds(0, 0, b.getWidth(), b.getHeight());
|
||||
d.draw(c);
|
||||
c.setBitmap(null);
|
||||
return b;
|
||||
return Utilities.createBadgedIconBitmap(unbadged, user, mContext);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -380,7 +372,8 @@ public class IconCache {
|
||||
}
|
||||
if (entry == null) {
|
||||
entry = new CacheEntry();
|
||||
entry.icon = Utilities.createIconBitmap(app.getBadgedIcon(mIconDpi), mContext);
|
||||
entry.icon = Utilities.createBadgedIconBitmap(
|
||||
app.getIcon(mIconDpi), app.getUser(), mContext);
|
||||
}
|
||||
entry.title = app.getLabel();
|
||||
entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, app.getUser());
|
||||
@@ -542,7 +535,8 @@ public class IconCache {
|
||||
// Check the DB first.
|
||||
if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) {
|
||||
if (info != null) {
|
||||
entry.icon = Utilities.createIconBitmap(info.getBadgedIcon(mIconDpi), mContext);
|
||||
entry.icon = Utilities.createBadgedIconBitmap(
|
||||
info.getIcon(mIconDpi), info.getUser(), mContext);
|
||||
} else {
|
||||
if (usePackageIcon) {
|
||||
CacheEntry packageEntry = getEntryForPackageLocked(
|
||||
@@ -623,9 +617,8 @@ public class IconCache {
|
||||
if (appInfo == null) {
|
||||
throw new NameNotFoundException("ApplicationInfo is null");
|
||||
}
|
||||
Drawable drawable = mUserManager.getBadgedDrawableForUser(
|
||||
appInfo.loadIcon(mPackageManager), user);
|
||||
entry.icon = Utilities.createIconBitmap(drawable, mContext);
|
||||
entry.icon = Utilities.createBadgedIconBitmap(
|
||||
appInfo.loadIcon(mPackageManager), user, mContext);
|
||||
entry.title = appInfo.loadLabel(mPackageManager);
|
||||
entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
|
||||
entry.isLowResIcon = false;
|
||||
|
||||
@@ -60,6 +60,8 @@ import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.launcher3.compat.UserHandleCompat;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -194,6 +196,28 @@ public final class Utilities {
|
||||
return createIconBitmap(new BitmapDrawable(context.getResources(), icon), context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a bitmap suitable for the all apps view. The icon is badged for {@param user}
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public static Bitmap createBadgedIconBitmap(
|
||||
Drawable icon, UserHandleCompat user, Context context) {
|
||||
Bitmap bitmap = createIconBitmap(icon, context);
|
||||
if (Utilities.ATLEAST_LOLLIPOP && user != null
|
||||
&& !UserHandleCompat.myUserHandle().equals(user)) {
|
||||
BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap);
|
||||
Drawable badged = context.getPackageManager().getUserBadgedIcon(
|
||||
drawable, user.getUser());
|
||||
if (badged instanceof BitmapDrawable) {
|
||||
return ((BitmapDrawable) badged).getBitmap();
|
||||
} else {
|
||||
return createIconBitmap(badged, context);
|
||||
}
|
||||
} else {
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a bitmap suitable for the all apps view.
|
||||
*/
|
||||
|
||||
@@ -33,7 +33,6 @@ public abstract class LauncherActivityInfoCompat {
|
||||
public abstract Drawable getIcon(int density);
|
||||
public abstract ApplicationInfo getApplicationInfo();
|
||||
public abstract long getFirstInstallTime();
|
||||
public abstract Drawable getBadgedIcon(int density);
|
||||
|
||||
/**
|
||||
* Creates a LauncherActivityInfoCompat for the primary user.
|
||||
|
||||
@@ -93,8 +93,4 @@ public class LauncherActivityInfoCompatV16 extends LauncherActivityInfoCompat {
|
||||
public String getName() {
|
||||
return mActivityInfo.name;
|
||||
}
|
||||
|
||||
public Drawable getBadgedIcon(int density) {
|
||||
return getIcon(density);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,8 +55,4 @@ public class LauncherActivityInfoCompatVL extends LauncherActivityInfoCompat {
|
||||
public long getFirstInstallTime() {
|
||||
return mLauncherActivityInfo.getFirstInstallTime();
|
||||
}
|
||||
|
||||
public Drawable getBadgedIcon(int density) {
|
||||
return mLauncherActivityInfo.getBadgedIcon(density);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class UserHandleCompat {
|
||||
}
|
||||
}
|
||||
|
||||
UserHandle getUser() {
|
||||
public UserHandle getUser() {
|
||||
return mUser;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
package com.android.launcher3.compat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
|
||||
import com.android.launcher3.Utilities;
|
||||
|
||||
@@ -54,7 +52,6 @@ public abstract class UserManagerCompat {
|
||||
public abstract List<UserHandleCompat> getUserProfiles();
|
||||
public abstract long getSerialNumberForUser(UserHandleCompat user);
|
||||
public abstract UserHandleCompat getUserForSerialNumber(long serialNumber);
|
||||
public abstract Drawable getBadgedDrawableForUser(Drawable unbadged, UserHandleCompat user);
|
||||
public abstract CharSequence getBadgedLabelForUser(CharSequence label, UserHandleCompat user);
|
||||
public abstract long getUserCreationTime(UserHandleCompat user);
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.android.launcher3.compat;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -36,11 +34,6 @@ public class UserManagerCompatV16 extends UserManagerCompat {
|
||||
return UserHandleCompat.myUserHandle();
|
||||
}
|
||||
|
||||
public Drawable getBadgedDrawableForUser(Drawable unbadged,
|
||||
UserHandleCompat user) {
|
||||
return unbadged;
|
||||
}
|
||||
|
||||
public long getSerialNumberForUser(UserHandleCompat user) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.UserHandle;
|
||||
|
||||
@@ -85,11 +84,6 @@ public class UserManagerCompatVL extends UserManagerCompatV17 {
|
||||
return compatUsers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getBadgedDrawableForUser(Drawable unbadged, UserHandleCompat user) {
|
||||
return mPm.getUserBadgedIcon(unbadged, user.getUser());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getBadgedLabelForUser(CharSequence label, UserHandleCompat user) {
|
||||
if (user == null) {
|
||||
|
||||
Reference in New Issue
Block a user