Search in sources :

Example 86 with WidgetsListContentEntry

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

the class WidgetsListContentEntryTest method equals_entriesWithDifferentPackageItemInfo_returnFalse.

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

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

the class WidgetsListContentEntryTest method unsortedWidgets_hodgepodge_shouldSortWidgetItems.

@Test
public void unsortedWidgets_hodgepodge_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);
    // Dog 2x2
    WidgetItem widgetItem3 = createWidgetItem(mWidget2, /* spanX= */
    2, /* spanY= */
    2);
    // Bird 2x2
    WidgetItem widgetItem4 = createWidgetItem(mWidget3, /* spanX= */
    2, /* spanY= */
    2);
    // WHEN creates a WidgetsListRowEntry with the unsorted widgets.
    WidgetsListContentEntry widgetsListRowEntry = new WidgetsListContentEntry(mPackageItemInfo1, /* titleSectionName= */
    "T", List.of(widgetItem1, widgetItem2, widgetItem3, widgetItem4));
    // THEN the widgets list is first sorted by labels alphabetically. Then, for widgets with
    // same labels, they are sorted by their gird sizes in an ascending order:
    // [Bird 2x2, Cat 1x2, Cat 3x3, Dog 2x2]
    assertThat(widgetsListRowEntry.mWidgets).containsExactly(widgetItem4, widgetItem2, widgetItem1, widgetItem3).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 88 with WidgetsListContentEntry

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

the class SimpleWidgetsSearchAlgorithmTest method createWidgetsContentEntry.

private WidgetsListContentEntry createWidgetsContentEntry(String packageName, String appName, int numOfWidgets) {
    List<WidgetItem> widgetItems = generateWidgetItems(packageName, numOfWidgets);
    PackageItemInfo pInfo = createPackageItemInfo(packageName, appName, widgetItems.get(0).user);
    return new WidgetsListContentEntry(pInfo, /* titleSectionName= */
    "", widgetItems);
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 89 with WidgetsListContentEntry

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

the class WidgetsListAdapter method scrollToPositionAndMaintainOffset.

/**
 * Scrolls to the selected header position with the provided offset. LinearLayoutManager
 * scrolls the minimum distance necessary, so this will keep the selected header in place during
 * clicks, without interrupting the animation.
 *
 * @param positionOptional The position too scroll to. No scrolling will be done if empty.
 * @param offsetOptional The offset from the top to maintain. If empty, then the list will
 *                       scroll to the top of the position.
 */
private void scrollToPositionAndMaintainOffset(OptionalInt positionOptional, OptionalInt offsetOptional) {
    if (!positionOptional.isPresent() || mRecyclerView == null)
        return;
    int position = positionOptional.getAsInt();
    LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
    if (layoutManager == null)
        return;
    if (position == mVisibleEntries.size() - 2 && mVisibleEntries.get(mVisibleEntries.size() - 1) instanceof WidgetsListContentEntry) {
        // If the selected header is in the last position and its content is showing, then
        // scroll to the final position so the last list of widgets will show.
        layoutManager.scrollToPosition(mVisibleEntries.size() - 1);
        return;
    }
    // Scroll to the header view's current offset, accounting for the recycler view's padding.
    // If the header view couldn't be found, then it will appear at the top of the list.
    layoutManager.scrollToPositionWithOffset(position, offsetOptional.orElse(0) - mRecyclerView.getPaddingTop());
}
Also used : WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 90 with WidgetsListContentEntry

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

the class WidgetsListAdapter method updateVisibleEntries.

private void updateVisibleEntries() {
    // Get the current top of the header with the matching key before adjusting the visible
    // entries.
    OptionalInt previousPositionForPackageUserKey = getPositionForPackageUserKey(mPendingClickHeader);
    OptionalInt topForPackageUserKey = getOffsetForPosition(previousPositionForPackageUserKey);
    List<WidgetsListBaseEntry> newVisibleEntries = mAllEntries.stream().filter(entry -> ((mFilter == null || mFilter.test(entry)) && mHeaderAndSelectedContentFilter.test(entry)) || entry instanceof WidgetListSpaceEntry).map(entry -> {
        if (entry instanceof WidgetsListBaseEntry.Header<?> && matchesKey(entry, mWidgetsContentVisiblePackageUserKey)) {
            // Adjust the original entries to expand headers for the selected content.
            return ((WidgetsListBaseEntry.Header<?>) entry).withWidgetListShown();
        } else if (entry instanceof WidgetsListContentEntry) {
            // maxSpanSize.
            return ((WidgetsListContentEntry) entry).withMaxSpanSize(mMaxSpanSize);
        }
        return entry;
    }).collect(Collectors.toList());
    mDiffReporter.process(mVisibleEntries, newVisibleEntries, mRowComparator);
    if (mPendingClickHeader != null) {
        // Get the position for the clicked header after adjusting the visible entries. The
        // position may have changed if another header had previously been expanded.
        OptionalInt positionForPackageUserKey = getPositionForPackageUserKey(mPendingClickHeader);
        scrollToPositionAndMaintainOffset(positionForPackageUserKey, topForPackageUserKey);
        mPendingClickHeader = null;
    }
}
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) WidgetListSpaceEntry(com.android.launcher3.widget.model.WidgetListSpaceEntry) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) OptionalInt(java.util.OptionalInt)

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