Search in sources :

Example 6 with WidgetListRowEntry

use of com.android.launcher3.widget.WidgetListRowEntry in project android_packages_apps_Trebuchet by LineageOS.

the class WidgetsModel method getWidgetsList.

/**
 * Returns a list of {@link WidgetListRowEntry}. All {@link WidgetItem} in a single row
 * are sorted (based on label and user), but the overall list of {@link WidgetListRowEntry}s
 * is not sorted. This list is sorted at the UI when using
 * {@link com.android.launcher3.widget.WidgetsDiffReporter}
 *
 * @see com.android.launcher3.widget.WidgetsListAdapter#setWidgets(ArrayList)
 */
public synchronized ArrayList<WidgetListRowEntry> getWidgetsList(Context context) {
    ArrayList<WidgetListRowEntry> result = new ArrayList<>();
    AlphabeticIndexCompat indexer = new AlphabeticIndexCompat(context);
    WidgetItemComparator widgetComparator = new WidgetItemComparator();
    for (Map.Entry<PackageItemInfo, ArrayList<WidgetItem>> entry : mWidgetsList.entrySet()) {
        WidgetListRowEntry row = new WidgetListRowEntry(entry.getKey(), entry.getValue());
        row.titleSectionName = (row.pkgItem.title == null) ? "" : indexer.computeSectionName(row.pkgItem.title);
        Collections.sort(row.widgets, widgetComparator);
        result.add(row);
    }
    return result;
}
Also used : AlphabeticIndexCompat(com.android.launcher3.compat.AlphabeticIndexCompat) WidgetItemComparator(com.android.launcher3.widget.WidgetItemComparator) ArrayList(java.util.ArrayList) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) WidgetListRowEntry(com.android.launcher3.widget.WidgetListRowEntry) HashMap(java.util.HashMap) Map(java.util.Map) MultiHashMap(com.android.launcher3.util.MultiHashMap)

Example 7 with WidgetListRowEntry

use of com.android.launcher3.widget.WidgetListRowEntry in project android_packages_apps_Trebuchet by LineageOS.

the class WidgetsListAdapterTest method generateSampleMap.

/**
 * Helper method to generate the sample widget model map that can be used for the tests
 * @param num the number of WidgetItem the map should contain
 */
private ArrayList<WidgetListRowEntry> generateSampleMap(int num) {
    ArrayList<WidgetListRowEntry> result = new ArrayList<>();
    if (num <= 0)
        return result;
    ShadowPackageManager spm = shadowOf(mContext.getPackageManager());
    for (int i = 0; i < num; i++) {
        ComponentName cn = new ComponentName("com.dummy.apk" + i, "DummyWidet");
        AppWidgetProviderInfo widgetInfo = new AppWidgetProviderInfo();
        widgetInfo.provider = cn;
        ReflectionHelpers.setField(widgetInfo, "providerInfo", spm.addReceiverIfNotPresent(cn));
        WidgetItem wi = new WidgetItem(LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, widgetInfo), mTestProfile, mIconCache);
        PackageItemInfo pInfo = new PackageItemInfo(wi.componentName.getPackageName());
        pInfo.title = pInfo.packageName;
        pInfo.user = wi.user;
        pInfo.bitmap = BitmapInfo.of(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8), 0);
        result.add(new WidgetListRowEntry(pInfo, new ArrayList<>(Collections.singleton(wi))));
    }
    return result;
}
Also used : ShadowPackageManager(org.robolectric.shadows.ShadowPackageManager) ArrayList(java.util.ArrayList) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) ComponentName(android.content.ComponentName) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 8 with WidgetListRowEntry

use of com.android.launcher3.widget.WidgetListRowEntry in project android_packages_apps_Trebuchet by LineageOS.

the class PopupDataProvider method getWidgetsForPackageUser.

public List<WidgetItem> getWidgetsForPackageUser(PackageUserKey packageUserKey) {
    for (WidgetListRowEntry entry : mAllWidgets) {
        if (entry.pkgItem.packageName.equals(packageUserKey.mPackageName)) {
            ArrayList<WidgetItem> widgets = new ArrayList<>(entry.widgets);
            // Remove widgets not associated with the correct user.
            Iterator<WidgetItem> iterator = widgets.iterator();
            while (iterator.hasNext()) {
                if (!iterator.next().user.equals(packageUserKey.mUser)) {
                    iterator.remove();
                }
            }
            return widgets.isEmpty() ? null : widgets;
        }
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetListRowEntry(com.android.launcher3.widget.WidgetListRowEntry)

Aggregations

WidgetItem (com.android.launcher3.model.WidgetItem)6 ArrayList (java.util.ArrayList)6 WidgetListRowEntry (com.android.launcher3.widget.WidgetListRowEntry)4 MultiHashMap (com.android.launcher3.util.MultiHashMap)3 Map (java.util.Map)3 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)2 ViewGroup (android.view.ViewGroup)2 LauncherAppWidgetProviderInfo (com.android.launcher3.LauncherAppWidgetProviderInfo)2 AlphabeticIndexCompat (com.android.launcher3.compat.AlphabeticIndexCompat)2 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)2 WidgetItemComparator (com.android.launcher3.widget.WidgetItemComparator)2 HashMap (java.util.HashMap)2 ComponentName (android.content.ComponentName)1 AppWidgetManagerCompat (com.android.launcher3.compat.AppWidgetManagerCompat)1 PackageItemInfo (com.android.launcher3.model.PackageItemInfo)1 ShadowPackageManager (org.robolectric.shadows.ShadowPackageManager)1