Search in sources :

Example 71 with WIDGETS

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

the class WidgetsDiffReporterTest method headersContentsMix_headerWidgetsModified_shouldInvokeCorrectCallbacks.

@Test
public void headersContentsMix_headerWidgetsModified_shouldInvokeCorrectCallbacks() {
    // GIVEN the current list has app headers [A, B, E content].
    ArrayList<WidgetsListBaseEntry> currentList = new ArrayList<>(List.of(mHeaderA, mHeaderB, mContentE));
    // GIVEN the new list has one of the headers widgets list modified.
    List<WidgetsListBaseEntry> newList = List.of(new WidgetsListHeaderEntry(mHeaderA.mPkgItem, mHeaderA.mTitleSectionName, mHeaderA.mWidgets.subList(0, 1)), mHeaderB, mContentE);
    // WHEN computing the list difference.
    mWidgetsDiffReporter.process(currentList, newList, COMPARATOR);
    // THEN notify "A" has been changed.
    verify(mAdapter).notifyItemChanged(/* position= */
    0);
    // THEN the current list contains all elements from the new list.
    assertThat(currentList).containsExactlyElementsIn(newList);
}
Also used : WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) ArrayList(java.util.ArrayList) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 72 with WIDGETS

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

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 73 with WIDGETS

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

the class WidgetsPredictionUpdateTask method execute.

/**
 * Uses the app predication result to infer widgets that the user may want to use.
 *
 * <p>The algorithm uses the app prediction ranking to create a widgets ranking which only
 * includes one widget per app and excludes widgets that have already been added to the
 * workspace.
 */
@Override
public void execute(LauncherAppState appState, BgDataModel dataModel, AllAppsList apps) {
    Set<ComponentKey> widgetsInWorkspace = dataModel.appWidgets.stream().map(widget -> new ComponentKey(widget.providerName, widget.user)).collect(Collectors.toSet());
    Map<PackageUserKey, List<WidgetItem>> allWidgets = dataModel.widgetsModel.getAllWidgetsWithoutShortcuts();
    FixedContainerItems fixedContainerItems = mPredictorState.items;
    fixedContainerItems.items.clear();
    if (FeatureFlags.ENABLE_LOCAL_RECOMMENDED_WIDGETS_FILTER.get()) {
        for (AppTarget app : mTargets) {
            PackageUserKey packageUserKey = new PackageUserKey(app.getPackageName(), app.getUser());
            if (allWidgets.containsKey(packageUserKey)) {
                List<WidgetItem> notAddedWidgets = allWidgets.get(packageUserKey).stream().filter(item -> !widgetsInWorkspace.contains(new ComponentKey(item.componentName, item.user))).collect(Collectors.toList());
                if (notAddedWidgets.size() > 0) {
                    // Even an apps have more than one widgets, we only include one widget.
                    fixedContainerItems.items.add(new PendingAddWidgetInfo(notAddedWidgets.get(0).widgetInfo, CONTAINER_WIDGETS_PREDICTION));
                }
            }
        }
    } else {
        Map<ComponentKey, WidgetItem> widgetItems = allWidgets.values().stream().flatMap(List::stream).distinct().collect(Collectors.toMap(widget -> (ComponentKey) widget, widget -> widget));
        for (AppTarget app : mTargets) {
            if (TextUtils.isEmpty(app.getClassName())) {
                continue;
            }
            ComponentKey targetWidget = new ComponentKey(new ComponentName(app.getPackageName(), app.getClassName()), app.getUser());
            if (widgetItems.containsKey(targetWidget)) {
                fixedContainerItems.items.add(new PendingAddWidgetInfo(widgetItems.get(targetWidget).widgetInfo, CONTAINER_WIDGETS_PREDICTION));
            }
        }
    }
    bindExtraContainerItems(fixedContainerItems);
// Don't store widgets prediction to disk because it is not used frequently.
}
Also used : CONTAINER_WIDGETS_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION) ComponentName(android.content.ComponentName) LauncherAppState(com.android.launcher3.LauncherAppState) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) PackageUserKey(com.android.launcher3.util.PackageUserKey) Set(java.util.Set) TextUtils(android.text.TextUtils) FeatureFlags(com.android.launcher3.config.FeatureFlags) Collectors(java.util.stream.Collectors) AppTarget(android.app.prediction.AppTarget) List(java.util.List) ComponentKey(com.android.launcher3.util.ComponentKey) Map(java.util.Map) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) PredictorState(com.android.launcher3.model.QuickstepModelDelegate.PredictorState) ComponentKey(com.android.launcher3.util.ComponentKey) PackageUserKey(com.android.launcher3.util.PackageUserKey) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) AppTarget(android.app.prediction.AppTarget) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) List(java.util.List) ComponentName(android.content.ComponentName)

