Search in sources :

Example 1 with WidgetsListHeaderEntry

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

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 -> new PackageUserKey(entry.packageName, entry.user), entry -> entry));
    for (WidgetsListBaseEntry visibleEntry : mVisibleEntries) {
        PackageUserKey key = new PackageUserKey(visibleEntry.mPkgItem.packageName, visibleEntry.mPkgItem.user);
        PackageItemInfo packageItemInfo = packagesInfo.get(key);
        if (packageItemInfo != null && !visibleEntry.mPkgItem.title.equals(packageItemInfo.title)) {
            return true;
        }
    }
    return false;
}
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) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) PackageUserKey(com.android.launcher3.util.PackageUserKey) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry)

Example 2 with WidgetsListHeaderEntry

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

the class WidgetsListHeader method applyIconAndLabel.

@UiThread
private void applyIconAndLabel(WidgetsListHeaderEntry entry) {
    PackageItemInfo info = entry.mPkgItem;
    setIcon(info);
    setTitles(entry);
    setExpanded(entry.isWidgetListShown());
    super.setTag(info);
    verifyHighRes();
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) UiThread(androidx.annotation.UiThread)

Example 3 with WidgetsListHeaderEntry

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

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

the class WidgetsListHeaderViewHolderBinderTest method bindViewHolder_shouldAttachOnHeaderClickListener.

@Test
public void bindViewHolder_shouldAttachOnHeaderClickListener() {
    WidgetsListHeaderHolder viewHolder = mViewHolderBinder.newViewHolder(new FrameLayout(mTestActivity));
    WidgetsListHeader widgetsListHeader = viewHolder.mWidgetsListHeader;
    WidgetsListHeaderEntry entry = generateSampleAppHeader(APP_NAME, TEST_PACKAGE, /* numOfWidgets= */
    3);
    mViewHolderBinder.bindViewHolder(viewHolder, entry, /* position= */
    0);
    widgetsListHeader.callOnClick();
    verify(mOnHeaderClickListener).onHeaderClicked(eq(true), eq(new PackageUserKey(entry.mPkgItem.packageName, entry.mPkgItem.user)));
}
Also used : FrameLayout(android.widget.FrameLayout) PackageUserKey(com.android.launcher3.util.PackageUserKey) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry) Test(org.junit.Test)

Example 5 with WidgetsListHeaderEntry

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

the class SimpleWidgetsSearchAlgorithmTest method createWidgetsHeaderEntry.

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

Aggregations

WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)10 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)7 WidgetItem (com.android.launcher3.model.WidgetItem)5 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)5 ArrayList (java.util.ArrayList)5 WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)4 List (java.util.List)3 FrameLayout (android.widget.FrameLayout)2 PackageUserKey (com.android.launcher3.util.PackageUserKey)2 Map (java.util.Map)2 Test (org.junit.Test)2 Context (android.content.Context)1 Rect (android.graphics.Rect)1 Handler (android.os.Handler)1 Process (android.os.Process)1 Log (android.util.Log)1 Size (android.util.Size)1 SparseArray (android.util.SparseArray)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1