use of com.android.launcher3.model.WidgetItem in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetCell method setPreviewSize.
/**
* Sets the widget preview image size, in number of cells, and preview scale.
*/
public Size setPreviewSize(WidgetItem widgetItem, float previewScale) {
DeviceProfile deviceProfile = mActivity.getDeviceProfile();
Size widgetSize = WidgetSizes.getWidgetItemSizePx(getContext(), deviceProfile, widgetItem);
mPreviewWidth = widgetSize.getWidth();
mPreviewHeight = widgetSize.getHeight();
mPreviewScale = previewScale;
return widgetSize;
}
use of com.android.launcher3.model.WidgetItem 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.model.WidgetItem 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);
}
}
}
use of com.android.launcher3.model.WidgetItem in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetsRecommendationTableLayout method fitRecommendedWidgetsToTableSpace.
private RecommendationTableData fitRecommendedWidgetsToTableSpace(float previewScale, List<ArrayList<WidgetItem>> recommendedWidgetsInTable) {
if (previewScale < MAX_DOWN_SCALE_RATIO) {
Log.w(TAG, "Hide recommended widgets. Can't down scale previews to " + previewScale);
return new RecommendationTableData(List.of(), previewScale);
}
// A naive estimation of the widgets recommendation table height without inflation.
float totalHeight = mWidgetsRecommendationTableVerticalPadding;
DeviceProfile deviceProfile = Launcher.getLauncher(getContext()).getDeviceProfile();
for (int i = 0; i < recommendedWidgetsInTable.size(); i++) {
List<WidgetItem> widgetItems = recommendedWidgetsInTable.get(i);
float rowHeight = 0;
for (int j = 0; j < widgetItems.size(); j++) {
WidgetItem widgetItem = widgetItems.get(j);
Size widgetSize = WidgetSizes.getWidgetItemSizePx(getContext(), deviceProfile, widgetItem);
float previewHeight = widgetSize.getHeight() * previewScale;
rowHeight = Math.max(rowHeight, previewHeight + mWidgetCellTextViewsHeight + mWidgetCellVerticalPadding);
}
totalHeight += rowHeight;
}
if (totalHeight < mRecommendationTableMaxHeight) {
return new RecommendationTableData(recommendedWidgetsInTable, previewScale);
}
if (recommendedWidgetsInTable.size() > 1) {
// num of row by 1 to see if it fits.
return fitRecommendedWidgetsToTableSpace(previewScale, recommendedWidgetsInTable.subList(/* fromIndex= */
0, /* toIndex= */
recommendedWidgetsInTable.size() - 1));
}
float nextPreviewScale = previewScale * DOWN_SCALE_RATIO;
return fitRecommendedWidgetsToTableSpace(nextPreviewScale, recommendedWidgetsInTable);
}
use of com.android.launcher3.model.WidgetItem in project android_packages_apps_Launcher3 by crdroidandroid.
the class SimpleWidgetsSearchAlgorithm method getFilteredWidgets.
/**
* Returns entries for all matched widgets
*/
public static ArrayList<WidgetsListBaseEntry> getFilteredWidgets(PopupDataProvider dataProvider, String input) {
ArrayList<WidgetsListBaseEntry> results = new ArrayList<>();
dataProvider.getAllWidgets().stream().filter(entry -> entry instanceof WidgetsListHeaderEntry).forEach(headerEntry -> {
List<WidgetItem> matchedWidgetItems = filterWidgetItems(input, headerEntry.mPkgItem.title.toString(), headerEntry.mWidgets);
if (matchedWidgetItems.size() > 0) {
results.add(new WidgetsListSearchHeaderEntry(headerEntry.mPkgItem, headerEntry.mTitleSectionName, matchedWidgetItems));
results.add(new WidgetsListContentEntry(headerEntry.mPkgItem, headerEntry.mTitleSectionName, matchedWidgetItems));
}
});
return results;
}
Aggregations