use of com.android.launcher3.widget.WidgetCell in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsBottomSheet method onWidgetsBound.
@Override
public void onWidgetsBound() {
List<WidgetItem> widgets = mActivityContext.getPopupDataProvider().getWidgetsForPackageUser(new PackageUserKey(mOriginalItemInfo.getTargetComponent().getPackageName(), mOriginalItemInfo.user));
TableLayout widgetsTable = findViewById(R.id.widgets_table);
widgetsTable.removeAllViews();
WidgetsTableUtils.groupWidgetItemsIntoTable(widgets, mMaxHorizontalSpan).forEach(row -> {
TableRow tableRow = new TableRow(getContext());
tableRow.setGravity(Gravity.TOP);
row.forEach(widgetItem -> {
WidgetCell widget = addItemCell(tableRow);
widget.setPreviewSize(widgetItem);
widget.applyFromCellItem(widgetItem, LauncherAppState.getInstance(mActivityContext).getWidgetCache());
widget.ensurePreview();
widget.setVisibility(View.VISIBLE);
});
widgetsTable.addView(tableRow);
});
}
use of com.android.launcher3.widget.WidgetCell in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsRecommendationTableLayout method bindData.
private void bindData(RecommendationTableData data) {
if (data.mRecommendationTable.size() == 0) {
setVisibility(GONE);
return;
}
removeAllViews();
for (int i = 0; i < data.mRecommendationTable.size(); i++) {
List<WidgetItem> widgetItems = data.mRecommendationTable.get(i);
TableRow tableRow = new TableRow(getContext());
tableRow.setGravity(Gravity.TOP);
for (WidgetItem widgetItem : widgetItems) {
WidgetCell widgetCell = addItemCell(tableRow);
widgetCell.setPreviewSize(widgetItem, data.mPreviewScale);
widgetCell.applyFromCellItem(widgetItem, LauncherAppState.getInstance(getContext()).getWidgetCache());
widgetCell.ensurePreview();
}
addView(tableRow);
}
setVisibility(VISIBLE);
}
use of com.android.launcher3.widget.WidgetCell in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsListTableViewHolderBinder method recycleTableBeforeBinding.
/**
* Adds and hides table rows and columns from {@code table} to ensure there is sufficient room
* to display {@code widgetItemsTable}.
*
* <p>Instead of recreating all UI elements in {@code table}, this function recycles all
* existing UI elements. Instead of deleting excessive elements, it hides them.
*/
private void recycleTableBeforeBinding(TableLayout table, List<ArrayList<WidgetItem>> widgetItemsTable) {
// Hide extra table rows.
for (int i = widgetItemsTable.size(); i < table.getChildCount(); i++) {
table.getChildAt(i).setVisibility(View.GONE);
}
for (int i = 0; i < widgetItemsTable.size(); i++) {
List<WidgetItem> widgetItems = widgetItemsTable.get(i);
TableRow tableRow;
if (i < table.getChildCount()) {
tableRow = (TableRow) table.getChildAt(i);
} else {
tableRow = new TableRow(table.getContext());
tableRow.setGravity(Gravity.TOP);
table.addView(tableRow);
}
if (tableRow.getChildCount() > widgetItems.size()) {
for (int j = widgetItems.size(); j < tableRow.getChildCount(); j++) {
tableRow.getChildAt(j).setVisibility(View.GONE);
}
} else {
for (int j = tableRow.getChildCount(); j < widgetItems.size(); j++) {
WidgetCell widget = (WidgetCell) mLayoutInflater.inflate(R.layout.widget_cell, tableRow, false);
// set up touch.
View preview = widget.findViewById(R.id.widget_preview_container);
preview.setOnClickListener(mIconClickListener);
preview.setOnLongClickListener(mIconLongClickListener);
tableRow.addView(widget);
}
}
}
}
use of com.android.launcher3.widget.WidgetCell in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsListTableViewHolderBinder method unbindViewHolder.
@Override
public void unbindViewHolder(WidgetsRowViewHolder holder) {
int numOfRows = holder.mTableContainer.getChildCount();
for (int i = 0; i < numOfRows; i++) {
TableRow tableRow = (TableRow) holder.mTableContainer.getChildAt(i);
int numOfCols = tableRow.getChildCount();
for (int j = 0; j < numOfCols; j++) {
WidgetCell widget = (WidgetCell) tableRow.getChildAt(j);
widget.clear();
}
}
}
use of com.android.launcher3.widget.WidgetCell in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsListTableViewHolderBinder method bindViewHolder.
@Override
public void bindViewHolder(WidgetsRowViewHolder holder, WidgetsListContentEntry entry, int position) {
WidgetsListTableView table = holder.mTableContainer;
if (DEBUG) {
Log.d(TAG, String.format("onBindViewHolder [widget#=%d, table.getChildCount=%d]", entry.mWidgets.size(), table.getChildCount()));
}
table.setListDrawableState(position == mWidgetsListAdapter.getItemCount() - 1 ? LAST : MIDDLE);
List<ArrayList<WidgetItem>> widgetItemsTable = WidgetsTableUtils.groupWidgetItemsIntoTable(entry.mWidgets, entry.getMaxSpanSizeInCells());
recycleTableBeforeBinding(table, widgetItemsTable);
// Bind the widget items.
for (int i = 0; i < widgetItemsTable.size(); i++) {
List<WidgetItem> widgetItemsPerRow = widgetItemsTable.get(i);
for (int j = 0; j < widgetItemsPerRow.size(); j++) {
TableRow row = (TableRow) table.getChildAt(i);
row.setVisibility(View.VISIBLE);
WidgetCell widget = (WidgetCell) row.getChildAt(j);
widget.clear();
WidgetItem widgetItem = widgetItemsPerRow.get(j);
Size previewSize = widget.setPreviewSize(widgetItem);
widget.applyFromCellItem(widgetItem, mWidgetPreviewLoader);
widget.setApplyBitmapDeferred(mApplyBitmapDeferred);
Bitmap preview = mWidgetPreviewLoader.getPreview(widgetItem, previewSize);
if (preview == null) {
widget.ensurePreview();
} else {
widget.applyPreview(preview);
}
widget.setVisibility(View.VISIBLE);
}
}
}
Aggregations