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;
}
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;
}
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;
}
Aggregations