Search in sources :

Example 66 with WIDGETS

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

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

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

the class WidgetsListAdapterTest method generateSampleMap.

/**
 * Generates a list of sample widget entries.
 *
 * <p>Each sample app has 1 widget only. An app is represented by 2 entries,
 * {@link WidgetsListHeaderEntry} & {@link WidgetsListContentEntry}. Only
 * {@link WidgetsListHeaderEntry} is always visible in the {@link WidgetsListAdapter}.
 * {@link WidgetsListContentEntry} is only shown upon clicking the corresponding app's
 * {@link WidgetsListHeaderEntry}. Only at most one {@link WidgetsListContentEntry} is shown at
 * a time.
 *
 * @param num the number of apps that have widgets.
 */
private ArrayList<WidgetsListBaseEntry> generateSampleMap(int num) {
    ArrayList<WidgetsListBaseEntry> result = new ArrayList<>();
    if (num <= 0)
        return result;
    for (int i = 0; i < num; i++) {
        String packageName = TEST_PACKAGE_PLACEHOLDER + i;
        List<WidgetItem> widgetItems = generateWidgetItems(packageName, /* numOfWidgets= */
        1);
        PackageItemInfo pInfo = new PackageItemInfo(packageName, widgetItems.get(0).user);
        pInfo.title = pInfo.packageName;
        pInfo.bitmap = BitmapInfo.of(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8), 0);
        result.add(new WidgetsListHeaderEntry(pInfo, /* titleSectionName= */
        "", widgetItems));
        result.add(new WidgetsListContentEntry(pInfo, /* titleSectionName= */
        "", widgetItems));
    }
    return result;
}
Also used : WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) ArrayList(java.util.ArrayList) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry)

Example 68 with WIDGETS

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

the class WidgetsListAdapterTest method setWidgets_expandedApp_moreWidgets_shouldNotifyItemChangedWithWidgetItemInfoDiff.

@Test
public void setWidgets_expandedApp_moreWidgets_shouldNotifyItemChangedWithWidgetItemInfoDiff() {
    // GIVEN the adapter was first populated with com.google.test0 & com.google.test1. Each app
    // has one widget.
    ArrayList<WidgetsListBaseEntry> allEntries = generateSampleMap(2);
    mAdapter.setWidgets(allEntries);
    // GIVEN test com.google.test1 is expanded.
    // Visible entries in the adapter are:
    // [com.google.test0, com.google.test1, com.google.test1 content]
    mAdapter.onHeaderClicked(/* showWidgets= */
    true, new PackageUserKey(TEST_PACKAGE_PLACEHOLDER + 1, mUserHandle));
    Mockito.reset(mListener);
    // WHEN the adapter is updated with the same list of apps but com.google.test1 has 2 widgets
    // now.
    WidgetsListContentEntry testPackage1ContentEntry = (WidgetsListContentEntry) allEntries.get(3);
    WidgetItem widgetItem = testPackage1ContentEntry.mWidgets.get(0);
    WidgetsListContentEntry newTestPackage1ContentEntry = new WidgetsListContentEntry(testPackage1ContentEntry.mPkgItem, testPackage1ContentEntry.mTitleSectionName, List.of(widgetItem, widgetItem));
    allEntries.set(3, newTestPackage1ContentEntry);
    mAdapter.setWidgets(allEntries);
    // THEN the onItemRangeChanged is invoked for "com.google.test1 content" at index 2.
    verify(mListener).onItemRangeChanged(eq(3), eq(1), isNull());
}
Also used : WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) PackageUserKey(com.android.launcher3.util.PackageUserKey) WidgetItem(com.android.launcher3.model.WidgetItem) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 69 with WIDGETS

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

the class WidgetsListContentEntryTest method unsortedWidgets_diffLabels_shouldSortWidgetItems.

@Test
public void unsortedWidgets_diffLabels_shouldSortWidgetItems() {
    // GIVEN a list of widgets in unsorted order.
    // Cat 2x3
    WidgetItem widgetItem1 = createWidgetItem(mWidget1, /* spanX= */
    2, /* spanY= */
    3);
    // Dog 2x3
    WidgetItem widgetItem2 = createWidgetItem(mWidget2, /* spanX= */
    2, /* spanY= */
    3);
    // Bird 2x3
    WidgetItem widgetItem3 = createWidgetItem(mWidget3, /* spanX= */
    2, /* spanY= */
    3);
    // WHEN creates a WidgetsListRowEntry with the unsorted widgets.
    WidgetsListContentEntry widgetsListRowEntry = new WidgetsListContentEntry(mPackageItemInfo1, /* titleSectionName= */
    "T", List.of(widgetItem1, widgetItem2, widgetItem3));
    // THEN the widgets list is sorted by their labels alphabetically: [Bird, Cat, Dog].
    assertThat(widgetsListRowEntry.mWidgets).containsExactly(widgetItem3, widgetItem1, widgetItem2).inOrder();
    assertThat(widgetsListRowEntry.mTitleSectionName).isEqualTo("T");
    assertThat(widgetsListRowEntry.mPkgItem).isEqualTo(mPackageItemInfo1);
}
Also used : WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 70 with WIDGETS

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

the class WidgetsListTableViewHolderBinderTest method bindViewHolder_appWith3Widgets_shouldHave3Widgets.

@Test
public void bindViewHolder_appWith3Widgets_shouldHave3Widgets() throws Exception {
    WidgetsRowViewHolder viewHolder = mViewHolderBinder.newViewHolder(new FrameLayout(mContext));
    WidgetsListContentEntry entry = generateSampleAppWithWidgets(APP_NAME, TEST_PACKAGE, /* numOfWidgets= */
    3);
    mViewHolderBinder.bindViewHolder(viewHolder, entry, /* position= */
    0, EMPTY_LIST);
    Executors.MAIN_EXECUTOR.submit(() -> {
    }).get();
    // THEN the table container has one row, which contains 3 widgets.
    // View:  .SampleWidget0 | .SampleWidget1 | .SampleWidget2
    assertThat(viewHolder.tableContainer.getChildCount()).isEqualTo(1);
    TableRow row = (TableRow) viewHolder.tableContainer.getChildAt(0);
    assertThat(row.getChildCount()).isEqualTo(3);
    // Widget 0 label is .SampleWidget0.
    assertWidgetCellWithLabel(row.getChildAt(0), ".SampleWidget0");
    // Widget 1 label is .SampleWidget1.
    assertWidgetCellWithLabel(row.getChildAt(1), ".SampleWidget1");
    // Widget 2 label is .SampleWidget2.
    assertWidgetCellWithLabel(row.getChildAt(2), ".SampleWidget2");
}
Also used : FrameLayout(android.widget.FrameLayout) TableRow(android.widget.TableRow) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

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