Search in sources :

Example 1 with WidgetCell

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);
    });
}
Also used : TableRow(android.widget.TableRow) WidgetItem(com.android.launcher3.model.WidgetItem) PackageUserKey(com.android.launcher3.util.PackageUserKey) TableLayout(android.widget.TableLayout)

Example 2 with WidgetCell

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);
}
Also used : TableRow(android.widget.TableRow) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetCell(com.android.launcher3.widget.WidgetCell)

Example 3 with WidgetCell

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);
            }
        }
    }
}
Also used : TableRow(android.widget.TableRow) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetCell(com.android.launcher3.widget.WidgetCell) View(android.view.View)

Example 4 with WidgetCell

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();
        }
    }
}
Also used : TableRow(android.widget.TableRow) WidgetCell(com.android.launcher3.widget.WidgetCell)

Example 5 with WidgetCell

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);
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) Size(android.util.Size) TableRow(android.widget.TableRow) ArrayList(java.util.ArrayList) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetCell(com.android.launcher3.widget.WidgetCell)

Aggregations

TableRow (android.widget.TableRow)5 WidgetCell (com.android.launcher3.widget.WidgetCell)5 WidgetItem (com.android.launcher3.model.WidgetItem)4 View (android.view.View)3 Bitmap (android.graphics.Bitmap)1 Point (android.graphics.Point)1 Rect (android.graphics.Rect)1 Size (android.util.Size)1 TableLayout (android.widget.TableLayout)1 DragOptions (com.android.launcher3.dragndrop.DragOptions)1 PackageUserKey (com.android.launcher3.util.PackageUserKey)1 AbstractSlideInView (com.android.launcher3.views.AbstractSlideInView)1 ArrowTipView (com.android.launcher3.views.ArrowTipView)1 ArrayList (java.util.ArrayList)1