Search in sources :

Example 16 with WIDGETS

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

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)

Example 17 with WIDGETS

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

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();
    WidgetResizeFrame resizeFrame = widgets.getWidget(mWidgetInfo.getLabel(mTargetContext.getPackageManager())).dragConfigWidgetToWorkspace(acceptConfig);
    // 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));
    if (acceptConfig) {
        assertNotNull("Widget resize frame not shown after widget added", resizeFrame);
        resizeFrame.dismiss();
        final Widget widget = mLauncher.getWorkspace().tryGetWidget(mWidgetInfo.label, DEFAULT_UI_TIMEOUT);
        assertNotNull("Widget not found on the workspace", widget);
    } else {
        final Widget widget = mLauncher.getWorkspace().tryGetWidget(mWidgetInfo.label, DEFAULT_UI_TIMEOUT);
        assertNull("Widget unexpectedly found on the workspace", widget);
    }
}
Also used : Widgets(com.android.launcher3.tapl.Widgets) WidgetResizeFrame(com.android.launcher3.tapl.WidgetResizeFrame) Widget(com.android.launcher3.tapl.Widget)

Example 18 with WIDGETS

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

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

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

the class WidgetsListAdapterTest method setWidgetsOnSearch_expandedApp_shouldResetExpandedApp.

@Test
public void setWidgetsOnSearch_expandedApp_shouldResetExpandedApp() {
    // GIVEN a list of widgets entries:
    // [Empty item
    // com.google.test0,
    // com.google.test0 content,
    // com.google.test1,
    // com.google.test1 content,
    // com.google.test2,
    // com.google.test2 content]
    // The visible widgets entries:
    // [Empty item,
    // com.google.test0,
    // com.google.test1,
    // com.google.test2].
    ArrayList<WidgetsListBaseEntry> allEntries = generateSampleMap(3);
    mAdapter.setWidgetsOnSearch(allEntries);
    // GIVEN com.google.test.1 header is expanded. The visible entries list becomes:
    // [Empty item, com.google.test0, com.google.test1, com.google.test1 content,
    // com.google.test2]
    mAdapter.onHeaderClicked(/* showWidgets= */
    true, new PackageUserKey(TEST_PACKAGE_PLACEHOLDER + 1, mUserHandle));
    Mockito.reset(mListener);
    // WHEN same widget entries are set again.
    mAdapter.setWidgetsOnSearch(allEntries);
    // THEN expanded app is reset and the visible entries list becomes:
    // [Empty item, com.google.test0, com.google.test1, com.google.test2]
    verify(mListener).onItemRangeChanged(eq(2), eq(1), isNull());
    verify(mListener).onItemRangeRemoved(/* positionStart= */
    3, /* itemCount= */
    1);
}
Also used : WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) PackageUserKey(com.android.launcher3.util.PackageUserKey) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 20 with WIDGETS

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

the class AbstractLauncherUiTest method checkLauncherIntegrity.

private void checkLauncherIntegrity(Launcher launcher, ContainerType expectedContainerType) {
    if (launcher != null) {
        final StateManager<LauncherState> stateManager = launcher.getStateManager();
        final LauncherState stableState = stateManager.getCurrentStableState();
        assertTrue("Stable state != state: " + stableState.getClass().getSimpleName() + ", " + stateManager.getState().getClass().getSimpleName(), stableState == stateManager.getState());
        final boolean isResumed = launcher.hasBeenResumed();
        final boolean isStarted = launcher.isStarted();
        checkLauncherState(launcher, expectedContainerType, isResumed, isStarted);
        final int ordinal = stableState.ordinal;
        switch(expectedContainerType) {
            case WORKSPACE:
            case WIDGETS:
                {
                    assertTrue("Launcher is not resumed in state: " + expectedContainerType, isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.NORMAL_STATE_ORDINAL);
                    break;
                }
            case ALL_APPS:
                {
                    assertTrue("Launcher is not resumed in state: " + expectedContainerType, isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.ALL_APPS_STATE_ORDINAL);
                    break;
                }
            case OVERVIEW:
                {
                    checkLauncherStateInOverview(launcher, expectedContainerType, isStarted, isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.OVERVIEW_STATE_ORDINAL);
                    break;
                }
            case BACKGROUND:
                {
                    assertTrue("Launcher is resumed in state: " + expectedContainerType, !isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal), ordinal == TestProtocol.NORMAL_STATE_ORDINAL);
                    break;
                }
            default:
                throw new IllegalArgumentException("Illegal container: " + expectedContainerType);
        }
    } else {
        assertTrue("Container type is not BACKGROUND or FALLBACK_OVERVIEW: " + expectedContainerType, expectedContainerType == ContainerType.BACKGROUND || expectedContainerType == ContainerType.FALLBACK_OVERVIEW);
    }
}
Also used : LauncherState(com.android.launcher3.LauncherState)

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