Search in sources :

Example 81 with WidgetsListContentEntry

use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ProtonAOSP.

the class SimpleWidgetsSearchAlgorithm method getFilteredWidgets.

/**
 * Returns entries for all matched widgets
 */
public static ArrayList<WidgetsListBaseEntry> getFilteredWidgets(PopupDataProvider dataProvider, String input) {
    ArrayList<WidgetsListBaseEntry> results = new ArrayList<>();
    dataProvider.getAllWidgets().stream().filter(entry -> entry instanceof WidgetsListHeaderEntry).forEach(headerEntry -> {
        List<WidgetItem> matchedWidgetItems = filterWidgetItems(input, headerEntry.mPkgItem.title.toString(), headerEntry.mWidgets);
        if (matchedWidgetItems.size() > 0) {
            results.add(new WidgetsListSearchHeaderEntry(headerEntry.mPkgItem, headerEntry.mTitleSectionName, matchedWidgetItems));
            results.add(new WidgetsListContentEntry(headerEntry.mPkgItem, headerEntry.mTitleSectionName, matchedWidgetItems));
        }
    });
    return results;
}
Also used : PopupDataProvider(com.android.launcher3.popup.PopupDataProvider) SearchCallback(com.android.launcher3.search.SearchCallback) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetsListSearchHeaderEntry(com.android.launcher3.widget.model.WidgetsListSearchHeaderEntry) SearchAlgorithm(com.android.launcher3.search.SearchAlgorithm) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) StringMatcher(com.android.launcher3.search.StringMatcherUtility.StringMatcher) List(java.util.List) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) StringMatcherUtility.matches(com.android.launcher3.search.StringMatcherUtility.matches) Handler(android.os.Handler) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) ArrayList(java.util.ArrayList) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry) WidgetsListSearchHeaderEntry(com.android.launcher3.widget.model.WidgetsListSearchHeaderEntry)

Example 82 with WidgetsListContentEntry

use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ProtonAOSP.

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)

Example 83 with WidgetsListContentEntry

use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ProtonAOSP.

the class WidgetsListContentEntryTest method unsortedWidgets_sameLabels_differentSize_shouldSortWidgetItems.

@Test
public void unsortedWidgets_sameLabels_differentSize_shouldSortWidgetItems() {
    // GIVEN a list of widgets in unsorted order.
    // Cat 3x3
    WidgetItem widgetItem1 = createWidgetItem(mWidget1, /* spanX= */
    3, /* spanY= */
    3);
    // Cat 1x2
    WidgetItem widgetItem2 = createWidgetItem(mWidget1, /* spanX= */
    1, /* spanY= */
    2);
    // Cat 2x2
    WidgetItem widgetItem3 = createWidgetItem(mWidget1, /* spanX= */
    2, /* spanY= */
    2);
    // 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 gird sizes in an ascending order:
    // [1x2, 2x2, 3x3].
    assertThat(widgetsListRowEntry.mWidgets).containsExactly(widgetItem2, widgetItem3, widgetItem1).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 84 with WidgetsListContentEntry

use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ProtonAOSP.

the class WidgetsListContentEntryTest method equals_entriesWithSameContents_returnTrue.

@Test
public void equals_entriesWithSameContents_returnTrue() {
    WidgetItem widgetItem1 = createWidgetItem(mWidget1, /* spanX= */
    2, /* spanY= */
    3);
    WidgetsListContentEntry widgetsListRowEntry1 = new WidgetsListContentEntry(mPackageItemInfo1, /* titleSectionName= */
    "T", List.of(widgetItem1), /* maxSpanSizeInCells= */
    3);
    WidgetsListContentEntry widgetsListRowEntry2 = new WidgetsListContentEntry(mPackageItemInfo1, /* titleSectionName= */
    "T", List.of(widgetItem1), /* maxSpanSizeInCells= */
    3);
    assertThat(widgetsListRowEntry1.equals(widgetsListRowEntry2)).isTrue();
}
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 85 with WidgetsListContentEntry

use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ProtonAOSP.

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)

Aggregations

WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)101 WidgetItem (com.android.launcher3.model.WidgetItem)77 Test (org.junit.Test)55 SmallTest (androidx.test.filters.SmallTest)44 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)36 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)30 ArrayList (java.util.ArrayList)30 WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)20 List (java.util.List)20 PackageUserKey (com.android.launcher3.util.PackageUserKey)15 Map (java.util.Map)15 Collectors (java.util.stream.Collectors)15 TableRow (android.widget.TableRow)11 Log (android.util.Log)10 NonNull (androidx.annotation.NonNull)10 Nullable (androidx.annotation.Nullable)10 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)10 WidgetsListSearchHeaderEntry (com.android.launcher3.widget.model.WidgetsListSearchHeaderEntry)10 Arrays (java.util.Arrays)10 HashMap (java.util.HashMap)10