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

Commit 9eb15556 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Improve starting offset calculation"

parents 70dc1ba4 98d3f0a8
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);