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

Commit 72729250 authored by Petar Šegina's avatar Petar Šegina
Browse files

Improve rectangle direction generation

The previous solution didn't take into account that the source rectangle
might be at either end of the selection, thus giving it the wrong
direction of CENTER, while it should have been RIGHT or LEFT.

Test: manual - verify that the rectangles expand properly in a smart
select animation when there are multiple rectangles and the source is
not in the center - e.g. a multiline case with the selection starting on
the first line

Change-Id: Id18ab8f9918e74a576503620dae2f7cdd593fb0e
parent 4b950cf6
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -248,6 +248,9 @@ final class SelectionActionModeHelper {
        // with the Smart Select animation
        layout.getSelection(start, end, (left, top, right, bottom) ->
                result.add(new RectF(left, top, right, bottom)));

        result.sort(SmartSelectSprite.RECTANGLE_COMPARATOR);

        return result;
    }

+19 −11
Original line number Diff line number Diff line
@@ -75,6 +75,10 @@ final class SmartSelectSprite {
    private final int mStrokeColor;
    private Set<Drawable> mExistingAnimationDrawables = new HashSet<>();

    static final Comparator<RectF> RECTANGLE_COMPARATOR = Comparator
            .<RectF>comparingDouble(e -> e.bottom)
            .thenComparingDouble(e -> e.left);

    /**
     * Represents a set of points connected by lines.
     */
@@ -267,13 +271,6 @@ final class SmartSelectSprite {

        private RectangleList(List<RoundedRectangleShape> rectangles) {
            mRectangles = new LinkedList<>(rectangles);
            mRectangles.sort((o1, o2) -> {
                if (o1.mBoundingRectangle.top == o2.mBoundingRectangle.top) {
                    return Float.compare(o1.mBoundingRectangle.left, o2.mBoundingRectangle.left);
                } else {
                    return Float.compare(o1.mBoundingRectangle.top, o2.mBoundingRectangle.top);
                }
            });
            mReversedRectangles = new LinkedList<>(rectangles);
            Collections.reverse(mReversedRectangles);
        }
@@ -425,7 +422,9 @@ final class SmartSelectSprite {
     * @param start                 The point from which the animation will start. Must be inside
     *                              destinationRectangles.
     * @param destinationRectangles The rectangles which the animation will fill out by its
     *                              "selection" and finally join them into a single polygon.
     *                              "selection" and finally join them into a single polygon. In
     *                              order to get the correct visual behavior, these rectangles
     *                              should be sorted according to {@link #RECTANGLE_COMPARATOR}.
     * @param onAnimationEnd        The callback which will be invoked once the whole animation
     *                              completes.
     * @throws IllegalArgumentException if the given start point is not in any of the
@@ -592,8 +591,7 @@ final class SmartSelectSprite {
    }

    private static @RoundedRectangleShape.ExpansionDirection int[] generateDirections(
            final RectF centerRectangle,
            final List<RectF> rectangles) throws IllegalArgumentException {
            final RectF centerRectangle, final List<RectF> rectangles) {
        final @RoundedRectangleShape.ExpansionDirection int[] result = new int[rectangles.size()];

        final int centerRectangleIndex = rectangles.indexOf(centerRectangle);
@@ -601,7 +599,17 @@ final class SmartSelectSprite {
        for (int i = 0; i < centerRectangleIndex - 1; ++i) {
            result[i] = RoundedRectangleShape.ExpansionDirection.LEFT;
        }

        if (rectangles.size() == 1) {
            result[centerRectangleIndex] = RoundedRectangleShape.ExpansionDirection.CENTER;
        } else if (centerRectangleIndex == 0) {
            result[centerRectangleIndex] = RoundedRectangleShape.ExpansionDirection.LEFT;
        } else if (centerRectangleIndex == rectangles.size() - 1) {
            result[centerRectangleIndex] = RoundedRectangleShape.ExpansionDirection.RIGHT;
        } else {
            result[centerRectangleIndex] = RoundedRectangleShape.ExpansionDirection.CENTER;
        }

        for (int i = centerRectangleIndex + 1; i < result.length; ++i) {
            result[i] = RoundedRectangleShape.ExpansionDirection.RIGHT;
        }