Search in sources :

Example 1 with WidgetsListContentEntry

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

the class WidgetsListAdapter method ensureAllPreviewsReady.

/**
 * Checks that all preview images are loaded and starts loading for those that aren't ready.
 *
 * @return true if all previews are ready and the data can be updated, false otherwise.
 */
private boolean ensureAllPreviewsReady() {
    boolean allReady = true;
    BaseActivity activity = BaseActivity.fromContext(mContext);
    for (WidgetsListBaseEntry entry : mAllEntries) {
        if (!(entry instanceof WidgetsListContentEntry))
            continue;
        WidgetsListContentEntry contentEntry = (WidgetsListContentEntry) entry;
        if (!matchesKey(entry, mWidgetsContentVisiblePackageUserKey)) {
            // If the entry isn't visible, clear any loaded previews.
            mCachingPreviewLoader.clearPreviews(contentEntry.mWidgets);
            continue;
        }
        for (int i = 0; i < entry.mWidgets.size(); i++) {
            WidgetItem widgetItem = entry.mWidgets.get(i);
            DeviceProfile deviceProfile = activity.getDeviceProfile();
            Size widgetSize = WidgetSizes.getWidgetItemSizePx(mContext, deviceProfile, widgetItem);
            if (widgetItem.isShortcut()) {
                widgetSize = new Size(widgetSize.getWidth() + mShortcutPreviewPadding, widgetSize.getHeight() + mShortcutPreviewPadding);
            }
            if (widgetItem.hasPreviewLayout() || mCachingPreviewLoader.isPreviewLoaded(widgetItem, widgetSize)) {
                // preview bitmap is in the cache.
                continue;
            }
            // If we've reached this point, we should load the preview for the widget.
            allReady = false;
            mCachingPreviewLoader.loadPreview(activity, widgetItem, widgetSize, mPreviewLoadedCallback);
        }
    }
    return allReady;
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) Size(android.util.Size) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) BaseActivity(com.android.launcher3.BaseActivity) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 2 with WidgetsListContentEntry

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

the class WidgetsListAdapter method updateVisibleEntries.

private void updateVisibleEntries() {
    // loads.
    if (!ensureAllPreviewsReady())
        return;
    // 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)).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 : 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) WidgetPreviewLoadedCallback(com.android.launcher3.widget.WidgetPreviewLoader.WidgetPreviewLoadedCallback) CachingWidgetPreviewLoader(com.android.launcher3.widget.CachingWidgetPreviewLoader) BaseActivity(com.android.launcher3.BaseActivity) WidgetItem(com.android.launcher3.model.WidgetItem) Map(java.util.Map) View(android.view.View) ViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder) RecyclerView(androidx.recyclerview.widget.RecyclerView) Log(android.util.Log) Launcher(com.android.launcher3.Launcher) 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) WidgetCell(com.android.launcher3.widget.WidgetCell) LAUNCHER_WIDGETSTRAY_APP_EXPANDED(com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WIDGETSTRAY_APP_EXPANDED) PackageUserKey(com.android.launcher3.util.PackageUserKey) DatabaseWidgetPreviewLoader(com.android.launcher3.widget.DatabaseWidgetPreviewLoader) WidgetsListSearchHeaderEntry(com.android.launcher3.widget.model.WidgetsListSearchHeaderEntry) Collectors(java.util.stream.Collectors) ViewGroup(android.view.ViewGroup) ViewHolderBinder(com.android.launcher3.recyclerview.ViewHolderBinder) DeviceProfile(com.android.launcher3.DeviceProfile) SparseArray(android.util.SparseArray) WidgetSizes(com.android.launcher3.widget.util.WidgetSizes) List(java.util.List) Nullable(androidx.annotation.Nullable) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) R(com.android.launcher3.R) TableRow(android.widget.TableRow) LayoutParams(androidx.recyclerview.widget.RecyclerView.LayoutParams) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Comparator(java.util.Comparator) OnLongClickListener(android.view.View.OnLongClickListener) Size(android.util.Size) OnClickListener(android.view.View.OnClickListener) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) OptionalInt(java.util.OptionalInt)

Example 3 with WidgetsListContentEntry

use of com.android.launcher3.widget.model.WidgetsListContentEntry 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;
}
Also used : AlphabeticIndexCompat(com.android.launcher3.compat.AlphabeticIndexCompat) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) ArrayList(java.util.ArrayList) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) ArrayList(java.util.ArrayList) ShortcutConfigActivityInfo.queryList(com.android.launcher3.pm.ShortcutConfigActivityInfo.queryList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ArrayMap(androidx.collection.ArrayMap) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry)

Example 4 with WidgetsListContentEntry

use of com.android.launcher3.widget.model.WidgetsListContentEntry 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());
}
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) Test(org.junit.Test)

Example 5 with WidgetsListContentEntry

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

the class WidgetsListTableViewHolderBinderTest method generateSampleAppWithWidgets.

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

Aggregations

WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)21 WidgetItem (com.android.launcher3.model.WidgetItem)17 Test (org.junit.Test)11 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)8 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)6 ArrayList (java.util.ArrayList)6 WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)4 List (java.util.List)4 Size (android.util.Size)3 TableRow (android.widget.TableRow)3 PackageUserKey (com.android.launcher3.util.PackageUserKey)3 Map (java.util.Map)3 Log (android.util.Log)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 BaseActivity (com.android.launcher3.BaseActivity)2 DeviceProfile (com.android.launcher3.DeviceProfile)2 Collectors (java.util.stream.Collectors)2 ComponentName (android.content.ComponentName)1