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

Commit aa4011e6 authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Scaling down the icon before applying the user badge > This also...

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
parents ac929f4a 0b621156
Loading
Loading
Loading
Loading
+7 −14
Original line number Diff line number Diff line
@@ -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;
+24 −0
Original line number Diff line number Diff line
@@ -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.
     */
+0 −1
Original line number Diff line number Diff line
@@ -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.
+0 −4
Original line number Diff line number Diff line
@@ -93,8 +93,4 @@ public class LauncherActivityInfoCompatV16 extends LauncherActivityInfoCompat {
    public String getName() {
        return mActivityInfo.name;
    }

    public Drawable getBadgedIcon(int density) {
        return getIcon(density);
    }
}
+0 −4
Original line number Diff line number Diff line
@@ -55,8 +55,4 @@ public class LauncherActivityInfoCompatVL extends LauncherActivityInfoCompat {
    public long getFirstInstallTime() {
        return mLauncherActivityInfo.getFirstInstallTime();
    }

    public Drawable getBadgedIcon(int density) {
        return mLauncherActivityInfo.getBadgedIcon(density);
    }
}
Loading