Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98d3f0a8 authored by Abodunrinwa Toki's avatar Abodunrinwa Toki
Browse files

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
parent 570a1681
Loading
Loading
Loading
Loading
+27 −5
Original line number Diff line number Diff line
@@ -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);