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

Commit af7e122d authored by Sumedh Sen's avatar Sumedh Sen Committed by Android (Google) Code Review
Browse files

Merge "Resize large app icons before adding them in a parcel" into main

parents e7bb976d 2fc482f6
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -609,7 +609,7 @@ public class PackageInstallerActivity extends AlertActivity {
                CharSequence label = mPm.getApplicationLabel(mPkgInfo.applicationInfo);
                if (mLocalLOGV) Log.i(TAG, "creating snippet for " + label);
                mAppSnippet = new PackageUtil.AppSnippet(label,
                        mPm.getApplicationIcon(mPkgInfo.applicationInfo));
                        mPm.getApplicationIcon(mPkgInfo.applicationInfo), getBaseContext());
            } break;

            case ContentResolver.SCHEME_FILE: {
@@ -647,7 +647,7 @@ public class PackageInstallerActivity extends AlertActivity {
        mPkgInfo = generateStubPackageInfo(info.getAppPackageName());
        mAppSnippet = new PackageUtil.AppSnippet(info.getAppLabel(),
                info.getAppIcon() != null ? new BitmapDrawable(getResources(), info.getAppIcon())
                        : getPackageManager().getDefaultActivityIcon());
                        : getPackageManager().getDefaultActivityIcon(), getBaseContext());
        return true;
    }

+14 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
package com.android.packageinstaller;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
@@ -135,15 +136,20 @@ public class PackageUtil {
    static final class AppSnippet implements Parcelable {
        @NonNull public CharSequence label;
        @Nullable public Drawable icon;
        public AppSnippet(@NonNull CharSequence label, @Nullable Drawable icon) {
        public int iconSize;

        AppSnippet(@NonNull CharSequence label, @Nullable Drawable icon, Context context) {
            this.label = label;
            this.icon = icon;
            final ActivityManager am = context.getSystemService(ActivityManager.class);
            this.iconSize = am.getLauncherLargeIconSize();
        }

        private AppSnippet(Parcel in) {
            label = in.readString();
            Bitmap bmp = in.readParcelable(getClass().getClassLoader(), Bitmap.class);
            icon = new BitmapDrawable(Resources.getSystem(), bmp);
            iconSize = in.readInt();
        }

        @Override
@@ -161,11 +167,12 @@ public class PackageUtil {
            dest.writeString(label.toString());
            Bitmap bmp = getBitmapFromDrawable(icon);
            dest.writeParcelable(bmp, 0);
            dest.writeInt(iconSize);
        }

        private Bitmap getBitmapFromDrawable(Drawable drawable) {
            // Create an empty bitmap with the dimensions of our drawable
            final Bitmap bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
            Bitmap bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                    drawable.getIntrinsicHeight(),
                    Bitmap.Config.ARGB_8888);
            // Associate it with a canvas. This canvas will draw the icon on the bitmap
@@ -174,6 +181,10 @@ public class PackageUtil {
            // bitmap held within
            drawable.draw(canvas);

            // Scale it down if the icon is too large
            if ((bmp.getWidth() > iconSize * 2) || (bmp.getHeight() > iconSize * 2)) {
                bmp = Bitmap.createScaledBitmap(bmp, iconSize, iconSize, true);
            }
            return bmp;
        }

@@ -241,7 +252,7 @@ public class PackageUtil {
        } catch (OutOfMemoryError e) {
            Log.i(LOG_TAG, "Could not load app icon", e);
        }
        return new PackageUtil.AppSnippet(label, icon);
        return new PackageUtil.AppSnippet(label, icon, pContext);
    }

    private static String findFilePath(File[] files, String postfix) {