Loading src/com/android/launcher3/CellLayout.java +13 −4 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; import androidx.annotation.IntDef; import androidx.annotation.Nullable; import androidx.core.view.ViewCompat; import com.android.launcher3.LauncherSettings.Favorites; Loading Loading @@ -2663,20 +2664,21 @@ public class CellLayout extends ViewGroup { } public void setup(int cellWidth, int cellHeight, boolean invertHorizontally, int colCount, int rowCount, int borderSpacing) { int rowCount, int borderSpacing, @Nullable Rect inset) { setup(cellWidth, cellHeight, invertHorizontally, colCount, rowCount, 1.0f, 1.0f, borderSpacing); borderSpacing, inset); } /** * Use this method, as opposed to {@link #setup(int, int, boolean, int, int, int)}, * Use this method, as opposed to {@link #setup(int, int, boolean, int, int, int, Rect)}, * if the view needs to be scaled. * * ie. In multi-window mode, we setup widgets so that they are measured and laid out * using their full/invariant device profile sizes. */ public void setup(int cellWidth, int cellHeight, boolean invertHorizontally, int colCount, int rowCount, float cellScaleX, float cellScaleY, int borderSpacing) { int rowCount, float cellScaleX, float cellScaleY, int borderSpacing, @Nullable Rect inset) { if (isLockedToGrid) { final int myCellHSpan = cellHSpan; final int myCellVSpan = cellVSpan; Loading @@ -2697,6 +2699,13 @@ public class CellLayout extends ViewGroup { height = Math.round(myCellHeight) - topMargin - bottomMargin; x = leftMargin + (myCellX * cellWidth) + (myCellX * borderSpacing); y = topMargin + (myCellY * cellHeight) + (myCellY * borderSpacing); if (inset != null) { x -= inset.left; y -= inset.top; width += inset.left + inset.right; height += inset.top + inset.bottom; } } } Loading src/com/android/launcher3/DeviceProfile.java +13 −0 Original line number Diff line number Diff line Loading @@ -331,6 +331,19 @@ public class DeviceProfile { } } /** * We inset the widget padding added by the system and instead rely on the border spacing * between cells to create reliable consistency between widgets */ public boolean shouldInsetWidgets() { Rect widgetPadding = inv.defaultWidgetPadding; // Check all sides to ensure that the widget won't overlap into another cell. return cellLayoutBorderSpacingPx > widgetPadding.left && cellLayoutBorderSpacingPx > widgetPadding.top && cellLayoutBorderSpacingPx > widgetPadding.right && cellLayoutBorderSpacingPx > widgetPadding.bottom; } public Builder toBuilder(Context context) { Point size = new Point(availableWidthPx, availableHeightPx); Loading src/com/android/launcher3/ShortcutAndWidgetContainer.java +8 −5 Original line number Diff line number Diff line Loading @@ -37,6 +37,8 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon. // return an (x, y) value from helper functions. Do NOT use them to maintain other state. private final int[] mTmpCellXY = new int[2]; private final Rect mTempRect = new Rect(); @ContainerType private final int mContainerType; private final WallpaperManager mWallpaperManager; Loading Loading @@ -101,11 +103,12 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon. CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams(); if (child instanceof LauncherAppWidgetHostView) { DeviceProfile profile = mActivity.getDeviceProfile(); ((LauncherAppWidgetHostView) child).getWidgetInset(profile, mTempRect); lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY, profile.appWidgetScale.x, profile.appWidgetScale.y, mBorderSpacing); profile.appWidgetScale.x, profile.appWidgetScale.y, mBorderSpacing, mTempRect); } else { lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY, mBorderSpacing); mBorderSpacing, null); } } Loading @@ -124,12 +127,12 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon. final DeviceProfile profile = mActivity.getDeviceProfile(); if (child instanceof LauncherAppWidgetHostView) { ((LauncherAppWidgetHostView) child).getWidgetInset(profile, mTempRect); lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY, profile.appWidgetScale.x, profile.appWidgetScale.y, mBorderSpacing); // Widgets have their own padding profile.appWidgetScale.x, profile.appWidgetScale.y, mBorderSpacing, mTempRect); } else { lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY, mBorderSpacing); mBorderSpacing, null); // Center the icon/folder int cHeight = getCellContentHeight(); int cellPaddingY = (int) Math.max(0, ((lp.height - cHeight) / 2f)); Loading src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java +6 −2 Original line number Diff line number Diff line Loading @@ -72,8 +72,12 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo // We want to account for the extra amount of padding that we are adding to the widget // to ensure that it gets the full amount of space that it has requested. Rect widgetPadding = AppWidgetHostView.getDefaultPaddingForWidget( context, provider, null); // If grids supports insetting widgets, we do not account for widget padding. Rect widgetPadding = new Rect(); if (!idp.landscapeProfile.shouldInsetWidgets() || !idp.portraitProfile.shouldInsetWidgets()) { AppWidgetHostView.getDefaultPaddingForWidget(context, provider, widgetPadding); } spanX = Math.max(1, (int) Math.ceil( (minWidth + widgetPadding.left + widgetPadding.right) / smallestCellWidth)); spanY = Math.max(1, (int) Math.ceil( Loading src/com/android/launcher3/widget/NavigableAppWidgetHostView.java +29 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.launcher3.widget; import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetProviderInfo; import android.content.Context; import android.graphics.PointF; import android.graphics.Rect; Loading @@ -25,8 +26,11 @@ import android.view.View; import android.view.ViewDebug; import android.view.ViewGroup; import com.android.launcher3.BaseActivity; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Reorderable; import com.android.launcher3.dragndrop.DraggableView; import com.android.launcher3.views.ActivityContext; import java.util.ArrayList; Loading @@ -50,11 +54,16 @@ public abstract class NavigableAppWidgetHostView extends AppWidgetHostView private final PointF mTranslationForReorderPreview = new PointF(0, 0); private float mScaleForReorderBounce = 1f; private final Rect mTempRect = new Rect(); @ViewDebug.ExportedProperty(category = "launcher") private boolean mChildrenFocused; protected final BaseActivity mActivity; public NavigableAppWidgetHostView(Context context) { super(context); mActivity = ActivityContext.lookupContext(context); } @Override Loading Loading @@ -222,6 +231,25 @@ public abstract class NavigableAppWidgetHostView extends AppWidgetHostView int width = (int) (getMeasuredWidth() * mScaleToFit); int height = (int) (getMeasuredHeight() * mScaleToFit); bounds.set(0, 0 , width, height); getWidgetInset(mActivity.getDeviceProfile(), mTempRect); bounds.set(mTempRect.left, mTempRect.top, width - mTempRect.right, height - mTempRect.bottom); } /** * Widgets have padding added by the system. We may choose to inset this padding if the grid * supports it. */ public void getWidgetInset(DeviceProfile grid, Rect out) { if (!grid.shouldInsetWidgets()) { out.setEmpty(); return; } AppWidgetProviderInfo info = getAppWidgetInfo(); if (info == null) { out.set(grid.inv.defaultWidgetPadding); } else { AppWidgetHostView.getDefaultPaddingForWidget(getContext(), info.provider, out); } } } Loading
src/com/android/launcher3/CellLayout.java +13 −4 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; import androidx.annotation.IntDef; import androidx.annotation.Nullable; import androidx.core.view.ViewCompat; import com.android.launcher3.LauncherSettings.Favorites; Loading Loading @@ -2663,20 +2664,21 @@ public class CellLayout extends ViewGroup { } public void setup(int cellWidth, int cellHeight, boolean invertHorizontally, int colCount, int rowCount, int borderSpacing) { int rowCount, int borderSpacing, @Nullable Rect inset) { setup(cellWidth, cellHeight, invertHorizontally, colCount, rowCount, 1.0f, 1.0f, borderSpacing); borderSpacing, inset); } /** * Use this method, as opposed to {@link #setup(int, int, boolean, int, int, int)}, * Use this method, as opposed to {@link #setup(int, int, boolean, int, int, int, Rect)}, * if the view needs to be scaled. * * ie. In multi-window mode, we setup widgets so that they are measured and laid out * using their full/invariant device profile sizes. */ public void setup(int cellWidth, int cellHeight, boolean invertHorizontally, int colCount, int rowCount, float cellScaleX, float cellScaleY, int borderSpacing) { int rowCount, float cellScaleX, float cellScaleY, int borderSpacing, @Nullable Rect inset) { if (isLockedToGrid) { final int myCellHSpan = cellHSpan; final int myCellVSpan = cellVSpan; Loading @@ -2697,6 +2699,13 @@ public class CellLayout extends ViewGroup { height = Math.round(myCellHeight) - topMargin - bottomMargin; x = leftMargin + (myCellX * cellWidth) + (myCellX * borderSpacing); y = topMargin + (myCellY * cellHeight) + (myCellY * borderSpacing); if (inset != null) { x -= inset.left; y -= inset.top; width += inset.left + inset.right; height += inset.top + inset.bottom; } } } Loading
src/com/android/launcher3/DeviceProfile.java +13 −0 Original line number Diff line number Diff line Loading @@ -331,6 +331,19 @@ public class DeviceProfile { } } /** * We inset the widget padding added by the system and instead rely on the border spacing * between cells to create reliable consistency between widgets */ public boolean shouldInsetWidgets() { Rect widgetPadding = inv.defaultWidgetPadding; // Check all sides to ensure that the widget won't overlap into another cell. return cellLayoutBorderSpacingPx > widgetPadding.left && cellLayoutBorderSpacingPx > widgetPadding.top && cellLayoutBorderSpacingPx > widgetPadding.right && cellLayoutBorderSpacingPx > widgetPadding.bottom; } public Builder toBuilder(Context context) { Point size = new Point(availableWidthPx, availableHeightPx); Loading
src/com/android/launcher3/ShortcutAndWidgetContainer.java +8 −5 Original line number Diff line number Diff line Loading @@ -37,6 +37,8 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon. // return an (x, y) value from helper functions. Do NOT use them to maintain other state. private final int[] mTmpCellXY = new int[2]; private final Rect mTempRect = new Rect(); @ContainerType private final int mContainerType; private final WallpaperManager mWallpaperManager; Loading Loading @@ -101,11 +103,12 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon. CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams(); if (child instanceof LauncherAppWidgetHostView) { DeviceProfile profile = mActivity.getDeviceProfile(); ((LauncherAppWidgetHostView) child).getWidgetInset(profile, mTempRect); lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY, profile.appWidgetScale.x, profile.appWidgetScale.y, mBorderSpacing); profile.appWidgetScale.x, profile.appWidgetScale.y, mBorderSpacing, mTempRect); } else { lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY, mBorderSpacing); mBorderSpacing, null); } } Loading @@ -124,12 +127,12 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon. final DeviceProfile profile = mActivity.getDeviceProfile(); if (child instanceof LauncherAppWidgetHostView) { ((LauncherAppWidgetHostView) child).getWidgetInset(profile, mTempRect); lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY, profile.appWidgetScale.x, profile.appWidgetScale.y, mBorderSpacing); // Widgets have their own padding profile.appWidgetScale.x, profile.appWidgetScale.y, mBorderSpacing, mTempRect); } else { lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY, mBorderSpacing); mBorderSpacing, null); // Center the icon/folder int cHeight = getCellContentHeight(); int cellPaddingY = (int) Math.max(0, ((lp.height - cHeight) / 2f)); Loading
src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java +6 −2 Original line number Diff line number Diff line Loading @@ -72,8 +72,12 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo // We want to account for the extra amount of padding that we are adding to the widget // to ensure that it gets the full amount of space that it has requested. Rect widgetPadding = AppWidgetHostView.getDefaultPaddingForWidget( context, provider, null); // If grids supports insetting widgets, we do not account for widget padding. Rect widgetPadding = new Rect(); if (!idp.landscapeProfile.shouldInsetWidgets() || !idp.portraitProfile.shouldInsetWidgets()) { AppWidgetHostView.getDefaultPaddingForWidget(context, provider, widgetPadding); } spanX = Math.max(1, (int) Math.ceil( (minWidth + widgetPadding.left + widgetPadding.right) / smallestCellWidth)); spanY = Math.max(1, (int) Math.ceil( Loading
src/com/android/launcher3/widget/NavigableAppWidgetHostView.java +29 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.launcher3.widget; import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetProviderInfo; import android.content.Context; import android.graphics.PointF; import android.graphics.Rect; Loading @@ -25,8 +26,11 @@ import android.view.View; import android.view.ViewDebug; import android.view.ViewGroup; import com.android.launcher3.BaseActivity; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Reorderable; import com.android.launcher3.dragndrop.DraggableView; import com.android.launcher3.views.ActivityContext; import java.util.ArrayList; Loading @@ -50,11 +54,16 @@ public abstract class NavigableAppWidgetHostView extends AppWidgetHostView private final PointF mTranslationForReorderPreview = new PointF(0, 0); private float mScaleForReorderBounce = 1f; private final Rect mTempRect = new Rect(); @ViewDebug.ExportedProperty(category = "launcher") private boolean mChildrenFocused; protected final BaseActivity mActivity; public NavigableAppWidgetHostView(Context context) { super(context); mActivity = ActivityContext.lookupContext(context); } @Override Loading Loading @@ -222,6 +231,25 @@ public abstract class NavigableAppWidgetHostView extends AppWidgetHostView int width = (int) (getMeasuredWidth() * mScaleToFit); int height = (int) (getMeasuredHeight() * mScaleToFit); bounds.set(0, 0 , width, height); getWidgetInset(mActivity.getDeviceProfile(), mTempRect); bounds.set(mTempRect.left, mTempRect.top, width - mTempRect.right, height - mTempRect.bottom); } /** * Widgets have padding added by the system. We may choose to inset this padding if the grid * supports it. */ public void getWidgetInset(DeviceProfile grid, Rect out) { if (!grid.shouldInsetWidgets()) { out.setEmpty(); return; } AppWidgetProviderInfo info = getAppWidgetInfo(); if (info == null) { out.set(grid.inv.defaultWidgetPadding); } else { AppWidgetHostView.getDefaultPaddingForWidget(getContext(), info.provider, out); } } }