Loading src/com/android/launcher3/widget/BaseWidgetSheet.java +11 −20 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.widget.Toast; import androidx.annotation.GuardedBy; import androidx.annotation.Nullable; import androidx.annotation.Px; import androidx.core.view.ViewCompat; import com.android.launcher3.DeviceProfile; Loading Loading @@ -61,7 +62,7 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher> implements OnClickListener, OnLongClickListener, DragSource, PopupDataProvider.PopupDataChangeListener, Insettable { /** The default number of cells that can fit horizontally in a widget sheet. */ protected static final int DEFAULT_MAX_HORIZONTAL_SPANS = 4; public static final int DEFAULT_MAX_HORIZONTAL_SPANS = 4; protected static final String KEY_WIDGETS_EDUCATION_TIP_SEEN = "launcher.widgets_education_tip_seen"; Loading @@ -70,15 +71,18 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher> /* Touch handling related member variables. */ private Toast mWidgetInstructionToast; private int mContentHorizontalMarginInPx; @Px protected int mContentHorizontalMargin; @Px protected int mWidgetCellHorizontalPadding; protected int mNavBarScrimHeight; private final Paint mNavBarScrimPaint; public BaseWidgetSheet(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mContentHorizontalMarginInPx = getResources().getDimensionPixelSize( mContentHorizontalMargin = getResources().getDimensionPixelSize( R.dimen.widget_list_horizontal_margin); mWidgetCellHorizontalPadding = getResources().getDimensionPixelSize( R.dimen.widget_cell_horizontal_padding); mNavBarScrimPaint = new Paint(); mNavBarScrimPaint.setColor(Themes.getAttrColor(context, R.attr.allAppsNavBarScrimColor)); } Loading Loading @@ -138,11 +142,11 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher> @Override public void setInsets(Rect insets) { mInsets.set(insets); int contentHorizontalMarginInPx = getResources().getDimensionPixelSize( @Px int contentHorizontalMargin = getResources().getDimensionPixelSize( R.dimen.widget_list_horizontal_margin); if (contentHorizontalMarginInPx != mContentHorizontalMarginInPx) { onContentHorizontalMarginChanged(contentHorizontalMarginInPx); mContentHorizontalMarginInPx = contentHorizontalMarginInPx; if (contentHorizontalMargin != mContentHorizontalMargin) { onContentHorizontalMarginChanged(contentHorizontalMargin); mContentHorizontalMargin = contentHorizontalMargin; } } Loading Loading @@ -198,19 +202,6 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher> MeasureSpec.getSize(heightMeasureSpec)); } /** Returns the number of cells that can fit horizontally in a given {@code content}. */ protected int computeMaxHorizontalSpans(View content, int contentHorizontalPaddingPx) { DeviceProfile deviceProfile = mActivityContext.getDeviceProfile(); int availableWidth = content.getMeasuredWidth() - contentHorizontalPaddingPx - (2 * mContentHorizontalMarginInPx); Point cellSize = deviceProfile.getCellSize(); if (cellSize.x > 0) { return availableWidth / cellSize.x; } return DEFAULT_MAX_HORIZONTAL_SPANS; } private boolean beginDraggingWidget(WidgetCell v) { if (TestProtocol.sDebugTracing) { Log.d(TestProtocol.NO_DROP_TARGET, "2"); Loading src/com/android/launcher3/widget/WidgetsBottomSheet.java +7 −6 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ import android.widget.TableLayout; import android.widget.TableRow; import android.widget.TextView; import androidx.annotation.Px; import com.android.launcher3.R; import com.android.launcher3.anim.PendingAnimation; import com.android.launcher3.model.WidgetItem; Loading Loading @@ -69,8 +71,7 @@ public class WidgetsBottomSheet extends BaseWidgetSheet { private static final long EDUCATION_TIP_DELAY_MS = 300; private ItemInfo mOriginalItemInfo; private int mMaxHorizontalSpan = DEFAULT_MAX_HORIZONTAL_SPANS; private final int mWidgetCellHorizontalPadding; @Px private int mMaxHorizontalSpan; private final OnLayoutChangeListener mLayoutChangeListenerToShowTips = new OnLayoutChangeListener() { Loading Loading @@ -111,8 +112,6 @@ public class WidgetsBottomSheet extends BaseWidgetSheet { if (!hasSeenEducationTip()) { addOnLayoutChangeListener(mLayoutChangeListenerToShowTips); } mWidgetCellHorizontalPadding = getResources().getDimensionPixelSize( R.dimen.widget_cell_horizontal_padding); setContentBackground(getContext().getDrawable(R.drawable.bg_rounded_corner_bottom_sheet)); } Loading @@ -134,7 +133,7 @@ public class WidgetsBottomSheet extends BaseWidgetSheet { private boolean updateMaxSpansPerRow() { if (getMeasuredWidth() == 0) return false; int maxHorizontalSpan = computeMaxHorizontalSpans(mContent, mWidgetCellHorizontalPadding); @Px int maxHorizontalSpan = mContent.getMeasuredWidth() - (2 * mContentHorizontalMargin); if (mMaxHorizontalSpan != maxHorizontalSpan) { // Ensure the table layout is showing widgets in the right column after measure. mMaxHorizontalSpan = maxHorizontalSpan; Loading Loading @@ -184,7 +183,9 @@ public class WidgetsBottomSheet extends BaseWidgetSheet { TableLayout widgetsTable = findViewById(R.id.widgets_table); widgetsTable.removeAllViews(); WidgetsTableUtils.groupWidgetItemsIntoTableWithReordering(widgets, mMaxHorizontalSpan) WidgetsTableUtils.groupWidgetItemsUsingRowPxWithReordering(widgets, mActivityContext, mActivityContext.getDeviceProfile(), mMaxHorizontalSpan, mWidgetCellHorizontalPadding) .forEach(row -> { TableRow tableRow = new TableRow(getContext()); tableRow.setGravity(Gravity.TOP); Loading src/com/android/launcher3/widget/model/WidgetsListContentEntry.java +19 −17 Original line number Diff line number Diff line Loading @@ -15,6 +15,8 @@ */ package com.android.launcher3.widget.model; import androidx.annotation.Px; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.data.PackageItemInfo; Loading @@ -26,7 +28,7 @@ import java.util.List; */ public final class WidgetsListContentEntry extends WidgetsListBaseEntry { private final int mMaxSpanSizeInCells; @Px private final int mMaxSpanSize; /** * Constructor for {@link WidgetsListContentEntry}. Loading @@ -37,7 +39,7 @@ public final class WidgetsListContentEntry extends WidgetsListBaseEntry { */ public WidgetsListContentEntry(PackageItemInfo pkgItem, String titleSectionName, List<WidgetItem> items) { this(pkgItem, titleSectionName, items, /* maxSpanSizeInCells= */ 0); this(pkgItem, titleSectionName, items, /* maxSpanSize= */ 0); } /** Loading @@ -46,43 +48,43 @@ public final class WidgetsListContentEntry extends WidgetsListBaseEntry { * @param pkgItem package info associated with the entry * @param titleSectionName title section name associated with the entry. * @param items list of widgets for the package. * @param maxSpanSizeInCells the max horizontal span in cells that is allowed for grouping more * @param maxSpanSize the max horizontal span in pixels that is allowed for grouping more * than one widgets in a table row. */ public WidgetsListContentEntry(PackageItemInfo pkgItem, String titleSectionName, List<WidgetItem> items, int maxSpanSizeInCells) { List<WidgetItem> items, @Px int maxSpanSize) { super(pkgItem, titleSectionName, items); mMaxSpanSizeInCells = maxSpanSizeInCells; mMaxSpanSize = maxSpanSize; } @Override public String toString() { return "Content:" + mPkgItem.packageName + ":" + mWidgets.size() + " maxSpanSizeInCells: " + mMaxSpanSizeInCells; return "Content:" + mPkgItem.packageName + ":" + mWidgets.size() + " maxSpanSize: " + mMaxSpanSize; } /** * Returns a copy of this {@link WidgetsListContentEntry} with updated * {@param maxSpanSizeInCells}. * Returns a copy of this {@link WidgetsListContentEntry} with updated {@code maxSpanSize}. * * @param maxSpanSizeInCells the maximum horizontal span in cells that is allowed for grouping * @param maxSpanSize the maximum horizontal span in pixels that is allowed for grouping * more than one widgets in a table row. */ public WidgetsListContentEntry withMaxSpanSize(int maxSpanSizeInCells) { if (mMaxSpanSizeInCells == maxSpanSizeInCells) return this; public WidgetsListContentEntry withMaxSpanSize(@Px int maxSpanSize) { if (mMaxSpanSize == maxSpanSize) return this; return new WidgetsListContentEntry( mPkgItem, mTitleSectionName, mWidgets, /* maxSpanSizeInCells= */ maxSpanSizeInCells); /* maxSpanSize= */ maxSpanSize); } /** * Returns the max horizontal span size in cells that is allowed for grouping more than one * Returns the max horizontal span size in pixels that is allowed for grouping more than one * widget in a table row. */ public int getMaxSpanSizeInCells() { return mMaxSpanSizeInCells; @Px public int getMaxSpanSize() { return mMaxSpanSize; } @Override Loading @@ -91,6 +93,6 @@ public final class WidgetsListContentEntry extends WidgetsListBaseEntry { WidgetsListContentEntry otherEntry = (WidgetsListContentEntry) obj; return mWidgets.equals(otherEntry.mWidgets) && mPkgItem.equals(otherEntry.mPkgItem) && mTitleSectionName.equals(otherEntry.mTitleSectionName) && mMaxSpanSizeInCells == otherEntry.mMaxSpanSizeInCells; && mMaxSpanSize == otherEntry.mMaxSpanSize; } } src/com/android/launcher3/widget/picker/WidgetsFullSheet.java +20 −20 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import android.widget.TextView; import androidx.annotation.FloatRange; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.Px; import androidx.annotation.VisibleForTesting; import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.RecyclerView; Loading Loading @@ -181,14 +182,13 @@ public class WidgetsFullSheet extends BaseWidgetSheet } }; private final int mTabsHeight; private final int mWidgetSheetContentHorizontalPadding; @Px private final int mTabsHeight; @Nullable private WidgetsRecyclerView mCurrentWidgetsRecyclerView; @Nullable private PersonalWorkPagedView mViewPager; private boolean mIsInSearchMode; private boolean mIsNoWidgetsViewNeeded; private int mMaxSpansPerRow = DEFAULT_MAX_HORIZONTAL_SPANS; @Px private int mMaxSpanPerRow; private TextView mNoWidgetsView; private StickyHeaderLayout mSearchScrollView; Loading Loading @@ -224,8 +224,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet mTabsHeight = mHasWorkProfile ? resources.getDimensionPixelSize(R.dimen.all_apps_header_pill_height) : 0; mWidgetSheetContentHorizontalPadding = 2 * resources.getDimensionPixelSize( R.dimen.widget_cell_horizontal_padding); mUserManagerState.init(UserCache.INSTANCE.get(context), context.getSystemService(UserManager.class)); Loading Loading @@ -337,7 +335,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet : mSearchScrollView.findViewById(R.id.title); mRightPane = mIsTwoPane ? mContent.findViewById(R.id.right_pane) : null; mWidgetsListTableViewHolderBinder = new WidgetsListTableViewHolderBinder(layoutInflater, this, this); new WidgetsListTableViewHolderBinder(mActivityContext, layoutInflater, this, this); onRecommendedWidgetsBound(); onWidgetsBound(); Loading Loading @@ -536,22 +534,20 @@ public class WidgetsFullSheet extends BaseWidgetSheet View content = mHasWorkProfile ? mViewPager : mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView; if (mIsTwoPane && mRightPane != null) { content = mRightPane; } int maxHorizontalSpans = computeMaxHorizontalSpans(content, mWidgetSheetContentHorizontalPadding); if (mMaxSpansPerRow != maxHorizontalSpans) { mMaxSpansPerRow = maxHorizontalSpans; mAdapters.get(AdapterHolder.PRIMARY).mWidgetsListAdapter.setMaxHorizontalSpansPerRow( mMaxSpansPerRow); mAdapters.get(AdapterHolder.SEARCH).mWidgetsListAdapter.setMaxHorizontalSpansPerRow( mMaxSpansPerRow); @Px int maxHorizontalSpan = content.getMeasuredWidth() - (2 * mContentHorizontalMargin); if (mMaxSpanPerRow != maxHorizontalSpan) { mMaxSpanPerRow = maxHorizontalSpan; mAdapters.get(AdapterHolder.PRIMARY).mWidgetsListAdapter.setMaxHorizontalSpansPxPerRow( maxHorizontalSpan); mAdapters.get(AdapterHolder.SEARCH).mWidgetsListAdapter.setMaxHorizontalSpansPxPerRow( maxHorizontalSpan); if (mHasWorkProfile) { mAdapters.get(AdapterHolder.WORK).mWidgetsListAdapter.setMaxHorizontalSpansPerRow( mMaxSpansPerRow); mAdapters.get(AdapterHolder.WORK).mWidgetsListAdapter.setMaxHorizontalSpansPxPerRow( maxHorizontalSpan); } onRecommendedWidgetsBound(); return true; Loading Loading @@ -700,8 +696,12 @@ public class WidgetsFullSheet extends BaseWidgetSheet - noWidgetsViewHeight) * RECOMMENDATION_TABLE_HEIGHT_RATIO; List<ArrayList<WidgetItem>> recommendedWidgetsInTable = WidgetsTableUtils.groupWidgetItemsIntoTableWithoutReordering( recommendedWidgets, mMaxSpansPerRow); WidgetsTableUtils.groupWidgetItemsUsingRowPxWithoutReordering( recommendedWidgets, mActivityContext, mActivityContext.getDeviceProfile(), mMaxSpanPerRow, mWidgetCellHorizontalPadding); mRecommendedWidgetsTable.setRecommendedWidgets( recommendedWidgetsInTable, maxTableHeight); } else { Loading Loading @@ -1051,7 +1051,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet if (mAdapterType == PRIMARY || mAdapterType == WORK) { mWidgetsRecyclerView.addOnAttachStateChangeListener(mBindScrollbarInSearchMode); } mWidgetsListAdapter.setMaxHorizontalSpansPerRow(mMaxSpansPerRow); mWidgetsListAdapter.setMaxHorizontalSpansPxPerRow(mMaxSpanPerRow); } } Loading src/com/android/launcher3/widget/picker/WidgetsListAdapter.java +13 −6 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH import static com.android.launcher3.recyclerview.ViewHolderBinder.POSITION_DEFAULT; import static com.android.launcher3.recyclerview.ViewHolderBinder.POSITION_FIRST; import static com.android.launcher3.recyclerview.ViewHolderBinder.POSITION_LAST; import static com.android.launcher3.widget.BaseWidgetSheet.DEFAULT_MAX_HORIZONTAL_SPANS; import android.content.Context; import android.os.Process; Loading @@ -32,6 +33,7 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.Px; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.DiffUtil.DiffResult; import androidx.recyclerview.widget.LinearLayoutManager; Loading @@ -49,6 +51,7 @@ import com.android.launcher3.widget.model.WidgetListSpaceEntry; import com.android.launcher3.widget.model.WidgetsListBaseEntry; import com.android.launcher3.widget.model.WidgetsListContentEntry; import com.android.launcher3.widget.model.WidgetsListHeaderEntry; import com.android.launcher3.widget.util.WidgetSizes; import java.util.ArrayList; import java.util.Arrays; Loading Loading @@ -99,7 +102,7 @@ public class WidgetsListAdapter extends Adapter<ViewHolder> implements OnHeaderC @Nullable private Predicate<WidgetsListBaseEntry> mFilter = null; @Nullable private RecyclerView mRecyclerView; @Nullable private PackageUserKey mPendingClickHeader; private int mMaxSpanSize = 4; @Px private int mMaxHorizontalSpan; public WidgetsListAdapter(Context context, LayoutInflater layoutInflater, IntSupplier emptySpaceHeightProvider, OnClickListener iconClickListener, Loading @@ -107,11 +110,14 @@ public class WidgetsListAdapter extends Adapter<ViewHolder> implements OnHeaderC WidgetsFullSheet.HeaderChangeListener headerChangeListener) { mHeaderChangeListener = headerChangeListener; mContext = context; mMaxHorizontalSpan = WidgetSizes.getWidgetSizePx( ActivityContext.lookupContext(context).getDeviceProfile(), DEFAULT_MAX_HORIZONTAL_SPANS, 1).getWidth(); mViewHolderBinders.put( VIEW_TYPE_WIDGETS_LIST, new WidgetsListTableViewHolderBinder( layoutInflater, iconClickListener, iconLongClickListener)); mContext, layoutInflater, iconClickListener, iconLongClickListener)); mViewHolderBinders.put( VIEW_TYPE_WIDGETS_HEADER, new WidgetsListHeaderViewHolderBinder( Loading Loading @@ -199,7 +205,8 @@ public class WidgetsListAdapter extends Adapter<ViewHolder> implements OnHeaderC } else if (entry instanceof WidgetsListContentEntry) { // Adjust the original content entries to accommodate for the current // maxSpanSize. return ((WidgetsListContentEntry) entry).withMaxSpanSize(mMaxSpanSize); return ((WidgetsListContentEntry) entry).withMaxSpanSize( mMaxHorizontalSpan); } return entry; }) Loading Loading @@ -407,11 +414,11 @@ public class WidgetsListAdapter extends Adapter<ViewHolder> implements OnHeaderC } /** * Sets the max horizontal span in cells that is allowed for grouping more than one widget in a * Sets the max horizontal span in pixels that is allowed for grouping more than one widget in a * table row. */ public void setMaxHorizontalSpansPerRow(int maxHorizontalSpans) { mMaxSpanSize = maxHorizontalSpans; public void setMaxHorizontalSpansPxPerRow(@Px int maxHorizontalSpan) { mMaxHorizontalSpan = maxHorizontalSpan; updateVisibleEntries(); } Loading Loading
src/com/android/launcher3/widget/BaseWidgetSheet.java +11 −20 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.widget.Toast; import androidx.annotation.GuardedBy; import androidx.annotation.Nullable; import androidx.annotation.Px; import androidx.core.view.ViewCompat; import com.android.launcher3.DeviceProfile; Loading Loading @@ -61,7 +62,7 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher> implements OnClickListener, OnLongClickListener, DragSource, PopupDataProvider.PopupDataChangeListener, Insettable { /** The default number of cells that can fit horizontally in a widget sheet. */ protected static final int DEFAULT_MAX_HORIZONTAL_SPANS = 4; public static final int DEFAULT_MAX_HORIZONTAL_SPANS = 4; protected static final String KEY_WIDGETS_EDUCATION_TIP_SEEN = "launcher.widgets_education_tip_seen"; Loading @@ -70,15 +71,18 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher> /* Touch handling related member variables. */ private Toast mWidgetInstructionToast; private int mContentHorizontalMarginInPx; @Px protected int mContentHorizontalMargin; @Px protected int mWidgetCellHorizontalPadding; protected int mNavBarScrimHeight; private final Paint mNavBarScrimPaint; public BaseWidgetSheet(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mContentHorizontalMarginInPx = getResources().getDimensionPixelSize( mContentHorizontalMargin = getResources().getDimensionPixelSize( R.dimen.widget_list_horizontal_margin); mWidgetCellHorizontalPadding = getResources().getDimensionPixelSize( R.dimen.widget_cell_horizontal_padding); mNavBarScrimPaint = new Paint(); mNavBarScrimPaint.setColor(Themes.getAttrColor(context, R.attr.allAppsNavBarScrimColor)); } Loading Loading @@ -138,11 +142,11 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher> @Override public void setInsets(Rect insets) { mInsets.set(insets); int contentHorizontalMarginInPx = getResources().getDimensionPixelSize( @Px int contentHorizontalMargin = getResources().getDimensionPixelSize( R.dimen.widget_list_horizontal_margin); if (contentHorizontalMarginInPx != mContentHorizontalMarginInPx) { onContentHorizontalMarginChanged(contentHorizontalMarginInPx); mContentHorizontalMarginInPx = contentHorizontalMarginInPx; if (contentHorizontalMargin != mContentHorizontalMargin) { onContentHorizontalMarginChanged(contentHorizontalMargin); mContentHorizontalMargin = contentHorizontalMargin; } } Loading Loading @@ -198,19 +202,6 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher> MeasureSpec.getSize(heightMeasureSpec)); } /** Returns the number of cells that can fit horizontally in a given {@code content}. */ protected int computeMaxHorizontalSpans(View content, int contentHorizontalPaddingPx) { DeviceProfile deviceProfile = mActivityContext.getDeviceProfile(); int availableWidth = content.getMeasuredWidth() - contentHorizontalPaddingPx - (2 * mContentHorizontalMarginInPx); Point cellSize = deviceProfile.getCellSize(); if (cellSize.x > 0) { return availableWidth / cellSize.x; } return DEFAULT_MAX_HORIZONTAL_SPANS; } private boolean beginDraggingWidget(WidgetCell v) { if (TestProtocol.sDebugTracing) { Log.d(TestProtocol.NO_DROP_TARGET, "2"); Loading
src/com/android/launcher3/widget/WidgetsBottomSheet.java +7 −6 Original line number Diff line number Diff line Loading @@ -36,6 +36,8 @@ import android.widget.TableLayout; import android.widget.TableRow; import android.widget.TextView; import androidx.annotation.Px; import com.android.launcher3.R; import com.android.launcher3.anim.PendingAnimation; import com.android.launcher3.model.WidgetItem; Loading Loading @@ -69,8 +71,7 @@ public class WidgetsBottomSheet extends BaseWidgetSheet { private static final long EDUCATION_TIP_DELAY_MS = 300; private ItemInfo mOriginalItemInfo; private int mMaxHorizontalSpan = DEFAULT_MAX_HORIZONTAL_SPANS; private final int mWidgetCellHorizontalPadding; @Px private int mMaxHorizontalSpan; private final OnLayoutChangeListener mLayoutChangeListenerToShowTips = new OnLayoutChangeListener() { Loading Loading @@ -111,8 +112,6 @@ public class WidgetsBottomSheet extends BaseWidgetSheet { if (!hasSeenEducationTip()) { addOnLayoutChangeListener(mLayoutChangeListenerToShowTips); } mWidgetCellHorizontalPadding = getResources().getDimensionPixelSize( R.dimen.widget_cell_horizontal_padding); setContentBackground(getContext().getDrawable(R.drawable.bg_rounded_corner_bottom_sheet)); } Loading @@ -134,7 +133,7 @@ public class WidgetsBottomSheet extends BaseWidgetSheet { private boolean updateMaxSpansPerRow() { if (getMeasuredWidth() == 0) return false; int maxHorizontalSpan = computeMaxHorizontalSpans(mContent, mWidgetCellHorizontalPadding); @Px int maxHorizontalSpan = mContent.getMeasuredWidth() - (2 * mContentHorizontalMargin); if (mMaxHorizontalSpan != maxHorizontalSpan) { // Ensure the table layout is showing widgets in the right column after measure. mMaxHorizontalSpan = maxHorizontalSpan; Loading Loading @@ -184,7 +183,9 @@ public class WidgetsBottomSheet extends BaseWidgetSheet { TableLayout widgetsTable = findViewById(R.id.widgets_table); widgetsTable.removeAllViews(); WidgetsTableUtils.groupWidgetItemsIntoTableWithReordering(widgets, mMaxHorizontalSpan) WidgetsTableUtils.groupWidgetItemsUsingRowPxWithReordering(widgets, mActivityContext, mActivityContext.getDeviceProfile(), mMaxHorizontalSpan, mWidgetCellHorizontalPadding) .forEach(row -> { TableRow tableRow = new TableRow(getContext()); tableRow.setGravity(Gravity.TOP); Loading
src/com/android/launcher3/widget/model/WidgetsListContentEntry.java +19 −17 Original line number Diff line number Diff line Loading @@ -15,6 +15,8 @@ */ package com.android.launcher3.widget.model; import androidx.annotation.Px; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.data.PackageItemInfo; Loading @@ -26,7 +28,7 @@ import java.util.List; */ public final class WidgetsListContentEntry extends WidgetsListBaseEntry { private final int mMaxSpanSizeInCells; @Px private final int mMaxSpanSize; /** * Constructor for {@link WidgetsListContentEntry}. Loading @@ -37,7 +39,7 @@ public final class WidgetsListContentEntry extends WidgetsListBaseEntry { */ public WidgetsListContentEntry(PackageItemInfo pkgItem, String titleSectionName, List<WidgetItem> items) { this(pkgItem, titleSectionName, items, /* maxSpanSizeInCells= */ 0); this(pkgItem, titleSectionName, items, /* maxSpanSize= */ 0); } /** Loading @@ -46,43 +48,43 @@ public final class WidgetsListContentEntry extends WidgetsListBaseEntry { * @param pkgItem package info associated with the entry * @param titleSectionName title section name associated with the entry. * @param items list of widgets for the package. * @param maxSpanSizeInCells the max horizontal span in cells that is allowed for grouping more * @param maxSpanSize the max horizontal span in pixels that is allowed for grouping more * than one widgets in a table row. */ public WidgetsListContentEntry(PackageItemInfo pkgItem, String titleSectionName, List<WidgetItem> items, int maxSpanSizeInCells) { List<WidgetItem> items, @Px int maxSpanSize) { super(pkgItem, titleSectionName, items); mMaxSpanSizeInCells = maxSpanSizeInCells; mMaxSpanSize = maxSpanSize; } @Override public String toString() { return "Content:" + mPkgItem.packageName + ":" + mWidgets.size() + " maxSpanSizeInCells: " + mMaxSpanSizeInCells; return "Content:" + mPkgItem.packageName + ":" + mWidgets.size() + " maxSpanSize: " + mMaxSpanSize; } /** * Returns a copy of this {@link WidgetsListContentEntry} with updated * {@param maxSpanSizeInCells}. * Returns a copy of this {@link WidgetsListContentEntry} with updated {@code maxSpanSize}. * * @param maxSpanSizeInCells the maximum horizontal span in cells that is allowed for grouping * @param maxSpanSize the maximum horizontal span in pixels that is allowed for grouping * more than one widgets in a table row. */ public WidgetsListContentEntry withMaxSpanSize(int maxSpanSizeInCells) { if (mMaxSpanSizeInCells == maxSpanSizeInCells) return this; public WidgetsListContentEntry withMaxSpanSize(@Px int maxSpanSize) { if (mMaxSpanSize == maxSpanSize) return this; return new WidgetsListContentEntry( mPkgItem, mTitleSectionName, mWidgets, /* maxSpanSizeInCells= */ maxSpanSizeInCells); /* maxSpanSize= */ maxSpanSize); } /** * Returns the max horizontal span size in cells that is allowed for grouping more than one * Returns the max horizontal span size in pixels that is allowed for grouping more than one * widget in a table row. */ public int getMaxSpanSizeInCells() { return mMaxSpanSizeInCells; @Px public int getMaxSpanSize() { return mMaxSpanSize; } @Override Loading @@ -91,6 +93,6 @@ public final class WidgetsListContentEntry extends WidgetsListBaseEntry { WidgetsListContentEntry otherEntry = (WidgetsListContentEntry) obj; return mWidgets.equals(otherEntry.mWidgets) && mPkgItem.equals(otherEntry.mPkgItem) && mTitleSectionName.equals(otherEntry.mTitleSectionName) && mMaxSpanSizeInCells == otherEntry.mMaxSpanSizeInCells; && mMaxSpanSize == otherEntry.mMaxSpanSize; } }
src/com/android/launcher3/widget/picker/WidgetsFullSheet.java +20 −20 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import android.widget.TextView; import androidx.annotation.FloatRange; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.Px; import androidx.annotation.VisibleForTesting; import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.RecyclerView; Loading Loading @@ -181,14 +182,13 @@ public class WidgetsFullSheet extends BaseWidgetSheet } }; private final int mTabsHeight; private final int mWidgetSheetContentHorizontalPadding; @Px private final int mTabsHeight; @Nullable private WidgetsRecyclerView mCurrentWidgetsRecyclerView; @Nullable private PersonalWorkPagedView mViewPager; private boolean mIsInSearchMode; private boolean mIsNoWidgetsViewNeeded; private int mMaxSpansPerRow = DEFAULT_MAX_HORIZONTAL_SPANS; @Px private int mMaxSpanPerRow; private TextView mNoWidgetsView; private StickyHeaderLayout mSearchScrollView; Loading Loading @@ -224,8 +224,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet mTabsHeight = mHasWorkProfile ? resources.getDimensionPixelSize(R.dimen.all_apps_header_pill_height) : 0; mWidgetSheetContentHorizontalPadding = 2 * resources.getDimensionPixelSize( R.dimen.widget_cell_horizontal_padding); mUserManagerState.init(UserCache.INSTANCE.get(context), context.getSystemService(UserManager.class)); Loading Loading @@ -337,7 +335,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet : mSearchScrollView.findViewById(R.id.title); mRightPane = mIsTwoPane ? mContent.findViewById(R.id.right_pane) : null; mWidgetsListTableViewHolderBinder = new WidgetsListTableViewHolderBinder(layoutInflater, this, this); new WidgetsListTableViewHolderBinder(mActivityContext, layoutInflater, this, this); onRecommendedWidgetsBound(); onWidgetsBound(); Loading Loading @@ -536,22 +534,20 @@ public class WidgetsFullSheet extends BaseWidgetSheet View content = mHasWorkProfile ? mViewPager : mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView; if (mIsTwoPane && mRightPane != null) { content = mRightPane; } int maxHorizontalSpans = computeMaxHorizontalSpans(content, mWidgetSheetContentHorizontalPadding); if (mMaxSpansPerRow != maxHorizontalSpans) { mMaxSpansPerRow = maxHorizontalSpans; mAdapters.get(AdapterHolder.PRIMARY).mWidgetsListAdapter.setMaxHorizontalSpansPerRow( mMaxSpansPerRow); mAdapters.get(AdapterHolder.SEARCH).mWidgetsListAdapter.setMaxHorizontalSpansPerRow( mMaxSpansPerRow); @Px int maxHorizontalSpan = content.getMeasuredWidth() - (2 * mContentHorizontalMargin); if (mMaxSpanPerRow != maxHorizontalSpan) { mMaxSpanPerRow = maxHorizontalSpan; mAdapters.get(AdapterHolder.PRIMARY).mWidgetsListAdapter.setMaxHorizontalSpansPxPerRow( maxHorizontalSpan); mAdapters.get(AdapterHolder.SEARCH).mWidgetsListAdapter.setMaxHorizontalSpansPxPerRow( maxHorizontalSpan); if (mHasWorkProfile) { mAdapters.get(AdapterHolder.WORK).mWidgetsListAdapter.setMaxHorizontalSpansPerRow( mMaxSpansPerRow); mAdapters.get(AdapterHolder.WORK).mWidgetsListAdapter.setMaxHorizontalSpansPxPerRow( maxHorizontalSpan); } onRecommendedWidgetsBound(); return true; Loading Loading @@ -700,8 +696,12 @@ public class WidgetsFullSheet extends BaseWidgetSheet - noWidgetsViewHeight) * RECOMMENDATION_TABLE_HEIGHT_RATIO; List<ArrayList<WidgetItem>> recommendedWidgetsInTable = WidgetsTableUtils.groupWidgetItemsIntoTableWithoutReordering( recommendedWidgets, mMaxSpansPerRow); WidgetsTableUtils.groupWidgetItemsUsingRowPxWithoutReordering( recommendedWidgets, mActivityContext, mActivityContext.getDeviceProfile(), mMaxSpanPerRow, mWidgetCellHorizontalPadding); mRecommendedWidgetsTable.setRecommendedWidgets( recommendedWidgetsInTable, maxTableHeight); } else { Loading Loading @@ -1051,7 +1051,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet if (mAdapterType == PRIMARY || mAdapterType == WORK) { mWidgetsRecyclerView.addOnAttachStateChangeListener(mBindScrollbarInSearchMode); } mWidgetsListAdapter.setMaxHorizontalSpansPerRow(mMaxSpansPerRow); mWidgetsListAdapter.setMaxHorizontalSpansPxPerRow(mMaxSpanPerRow); } } Loading
src/com/android/launcher3/widget/picker/WidgetsListAdapter.java +13 −6 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH import static com.android.launcher3.recyclerview.ViewHolderBinder.POSITION_DEFAULT; import static com.android.launcher3.recyclerview.ViewHolderBinder.POSITION_FIRST; import static com.android.launcher3.recyclerview.ViewHolderBinder.POSITION_LAST; import static com.android.launcher3.widget.BaseWidgetSheet.DEFAULT_MAX_HORIZONTAL_SPANS; import android.content.Context; import android.os.Process; Loading @@ -32,6 +33,7 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.Px; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.DiffUtil.DiffResult; import androidx.recyclerview.widget.LinearLayoutManager; Loading @@ -49,6 +51,7 @@ import com.android.launcher3.widget.model.WidgetListSpaceEntry; import com.android.launcher3.widget.model.WidgetsListBaseEntry; import com.android.launcher3.widget.model.WidgetsListContentEntry; import com.android.launcher3.widget.model.WidgetsListHeaderEntry; import com.android.launcher3.widget.util.WidgetSizes; import java.util.ArrayList; import java.util.Arrays; Loading Loading @@ -99,7 +102,7 @@ public class WidgetsListAdapter extends Adapter<ViewHolder> implements OnHeaderC @Nullable private Predicate<WidgetsListBaseEntry> mFilter = null; @Nullable private RecyclerView mRecyclerView; @Nullable private PackageUserKey mPendingClickHeader; private int mMaxSpanSize = 4; @Px private int mMaxHorizontalSpan; public WidgetsListAdapter(Context context, LayoutInflater layoutInflater, IntSupplier emptySpaceHeightProvider, OnClickListener iconClickListener, Loading @@ -107,11 +110,14 @@ public class WidgetsListAdapter extends Adapter<ViewHolder> implements OnHeaderC WidgetsFullSheet.HeaderChangeListener headerChangeListener) { mHeaderChangeListener = headerChangeListener; mContext = context; mMaxHorizontalSpan = WidgetSizes.getWidgetSizePx( ActivityContext.lookupContext(context).getDeviceProfile(), DEFAULT_MAX_HORIZONTAL_SPANS, 1).getWidth(); mViewHolderBinders.put( VIEW_TYPE_WIDGETS_LIST, new WidgetsListTableViewHolderBinder( layoutInflater, iconClickListener, iconLongClickListener)); mContext, layoutInflater, iconClickListener, iconLongClickListener)); mViewHolderBinders.put( VIEW_TYPE_WIDGETS_HEADER, new WidgetsListHeaderViewHolderBinder( Loading Loading @@ -199,7 +205,8 @@ public class WidgetsListAdapter extends Adapter<ViewHolder> implements OnHeaderC } else if (entry instanceof WidgetsListContentEntry) { // Adjust the original content entries to accommodate for the current // maxSpanSize. return ((WidgetsListContentEntry) entry).withMaxSpanSize(mMaxSpanSize); return ((WidgetsListContentEntry) entry).withMaxSpanSize( mMaxHorizontalSpan); } return entry; }) Loading Loading @@ -407,11 +414,11 @@ public class WidgetsListAdapter extends Adapter<ViewHolder> implements OnHeaderC } /** * Sets the max horizontal span in cells that is allowed for grouping more than one widget in a * Sets the max horizontal span in pixels that is allowed for grouping more than one widget in a * table row. */ public void setMaxHorizontalSpansPerRow(int maxHorizontalSpans) { mMaxSpanSize = maxHorizontalSpans; public void setMaxHorizontalSpansPxPerRow(@Px int maxHorizontalSpan) { mMaxHorizontalSpan = maxHorizontalSpan; updateVisibleEntries(); } Loading