Search in sources :

Example 36 with WidgetsListContentEntry

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

the class WidgetsListTableViewHolderBinder method bindViewHolder.

@Override
public void bindViewHolder(WidgetsRowViewHolder holder, WidgetsListContentEntry entry, @ListPosition int position, List<Object> payloads) {
    for (Object payload : payloads) {
        Pair<WidgetItem, Bitmap> pair = (Pair) payload;
        holder.previewCache.put(pair.first, pair.second);
    }
    WidgetsListTableView table = holder.tableContainer;
    if (DEBUG) {
        Log.d(TAG, String.format("onBindViewHolder [widget#=%d, table.getChildCount=%d]", entry.mWidgets.size(), table.getChildCount()));
    }
    table.setListDrawableState(((position & POSITION_LAST) != 0) ? LAST : MIDDLE);
    List<ArrayList<WidgetItem>> widgetItemsTable = WidgetsTableUtils.groupWidgetItemsIntoTableWithReordering(entry.mWidgets, entry.getMaxSpanSizeInCells());
    recycleTableBeforeBinding(table, widgetItemsTable);
    // Bind the widget items.
    for (int i = 0; i < widgetItemsTable.size(); i++) {
        List<WidgetItem> widgetItemsPerRow = widgetItemsTable.get(i);
        for (int j = 0; j < widgetItemsPerRow.size(); j++) {
            TableRow row = (TableRow) table.getChildAt(i);
            row.setVisibility(View.VISIBLE);
            WidgetCell widget = (WidgetCell) row.getChildAt(j);
            widget.clear();
            WidgetItem widgetItem = widgetItemsPerRow.get(j);
            widget.setVisibility(View.VISIBLE);
            // When preview loads, notify adapter to rebind the item and possibly animate
            widget.applyFromCellItem(widgetItem, 1f, bitmap -> {
                if (holder.getBindingAdapter() != null) {
                    holder.getBindingAdapter().notifyItemChanged(holder.getBindingAdapterPosition(), Pair.create(widgetItem, bitmap));
                }
            }, holder.previewCache.get(widgetItem));
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) TableRow(android.widget.TableRow) ArrayList(java.util.ArrayList) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetCell(com.android.launcher3.widget.WidgetCell) Pair(android.util.Pair)

Example 37 with WidgetsListContentEntry

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

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

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

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

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

the class WidgetsListTableViewHolderBinderTest method generateSampleAppWithWidgets.

private WidgetsListContentEntry generateSampleAppWithWidgets(String appName, String packageName, int numOfWidgets) {
    PackageItemInfo appInfo = new PackageItemInfo(packageName, UserHandle.CURRENT);
    appInfo.title = appName;
    appInfo.bitmap = BitmapInfo.of(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8), 0);
    return new WidgetsListContentEntry(appInfo, /* titleSectionName= */
    "", generateWidgetItems(packageName, numOfWidgets), Integer.MAX_VALUE);
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry)

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