Example 74 with WIDGETS

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

the class PopupDataProvider method getRecommendedWidgets.

/**
 * Returns a list of recommended widgets.
 */
public List<WidgetItem> getRecommendedWidgets() {
    HashMap<ComponentKey, WidgetItem> allWidgetItems = new HashMap<>();
    mAllWidgets.stream().filter(entry -> entry instanceof WidgetsListContentEntry).forEach(entry -> ((WidgetsListContentEntry) entry).mWidgets.forEach(widget -> allWidgetItems.put(new ComponentKey(widget.componentName, widget.user), widget)));
    return mRecommendedWidgets.stream().map(recommendedWidget -> allWidgetItems.get(new ComponentKey(recommendedWidget.getTargetComponent(), recommendedWidget.user))).filter(Objects::nonNull).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) NonNull(androidx.annotation.NonNull) ItemInfo(com.android.launcher3.model.data.ItemInfo) HashMap(java.util.HashMap) NotificationKeyData(com.android.launcher3.notification.NotificationKeyData) WidgetItem(com.android.launcher3.model.WidgetItem) Map(java.util.Map) Log(android.util.Log) PrintWriter(java.io.PrintWriter) ComponentName(android.content.ComponentName) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) Predicate(java.util.function.Predicate) PackageUserKey(com.android.launcher3.util.PackageUserKey) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Nullable(androidx.annotation.Nullable) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) NotificationListener(com.android.launcher3.notification.NotificationListener) ShortcutUtil(com.android.launcher3.util.ShortcutUtil) ComponentKey(com.android.launcher3.util.ComponentKey) Collections(java.util.Collections) StatusBarNotification(android.service.notification.StatusBarNotification) DotInfo(com.android.launcher3.dot.DotInfo) HashMap(java.util.HashMap) ComponentKey(com.android.launcher3.util.ComponentKey) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 75 with WIDGETS

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

the class Workspace method widgetsRestored.

public void widgetsRestored(final ArrayList<LauncherAppWidgetInfo> changedInfo) {
    if (!changedInfo.isEmpty()) {
        DeferredWidgetRefresh widgetRefresh = new DeferredWidgetRefresh(changedInfo, mLauncher.getAppWidgetHost());
        LauncherAppWidgetInfo item = changedInfo.get(0);
        final AppWidgetProviderInfo widgetInfo;
        WidgetManagerHelper widgetHelper = new WidgetManagerHelper(getContext());
        if (item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
            widgetInfo = widgetHelper.findProvider(item.providerName, item.user);
        } else {
            widgetInfo = widgetHelper.getLauncherAppWidgetInfo(item.appWidgetId);
        }
        if (widgetInfo != null) {
            // Re-inflate the widgets which have changed status
            widgetRefresh.run();
        } else {
            // widgetRefresh will automatically run when the packages are updated.
            // For now just update the progress bars
            mapOverItems(new ItemOperator() {

                @Override
                public boolean evaluate(ItemInfo info, View view) {
                    if (view instanceof PendingAppWidgetHostView && changedInfo.contains(info)) {
                        ((LauncherAppWidgetInfo) info).installProgress = 100;
                        ((PendingAppWidgetHostView) view).applyState();
                    }
                    // process all the shortcuts
                    return false;
                }
            });
        }
    }
}
Also used : WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) SearchActionItemInfo(com.android.launcher3.model.data.SearchActionItemInfo) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) 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)

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