Search in sources :

Example 46 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project Neo-Launcher by NeoApplications.

the class WidgetsModel method update.

/**
 * @param packageUser If null, all widgets and shortcuts are updated and returned, otherwise
 *                    only widgets and shortcuts associated with the package/user are.
 */
public List<ComponentWithLabel> update(LauncherAppState app, @Nullable PackageUserKey packageUser) {
    Preconditions.assertWorkerThread();
    Context context = app.getContext();
    final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
    List<ComponentWithLabel> updatedItems = new ArrayList<>();
    try {
        InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
        PackageManager pm = app.getContext().getPackageManager();
        // Widgets
        AppWidgetManagerCompat widgetManager = AppWidgetManagerCompat.getInstance(context);
        for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(packageUser)) {
            LauncherAppWidgetProviderInfo launcherWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo);
            widgetsAndShortcuts.add(new WidgetItem(launcherWidgetInfo, idp, app.getIconCache()));
            updatedItems.add(launcherWidgetInfo);
        }
        // Shortcuts
        for (ShortcutConfigActivityInfo info : LauncherAppsCompat.getInstance(context).getCustomShortcutActivityList(packageUser)) {
            widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache(), pm));
            updatedItems.add(info);
        }
        setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser);
    } catch (Exception e) {
        if (!FeatureFlags.IS_DOGFOOD_BUILD && Utilities.isBinderSizeError(e)) {
        // the returned value may be incomplete and will not be refreshed until the next
        // time Launcher starts.
        // TODO: after figuring out a repro step, introduce a dirty bit to check when
        // onResume is called to refresh the widget provider list.
        } else {
            throw e;
        }
    }
    app.getWidgetCache().removeObsoletePreviews(widgetsAndShortcuts, packageUser);
    return updatedItems;
}
Also used : Context(android.content.Context) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ArrayList(java.util.ArrayList) AppWidgetManagerCompat(com.android.launcher3.compat.AppWidgetManagerCompat) PackageManager(android.content.pm.PackageManager) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) ShortcutConfigActivityInfo(com.android.launcher3.compat.ShortcutConfigActivityInfo) ComponentWithLabel(com.android.launcher3.icons.ComponentWithLabel)

Example 47 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project Neo-Launcher by NeoApplications.

the class CustomWidgetParser method parseCustomWidgets.

private static void parseCustomWidgets(Context context) {
    ArrayList<LauncherAppWidgetProviderInfo> widgets = new ArrayList<>();
    SparseArray<ComponentName> idMap = new SparseArray<>();
    List<AppWidgetProviderInfo> providers = AppWidgetManager.getInstance(context).getInstalledProvidersForProfile(Process.myUserHandle());
    if (providers.isEmpty()) {
        sCustomWidgets = widgets;
        sWidgetsIdMap = idMap;
        return;
    }
    Parcel parcel = Parcel.obtain();
    providers.get(0).writeToParcel(parcel, 0);
    try (XmlResourceParser parser = context.getResources().getXml(R.xml.custom_widgets)) {
        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) && "widget".equals(parser.getName())) {
                TypedArray a = context.obtainStyledAttributes(Xml.asAttributeSet(parser), R.styleable.CustomAppWidgetProviderInfo);
                parcel.setDataPosition(0);
                CustomAppWidgetProviderInfo info = newInfo(a, parcel, context);
                widgets.add(info);
                a.recycle();
                idMap.put(info.providerId, info.provider);
            }
        }
    } catch (IOException | XmlPullParserException e) {
        throw new RuntimeException(e);
    }
    parcel.recycle();
    sCustomWidgets = widgets;
    sWidgetsIdMap = idMap;
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) XmlResourceParser(android.content.res.XmlResourceParser) Parcel(android.os.Parcel) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SparseArray(android.util.SparseArray) TypedArray(android.content.res.TypedArray) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 48 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project Neo-Launcher by NeoApplications.

the class TaplTestsLauncher3 method testWidgets.

@Test
@PortraitLandscape
public void testWidgets() throws Exception {
    // Test opening widgets.
    executeOnLauncher(launcher -> assertTrue("Widgets is initially opened", getWidgetsView(launcher) == null));
    Widgets widgets = mLauncher.getWorkspace().openAllWidgets();
    assertNotNull("openAllWidgets() returned null", widgets);
    widgets = mLauncher.getAllWidgets();
    assertNotNull("getAllWidgets() returned null", widgets);
    executeOnLauncher(launcher -> assertTrue("Widgets is not shown", getWidgetsView(launcher).isShown()));
    executeOnLauncher(launcher -> assertEquals("Widgets is scrolled upon opening", 0, getWidgetsScroll(launcher)));
    // Test flinging widgets.
    widgets.flingForward();
    Integer flingForwardY = getFromLauncher(launcher -> getWidgetsScroll(launcher));
    executeOnLauncher(launcher -> assertTrue("Flinging forward didn't scroll widgets", flingForwardY > 0));
    widgets.flingBackward();
    executeOnLauncher(launcher -> assertTrue("Flinging backward didn't scroll widgets", getWidgetsScroll(launcher) < flingForwardY));
    mLauncher.pressHome();
    waitForLauncherCondition("Widgets were not closed", launcher -> getWidgetsView(launcher) == null);
}
Also used : Widgets(com.android.launcher3.tapl.Widgets) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 49 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project Neo-Launcher by NeoApplications.

