diff --git a/src/com/android/launcher3/AppWidgetResizeFrame.java b/src/com/android/launcher3/AppWidgetResizeFrame.java index 6fd48b5f23..0673284ffd 100644 --- a/src/com/android/launcher3/AppWidgetResizeFrame.java +++ b/src/com/android/launcher3/AppWidgetResizeFrame.java @@ -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; }