From 98d3f0a8202cf90941737ec60be728a53b567582 Mon Sep 17 00:00:00 2001 From: Abodunrinwa Toki Date: Fri, 6 Oct 2017 17:19:00 +0100 Subject: [PATCH] Improve starting offset calculation The previous implementation did not take into account the various expansions that happen for OVERSHOOT and LEFT and RIGHT rectangles, thus causing the initial shape to be an oval instead of a circle. Test: manual - triggered smart select and verified that the intial shape is a circle under the touch point for both single line and multiline scenarios Change-Id: I75175bc3972db3f0608ef364109e0571268da4af --- .../android/widget/SmartSelectSprite.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/core/java/android/widget/SmartSelectSprite.java b/core/java/android/widget/SmartSelectSprite.java index 7cbc494b37afa..a391c6ee8ec35 100644 --- a/core/java/android/widget/SmartSelectSprite.java +++ b/core/java/android/widget/SmartSelectSprite.java @@ -206,7 +206,7 @@ final class SmartSelectSprite { if (mRectangleBorderType == RectangleBorderType.OVERSHOOT) { mDrawRect.left -= cornerRadius / 2; - mDrawRect.right -= cornerRadius / 2; + mDrawRect.right += cornerRadius / 2; } else { switch (mExpansionDirection) { case ExpansionDirection.CENTER: @@ -437,6 +437,7 @@ final class SmartSelectSprite { RectangleWithTextSelectionLayout centerRectangle = null; int startingOffset = 0; + int startingRectangleIndex = 0; for (int index = 0; index < rectangleCount; ++index) { final RectangleWithTextSelectionLayout rectangleWithTextSelectionLayout = destinationRectangles.get(index); @@ -446,6 +447,7 @@ final class SmartSelectSprite { break; } startingOffset += rectangle.width(); + ++startingRectangleIndex; } if (centerRectangle == null) { @@ -454,10 +456,6 @@ final class SmartSelectSprite { startingOffset += start.x - centerRectangle.getRectangle().left; - final float centerRectangleHalfHeight = centerRectangle.getRectangle().height() / 2; - final float startingOffsetLeft = startingOffset - centerRectangleHalfHeight; - final float startingOffsetRight = startingOffset + centerRectangleHalfHeight; - final @RoundedRectangleShape.ExpansionDirection int[] expansionDirections = generateDirections(centerRectangle, destinationRectangles); @@ -482,6 +480,30 @@ final class SmartSelectSprite { final RectangleList rectangleList = new RectangleList(shapes); final ShapeDrawable shapeDrawable = new ShapeDrawable(rectangleList); + final float startingOffsetLeft; + final float startingOffsetRight; + + final RoundedRectangleShape startingRectangleShape = shapes.get(startingRectangleIndex); + final float cornerRadius = startingRectangleShape.getCornerRadius(); + if (startingRectangleShape.mRectangleBorderType + == RoundedRectangleShape.RectangleBorderType.FIT) { + switch (startingRectangleShape.mExpansionDirection) { + case RoundedRectangleShape.ExpansionDirection.LEFT: + startingOffsetLeft = startingOffsetRight = startingOffset - cornerRadius / 2; + break; + case RoundedRectangleShape.ExpansionDirection.RIGHT: + startingOffsetLeft = startingOffsetRight = startingOffset + cornerRadius / 2; + break; + case RoundedRectangleShape.ExpansionDirection.CENTER: // fall through + default: + startingOffsetLeft = startingOffset - cornerRadius / 2; + startingOffsetRight = startingOffset + cornerRadius / 2; + break; + } + } else { + startingOffsetLeft = startingOffsetRight = startingOffset; + } + final Paint paint = shapeDrawable.getPaint(); paint.setColor(mStrokeColor); paint.setStyle(Paint.Style.STROKE);