the class AddConfigWidgetTest method runTest.

/**
 * @param acceptConfig accept the config activity
 */
private void runTest(boolean acceptConfig) throws Throwable {
    clearHomescreen();
    mDevice.pressHome();
    final Widgets widgets = mLauncher.getWorkspace().openAllWidgets();
    // Drag widget to homescreen
    WidgetConfigStartupMonitor monitor = new WidgetConfigStartupMonitor();
    widgets.getWidget(mWidgetInfo.getLabel(mTargetContext.getPackageManager())).dragToWorkspace();
    // Widget id for which the config activity was opened
    mWidgetId = monitor.getWidgetId();
    // Verify that the widget id is valid and bound
    assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
    setResult(acceptConfig);
    if (acceptConfig) {
        Wait.atMost(null, new WidgetSearchCondition(), DEFAULT_ACTIVITY_TIMEOUT);
        assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
    } else {
        // Verify that the widget id is deleted.
        Wait.atMost(null, () -> mAppWidgetManager.getAppWidgetInfo(mWidgetId) == null, DEFAULT_ACTIVITY_TIMEOUT);
    }
}
Also used : Widgets(com.android.launcher3.tapl.Widgets)

Example 50 with WIDGETS

use of com.android.launcher3.popup.SystemShortcut.WIDGETS in project android_packages_apps_Launcher3 by ArrowOS.

the class Workspace method removeItemsByMatcher.

/**
 * Removes items that match the {@param matcher}. When applications are removed
 * as a part of an update, this is called to ensure that other widgets and application
 * shortcuts are not removed.
 */
public void removeItemsByMatcher(final ItemInfoMatcher matcher) {
    for (CellLayout layout : getWorkspaceAndHotseatCellLayouts()) {
        ShortcutAndWidgetContainer container = layout.getShortcutsAndWidgets();
        // Iterate in reverse order as we are removing items
        for (int i = container.getChildCount() - 1; i >= 0; i--) {
            View child = container.getChildAt(i);
            ItemInfo info = (ItemInfo) child.getTag();
            if (matcher.matchesInfo(info)) {
                layout.removeViewInLayout(child);
                if (child instanceof DropTarget) {
                    mDragController.removeDropTarget((DropTarget) child);
                }
            } else if (child instanceof FolderIcon) {
                FolderInfo folderInfo = (FolderInfo) info;
                List<WorkspaceItemInfo> matches = folderInfo.contents.stream().filter(matcher::matchesInfo).collect(Collectors.toList());
                if (!matches.isEmpty()) {
                    folderInfo.removeAll(matches, false);
                    if (((FolderIcon) child).getFolder().isOpen()) {
                        ((FolderIcon) child).getFolder().close(false);
                    }
                }
            }
        }
    }
    // Strip all the empty screens
    stripEmptyScreens();
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) SearchActionItemInfo(com.android.launcher3.model.data.SearchActionItemInfo) FolderIcon(com.android.launcher3.folder.FolderIcon) ArrayList(java.util.ArrayList) RunnableList(com.android.launcher3.util.RunnableList) List(java.util.List) DraggableView(com.android.launcher3.dragndrop.DraggableView) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) DragView(com.android.launcher3.dragndrop.DragView) FolderInfo(com.android.launcher3.model.data.FolderInfo) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Aggregations

ArrayList (java.util.ArrayList)64 Test (org.junit.Test)64 WidgetItem (com.android.launcher3.model.WidgetItem)54 WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)54 PackageUserKey (com.android.launcher3.util.PackageUserKey)50 List (java.util.List)50 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)46 SmallTest (androidx.test.filters.SmallTest)44 ComponentName (android.content.ComponentName)42 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)41 Point (android.graphics.Point)40 View (android.view.View)37 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)32 Collectors (java.util.stream.Collectors)31 Context (android.content.Context)29 IconCache (com.android.launcher3.icons.IconCache)29 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)29 WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)29 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)27 PendingAddWidgetInfo (com.android.launcher3.widget.PendingAddWidgetInfo)27