Search in sources :

Example 1 with WidgetsDiffReporter

use of com.android.launcher3.widget.picker.WidgetsDiffReporter 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 2 with WidgetsDiffReporter

use of com.android.launcher3.widget.picker.WidgetsDiffReporter in project android_packages_apps_Launcher3 by crdroidandroid.

the class WidgetsDiffReporterTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mTestProfile = new InvariantDeviceProfile();
    mTestProfile.numRows = 5;
    mTestProfile.numColumns = 5;
    doAnswer(invocation -> ((ComponentWithLabel) invocation.getArgument(0)).getComponent().getPackageName()).when(mIconCache).getTitleNoCache(any());
    mContext = RuntimeEnvironment.application;
    mWidgetsDiffReporter = new WidgetsDiffReporter(mIconCache, mAdapter);
    mHeaderA = createWidgetsHeaderEntry(TEST_PACKAGE_PREFIX + "A", /* appName= */
    "A", /* numOfWidgets= */
    3);
    mHeaderB = createWidgetsHeaderEntry(TEST_PACKAGE_PREFIX + "B", /* appName= */
    "B", /* numOfWidgets= */
    3);
    mHeaderC = createWidgetsHeaderEntry(TEST_PACKAGE_PREFIX + "C", /* appName= */
    "C", /* numOfWidgets= */
    3);
    mContentC = createWidgetsContentEntry(TEST_PACKAGE_PREFIX + "C", /* appName= */
    "C", /* numOfWidgets= */
    3);
    mHeaderD = createWidgetsHeaderEntry(TEST_PACKAGE_PREFIX + "D", /* appName= */
    "D", /* numOfWidgets= */
    3);
    mHeaderE = createWidgetsHeaderEntry(TEST_PACKAGE_PREFIX + "E", /* appName= */
    "E", /* numOfWidgets= */
    3);
    mContentE = createWidgetsContentEntry(TEST_PACKAGE_PREFIX + "E", /* appName= */
    "E", /* numOfWidgets= */
    3);
}
Also used : InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ComponentWithLabel(com.android.launcher3.icons.ComponentWithLabel) Before(org.junit.Before)

Aggregations

ArrayMap (androidx.collection.ArrayMap)1 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)1 AlphabeticIndexCompat (com.android.launcher3.compat.AlphabeticIndexCompat)1 ComponentWithLabel (com.android.launcher3.icons.ComponentWithLabel)1 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)1 ShortcutConfigActivityInfo.queryList (com.android.launcher3.pm.ShortcutConfigActivityInfo.queryList)1 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)1 WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)1 WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors.toList (java.util.stream.Collectors.toList)1 Before (org.junit.Before)1