fix: Align widget visually to the icon (#7047)
Signed-off-by: Pun Butrach <pun.butrach@gmail.com>
This commit is contained in:
1 parent
0adb25e7e9
commit
beeb036ff7
3 files changed
+40
-5
No files matched your search
@@ -258,6 +258,10 @@ public class DeviceProfile {
|
||||
// Additional padding added to the widget inside its cellSpace. It is applied outside
|
||||
// the widgetView, such that the actual view size is same as the widget size.
|
||||
public final Rect widgetPadding = new Rect();
|
||||
// Lawnchair: extra horizontal inset applied only to widgets touching the left/right
|
||||
// edge of the grid, so that widget edges align closer to icon centers without
|
||||
// inflating the gap between adjacent widgets.
|
||||
public int widgetEdgeInsetPx;
|
||||
|
||||
// Notification dots
|
||||
public final DotRenderer mDotRendererWorkSpace;
|
||||
@@ -1399,9 +1403,11 @@ public class DeviceProfile {
|
||||
} else {
|
||||
widgetPadding.setEmpty();
|
||||
}
|
||||
// Lawnchair: extra inset for edge widgets to align closer to icon centre.
|
||||
widgetEdgeInsetPx = widgetPadding.left;
|
||||
// Lawnchair: scale widget padding by user factor (0 = remove, 1 = default).
|
||||
widgetPadding.left = Math.round(widgetPadding.left * widgetPaddingFactor);
|
||||
widgetPadding.right = Math.round(widgetPadding.right * widgetPaddingFactor);
|
||||
widgetPadding.left = widgetPadding.right =
|
||||
Math.round(widgetPadding.left * widgetPaddingFactor);
|
||||
widgetPadding.top = Math.round(widgetPadding.top * widgetPaddingFactor);
|
||||
widgetPadding.bottom = Math.round(widgetPadding.bottom * widgetPaddingFactor);
|
||||
}
|
||||
|
||||
@@ -150,7 +150,8 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
|
||||
DeviceProfile profile = mActivity.getDeviceProfile();
|
||||
final PointF appWidgetScale = profile.getAppWidgetScale((ItemInfo) child.getTag());
|
||||
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
|
||||
appWidgetScale.x, appWidgetScale.y, mBorderSpace, profile.widgetPadding);
|
||||
appWidgetScale.x, appWidgetScale.y, mBorderSpace, profile.widgetPadding,
|
||||
profile.widgetEdgeInsetPx);
|
||||
} else {
|
||||
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
|
||||
mBorderSpace);
|
||||
@@ -175,13 +176,15 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
|
||||
if (child instanceof NavigableAppWidgetHostView) {
|
||||
final PointF appWidgetScale = dp.getAppWidgetScale((ItemInfo) child.getTag());
|
||||
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
|
||||
appWidgetScale.x, appWidgetScale.y, mBorderSpace, dp.widgetPadding);
|
||||
appWidgetScale.x, appWidgetScale.y, mBorderSpace, dp.widgetPadding,
|
||||
dp.widgetEdgeInsetPx);
|
||||
} else if (isChildQsb(child)) {
|
||||
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
|
||||
mBorderSpace);
|
||||
1.0f, 1.0f, mBorderSpace, null, dp.widgetEdgeInsetPx);
|
||||
// No need to add padding for Qsb, which is either Smartspace (actual or
|
||||
// preview), or
|
||||
// QsbContainerView.
|
||||
// LC-Note: but still apply edge inset so its outer edges align with icon centre
|
||||
} else {
|
||||
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
|
||||
mBorderSpace);
|
||||
|
||||
@@ -128,6 +128,19 @@ public class CellLayoutLayoutParams extends ViewGroup.MarginLayoutParams {
|
||||
public void setup(int cellWidth, int cellHeight, boolean invertHorizontally, int colCount,
|
||||
int rowCount, float cellScaleX, float cellScaleY, Point borderSpace,
|
||||
@Nullable Rect inset) {
|
||||
setup(cellWidth, cellHeight, invertHorizontally, colCount, rowCount, cellScaleX,
|
||||
cellScaleY, borderSpace, inset, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lawnchair: {@link #setup(int, int, boolean, int, int, float, float, Point, Rect)},
|
||||
* with the addition of [edgeInset] (after inset) in case extra inset needs to be applied on the outer grid edges
|
||||
*
|
||||
* Lawnchair-TODO: Maybe the proper solution is to modify the profile of the device directly, but what value?
|
||||
*/
|
||||
public void setup(int cellWidth, int cellHeight, boolean invertHorizontally, int colCount,
|
||||
int rowCount, float cellScaleX, float cellScaleY, Point borderSpace,
|
||||
@Nullable Rect inset, int edgeInset) {
|
||||
if (isLockedToGrid) {
|
||||
final int myCellHSpan = cellHSpan;
|
||||
final int myCellVSpan = cellVSpan;
|
||||
@@ -155,6 +168,19 @@ public class CellLayoutLayoutParams extends ViewGroup.MarginLayoutParams {
|
||||
width -= inset.left + inset.right;
|
||||
height -= inset.top + inset.bottom;
|
||||
}
|
||||
|
||||
// Lawnchair: apply extra inset only on the outer edges of the grid
|
||||
if (edgeInset > 0) {
|
||||
boolean atLeft = myCellX == 0;
|
||||
boolean atRight = myCellX + myCellHSpan >= colCount;
|
||||
if (atLeft) {
|
||||
x += edgeInset;
|
||||
width -= edgeInset;
|
||||
}
|
||||
if (atRight) {
|
||||
width -= edgeInset;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user