Search in sources :

Example 16 with NO_CATEGORY

use of com.android.launcher3.widget.WidgetSections.NO_CATEGORY in project android_packages_apps_Launcher3 by ProtonAOSP.

the class PackageUserKeyTest method fromPackageItemInfo_shouldCreateExpectedObject.

@Test
public void fromPackageItemInfo_shouldCreateExpectedObject() {
    PackageUserKey packageUserKey = PackageUserKey.fromPackageItemInfo(new PackageItemInfo(TEST_PACKAGE, UserHandle.CURRENT));
    assertThat(packageUserKey.mPackageName).isEqualTo(TEST_PACKAGE);
    assertThat(packageUserKey.mWidgetCategory).isEqualTo(NO_CATEGORY);
    assertThat(packageUserKey.mUser).isEqualTo(UserHandle.CURRENT);
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 17 with NO_CATEGORY

use of com.android.launcher3.widget.WidgetSections.NO_CATEGORY in project android_packages_apps_Launcher3 by ProtonAOSP.

the class WidgetsModel method getPackageUserKeys.

private List<PackageUserKey> getPackageUserKeys(Context context, WidgetItem item) {
    Map<ComponentName, IntSet> widgetsToCategories = WidgetSections.getWidgetsToCategory(context);
    IntSet categories = widgetsToCategories.get(item.componentName);
    if (categories == null || categories.isEmpty()) {
        return Arrays.asList(new PackageUserKey(item.componentName.getPackageName(), item.user));
    }
    List<PackageUserKey> packageUserKeys = new ArrayList<>();
    categories.forEach(category -> {
        if (category == NO_CATEGORY) {
            packageUserKeys.add(new PackageUserKey(item.componentName.getPackageName(), item.user));
        } else {
            packageUserKeys.add(new PackageUserKey(category, item.user));
        }
    });
    return packageUserKeys;
}
Also used : IntSet(com.android.launcher3.util.IntSet) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) PackageUserKey(com.android.launcher3.util.PackageUserKey)

Example 18 with NO_CATEGORY

use of com.android.launcher3.widget.WidgetSections.NO_CATEGORY in project android_packages_apps_Launcher3 by ProtonAOSP.

the class WidgetSections method parseWidgetSectionsXml.

private static synchronized void parseWidgetSectionsXml(Context context) {
    SparseArray<WidgetSection> widgetSections = new SparseArray();
    Map<ComponentName, IntSet> widgetsToCategories = new ArrayMap<>();
    try (XmlResourceParser parser = context.getResources().getXml(R.xml.widget_sections)) {
        final int depth = parser.getDepth();
        int type;
        while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
            if ((type == XmlPullParser.START_TAG) && TAG_SECTION_NAME.equals(parser.getName())) {
                AttributeSet sectionAttributes = Xml.asAttributeSet(parser);
                WidgetSection section = new WidgetSection(context, sectionAttributes);
                final int sectionDepth = parser.getDepth();
                while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > sectionDepth) && type != XmlPullParser.END_DOCUMENT) {
                    if ((type == XmlPullParser.START_TAG) && TAG_WIDGET_NAME.equals(parser.getName())) {
                        TypedArray a = context.obtainStyledAttributes(Xml.asAttributeSet(parser), R.styleable.WidgetSections);
                        ComponentName provider = ComponentName.unflattenFromString(a.getString(R.styleable.WidgetSections_provider));
                        boolean alsoKeepInApp = a.getBoolean(R.styleable.WidgetSections_alsoKeepInApp, /* defValue= */
                        false);
                        final IntSet categories;
                        if (widgetsToCategories.containsKey(provider)) {
                            categories = widgetsToCategories.get(provider);
                        } else {
                            categories = new IntSet();
                            widgetsToCategories.put(provider, categories);
                        }
                        if (alsoKeepInApp) {
                            categories.add(NO_CATEGORY);
                        }
                        categories.add(section.mCategory);
                    }
                }
                widgetSections.put(section.mCategory, section);
            }
        }
        sWidgetSections = widgetSections;
        sWidgetsToCategories = widgetsToCategories;
    } catch (IOException | XmlPullParserException e) {
        throw new RuntimeException(e);
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) IntSet(com.android.launcher3.util.IntSet) ArrayMap(android.util.ArrayMap) IOException(java.io.IOException) SparseArray(android.util.SparseArray) AttributeSet(android.util.AttributeSet) TypedArray(android.content.res.TypedArray) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 19 with NO_CATEGORY

