Search in sources :

Example 1 with WidgetListRowEntry

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

Example 2 with WidgetListRowEntry

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;
}
Also used : ArrayList(java.util.ArrayList) PackageItemInfo(com.android.launcher3.model.PackageItemInfo) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) WidgetItem(com.android.launcher3.model.WidgetItem) AppWidgetManagerCompat(com.android.launcher3.compat.AppWidgetManagerCompat) MultiHashMap(com.android.launcher3.util.MultiHashMap) Map(java.util.Map) MultiHashMap(com.android.launcher3.util.MultiHashMap)

Example 3 with WidgetListRowEntry

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

Example 4 with WidgetListRowEntry

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

Example 5 with WidgetListRowEntry

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;
}
Also used : AlphabeticIndexCompat(com.android.launcher3.compat.AlphabeticIndexCompat) WidgetItemComparator(com.android.launcher3.widget.WidgetItemComparator) ArrayList(java.util.ArrayList) WidgetListRowEntry(com.android.launcher3.widget.WidgetListRowEntry) HashMap(java.util.HashMap) Map(java.util.Map) MultiHashMap(com.android.launcher3.util.MultiHashMap)

Aggregations

WidgetItem (com.android.launcher3.model.WidgetItem)6 ArrayList (java.util.ArrayList)6 WidgetListRowEntry (com.android.launcher3.widget.WidgetListRowEntry)4 MultiHashMap (com.android.launcher3.util.MultiHashMap)3 Map (java.util.Map)3 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)2 ViewGroup (android.view.ViewGroup)2 LauncherAppWidgetProviderInfo (com.android.launcher3.LauncherAppWidgetProviderInfo)2 AlphabeticIndexCompat (com.android.launcher3.compat.AlphabeticIndexCompat)2 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)2 WidgetItemComparator (com.android.launcher3.widget.WidgetItemComparator)2 HashMap (java.util.HashMap)2 ComponentName (android.content.ComponentName)1 AppWidgetManagerCompat (com.android.launcher3.compat.AppWidgetManagerCompat)1 PackageItemInfo (com.android.launcher3.model.PackageItemInfo)1 ShadowPackageManager (org.robolectric.shadows.ShadowPackageManager)1