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

Commit f60ca049 authored by Longbo Wei's avatar Longbo Wei
Browse files

autoclick: Fix panel jumping issue when drag

Problem: Panel jumps down when drag starts.

Cause: LayoutParams.y is relative to the content area (below the status
bar), but when we calculate delta during drag, we use absolute screen Y
from getLocationOnScreen(), which includes the status bar height.

Fix: Subtract status bar height to avoid any "jump".

Video:
 - Before: http://shortn/_inTwbPw50q
 - After:  http://shortn/_znCNEgbKXU

Bug: b/413444209
Test: atest
Flag: com.android.server.accessibility.enable_autoclick_indicator
Change-Id: I809ca53168e070b1cfab0d57920cb9f859c74422
parent 5c33b4ba
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;

import com.android.internal.R;
import com.android.internal.policy.SystemBarUtils;

public class AutoclickTypePanel {

@@ -134,6 +135,8 @@ public class AutoclickTypePanel {
    // Whether autoclick is paused.
    private boolean mPaused = false;

    private int mStatusBarHeight = 0;

    // The current corner position of the panel, default to bottom right.
    private @Corner int mCurrentCorner = CORNER_BOTTOM_RIGHT;

@@ -197,6 +200,8 @@ public class AutoclickTypePanel {
        mLongPressButton =
                mContentView.findViewById(R.id.accessibility_autoclick_long_press_layout);

        // Get status bar height.
        mStatusBarHeight = SystemBarUtils.getStatusBarHeight(context);
        // Initialize the cursor icons.
        mCurrentCursor = PointerIcon.getSystemIcon(context, PointerIcon.TYPE_ARROW);

@@ -259,7 +264,12 @@ public class AutoclickTypePanel {

                    // Update panel position, based on Top-Left absolute positioning.
                    mParams.x = mPanelStartX + (int) deltaX;
                    mParams.y = mPanelStartY + (int) deltaY;

                    // Adjust Y by status bar height:
                    // Note: mParams.y is relative to the content area (below the status bar),
                    // but mPanelStartY uses absolute screen coordinates. Subtract status bar
                    // height to align coordinates properly.
                    mParams.y = Math.max(0, mPanelStartY + (int) deltaY - mStatusBarHeight);
                    mWindowManager.updateViewLayout(mContentView, mParams);
                }
                return true;
@@ -747,6 +757,10 @@ public class AutoclickTypePanel {
    }

    @VisibleForTesting
    int getStatusBarHeightForTesting() {
        return mStatusBarHeight;
    }

    PointerIcon getCurrentCursorForTesting() {
        return mCurrentCursor;
    }
+8 −3
Original line number Diff line number Diff line
@@ -351,7 +351,9 @@ public class AutoclickTypePanelTest {
        assertThat(mAutoclickTypePanel.getIsDraggingForTesting()).isTrue();
        assertThat(params.gravity).isEqualTo(Gravity.LEFT | Gravity.TOP);
        assertThat(params.x).isEqualTo(panelLocation[0] + delta);
        assertThat(params.y).isEqualTo(panelLocation[1] + delta);
        assertThat(params.y).isEqualTo(
                Math.max(0, panelLocation[1] + delta
                        - mAutoclickTypePanel.getStatusBarHeightForTesting()));
    }

    @Test
@@ -475,7 +477,9 @@ public class AutoclickTypePanelTest {
        assertThat(parts).hasLength(4);
        assertThat(Integer.parseInt(parts[0])).isEqualTo(Gravity.START | Gravity.TOP);
        assertThat(Integer.parseInt(parts[1])).isEqualTo(15);
        assertThat(Integer.parseInt(parts[2])).isEqualTo(panelLocation[1] + 10);
        assertThat(Integer.parseInt(parts[2])).isEqualTo(
                Math.max(0, panelLocation[1] + 10
                        - mAutoclickTypePanel.getStatusBarHeightForTesting()));
        assertThat(Integer.parseInt(parts[3])).isEqualTo(CORNER_BOTTOM_LEFT);

        // Show panel to trigger position restoration.
@@ -485,7 +489,8 @@ public class AutoclickTypePanelTest {
        WindowManager.LayoutParams params = mAutoclickTypePanel.getLayoutParamsForTesting();
        assertThat(params.gravity).isEqualTo(Gravity.START | Gravity.TOP);
        assertThat(params.x).isEqualTo(15); // PANEL_EDGE_MARGIN
        assertThat(params.y).isEqualTo(panelLocation[1] + 10);
        assertThat(params.y).isEqualTo(Math.max(0,
                panelLocation[1] + 10 - mAutoclickTypePanel.getStatusBarHeightForTesting()));
        assertThat(mAutoclickTypePanel.getCurrentCornerForTesting()).isEqualTo(
                CORNER_BOTTOM_LEFT);
    }