fix(widgets): let the resize frame reach the screen edge horizontally (#7387)
* fix(widgets): let the resize frame reach the screen edge horizontally The resize frame is drawn resize_frame_background_padding (24dp) outside the widget, but the horizontal drag range clamped the frame's outer edge to the DragLayer. When the grid sits close to the screen edge (low workspace/widget padding, many columns) the last column could not be reached. When the frame already overhung the screen edge (gap + widget padding < 24dp, which is the default), the old range did not contain 0 (left start positive, right end negative), so the first move event snapped the frame up to 24dp inward on either side. With half-cell resize steps that would be enough to drop a step. Bound the widget's edge instead of the frame's, and keep 0 inside the range so a touch without movement never moves the frame. The vertical range is unchanged. * fix(widgets): count the last partial resize step when the finger hits the edge The finger cannot travel past the screen edge, and the handle can be grabbed up to 24dp outside the widget. With little workspace/widget padding, the travel left for the last column can then be shorter than RESIZE_THRESHOLD of a step. While a left/right handle is dragged and the finger is within resize_frame_background_padding of that screen edge, a partial step of more than 1 - RESIZE_THRESHOLD towards the edge counts as reached. That threshold keeps the step from being undone right after it is taken, and it only applies in the growth direction. * refactor(widgets): shorten resize frame LC-Notes Comment-only change: trim the edge-clamp LC-Notes in AppWidgetResizeFrame to one or two lines. No behaviour change.
This commit is contained in:
1 parent
5a9f6e05ba
commit
f83fbb0226
1 file changed
+44
-3
@@ -63,6 +63,9 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
private static final int SNAP_DURATION_MS = 150;
|
||||
private static final float DIMMED_HANDLE_ALPHA = 0f;
|
||||
private static final float RESIZE_THRESHOLD = 0.66f;
|
||||
// LC-Note: Threshold for growing towards the screen edge once the finger has reached it.
|
||||
// Using 1 - RESIZE_THRESHOLD means the step can't be undone right after it is taken.
|
||||
private static final float EDGE_RESIZE_THRESHOLD = 1f - RESIZE_THRESHOLD;
|
||||
private static final int RESIZE_TRANSITION_DURATION_MS = 150;
|
||||
|
||||
private static final String KEY_RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN = "launcher.reconfigurable_widget_education_tip_seen";
|
||||
@@ -125,6 +128,9 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
private boolean mHorizontalResizeActive;
|
||||
private boolean mVerticalResizeActive;
|
||||
|
||||
// LC-Note: Whether the finger dragging the left/right handle is at that screen edge.
|
||||
private boolean mHorizontalEdgeReached;
|
||||
|
||||
private int mRunningHInc;
|
||||
private int mRunningVInc;
|
||||
private int mMinHSpan;
|
||||
@@ -412,10 +418,14 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
mDragHandles[INDEX_BOTTOM].setAlpha(mBottomBorderActive ? 1.0f : DIMMED_HANDLE_ALPHA);
|
||||
}
|
||||
|
||||
// LC-Note: Bound the widget's edge (the frame overhangs it by mBackgroundPadding) so the
|
||||
// last column stays reachable; include 0 so an overhanging frame isn't pulled inward.
|
||||
if (mLeftBorderActive) {
|
||||
mDeltaXRange.set(-getLeft(), getWidth() - 2 * mTouchTargetWidth);
|
||||
mDeltaXRange.setIncludingZero(-getLeft() - mBackgroundPadding,
|
||||
getWidth() - 2 * mTouchTargetWidth);
|
||||
} else if (mRightBorderActive) {
|
||||
mDeltaXRange.set(2 * mTouchTargetWidth - getWidth(), mDragLayer.getWidth() - getRight());
|
||||
mDeltaXRange.setIncludingZero(2 * mTouchTargetWidth - getWidth(),
|
||||
mDragLayer.getWidth() - getRight() + mBackgroundPadding);
|
||||
} else {
|
||||
mDeltaXRange.set(0, 0);
|
||||
}
|
||||
@@ -451,6 +461,11 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
lp.y = mTempRange1.start;
|
||||
lp.height = mTempRange1.size();
|
||||
|
||||
// LC-Note: The finger can't travel past the screen edge, see getHSpanIncrement.
|
||||
int fingerX = mXDown + deltaX;
|
||||
mHorizontalEdgeReached = (mLeftBorderActive && fingerX <= mBackgroundPadding)
|
||||
|| (mRightBorderActive && fingerX >= mDragLayer.getWidth() - mBackgroundPadding);
|
||||
|
||||
resizeWidgetIfNeeded(false);
|
||||
|
||||
// Handle invalid resize across CellLayouts in the two panel UI.
|
||||
@@ -491,6 +506,22 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
return Math.abs(deltaFrac) > RESIZE_THRESHOLD ? Math.round(deltaFrac) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* LC-Note: Like {@link #getSpanIncrement(float)}, but once the finger hits the screen edge a
|
||||
* partial step towards it counts, so the last column stays reachable.
|
||||
*/
|
||||
private int getHSpanIncrement(float deltaFrac) {
|
||||
if (mHorizontalEdgeReached) {
|
||||
if (mRightBorderActive && deltaFrac > EDGE_RESIZE_THRESHOLD) {
|
||||
return Math.max(1, Math.round(deltaFrac));
|
||||
}
|
||||
if (mLeftBorderActive && deltaFrac < -EDGE_RESIZE_THRESHOLD) {
|
||||
return Math.min(-1, Math.round(deltaFrac));
|
||||
}
|
||||
}
|
||||
return getSpanIncrement(deltaFrac);
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on the current deltas, we determine if and how to resize the widget.
|
||||
*/
|
||||
@@ -503,7 +534,8 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
float xThreshold = mCellLayout.getCellWidth() + dp.cellLayoutBorderSpacePx.x;
|
||||
float yThreshold = mCellLayout.getCellHeight() + dp.cellLayoutBorderSpacePx.y;
|
||||
|
||||
int hSpanInc = getSpanIncrement((mDeltaX + mDeltaXAddOn) / xThreshold - mRunningHInc);
|
||||
// LC-Note: Horizontal steps use the edge-aware increment, see getHSpanIncrement.
|
||||
int hSpanInc = getHSpanIncrement((mDeltaX + mDeltaXAddOn) / xThreshold - mRunningHInc);
|
||||
int vSpanInc = getSpanIncrement((mDeltaY + mDeltaYAddOn) / yThreshold - mRunningVInc);
|
||||
|
||||
if (!onDismiss && (hSpanInc == 0 && vSpanInc == 0)) return;
|
||||
@@ -596,6 +628,7 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
mDeltaYAddOn = mRunningVInc * yThreshold;
|
||||
mDeltaX = 0;
|
||||
mDeltaY = 0;
|
||||
mHorizontalEdgeReached = false; // LC-Note: Reset along with the deltas.
|
||||
|
||||
post(() -> snapToWidget(true));
|
||||
}
|
||||
@@ -874,6 +907,14 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||
end = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* LC-Note: Same as {@link #set(int, int)}, but widens the range to contain 0 so that
|
||||
* clamping a zero delta never moves the edge.
|
||||
*/
|
||||
public void setIncludingZero(int s, int e) {
|
||||
set(Math.min(s, 0), Math.max(e, 0));
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return end - start;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user