use of com.android.launcher3.widget.WidgetSections.NO_CATEGORY in project android_packages_apps_Launcher3 by AOSPA.

the class PackageUserKeyTest method fromPackageItemInfo_shouldCreateExpectedObject.

@Test
public void fromPackageItemInfo_shouldCreateExpectedObject() {
    PackageUserKey packageUserKey = PackageUserKey.fromPackageItemInfo(new PackageItemInfo(TEST_PACKAGE, UserHandle.CURRENT));
    assertThat(packageUserKey.mPackageName).isEqualTo(TEST_PACKAGE);
    assertThat(packageUserKey.mWidgetCategory).isEqualTo(NO_CATEGORY);
    assertThat(packageUserKey.mUser).isEqualTo(UserHandle.CURRENT);
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 20 with NO_CATEGORY

use of com.android.launcher3.widget.WidgetSections.NO_CATEGORY in project android_packages_apps_Launcher3 by AOSPA.

the class WidgetSections method parseWidgetSectionsXml.

private static synchronized void parseWidgetSectionsXml(Context context) {
    SparseArray<WidgetSection> widgetSections = new SparseArray();
    Map<ComponentName, IntSet> widgetsToCategories = new ArrayMap<>();
    try (XmlResourceParser parser = context.getResources().getXml(R.xml.widget_sections)) {
        final int depth = parser.getDepth();
        int type;
        while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
            if ((type == XmlPullParser.START_TAG) && TAG_SECTION_NAME.equals(parser.getName())) {
                AttributeSet sectionAttributes = Xml.asAttributeSet(parser);
                WidgetSection section = new WidgetSection(context, sectionAttributes);
                final int sectionDepth = parser.getDepth();
                while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > sectionDepth) && type != XmlPullParser.END_DOCUMENT) {
                    if ((type == XmlPullParser.START_TAG) && TAG_WIDGET_NAME.equals(parser.getName())) {
                        TypedArray a = context.obtainStyledAttributes(Xml.asAttributeSet(parser), R.styleable.WidgetSections);
                        ComponentName provider = ComponentName.unflattenFromString(a.getString(R.styleable.WidgetSections_provider));
                        boolean alsoKeepInApp = a.getBoolean(R.styleable.WidgetSections_alsoKeepInApp, /* defValue= */
                        false);
                        final IntSet categories;
                        if (widgetsToCategories.containsKey(provider)) {
                            categories = widgetsToCategories.get(provider);
                        } else {
                            categories = new IntSet();
                            widgetsToCategories.put(provider, categories);
                        }
                        if (alsoKeepInApp) {
                            categories.add(NO_CATEGORY);
                        }
                        categories.add(section.mCategory);
                    }
                }
                widgetSections.put(section.mCategory, section);
            }
        }
        sWidgetSections = widgetSections;
        sWidgetsToCategories = widgetsToCategories;
    } catch (IOException | XmlPullParserException e) {
        throw new RuntimeException(e);
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) IntSet(com.android.launcher3.util.IntSet) ArrayMap(android.util.ArrayMap) IOException(java.io.IOException) SparseArray(android.util.SparseArray) AttributeSet(android.util.AttributeSet) TypedArray(android.content.res.TypedArray) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Aggregations

ComponentName (android.content.ComponentName)8 IntSet (com.android.launcher3.util.IntSet)8 WidgetSection (com.android.launcher3.widget.WidgetSections.WidgetSection)8 TypedArray (android.content.res.TypedArray)4 XmlResourceParser (android.content.res.XmlResourceParser)4 Drawable (android.graphics.drawable.Drawable)4 ArrayMap (android.util.ArrayMap)4 AttributeSet (android.util.AttributeSet)4 SparseArray (android.util.SparseArray)4 SmallTest (androidx.test.filters.SmallTest)4 PlaceHolderIconDrawable (com.android.launcher3.icons.PlaceHolderIconDrawable)4 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)4 PackageUserKey (com.android.launcher3.util.PackageUserKey)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)4