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