use of com.android.launcher3.widget.model.WidgetsListBaseEntry in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsModel method getWidgetsListForPicker.
/**
* Returns a list of {@link WidgetsListBaseEntry}. All {@link WidgetItem} in a single row
* are sorted (based on label and user), but the overall list of
* {@link WidgetsListBaseEntry}s is not sorted. This list is sorted at the UI when using
* {@link WidgetsDiffReporter}
*
* @see com.android.launcher3.widget.picker.WidgetsListAdapter#setWidgets(List)
*/
public synchronized ArrayList<WidgetsListBaseEntry> getWidgetsListForPicker(Context context) {
ArrayList<WidgetsListBaseEntry> result = new ArrayList<>();
AlphabeticIndexCompat indexer = new AlphabeticIndexCompat(context);
for (Map.Entry<PackageItemInfo, List<WidgetItem>> entry : mWidgetsList.entrySet()) {
PackageItemInfo pkgItem = entry.getKey();
List<WidgetItem> widgetItems = entry.getValue();
String sectionName = (pkgItem.title == null) ? "" : indexer.computeSectionName(pkgItem.title);
result.add(new WidgetsListHeaderEntry(pkgItem, sectionName, widgetItems));
result.add(new WidgetsListContentEntry(pkgItem, sectionName, widgetItems));
}
return result;
}
use of com.android.launcher3.widget.model.WidgetsListBaseEntry in project android_packages_apps_Launcher3 by crdroidandroid.
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(2), eq(1), isNull());
}
use of com.android.launcher3.widget.model.WidgetsListBaseEntry 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);
}
use of com.android.launcher3.widget.model.WidgetsListBaseEntry in project android_packages_apps_Launcher3 by AOSPA.
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;
}
use of com.android.launcher3.widget.model.WidgetsListBaseEntry in project android_packages_apps_Launcher3 by AOSPA.
the class WidgetsModel method getWidgetsListForPicker.
/**
* Returns a list of {@link WidgetsListBaseEntry}. All {@link WidgetItem} in a single row
* are sorted (based on label and user), but the overall list of
* {@link WidgetsListBaseEntry}s is not sorted. This list is sorted at the UI when using
* {@link WidgetsDiffReporter}
*
* @see com.android.launcher3.widget.picker.WidgetsListAdapter#setWidgets(List)
*/
public synchronized ArrayList<WidgetsListBaseEntry> getWidgetsListForPicker(Context context) {
ArrayList<WidgetsListBaseEntry> result = new ArrayList<>();
AlphabeticIndexCompat indexer = new AlphabeticIndexCompat(context);
for (Map.Entry<PackageItemInfo, List<WidgetItem>> entry : mWidgetsList.entrySet()) {
PackageItemInfo pkgItem = entry.getKey();
List<WidgetItem> widgetItems = entry.getValue();
String sectionName = (pkgItem.title == null) ? "" : indexer.computeSectionName(pkgItem.title);
result.add(new WidgetsListHeaderEntry(pkgItem, sectionName, widgetItems));
result.add(new WidgetsListContentEntry(pkgItem, sectionName, widgetItems));
}
return result;
}
Aggregations