summaryrefslogtreecommitdiff
path: root/services/accessibility
diff options
context:
space:
mode:
author Longbo Wei <longbowei@google.com> 2025-03-06 22:24:01 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-03-06 22:24:01 -0800
commita6cc743a2f2ffa174b2a1314c413cf2fab0f0f77 (patch)
tree7703757a4efaaee51c56a2c13d4a82c8abb8bf0a /services/accessibility
parent3ee821a4b67062df4b7265ce0445b76fa446bd98 (diff)
parentf7ee48d8f7aa4bc7b1b70047857708fee4326828 (diff)
Merge "A11y: autoclickScrollPanel - Add Button Hover listeners" into main
Diffstat (limited to 'services/accessibility')
-rw-r--r--services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickController.java19
-rw-r--r--services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickScrollPanel.java90
2 files changed, 107 insertions, 2 deletions
diff --git a/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickController.java b/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickController.java
index cc93d0887d89..a71224a68125 100644
--- a/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickController.java
+++ b/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickController.java
@@ -124,6 +124,22 @@ public class AutoclickController extends BaseEventStreamTransformation {
}
};
+ @VisibleForTesting
+ final AutoclickScrollPanel.ScrollPanelControllerInterface mScrollPanelController =
+ new AutoclickScrollPanel.ScrollPanelControllerInterface() {
+ @Override
+ public void handleScroll(@AutoclickScrollPanel.ScrollDirection int direction) {
+ // TODO(b/388845721): Perform actual scroll.
+ }
+
+ @Override
+ public void exitScrollMode() {
+ if (mAutoclickScrollPanel != null) {
+ mAutoclickScrollPanel.hide();
+ }
+ }
+ };
+
public AutoclickController(Context context, int userId, AccessibilityTraceManager trace) {
mTrace = trace;
mContext = context;
@@ -168,7 +184,8 @@ public class AutoclickController extends BaseEventStreamTransformation {
mWindowManager = mContext.getSystemService(WindowManager.class);
mAutoclickTypePanel =
new AutoclickTypePanel(mContext, mWindowManager, mUserId, clickPanelController);
- mAutoclickScrollPanel = new AutoclickScrollPanel(mContext, mWindowManager);
+ mAutoclickScrollPanel = new AutoclickScrollPanel(mContext, mWindowManager,
+ mScrollPanelController);
mAutoclickTypePanel.show();
mWindowManager.addView(mAutoclickIndicatorView, mAutoclickIndicatorView.getLayoutParams());
diff --git a/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickScrollPanel.java b/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickScrollPanel.java
index 86f79a83ea28..e79be502a6fc 100644
--- a/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickScrollPanel.java
+++ b/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickScrollPanel.java
@@ -18,6 +18,7 @@ package com.android.server.accessibility.autoclick;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
+import android.annotation.IntDef;
import android.content.Context;
import android.graphics.PixelFormat;
import android.view.Gravity;
@@ -25,23 +26,97 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowInsets;
import android.view.WindowManager;
+import android.widget.ImageButton;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.android.internal.R;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
public class AutoclickScrollPanel {
+ public static final int DIRECTION_UP = 0;
+ public static final int DIRECTION_DOWN = 1;
+ public static final int DIRECTION_LEFT = 2;
+ public static final int DIRECTION_RIGHT = 3;
+
+ @IntDef({
+ DIRECTION_UP,
+ DIRECTION_DOWN,
+ DIRECTION_LEFT,
+ DIRECTION_RIGHT
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface ScrollDirection {}
+
private final Context mContext;
private final View mContentView;
private final WindowManager mWindowManager;
+ private ScrollPanelControllerInterface mScrollPanelController;
+
+ // Scroll panel buttons.
+ private final ImageButton mUpButton;
+ private final ImageButton mDownButton;
+ private final ImageButton mLeftButton;
+ private final ImageButton mRightButton;
+ private final ImageButton mExitButton;
+
private boolean mInScrollMode = false;
- public AutoclickScrollPanel(Context context, WindowManager windowManager) {
+ /**
+ * Interface for handling scroll operations.
+ */
+ public interface ScrollPanelControllerInterface {
+ /**
+ * Called when a scroll direction is hovered.
+ *
+ * @param direction The direction to scroll: one of {@link ScrollDirection} values.
+ */
+ void handleScroll(@ScrollDirection int direction);
+
+ /**
+ * Called when the exit button is hovered.
+ */
+ void exitScrollMode();
+ }
+
+ public AutoclickScrollPanel(Context context, WindowManager windowManager,
+ ScrollPanelControllerInterface controller) {
mContext = context;
mWindowManager = windowManager;
+ mScrollPanelController = controller;
mContentView = LayoutInflater.from(context).inflate(
R.layout.accessibility_autoclick_scroll_panel, null);
+
+ // Initialize buttons.
+ mUpButton = mContentView.findViewById(R.id.scroll_up);
+ mLeftButton = mContentView.findViewById(R.id.scroll_left);
+ mRightButton = mContentView.findViewById(R.id.scroll_right);
+ mDownButton = mContentView.findViewById(R.id.scroll_down);
+ mExitButton = mContentView.findViewById(R.id.scroll_exit);
+
+ initializeButtonState();
+ }
+
+ /**
+ * Sets up hover listeners for scroll panel buttons.
+ */
+ private void initializeButtonState() {
+ // Set up hover listeners for direction buttons.
+ setupHoverListenerForDirectionButton(mUpButton, DIRECTION_UP);
+ setupHoverListenerForDirectionButton(mLeftButton, DIRECTION_LEFT);
+ setupHoverListenerForDirectionButton(mRightButton, DIRECTION_RIGHT);
+ setupHoverListenerForDirectionButton(mDownButton, DIRECTION_DOWN);
+
+ // Set up hover listener for exit button.
+ mExitButton.setOnHoverListener((v, event) -> {
+ if (mScrollPanelController != null) {
+ mScrollPanelController.exitScrollMode();
+ }
+ return true;
+ });
}
/**
@@ -67,6 +142,19 @@ public class AutoclickScrollPanel {
}
/**
+ * Sets up a hover listener for a direction button.
+ */
+ private void setupHoverListenerForDirectionButton(ImageButton button,
+ @ScrollDirection int direction) {
+ button.setOnHoverListener((v, event) -> {
+ if (mScrollPanelController != null) {
+ mScrollPanelController.handleScroll(direction);
+ }
+ return true;
+ });
+ }
+
+ /**
* Retrieves the layout params for AutoclickScrollPanel, used when it's added to the Window
* Manager.
*/