Search in sources :

Example 11 with WidgetsListBaseEntry

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

the class WidgetsListAdapter method setWidgets.

/**
 * Updates the widget list based on {@code tempEntries}.
 */
public void setWidgets(List<WidgetsListBaseEntry> tempEntries) {
    mAllEntries.clear();
    mAllEntries.add(new WidgetListSpaceEntry());
    tempEntries.stream().sorted(mRowComparator).forEach(mAllEntries::add);
    if (shouldClearVisibleEntries()) {
        mVisibleEntries.clear();
    }
    updateVisibleEntries();
}
Also used : WidgetListSpaceEntry(com.android.launcher3.widget.model.WidgetListSpaceEntry)

Example 12 with WidgetsListBaseEntry

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

the class WidgetsListAdapter method shouldClearVisibleEntries.

/**
 * Returns {@code true} if there is a change in {@link #mAllEntries} that results in an
 * invalidation of {@link #mVisibleEntries}. e.g. there is change in the device language.
 */
private boolean shouldClearVisibleEntries() {
    Map<PackageUserKey, PackageItemInfo> packagesInfo = mAllEntries.stream().filter(entry -> entry instanceof WidgetsListHeaderEntry).map(entry -> entry.mPkgItem).collect(Collectors.toMap(entry -> PackageUserKey.fromPackageItemInfo(entry), entry -> entry));
    for (WidgetsListBaseEntry visibleEntry : mVisibleEntries) {
        PackageUserKey key = PackageUserKey.fromPackageItemInfo(visibleEntry.mPkgItem);
        PackageItemInfo packageItemInfo = packagesInfo.get(key);
        if (packageItemInfo != null && !visibleEntry.mPkgItem.title.equals(packageItemInfo.title)) {
            return true;
        }
    }
    return false;
}
Also used : POSITION_LAST(com.android.launcher3.recyclerview.ViewHolderBinder.POSITION_LAST) IntStream(java.util.stream.IntStream) Context(android.content.Context) Rect(android.graphics.Rect) Arrays(java.util.Arrays) NonNull(androidx.annotation.NonNull) LabelComparator(com.android.launcher3.util.LabelComparator) IconCache(com.android.launcher3.icons.IconCache) OptionalInt(java.util.OptionalInt) Process(android.os.Process) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) ArrayList(java.util.ArrayList) POSITION_FIRST(com.android.launcher3.recyclerview.ViewHolderBinder.POSITION_FIRST) WidgetListSpaceEntry(com.android.launcher3.widget.model.WidgetListSpaceEntry) POSITION_DEFAULT(com.android.launcher3.recyclerview.ViewHolderBinder.POSITION_DEFAULT) Map(java.util.Map) View(android.view.View) ViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder) RecyclerView(androidx.recyclerview.widget.RecyclerView) Log(android.util.Log) IntSupplier(java.util.function.IntSupplier) ActivityContext(com.android.launcher3.views.ActivityContext) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry) LayoutInflater(android.view.LayoutInflater) Adapter(androidx.recyclerview.widget.RecyclerView.Adapter) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) Predicate(java.util.function.Predicate) LAUNCHER_WIDGETSTRAY_APP_EXPANDED(com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WIDGETSTRAY_APP_EXPANDED) PackageUserKey(com.android.launcher3.util.PackageUserKey) WidgetsListSearchHeaderEntry(com.android.launcher3.widget.model.WidgetsListSearchHeaderEntry) Collectors(java.util.stream.Collectors) ViewGroup(android.view.ViewGroup) ViewHolderBinder(com.android.launcher3.recyclerview.ViewHolderBinder) SparseArray(android.util.SparseArray) List(java.util.List) Nullable(androidx.annotation.Nullable) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) R(com.android.launcher3.R) LayoutParams(androidx.recyclerview.widget.RecyclerView.LayoutParams) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Comparator(java.util.Comparator) OnLongClickListener(android.view.View.OnLongClickListener) Collections(java.util.Collections) OnClickListener(android.view.View.OnClickListener) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) PackageUserKey(com.android.launcher3.util.PackageUserKey) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry)

Example 13 with WidgetsListBaseEntry

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

the class WidgetsListAdapter method setWidgets.

/**
 * Updates the widget list based on {@code tempEntries}.
 */
public void setWidgets(List<WidgetsListBaseEntry> tempEntries) {
    mAllEntries.clear();
    mAllEntries.add(new WidgetListSpaceEntry());
    tempEntries.stream().sorted(mRowComparator).forEach(mAllEntries::add);
    if (shouldClearVisibleEntries()) {
        mVisibleEntries.clear();
    }
    updateVisibleEntries();
}
Also used : WidgetListSpaceEntry(com.android.launcher3.widget.model.WidgetListSpaceEntry)

Example 14 with WidgetsListBaseEntry

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

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

use of com.android.launcher3.widget.model.WidgetsListBaseEntry 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)

Aggregations

WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)45 ArrayList (java.util.ArrayList)32 WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)29 WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)24 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)16 PackageUserKey (com.android.launcher3.util.PackageUserKey)16 List (java.util.List)16 Test (org.junit.Test)16 WidgetItem (com.android.launcher3.model.WidgetItem)15 SmallTest (androidx.test.filters.SmallTest)12 ViewHolderBinder (com.android.launcher3.recyclerview.ViewHolderBinder)12 WidgetsListSearchHeaderEntry (com.android.launcher3.widget.model.WidgetsListSearchHeaderEntry)12 Map (java.util.Map)12 Collectors (java.util.stream.Collectors)12 WidgetListSpaceEntry (com.android.launcher3.widget.model.WidgetListSpaceEntry)9 Context (android.content.Context)8 Rect (android.graphics.Rect)8 Process (android.os.Process)8 Log (android.util.Log)8 SparseArray (android.util.SparseArray)8