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

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

Merge "Handling label and icon from SessionInfo." into ub-now-porkchop

parents 66205ce9 34942623
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -298,7 +298,7 @@ public class AutoInstallsLayout implements WorkspaceLoader {
                return -1;
            }

            mValues.put(Favorites.RESTORED, 1);
            mValues.put(Favorites.RESTORED, ShortcutInfo.FLAG_AUTOINTALL_ICON);
            final Intent intent = new Intent(Intent.ACTION_MAIN, null)
                .addCategory(Intent.CATEGORY_LAUNCHER)
                .setComponent(new ComponentName(packageName, className))
+14 −35
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.graphics.Canvas;
import android.graphics.Region;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.KeyEvent;
@@ -50,10 +49,6 @@ public class BubbleTextView extends TextView {
    private static final int SHADOW_SMALL_COLOUR = 0xCC000000;
    static final float PADDING_V = 3.0f;

    private static final String TAG = "BubbleTextView";

    private static final boolean DEBUG = false;

    private HolographicOutlineHelper mOutlineHelper;
    private Bitmap mPressedBackground;

@@ -118,6 +113,11 @@ public class BubbleTextView extends TextView {

    public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache,
            boolean setDefaultPadding) {
        applyFromShortcutInfo(info, iconCache, setDefaultPadding, false);
    }

    public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache,
            boolean setDefaultPadding, boolean promiseStateChanged) {
        Bitmap b = info.getIcon(iconCache);
        LauncherAppState app = LauncherAppState.getInstance();

@@ -135,8 +135,8 @@ public class BubbleTextView extends TextView {
        setText(info.title);
        setTag(info);

        if (info.wasPromise) {
            applyState();
        if (promiseStateChanged || info.isPromise()) {
            applyState(promiseStateChanged);
        }
    }

@@ -377,31 +377,13 @@ public class BubbleTextView extends TextView {
        mLongPressHelper.cancelLongPress();
    }

    public void applyState() {
    public void applyState(boolean promiseStateChanged) {
        if (getTag() instanceof ShortcutInfo) {
            ShortcutInfo info = (ShortcutInfo) getTag();
            final int state = info.getState();

            final int progressLevel;
            if (DEBUG) Log.d(TAG, "applying icon state: " + state);

            switch(state) {
                case ShortcutInfo.PACKAGE_STATE_DEFAULT:
                    progressLevel = 100;
                    break;

                case ShortcutInfo.PACKAGE_STATE_INSTALLING:
                    setText(R.string.package_state_installing);
                    progressLevel = info.getProgress();
                    break;

                case ShortcutInfo.PACKAGE_STATE_ERROR:
                case ShortcutInfo.PACKAGE_STATE_UNKNOWN:
                default:
                    progressLevel = 0;
                    setText(R.string.package_state_unknown);
                    break;
            }
            final boolean isPromise = info.isPromise();
            final int progressLevel = isPromise ?
                    ((info.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE) ?
                            info.getInstallProgress() : 0)) : 100;

            Drawable[] drawables = getCompoundDrawables();
            Drawable top = drawables[1];
@@ -415,12 +397,9 @@ public class BubbleTextView extends TextView {
                }

                preloadDrawable.setLevel(progressLevel);
                if ((state == ShortcutInfo.PACKAGE_STATE_DEFAULT) && info.wasPromise) {
                    // Clear the promise flag as it is no longer different than a normal shortcut,
                    // once the animation has been run.
                    info.wasPromise = !preloadDrawable.maybePerformFinishedAnimation();
                if (promiseStateChanged) {
                    preloadDrawable.maybePerformFinishedAnimation();
                }

            }
        }
    }
+47 −5
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.Log;

import com.android.launcher3.compat.LauncherActivityInfoCompat;
@@ -254,18 +255,16 @@ public class IconCache {
        return getIcon(intent, null, user, true);
    }

    public Bitmap getIcon(Intent intent, String title, UserHandleCompat user, boolean usePkgIcon) {
    private Bitmap getIcon(Intent intent, String title, UserHandleCompat user, boolean usePkgIcon) {
        synchronized (mCache) {
            LauncherActivityInfoCompat launcherActInfo =
                    mLauncherApps.resolveActivity(intent, user);
            ComponentName component = intent.getComponent();

            // null info means not installed, but if we have a component from the intent then
            // we should still look in the cache for restored app icons.
            if (component == null) {
                return getDefaultIcon(user);
            }

            LauncherActivityInfoCompat launcherActInfo = mLauncherApps.resolveActivity(intent, user);
            CacheEntry entry = cacheLocked(component, launcherActInfo, null, user, usePkgIcon);
            if (title != null) {
                entry.title = title;
@@ -275,6 +274,32 @@ public class IconCache {
        }
    }

    /**
     * Fill in "shortcutInfo" with the icon and label for "info."
     */
    public void getTitleAndIcon(ShortcutInfo shortcutInfo, Intent intent, UserHandleCompat user,
            boolean usePkgIcon) {
        synchronized (mCache) {
            ComponentName component = intent.getComponent();
            // null info means not installed, but if we have a component from the intent then
            // we should still look in the cache for restored app icons.
            if (component == null) {
                shortcutInfo.setIcon(getDefaultIcon(user));
                shortcutInfo.title = "";
                shortcutInfo.usingFallbackIcon = true;
            } else {
                LauncherActivityInfoCompat launcherActInfo =
                        mLauncherApps.resolveActivity(intent, user);
                CacheEntry entry = cacheLocked(component, launcherActInfo, null, user, usePkgIcon);

                shortcutInfo.setIcon(entry.icon);
                shortcutInfo.title = entry.title;
                shortcutInfo.usingFallbackIcon = isDefaultIcon(entry.icon, user);
            }
        }
    }


    public Bitmap getDefaultIcon(UserHandleCompat user) {
        if (!mDefaultIcons.containsKey(user)) {
            mDefaultIcons.put(user, makeDefaultIcon(user));
@@ -332,10 +357,11 @@ public class IconCache {
                    if (usePackageIcon) {
                        CacheEntry packageEntry = getEntryForPackage(
                                componentName.getPackageName(), user);
                        if (packageEntry != null && packageEntry.icon != null) {
                        if (packageEntry != null) {
                            if (DEBUG) Log.d(TAG, "using package default icon for " +
                                    componentName.toShortString());
                            entry.icon = packageEntry.icon;
                            entry.title = packageEntry.title;
                        }
                    }
                    if (entry.icon == null) {
@@ -349,6 +375,21 @@ public class IconCache {
        return entry;
    }

    /**
     * Adds a default package entry in the cache. This entry is not persisted and will be removed
     * when the cache is flushed.
     */
    public void cachePackageInstallInfo(String packageName, UserHandleCompat user,
            Bitmap icon, CharSequence title) {
        CacheEntry entry = getEntryForPackage(packageName, user);
        if (!TextUtils.isEmpty(title)) {
            entry.title = title;
        }
        if (icon != null) {
            entry.icon = Utilities.createIconBitmap(icon, mContext);
        }
    }

    /**
     * Gets an entry for the package, which can be used as a fallback entry for various components.
     */
@@ -358,6 +399,7 @@ public class IconCache {
        CacheEntry entry = mCache.get(cacheKey);
        if (entry == null) {
            entry = new CacheEntry();
            entry.title = "";
            mCache.put(cacheKey, entry);

            try {
+0 −4
Original line number Diff line number Diff line
@@ -146,10 +146,6 @@ public class ItemInfo {
        throw new RuntimeException("Unexpected Intent");
    }

    protected Intent getRestoredIntent() {
        throw new RuntimeException("Unexpected Intent");
    }

    /**
     * Write the fields of this item to the DB
     * 
+4 −2
Original line number Diff line number Diff line
@@ -2600,9 +2600,11 @@ public class Launcher extends Activity
        }

        // Check for abandoned promise
        if (shortcut.isAbandoned() && v instanceof BubbleTextView) {
        if ((v instanceof BubbleTextView)
                && shortcut.isPromise()
                && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
            showBrokenAppInstallDialog(
                    shortcut.getRestoredIntent().getComponent().getPackageName(),
                    shortcut.getTargetComponent().getPackageName(),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            startAppShortcutOrInfoActivity(v);
Loading