Search in sources :

Example 31 with WidgetsListBaseEntry

use of com.android.launcher3.widget.model.WidgetsListBaseEntry in project android_packages_apps_404Launcher by P-404.

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 32 with WidgetsListBaseEntry

use of com.android.launcher3.widget.model.WidgetsListBaseEntry in project android_packages_apps_404Launcher by P-404.

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 33 with WidgetsListBaseEntry

use of com.android.launcher3.widget.model.WidgetsListBaseEntry in project android_packages_apps_Launcher3 by crdroidandroid.

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 34 with WidgetsListBaseEntry

use of com.android.launcher3.widget.model.WidgetsListBaseEntry in project android_packages_apps_Launcher3 by crdroidandroid.

the class WidgetsDiffReporterTest method headersContentsMix_contentMaxSpanSizeModified_shouldInvokeCorrectCallbacks.

@Test
public void headersContentsMix_contentMaxSpanSizeModified_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 max span size in "E content" modified.
    List<WidgetsListBaseEntry> newList = List.of(mHeaderA, mHeaderB, new WidgetsListContentEntry(mContentE.mPkgItem, mContentE.mTitleSectionName, mContentE.mWidgets, mContentE.getMaxSpanSizeInCells() + 1));
    // WHEN computing the list difference.
    mWidgetsDiffReporter.process(currentList, newList, COMPARATOR);
    // THEN notify "E content" has been changed.
    verify(mAdapter).notifyItemChanged(/* position= */
    2);
    // 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) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) Test(org.junit.Test)

Example 35 with WidgetsListBaseEntry

use of com.android.launcher3.widget.model.WidgetsListBaseEntry in project android_packages_apps_Launcher3 by crdroidandroid.

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) Test(org.junit.Test)

Aggregations

WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)56 ArrayList (java.util.ArrayList)40 WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)36 WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)30 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)20 PackageUserKey (com.android.launcher3.util.PackageUserKey)20 List (java.util.List)20 Test (org.junit.Test)20 WidgetItem (com.android.launcher3.model.WidgetItem)18 SmallTest (androidx.test.filters.SmallTest)16 ViewHolderBinder (com.android.launcher3.recyclerview.ViewHolderBinder)15 WidgetsListSearchHeaderEntry (com.android.launcher3.widget.model.WidgetsListSearchHeaderEntry)15 Map (java.util.Map)15 Collectors (java.util.stream.Collectors)15 WidgetListSpaceEntry (com.android.launcher3.widget.model.WidgetListSpaceEntry)12 Context (android.content.Context)10 Rect (android.graphics.Rect)10 Process (android.os.Process)10 Log (android.util.Log)10 SparseArray (android.util.SparseArray)10