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

Commit 43859f10 authored by Steven Ng's avatar Steven Ng
Browse files

Group weather widgets under the widget category

Test: manual (see video in bug) and added PackageUserKeyTest
      Also tested pending conversation widget to ensure the right icon
      is shown.
Fix: 201062480
Change-Id: If23c28bd93c54fb1747648309ab3c238a1810902
parent 9c871ae7
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -79,12 +79,13 @@ public class WidgetsModel {
    }

    public WidgetItem getWidgetProviderInfoByProviderName(
            ComponentName providerName) {
            ComponentName providerName, UserHandle user) {
        return null;
    }

    /** Returns {@link PackageItemInfo} of a pending widget. */
    public static PackageItemInfo newPendingItemInfo(ComponentName provider) {
        return new PackageItemInfo(provider.getPackageName());
    public static PackageItemInfo newPendingItemInfo(
            Context context, ComponentName provider, UserHandle userHandle) {
        return new PackageItemInfo(provider.getPackageName(), userHandle);
    }
}
 No newline at end of file
+14 −0
Original line number Diff line number Diff line
@@ -258,4 +258,18 @@
    <declare-styleable name="WidgetsListRowHeader">
        <attr name="appIconSize" format="dimension" />
    </declare-styleable>

    <declare-styleable name="WidgetSections">
        <!-- Component name of an app widget provider. -->
        <attr name="provider" format="string" />
        <!-- If true, keep the app widget under its app listing in addition to the widget category
             in the widget picker. Defaults to false if not specified. -->
        <attr name="alsoKeepInApp" format="boolean" />
        <!-- The category of an app widget provider. Defaults to -1 if not specified. -->
        <attr name="category" format="integer" />
        <!-- The title name of a widget category. -->
        <attr name="sectionTitle" format="reference" />
        <!-- The icon drawable of a widget category. -->
        <attr name="sectionDrawable" format="reference" />
    </declare-styleable>
</resources>
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2021 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<widget-sections xmlns:launcher="http://schemas.android.com/apk/res-auto">
    <section
        launcher:category="0"
        launcher:sectionDrawable="@drawable/ic_conversations_widget_category"
        launcher:sectionTitle="@string/widget_category_conversations">
        <widget launcher:provider="com.android.systemui/.people.widget.PeopleSpaceWidgetProvider" />
    </section>
</widget-sections>
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -349,7 +349,7 @@ public class LauncherPreviewRenderer extends ContextWrapper

    private void inflateAndAddWidgets(LauncherAppWidgetInfo info, WidgetsModel widgetsModel) {
        WidgetItem widgetItem = widgetsModel.getWidgetProviderInfoByProviderName(
                info.providerName);
                info.providerName, info.user);
        if (widgetItem == null) {
            return;
        }
+9 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.launcher3.icons;

import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import static com.android.launcher3.widget.WidgetSections.NO_CATEGORY;

import static java.util.stream.Collectors.groupingBy;

@@ -46,7 +47,6 @@ import androidx.annotation.NonNull;

import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherFiles;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.icons.ComponentWithLabel.ComponentCachingLogic;
@@ -63,6 +63,8 @@ import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.util.InstantAppResolver;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.widget.WidgetSections;
import com.android.launcher3.widget.WidgetSections.WidgetSection;

import java.util.Collections;
import java.util.List;
@@ -275,7 +277,8 @@ public class IconCache extends BaseIconCache {
            getTitleAndIcon(appInfo, false);
            return appInfo.bitmap;
        } else {
            PackageItemInfo pkgInfo = new PackageItemInfo(shortcutInfo.getPackage());
            PackageItemInfo pkgInfo = new PackageItemInfo(shortcutInfo.getPackage(),
                    shortcutInfo.getUserHandle());
            getTitleAndIconForApp(pkgInfo, false);
            return pkgInfo.bitmap;
        }
@@ -409,8 +412,10 @@ public class IconCache extends BaseIconCache {
        CacheEntry entry = getEntryForPackageLocked(
                infoInOut.packageName, infoInOut.user, useLowResIcon);
        applyCacheEntry(entry, infoInOut);
        if (infoInOut.category == PackageItemInfo.CONVERSATIONS) {
            infoInOut.title = mContext.getString(R.string.widget_category_conversations);
        if (infoInOut.widgetCategory != NO_CATEGORY) {
            WidgetSection widgetSection = WidgetSections.getWidgetSections(mContext)
                    .get(infoInOut.widgetCategory);
            infoInOut.title = mContext.getString(widgetSection.mSectionTitle);
            infoInOut.contentDescription = mPackageManager.getUserBadgedLabel(
                    infoInOut.title, infoInOut.user);
        }
Loading