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);
}
/**
}
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());
// 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(
// Load the full res icon for the application, but if useLowResIcon is set, then
// only keep the low resolution icon instead of the larger full-sized icon
- Drawable drawable = mUserManager.getBadgedDrawableForUser(
- appInfo.loadIcon(mPackageManager), user);
- Bitmap icon = Utilities.createIconBitmap(drawable, mContext);
+ Bitmap icon = Utilities.createBadgedIconBitmap(
+ appInfo.loadIcon(mPackageManager), user, mContext);
Bitmap lowResIcon = generateLowResIcon(icon, mPackageBgColor);
entry.title = appInfo.loadLabel(mPackageManager);
entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
import android.view.View;
import android.widget.Toast;
+import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.config.ProviderConfig;
import java.io.ByteArrayOutputStream;
}
/**
+ * 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.
*/
public static Bitmap createIconBitmap(Drawable icon, Context context) {
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.
public String getName() {
return mActivityInfo.name;
}
-
- public Drawable getBadgedIcon(int density) {
- return getIcon(density);
- }
}
public long getFirstInstallTime() {
return mLauncherActivityInfo.getFirstInstallTime();
}
-
- public Drawable getBadgedIcon(int density) {
- return mLauncherActivityInfo.getBadgedIcon(density);
- }
}
}
}
- UserHandle getUser() {
+ public UserHandle getUser() {
return mUser;
}
package com.android.launcher3.compat;
import android.content.Context;
-import android.graphics.drawable.Drawable;
-import android.os.Build;
import com.android.launcher3.Utilities;
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);
}
package com.android.launcher3.compat;
-import android.graphics.drawable.Drawable;
-
import java.util.ArrayList;
import java.util.List;
return UserHandleCompat.myUserHandle();
}
- public Drawable getBadgedDrawableForUser(Drawable unbadged,
- UserHandleCompat user) {
- return unbadged;
- }
-
public long getSerialNumberForUser(UserHandleCompat user) {
return 0;
}
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;
}
@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) {
return label;