Search in sources :

Example 11 with WidgetsListContentEntry

use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by AOSPA.

the class WidgetsListAdapter method scrollToPositionAndMaintainOffset.

/**
 * Scrolls to the selected header position with the provided offset. LinearLayoutManager
 * scrolls the minimum distance necessary, so this will keep the selected header in place during
 * clicks, without interrupting the animation.
 *
 * @param positionOptional The position too scroll to. No scrolling will be done if empty.
 * @param offsetOptional The offset from the top to maintain. If empty, then the list will
 *                       scroll to the top of the position.
 */
private void scrollToPositionAndMaintainOffset(OptionalInt positionOptional, OptionalInt offsetOptional) {
    if (!positionOptional.isPresent() || mRecyclerView == null)
        return;
    int position = positionOptional.getAsInt();
    LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
    if (layoutManager == null)
        return;
    if (position == mVisibleEntries.size() - 2 && mVisibleEntries.get(mVisibleEntries.size() - 1) instanceof WidgetsListContentEntry) {
        // If the selected header is in the last position and its content is showing, then
        // scroll to the final position so the last list of widgets will show.
        layoutManager.scrollToPosition(mVisibleEntries.size() - 1);
        return;
    }
    // Scroll to the header view's current offset, accounting for the recycler view's padding.
    // If the header view couldn't be found, then it will appear at the top of the list.
    layoutManager.scrollToPositionWithOffset(position, offsetOptional.orElse(0) - mRecyclerView.getPaddingTop());
}
Also used : WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 12 with WidgetsListContentEntry

use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by AOSPA.

the class WidgetsListTableViewHolderBinder method bindViewHolder.

@Override
public void bindViewHolder(WidgetsRowViewHolder holder, WidgetsListContentEntry entry, @ListPosition int position, List<Object> payloads) {
    for (Object payload : payloads) {
        Pair<WidgetItem, Bitmap> pair = (Pair) payload;
        holder.previewCache.put(pair.first, pair.second);
    }
    WidgetsListTableView table = holder.tableContainer;
    if (DEBUG) {
        Log.d(TAG, String.format("onBindViewHolder [widget#=%d, table.getChildCount=%d]", entry.mWidgets.size(), table.getChildCount()));
    }
    table.setListDrawableState(((position & POSITION_LAST) != 0) ? LAST : MIDDLE);
    List<ArrayList<WidgetItem>> widgetItemsTable = WidgetsTableUtils.groupWidgetItemsIntoTableWithReordering(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);
            widget.setVisibility(View.VISIBLE);
            // When preview loads, notify adapter to rebind the item and possibly animate
            widget.applyFromCellItem(widgetItem, 1f, bitmap -> {
                if (holder.getBindingAdapter() != null) {
                    holder.getBindingAdapter().notifyItemChanged(holder.getBindingAdapterPosition(), Pair.create(widgetItem, bitmap));
                }
            }, holder.previewCache.get(widgetItem));
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) TableRow(android.widget.TableRow) ArrayList(java.util.ArrayList) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetCell(com.android.launcher3.widget.WidgetCell) Pair(android.util.Pair)

Example 13 with WidgetsListContentEntry

use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ArrowOS.

the class WidgetsListAdapter method scrollToPositionAndMaintainOffset.

/**
 * Scrolls to the selected header position with the provided offset. LinearLayoutManager
 * scrolls the minimum distance necessary, so this will keep the selected header in place during
 * clicks, without interrupting the animation.
 *
 * @param positionOptional The position too scroll to. No scrolling will be done if empty.
 * @param offsetOptional The offset from the top to maintain. If empty, then the list will
 *                       scroll to the top of the position.
 */
private void scrollToPositionAndMaintainOffset(OptionalInt positionOptional, OptionalInt offsetOptional) {
    if (!positionOptional.isPresent() || mRecyclerView == null)
        return;
    int position = positionOptional.getAsInt();
    LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
    if (layoutManager == null)
        return;
    if (position == mVisibleEntries.size() - 2 && mVisibleEntries.get(mVisibleEntries.size() - 1) instanceof WidgetsListContentEntry) {
        // If the selected header is in the last position and its content is showing, then
        // scroll to the final position so the last list of widgets will show.
        layoutManager.scrollToPosition(mVisibleEntries.size() - 1);
        return;
    }
    // Scroll to the header view's current offset, accounting for the recycler view's padding.
    // If the header view couldn't be found, then it will appear at the top of the list.
    layoutManager.scrollToPositionWithOffset(position, offsetOptional.orElse(0) - mRecyclerView.getPaddingTop());
}
Also used : WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 14 with WidgetsListContentEntry

use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ArrowOS.

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)

Example 15 with WidgetsListContentEntry

use of com.android.launcher3.widget.model.WidgetsListContentEntry in project android_packages_apps_Launcher3 by ArrowOS.

the class WidgetsListAdapterTest method generateSampleMap.

/**
 * Generates a list of sample widget entries.
 *
 * <p>Each sample app has 1 widget only. An app is represented by 2 entries,
 * {@link WidgetsListHeaderEntry} & {@link WidgetsListContentEntry}. Only
 * {@link WidgetsListHeaderEntry} is always visible in the {@link WidgetsListAdapter}.
 * {@link WidgetsListContentEntry} is only shown upon clicking the corresponding app's
 * {@link WidgetsListHeaderEntry}. Only at most one {@link WidgetsListContentEntry} is shown at
 * a time.
 *
 * @param num the number of apps that have widgets.
 */
private ArrayList<WidgetsListBaseEntry> generateSampleMap(int num) {
    ArrayList<WidgetsListBaseEntry> result = new ArrayList<>();
    if (num <= 0)
        return result;
    for (int i = 0; i < num; i++) {
        String packageName = TEST_PACKAGE_PLACEHOLDER + i;
        List<WidgetItem> widgetItems = generateWidgetItems(packageName, /* numOfWidgets= */
        1);
        PackageItemInfo pInfo = new PackageItemInfo(packageName, widgetItems.get(0).user);
        pInfo.title = pInfo.packageName;
        pInfo.bitmap = BitmapInfo.of(Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8), 0);
        result.add(new WidgetsListHeaderEntry(pInfo, /* titleSectionName= */
        "", widgetItems));
        result.add(new WidgetsListContentEntry(pInfo, /* titleSectionName= */
        "", widgetItems));
    }
    return result;
}
Also used : WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) ArrayList(java.util.ArrayList) PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) WidgetsListContentEntry(com.android.launcher3.widget.model.WidgetsListContentEntry) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetsListHeaderEntry(com.android.launcher3.widget.model.WidgetsListHeaderEntry)

Aggregations

WidgetsListContentEntry (com.android.launcher3.widget.model.WidgetsListContentEntry)101 WidgetItem (com.android.launcher3.model.WidgetItem)77 Test (org.junit.Test)55 SmallTest (androidx.test.filters.SmallTest)44 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)36 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)30 ArrayList (java.util.ArrayList)30 WidgetsListHeaderEntry (com.android.launcher3.widget.model.WidgetsListHeaderEntry)20 List (java.util.List)20 PackageUserKey (com.android.launcher3.util.PackageUserKey)15 Map (java.util.Map)15 Collectors (java.util.stream.Collectors)15 TableRow (android.widget.TableRow)11 Log (android.util.Log)10 NonNull (androidx.annotation.NonNull)10 Nullable (androidx.annotation.Nullable)10 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)10 WidgetsListSearchHeaderEntry (com.android.launcher3.widget.model.WidgetsListSearchHeaderEntry)10 Arrays (java.util.Arrays)10 HashMap (java.util.HashMap)10