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

Commit d438db7b authored by Gavin Williams's avatar Gavin Williams
Browse files

Autoclick: Center indicator ring around the mouse

This change revamps the ring positioning logic. The previous logic
left the indicator with stale coordinates so when it began drawing
the indicator would not be located on the mouse.

Now the indicator is continosuly updated with mouse coordinates so it
can snapshot its position and use it for drawing.

Demo before: http://b/421980970#comment3
Demo after: http://b/421980970#comment4

Bug: b/421980970
Test: AutoclickControllerTest
Flag: com.android.server.accessibility.enable_autoclick_indicator
Change-Id: Ie699187a0d8ed4865e9f514d37754b25bae54f27
parent 35669e44
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -925,13 +925,18 @@ public class AutoclickController extends BaseEventStreamTransformation {
            boolean moved = detectMovement(event);
            cacheLastEvent(event, policyFlags, mLastMotionEvent == null || moved /* useAsAnchor */);

            if (moved) {
                rescheduleClick(mDelay);

            if (Flags.enableAutoclickIndicator()) {
                // Give the indicator the latest mouse coordinates for when the indicator is ready
                // to redraw.
                final int pointerIndex = event.getActionIndex();
                mAutoclickIndicatorView.setCoordination(
                        event.getX(pointerIndex), event.getY(pointerIndex));
            }

            if (moved) {
                rescheduleClick(mDelay);

                if (Flags.enableAutoclickIndicator()) {
                    mAutoclickIndicatorScheduler.update();
                }
            }
+15 −9
Original line number Diff line number Diff line
@@ -53,9 +53,13 @@ public class AutoclickIndicatorView extends View {

    private final RectF mRingRect;

    // x and y coordinates of the visual indicator.
    private float mX;
    private float mY;
    // x and y coordinates of the mouse.
    private float mMouseX;
    private float mMouseY;

    // x and y coordinates of the visual indicator, set when drawing of the indicator begins.
    private float mSnapshotX;
    private float mSnapshotY;

    // Current sweep angle of the animated ring.
    private float mSweepAngle;
@@ -114,10 +118,10 @@ public class AutoclickIndicatorView extends View {

        if (showIndicator) {
            mRingRect.set(
                    /* left= */ mX - mRadius,
                    /* top= */ mY - mRadius,
                    /* right= */ mX + mRadius,
                    /* bottom= */ mY + mRadius);
                    /* left= */ mSnapshotX - mRadius,
                    /* top= */ mSnapshotY - mRadius,
                    /* right= */ mSnapshotX + mRadius,
                    /* bottom= */ mSnapshotY + mRadius);
            canvas.drawArc(mRingRect, /* startAngle= */ -90, mSweepAngle, false, mPaint);
        }
    }
@@ -134,8 +138,8 @@ public class AutoclickIndicatorView extends View {
    }

    public void setCoordination(float x, float y) {
        mX = x;
        mY = y;
        mMouseX = x;
        mMouseY = y;
    }

    public void setRadius(int radius) {
@@ -148,6 +152,8 @@ public class AutoclickIndicatorView extends View {
    }

    public void redrawIndicator() {
        mSnapshotX = mMouseX;
        mSnapshotY = mMouseY;
        showIndicator = true;
        invalidate();
        mAnimator.start();