use of com.android.launcher3.widget.WidgetListRowEntry in project android_packages_apps_Trebuchet by LineageOS.
the class WidgetsListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(WidgetsRowViewHolder holder, int pos) {
WidgetListRowEntry entry = mEntries.get(pos);
List<WidgetItem> infoList = entry.widgets;
ViewGroup row = holder.cellContainer;
if (DEBUG) {
Log.d(TAG, String.format("onBindViewHolder [pos=%d, widget#=%d, row.getChildCount=%d]", pos, infoList.size(), row.getChildCount()));
}
// Add more views.
// if there are too many, hide them.
int expectedChildCount = infoList.size() + Math.max(0, infoList.size() - 1);
int childCount = row.getChildCount();
if (expectedChildCount > childCount) {
for (int i = childCount; i < expectedChildCount; i++) {
if ((i & 1) == 1) {
// Add a divider for odd index
mLayoutInflater.inflate(R.layout.widget_list_divider, row);
} else {
// Add cell for even index
WidgetCell widget = (WidgetCell) mLayoutInflater.inflate(R.layout.widget_cell, row, false);
// set up touch.
widget.setOnClickListener(mIconClickListener);
widget.setOnLongClickListener(mIconLongClickListener);
row.addView(widget);
}
}
} else if (expectedChildCount < childCount) {
for (int i = expectedChildCount; i < childCount; i++) {
row.getChildAt(i).setVisibility(View.GONE);
}
}
// Bind the views in the application info section.
holder.title.applyFromPackageItemInfo(entry.pkgItem);
// Bind the view in the widget horizontal tray region.
for (int i = 0; i < infoList.size(); i++) {
WidgetCell widget = (WidgetCell) row.getChildAt(2 * i);
widget.applyFromCellItem(infoList.get(i), mWidgetPreviewLoader);
widget.setApplyBitmapDeferred(mApplyBitmapDeferred);
widget.ensurePreview();
widget.setVisibility(View.VISIBLE);
if (i > 0) {
row.getChildAt(2 * i - 1).setVisibility(View.VISIBLE);
}
}
}
use of com.android.launcher3.widget.WidgetListRowEntry in project Neo-Launcher by NeoApplications.
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
* @return
*/
private ArrayList<WidgetListRowEntry> generateSampleMap(int num) {
ArrayList<WidgetListRowEntry> result = new ArrayList<>();
if (num <= 0)
return result;
MultiHashMap<PackageItemInfo, WidgetItem> newMap = new MultiHashMap();
AppWidgetManagerCompat widgetManager = AppWidgetManagerCompat.getInstance(mContext);
for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(null)) {
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.iconBitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8);
newMap.addToList(pInfo, wi);
if (newMap.size() == num) {
break;
}
}
for (Map.Entry<PackageItemInfo, ArrayList<WidgetItem>> entry : newMap.entrySet()) {
result.add(new WidgetListRowEntry(entry.getKey(), entry.getValue()));
}
return result;
}
use of com.android.launcher3.widget.WidgetListRowEntry in project Neo-Launcher by NeoApplications.
the class WidgetsListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(WidgetsRowViewHolder holder, int pos) {
WidgetListRowEntry entry = mEntries.get(pos);
List<WidgetItem> infoList = entry.widgets;
ViewGroup row = holder.cellContainer;
if (DEBUG) {
Log.d(TAG, String.format("onBindViewHolder [pos=%d, widget#=%d, row.getChildCount=%d]", pos, infoList.size(), row.getChildCount()));
}
// Add more views.
// if there are too many, hide them.
int expectedChildCount = infoList.size() + Math.max(0, infoList.size() - 1);
int childCount = row.getChildCount();
if (expectedChildCount > childCount) {
for (int i = childCount; i < expectedChildCount; i++) {
if ((i & 1) == 1) {
// Add a divider for odd index
mLayoutInflater.inflate(R.layout.widget_list_divider, row);
} else {
// Add cell for even index
WidgetCell widget = (WidgetCell) mLayoutInflater.inflate(R.layout.widget_cell, row, false);
// set up touch.
widget.setOnClickListener(mIconClickListener);
widget.setOnLongClickListener(mIconLongClickListener);
row.addView(widget);
}
}
} else if (expectedChildCount < childCount) {
for (int i = expectedChildCount; i < childCount; i++) {
row.getChildAt(i).setVisibility(View.GONE);
}
}
// Bind the views in the application info section.
holder.title.applyFromPackageItemInfo(entry.pkgItem);
// Bind the view in the widget horizontal tray region.
for (int i = 0; i < infoList.size(); i++) {
WidgetCell widget = (WidgetCell) row.getChildAt(2 * i);
widget.applyFromCellItem(infoList.get(i), mWidgetPreviewLoader);
widget.setApplyBitmapDeferred(mApplyBitmapDeferred);
widget.ensurePreview();
widget.setVisibility(View.VISIBLE);
if (i > 0) {
row.getChildAt(2 * i - 1).setVisibility(View.VISIBLE);
}
}
}
use of com.android.launcher3.widget.WidgetListRowEntry in project Neo-Launcher by NeoApplications.
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;
}
use of com.android.launcher3.widget.WidgetListRowEntry in project Neo-Launcher by NeoApplications.
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;
}
Aggregations