From db1be9d95723a74975a3271bb74b2bd3aef058c8 Mon Sep 17 00:00:00 2001 From: chihtinglo Date: Tue, 20 Dec 2022 17:05:08 +0800 Subject: [PATCH] Style panel with Material designs (3/n) The following components are styled to follow Material designs in this modification: 1. All image buttons for adjusting magnifier window size - The background for image buttons - The tint for image buttons The icon button will get a background color when it is selected and the background color will be cleared when "Edit mode" for the window is triggered. Bug: 257272333 Test: manual - attach screenshots with the bug Test: atest SystemUITests:com.android.systemui.accessibility.WindowMagnificationSettingsTest Change-Id: I300f88be6fb9cc9e4c4bc4eaa7f5bf0e2c124d58 --- ..._magnification_image_button_background.xml | 22 +++++++ ...bility_magnification_image_button_tint.xml | 22 +++++++ ...agnification_setting_view_image_btn_bg.xml | 30 +++++++++ ...tion_setting_view_image_btn_layout_bg.xml} | 50 +++++++-------- ...new_fullscreen.xml => ic_open_in_full.xml} | 24 +++---- .../window_magnification_settings_view.xml | 63 ++++++++++++------- packages/SystemUI/res/values/dimens.xml | 8 +++ .../WindowMagnificationSettings.java | 35 ++++++++++- .../WindowMagnificationSettingsTest.java | 18 ++++++ 9 files changed, 203 insertions(+), 69 deletions(-) create mode 100644 packages/SystemUI/res/color/accessibility_magnification_image_button_background.xml create mode 100644 packages/SystemUI/res/color/accessibility_magnification_image_button_tint.xml create mode 100644 packages/SystemUI/res/drawable/accessibility_magnification_setting_view_image_btn_bg.xml rename packages/SystemUI/res/drawable/{accessibility_magnification_setting_view_btn_bg.xml => accessibility_magnification_setting_view_image_btn_layout_bg.xml} (60%) rename packages/SystemUI/res/drawable/{ic_open_in_new_fullscreen.xml => ic_open_in_full.xml} (53%) diff --git a/packages/SystemUI/res/color/accessibility_magnification_image_button_background.xml b/packages/SystemUI/res/color/accessibility_magnification_image_button_background.xml new file mode 100644 index 0000000000000..5e0539a211d11 --- /dev/null +++ b/packages/SystemUI/res/color/accessibility_magnification_image_button_background.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/packages/SystemUI/res/color/accessibility_magnification_image_button_tint.xml b/packages/SystemUI/res/color/accessibility_magnification_image_button_tint.xml new file mode 100644 index 0000000000000..d444e4c63885a --- /dev/null +++ b/packages/SystemUI/res/color/accessibility_magnification_image_button_tint.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/packages/SystemUI/res/drawable/accessibility_magnification_setting_view_image_btn_bg.xml b/packages/SystemUI/res/drawable/accessibility_magnification_setting_view_image_btn_bg.xml new file mode 100644 index 0000000000000..16ddcd82402d2 --- /dev/null +++ b/packages/SystemUI/res/drawable/accessibility_magnification_setting_view_image_btn_bg.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/SystemUI/res/drawable/accessibility_magnification_setting_view_btn_bg.xml b/packages/SystemUI/res/drawable/accessibility_magnification_setting_view_image_btn_layout_bg.xml similarity index 60% rename from packages/SystemUI/res/drawable/accessibility_magnification_setting_view_btn_bg.xml rename to packages/SystemUI/res/drawable/accessibility_magnification_setting_view_image_btn_layout_bg.xml index 5c9dd569b9d74..900711f63c379 100644 --- a/packages/SystemUI/res/drawable/accessibility_magnification_setting_view_btn_bg.xml +++ b/packages/SystemUI/res/drawable/accessibility_magnification_setting_view_image_btn_layout_bg.xml @@ -1,28 +1,22 @@ - - - - - - - - - - - \ No newline at end of file + + + + + + \ No newline at end of file diff --git a/packages/SystemUI/res/drawable/ic_open_in_new_fullscreen.xml b/packages/SystemUI/res/drawable/ic_open_in_full.xml similarity index 53% rename from packages/SystemUI/res/drawable/ic_open_in_new_fullscreen.xml rename to packages/SystemUI/res/drawable/ic_open_in_full.xml index c7434f5e46fdc..c7f3236f94cf7 100644 --- a/packages/SystemUI/res/drawable/ic_open_in_new_fullscreen.xml +++ b/packages/SystemUI/res/drawable/ic_open_in_full.xml @@ -1,5 +1,5 @@ - - - - - + android:width="48dp" + android:height="48dp" + android:viewportWidth="48" + android:viewportHeight="48" + android:tint="?attr/colorControlNormal"> + diff --git a/packages/SystemUI/res/layout/window_magnification_settings_view.xml b/packages/SystemUI/res/layout/window_magnification_settings_view.xml index 714d551f31ea9..377eb9794817d 100644 --- a/packages/SystemUI/res/layout/window_magnification_settings_view.xml +++ b/packages/SystemUI/res/layout/window_magnification_settings_view.xml @@ -46,55 +46,72 @@ diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index ade75cb2805f4..7bf5e29a3e68a 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -1121,6 +1121,14 @@ 100dp 10dp 24dp + 58dp + 48dp + 316dp + 80dp + 12dp + 24dp + 16dp + 28dp diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java index 527c12493b3f1..d4b506eeeed07 100644 --- a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java +++ b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java @@ -90,6 +90,7 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest private Button mDoneButton; private Button mEditButton; private ImageButton mChangeModeButton; + private int mLastSelectedButtonIndex = MagnificationSize.NONE; private boolean mAllowDiagonalScrolling = false; private static final float A11Y_CHANGE_SCALE_DIFFERENCE = 1.0f; private static final float A11Y_SCALE_MIN_VALUE = 2.0f; @@ -124,10 +125,11 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest Settings.Secure.ACCESSIBILITY_ALLOW_DIAGONAL_SCROLLING, 0, UserHandle.USER_CURRENT) == 1; - inflateView(); - mParams = createLayoutParams(context); mWindowInsetChangeRunnable = this::onWindowInsetChanged; + + inflateView(); + mGestureDetector = new MagnificationGestureDetector(context, context.getMainThreadHandler(), this); } @@ -423,11 +425,14 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest mSettingView.setOnApplyWindowInsetsListener((v, insets) -> { // Adds a pending post check to avoiding redundant calculation because this callback // is sent frequently when the switch icon window dragged by the users. - if (!mSettingView.getHandler().hasCallbacks(mWindowInsetChangeRunnable)) { + if (mSettingView.isAttachedToWindow() + && !mSettingView.getHandler().hasCallbacks(mWindowInsetChangeRunnable)) { mSettingView.getHandler().post(mWindowInsetChangeRunnable); } return v.onApplyWindowInsets(insets); }); + + updateSelectedButton(mLastSelectedButtonIndex); } void onConfigurationChanged(int configDiff) { @@ -505,11 +510,13 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest public void editMagnifierSizeMode(boolean enable) { setEditMagnifierSizeMode(enable); + updateSelectedButton(MagnificationSize.NONE); hideSettingPanel(); } private void setMagnifierSize(@MagnificationSize int index) { mCallback.onSetMagnifierSize(index); + updateSelectedButton(index); } private void toggleDiagonalScrolling() { @@ -567,4 +574,26 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest new Rect(0, 0, mSettingView.getWidth(), mSettingView.getHeight()))); }); } + + private void updateSelectedButton(@MagnificationSize int index) { + // Clear the state of last selected button + if (mLastSelectedButtonIndex == MagnificationSize.SMALL) { + mSmallButton.setSelected(false); + } else if (mLastSelectedButtonIndex == MagnificationSize.MEDIUM) { + mMediumButton.setSelected(false); + } else if (mLastSelectedButtonIndex == MagnificationSize.LARGE) { + mLargeButton.setSelected(false); + } + + // Set the state for selected button + if (index == MagnificationSize.SMALL) { + mSmallButton.setSelected(true); + } else if (index == MagnificationSize.MEDIUM) { + mMediumButton.setSelected(true); + } else if (index == MagnificationSize.LARGE) { + mLargeButton.setSelected(true); + } + + mLastSelectedButtonIndex = index; + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationSettingsTest.java b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationSettingsTest.java index d80307588cccc..47c91911e52aa 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationSettingsTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationSettingsTest.java @@ -16,6 +16,8 @@ package com.android.systemui.accessibility; +import static com.google.common.truth.Truth.assertThat; + import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; @@ -24,6 +26,7 @@ import static org.mockito.Mockito.verify; import android.annotation.IdRes; import android.content.Context; +import android.content.pm.ActivityInfo; import android.provider.Settings; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; @@ -183,6 +186,21 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase { verify(mWindowMagnificationSettingsCallback).onSetDiagonalScrolling(!currentCheckedState); } + @Test + public void onConfigurationChanged_selectedButtonIsStillSelected() { + // Open view + mWindowMagnificationSettings.showSettingPanel(); + View magnifierMediumButton = getInternalView(R.id.magnifier_medium_button); + magnifierMediumButton.performClick(); + + mWindowMagnificationSettings.onConfigurationChanged(ActivityInfo.CONFIG_UI_MODE); + + // Since the view is re-inflated after onConfigurationChanged, + // we need to get the view again. + magnifierMediumButton = getInternalView(R.id.magnifier_medium_button); + assertThat(magnifierMediumButton.isSelected()).isTrue(); + } + private T getInternalView(@IdRes int idRes) { T view = mSettingView.findViewById(idRes); assertNotNull(view);