summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Roy Chou <juchengchou@google.com> 2023-12-07 04:58:37 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-12-07 04:58:37 +0000
commitbd8bd81a0af70701a03e989f495ecb0c9cd0242c (patch)
tree00a048e8818df2f2e04977f9fbedfd07b6eb3452
parenta6c59e8199af5cd5d6b85108c56dc8edd51b489b (diff)
parent5776f6003538158688bf5415c4f1e4ff5448328d (diff)
Merge "fix(magnification): draggable bounds of the settings panel is not correctly computed" into main
-rw-r--r--packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java12
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationSettingsTest.java41
2 files changed, 46 insertions, 7 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java
index c03e403b754b..a98990af00c7 100644
--- a/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java
+++ b/packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java
@@ -59,8 +59,8 @@ import android.widget.TextView;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.graphics.SfVsyncFrameCallbackProvider;
-import com.android.systemui.res.R;
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView;
+import com.android.systemui.res.R;
import com.android.systemui.util.settings.SecureSettings;
import java.lang.annotation.Retention;
@@ -671,17 +671,17 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest
}
private Rect getDraggableWindowBounds() {
- final int layoutMargin = mContext.getResources().getDimensionPixelSize(
- R.dimen.magnification_switch_button_margin);
final WindowMetrics windowMetrics = mWindowManager.getCurrentWindowMetrics();
final Insets windowInsets = windowMetrics.getWindowInsets().getInsetsIgnoringVisibility(
WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout());
+ // re-measure the settings panel view so that we can get the correct view size to inset
+ int unspecificSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
+ mSettingView.measure(unspecificSpec, unspecificSpec);
+
final Rect boundRect = new Rect(windowMetrics.getBounds());
boundRect.offsetTo(0, 0);
- boundRect.inset(0, 0, mParams.width, mParams.height);
+ boundRect.inset(0, 0, mSettingView.getMeasuredWidth(), mSettingView.getMeasuredHeight());
boundRect.inset(windowInsets);
- boundRect.inset(layoutMargin, layoutMargin);
-
return boundRect;
}
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 95e21cf6138a..92b06ba3f714 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationSettingsTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationSettingsTest.java
@@ -20,6 +20,7 @@ import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_CAPAB
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_ALL;
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_FULLSCREEN;
import static android.provider.Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW;
+import static android.view.WindowInsets.Type.systemBars;
import static com.google.common.truth.Truth.assertThat;
@@ -42,6 +43,7 @@ import android.annotation.IdRes;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.database.ContentObserver;
+import android.graphics.Insets;
import android.graphics.Rect;
import android.os.UserHandle;
import android.provider.Settings;
@@ -49,6 +51,7 @@ import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.View;
import android.view.ViewGroup;
+import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
import android.widget.Button;
@@ -59,10 +62,10 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import com.android.internal.graphics.SfVsyncFrameCallbackProvider;
-import com.android.systemui.res.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView;
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView.OnSeekBarWithIconButtonsChangeListener;
+import com.android.systemui.res.R;
import com.android.systemui.util.settings.SecureSettings;
import org.junit.After;
@@ -314,6 +317,42 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase {
}
@Test
+ public void onWindowBoundsChanged_updateDraggableWindowBounds() {
+ setupMagnificationCapabilityAndMode(
+ /* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_ALL,
+ /* mode= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW);
+ mWindowMagnificationSettings.showSettingPanel();
+
+ // get the measured panel view frame size
+ final int panelWidth = mSettingView.getMeasuredWidth();
+ final int panelHeight = mSettingView.getMeasuredHeight();
+
+ final Rect testWindowBounds = new Rect(10, 20, 1010, 2020);
+ final WindowInsets testWindowInsets = new WindowInsets.Builder()
+ .setInsetsIgnoringVisibility(systemBars(), Insets.of(100, 200, 100, 200))
+ .build();
+ mWindowManager.setWindowBounds(testWindowBounds);
+ mWindowManager.setWindowInsets(testWindowInsets);
+
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
+ mWindowMagnificationSettings.onConfigurationChanged(ActivityInfo.CONFIG_SCREEN_SIZE);
+ });
+
+ // the draggable window bounds left/top should be only related to the insets,
+ // and the bounds right/bottom should consider the panel frame size
+ // inset left (100) = 100
+ int expectedLeft = 100;
+ // inset top (200) = 200
+ int expectedTop = 200;
+ // window width (1010 - 10) - inset right (100) - panel width
+ int expectedRight = 900 - panelWidth;
+ // window height (2020 - 20) - inset bottom (200) - panel height
+ int expectedBottom = 1800 - panelHeight;
+ Rect expectedBounds = new Rect(expectedLeft, expectedTop, expectedRight, expectedBottom);
+ assertThat(mWindowMagnificationSettings.mDraggableWindowBounds).isEqualTo(expectedBounds);
+ }
+
+ @Test
public void onScreenSizeChanged_resetPositionToRightBottomCorner() {
setupMagnificationCapabilityAndMode(
/* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_ALL,