Search in sources :

Example 56 with WidgetsListContentEntry

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

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 57 with WidgetsListContentEntry

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

the class WidgetsDiffReporterTest 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 58 with WidgetsListContentEntry

use of com.android.launcher3.widget.model.WidgetsListContentEntry 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 59 with WidgetsListContentEntry

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

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);
        pInfo.title = pInfo.packageName;
        pInfo.user = widgetItems.get(0).user;
        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 60 with WidgetsListContentEntry

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

the class WidgetsListTableViewHolderBinderTest method bindViewHolder_appWith3Widgets_shouldHave3Widgets.

@Test
public void bindViewHolder_appWith3Widgets_shouldHave3Widgets() {
    WidgetsRowViewHolder viewHolder = mViewHolderBinder.newViewHolder(new FrameLayout(mTestActivity));
    WidgetsListContentEntry entry = generateSampleAppWithWidgets(APP_NAME, TEST_PACKAGE, /* numOfWidgets= */
    3);
    mViewHolderBinder.bindViewHolder(viewHolder, entry, /* position= */
    0);
    shadowOf(getMainLooper()).idle();
    // THEN the table container has one row, which contains 3 widgets.
    // View:  .SampleWidget0 | .SampleWidget1 | .SampleWidget2
    assertThat(viewHolder.mTableContainer.getChildCount()).isEqualTo(1);
    TableRow row = (TableRow) viewHolder.mTableContainer.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) 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