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

Commit aed1a7f1 authored by Longbo Wei's avatar Longbo Wei Committed by Android (Google) Code Review
Browse files

Merge "autoclick: Handle scroll panel theme change" into main

parents 2df9accd b80f25dd
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -662,7 +662,6 @@ public class AutoclickController extends BaseEventStreamTransformation implement


    @Override
    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        // TODO(b/431038033): Add a similar onConfigurationChanged to AutoclickScrollPanel.
        // When system configuration is changed, update the indicator view
        // When system configuration is changed, update the indicator view
        // and type panel configuration.
        // and type panel configuration.
        if (mAutoclickIndicatorView != null) {
        if (mAutoclickIndicatorView != null) {
@@ -671,6 +670,9 @@ public class AutoclickController extends BaseEventStreamTransformation implement
        if (mAutoclickTypePanel != null) {
        if (mAutoclickTypePanel != null) {
            mAutoclickTypePanel.onConfigurationChanged(newConfig);
            mAutoclickTypePanel.onConfigurationChanged(newConfig);
        }
        }
        if (mAutoclickScrollPanel != null) {
            mAutoclickScrollPanel.onConfigurationChanged(newConfig);
        }
    }
    }


    @Override
    @Override
+38 −8
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_M


import android.annotation.IntDef;
import android.annotation.IntDef;
import android.content.Context;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.BlendMode;
import android.graphics.BlendMode;
import android.graphics.BlendModeColorFilter;
import android.graphics.BlendModeColorFilter;
import android.graphics.Color;
import android.graphics.Color;
@@ -77,18 +78,18 @@ public class AutoclickScrollPanel {
    public @interface ScrollDirection {}
    public @interface ScrollDirection {}


    private final Context mContext;
    private final Context mContext;
    private final AutoclickLinearLayout mContentView;
    private AutoclickLinearLayout mContentView;
    private final WindowManager mWindowManager;
    private final WindowManager mWindowManager;
    private final WindowManager.LayoutParams mParams;
    private final WindowManager.LayoutParams mParams;
    private ScrollPanelControllerInterface mScrollPanelController;
    private ScrollPanelControllerInterface mScrollPanelController;
    private final AutoclickScrollPointIndicator mAutoclickScrollPointIndicator;
    private final AutoclickScrollPointIndicator mAutoclickScrollPointIndicator;


    // Scroll panel buttons.
    // Scroll panel buttons.
    private final ImageButton mUpButton;
    private ImageButton mUpButton;
    private final ImageButton mDownButton;
    private ImageButton mDownButton;
    private final ImageButton mLeftButton;
    private ImageButton mLeftButton;
    private final ImageButton mRightButton;
    private ImageButton mRightButton;
    private final ImageButton mExitButton;
    private ImageButton mExitButton;


    private final int mStatusBarHeight;
    private final int mStatusBarHeight;


@@ -122,11 +123,17 @@ public class AutoclickScrollPanel {
        mWindowManager = windowManager;
        mWindowManager = windowManager;
        mScrollPanelController = controller;
        mScrollPanelController = controller;
        mAutoclickScrollPointIndicator = new AutoclickScrollPointIndicator(context);
        mAutoclickScrollPointIndicator = new AutoclickScrollPointIndicator(context);
        mContentView = (AutoclickLinearLayout) LayoutInflater.from(context).inflate(
                R.layout.accessibility_autoclick_scroll_panel, null);
        mParams = getDefaultLayoutParams();
        mParams = getDefaultLayoutParams();
        mStatusBarHeight = SystemBarUtils.getStatusBarHeight(context);
        mStatusBarHeight = SystemBarUtils.getStatusBarHeight(context);


        inflateViewAndResources();
    }

    private void inflateViewAndResources() {
        // Inflate the panel layout.
        mContentView = (AutoclickLinearLayout) LayoutInflater.from(mContext).inflate(
                R.layout.accessibility_autoclick_scroll_panel, null);

        // Initialize buttons.
        // Initialize buttons.
        mUpButton = mContentView.findViewById(R.id.scroll_up);
        mUpButton = mContentView.findViewById(R.id.scroll_up);
        mLeftButton = mContentView.findViewById(R.id.scroll_left);
        mLeftButton = mContentView.findViewById(R.id.scroll_left);
@@ -308,6 +315,29 @@ public class AutoclickScrollPanel {
        }
        }
    }
    }


    /**
     * Updates the autoclick scroll panel when the system configuration is changed.
     * @param newConfig The new system configuration.
     */
    public void onConfigurationChanged(@android.annotation.NonNull Configuration newConfig) {
        mContext.getMainThreadHandler().post(() -> {
            // Only remove the view if it's currently shown.
            if (mInScrollMode) {
                mWindowManager.removeView(mContentView);
            }

            // Always re-inflate the views and resources to adopt the new configuration.
            // This is important even if the panel is hidden.
            inflateViewAndResources();

            // If the panel was shown before the configuration change, add the newly
            // inflated view back to the window to restore its state.
            if (mInScrollMode) {
                mWindowManager.addView(mContentView, mParams);
            }
        });
    }

    /**
    /**
     * Retrieves the layout params for AutoclickScrollPanel, used when it's added to the Window
     * Retrieves the layout params for AutoclickScrollPanel, used when it's added to the Window
     * Manager.
     * Manager.
+17 −0
Original line number Original line Diff line number Diff line
@@ -1620,6 +1620,23 @@ public class AutoclickControllerTest {
        verify(spyTypePanel).onConfigurationChanged(newConfig);
        verify(spyTypePanel).onConfigurationChanged(newConfig);
    }
    }


    @Test
    @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
    public void onConfigurationChanged_notifiesScrollPanelToUpdateTheme() throws Exception {
        injectFakeMouseActionHoverMoveEvent();

        // Create a spy on the real object to verify method calls.
        AutoclickScrollPanel spyScrollPanel = spy(mController.mAutoclickScrollPanel);
        mController.mAutoclickScrollPanel = spyScrollPanel;

        // Simulate a theme change.
        Configuration newConfig = new Configuration();
        mController.onConfigurationChanged(newConfig);

        // Verify onConfigurationChanged was called.
        verify(spyScrollPanel).onConfigurationChanged(newConfig);
    }

    @Test
    @Test
    @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
    @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
    public void onInputDeviceChanged_disconnectAndReconnect_hidesAndShowsTypePanel() {
    public void onInputDeviceChanged_disconnectAndReconnect_hidesAndShowsTypePanel() {