Search in sources :

Example 21 with WidgetItem

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;
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) Size(android.util.Size)

Example 22 with WidgetItem

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

Example 23 with WidgetItem

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

Example 24 with WidgetItem

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);
}
Also used : DeviceProfile(com.android.launcher3.DeviceProfile) Size(android.util.Size) WidgetItem(com.android.launcher3.model.WidgetItem)

Example 25 with WidgetItem

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;
}
Also used : PopupDataProvider(com.android.launcher3.popup.PopupDataProvider) SearchCallback(com.android.launcher3.search.SearchCallback) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetsListSearchHeaderEntry(com.android.launcher3.widget.model.WidgetsListSearchHeaderEntry) SearchAlgorithm(com.android.launcher3.search.SearchAlgorithm) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) StringMatcher(com.android.launcher3.search.StringMatcherUtility.StringMatcher) List(java.util.List) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) StringMatcherUtility.matches(com.android.launcher3.search.StringMatcherUtility.matches) Handler(android.os.Handler) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) ArrayList(java.util.ArrayList) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry) WidgetsListSearchHeaderEntry(com.android.launcher3.widget.model.WidgetsListSearchHeaderEntry)

Aggregations

WidgetItem (com.android.launcher3.model.WidgetItem)37 WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)17 ArrayList (java.util.ArrayList)15 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)11 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)10 ComponentName (android.content.ComponentName)9 Test (org.junit.Test)9 ShadowPackageManager (org.robolectric.shadows.ShadowPackageManager)9 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)8 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)7 Size (android.util.Size)6 WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)5 TableRow (android.widget.TableRow)4 PackageUserKey (com.android.launcher3.util.PackageUserKey)4 PackageManager (android.content.pm.PackageManager)3 Nullable (androidx.annotation.Nullable)3 DeviceProfile (com.android.launcher3.DeviceProfile)3 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)3