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

Commit d35dcdec authored by Steven Ng's avatar Steven Ng Committed by Android (Google) Code Review
Browse files

Merge "Use category icon for pending conversation widgets" into sc-dev

parents 1b6a8b22 12f7a59e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import androidx.annotation.Nullable;

import com.android.launcher3.LauncherAppState;
import com.android.launcher3.icons.ComponentWithLabelAndIcon;
import com.android.launcher3.model.data.PackageItemInfo;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.widget.model.WidgetsListBaseEntry;

@@ -81,4 +82,9 @@ public class WidgetsModel {
            ComponentName providerName) {
        return null;
    }

    /** Returns {@link PackageItemInfo} of a pending widget. */
    public static PackageItemInfo newPendingItemInfo(ComponentName provider) {
        return new PackageItemInfo(provider.getPackageName());
    }
}
 No newline at end of file
+2 −3
Original line number Diff line number Diff line
@@ -75,7 +75,6 @@ import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.ItemInfoWithIcon;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.model.data.PackageItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.pm.InstallSessionHelper;
import com.android.launcher3.pm.PackageInstallInfo;
@@ -791,8 +790,8 @@ public class LoaderTask implements Runnable {

                                if (appWidgetInfo.restoreStatus !=
                                        LauncherAppWidgetInfo.RESTORE_COMPLETED) {
                                    String pkg = appWidgetInfo.providerName.getPackageName();
                                    appWidgetInfo.pendingItemInfo = new PackageItemInfo(pkg);
                                    appWidgetInfo.pendingItemInfo = WidgetsModel.newPendingItemInfo(
                                            appWidgetInfo.providerName);
                                    appWidgetInfo.pendingItemInfo.user = appWidgetInfo.user;
                                    mIconCache.getTitleAndIconForApp(
                                            appWidgetInfo.pendingItemInfo, false);
+34 −5
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.launcher3.widget;

import static com.android.launcher3.graphics.PreloadIconDrawable.newPendingIcon;
import static com.android.launcher3.model.data.PackageItemInfo.CONVERSATIONS;

import android.content.Context;
import android.graphics.Canvas;
@@ -35,6 +36,8 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RemoteViews;

import androidx.annotation.Nullable;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.icons.FastBitmapDrawable;
@@ -146,21 +149,32 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView
            mCenterDrawable = null;
        }
        if (info.bitmap.icon != null) {
            Drawable widgetCategoryIcon = getWidgetCategoryIcon();
            // The view displays three modes,
            //   1) App icon in the center
            //   2) Preload icon in the center
            //   3) App icon in the center with a setup icon on the top left corner.
            if (mDisabledForSafeMode) {
                if (widgetCategoryIcon == null) {
                    FastBitmapDrawable disabledIcon = info.newIcon(getContext());
                    disabledIcon.setIsDisabled(true);
                    mCenterDrawable = disabledIcon;
                } else {
                    widgetCategoryIcon.setColorFilter(
                            FastBitmapDrawable.getDisabledFColorFilter(/* disabledAlpha= */ 1f));
                    mCenterDrawable = widgetCategoryIcon;
                }
                mSettingIconDrawable = null;
            } else if (isReadyForClickSetup()) {
                mCenterDrawable = info.newIcon(getContext());
                mCenterDrawable = widgetCategoryIcon == null
                        ? info.newIcon(getContext())
                        : widgetCategoryIcon;
                mSettingIconDrawable = getResources().getDrawable(R.drawable.ic_setting).mutate();
                updateSettingColor(info.bitmap.color);
            } else {
                mCenterDrawable = newPendingIcon(getContext(), info);
                mCenterDrawable = widgetCategoryIcon == null
                        ? newPendingIcon(getContext(), info)
                        : widgetCategoryIcon;
                mSettingIconDrawable = null;
                applyState();
            }
@@ -316,4 +330,19 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView
        }

    }

    /**
     * Returns the widget category icon for {@link #mInfo}.
     *
     * <p>If {@link #mInfo}'s category is {@code PackageItemInfo#NO_CATEGORY} or unknown, returns
     * {@code null}.
     */
    @Nullable
    private Drawable getWidgetCategoryIcon() {
        switch (mInfo.pendingItemInfo.category) {
            case CONVERSATIONS:
                return getContext().getDrawable(R.drawable.ic_conversations_widget_category);
        }
        return null;
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -225,6 +225,14 @@ public class WidgetsModel {
        return null;
    }

    /** Returns {@link PackageItemInfo} of a pending widget. */
    public static PackageItemInfo newPendingItemInfo(ComponentName provider) {
        if (CONVERSATION_WIDGET.equals(provider)) {
            return new PackageItemInfo(provider.getPackageName(), PackageItemInfo.CONVERSATIONS);
        }
        return new PackageItemInfo(provider.getPackageName());
    }

    private WidgetPackageOrCategoryKey getWidgetPackageOrCategoryKey(WidgetItem item) {
        if (CONVERSATION_WIDGET.equals(item.componentName)) {
            return new WidgetPackageOrCategoryKey(PackageItemInfo.CONVERSATIONS, item.user);