Loading packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java +10 −12 Original line number Diff line number Diff line Loading @@ -79,7 +79,8 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest private final Runnable mWindowInsetChangeRunnable; private final SfVsyncFrameCallbackProvider mSfVsyncFrameProvider; private final LayoutParams mParams; @VisibleForTesting final LayoutParams mParams; @VisibleForTesting final Rect mDraggableWindowBounds = new Rect(); private boolean mIsVisible = false; Loading Loading @@ -529,7 +530,6 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest // CONFIG_FONT_SCALE: font size change // CONFIG_LOCALE: language change // CONFIG_DENSITY: display size change mParams.accessibilityTitle = getAccessibilityWindowTitle(mContext); boolean showSettingPanelAfterConfigChange = mIsVisible; Loading @@ -541,16 +541,13 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest return; } if ((configDiff & ActivityInfo.CONFIG_ORIENTATION) != 0) { final Rect previousDraggableBounds = new Rect(mDraggableWindowBounds); if ((configDiff & ActivityInfo.CONFIG_ORIENTATION) != 0 || (configDiff & ActivityInfo.CONFIG_SCREEN_SIZE) != 0) { mDraggableWindowBounds.set(getDraggableWindowBounds()); // Keep the Y position with the same height ratio before the window bounds and // draggable bounds are changed. final float windowHeightFraction = (float) (mParams.y - previousDraggableBounds.top) / previousDraggableBounds.height(); mParams.y = (int) (windowHeightFraction * mDraggableWindowBounds.height()) + mDraggableWindowBounds.top; return; // reset the panel position to the right-bottom corner mParams.x = mDraggableWindowBounds.right; mParams.y = mDraggableWindowBounds.bottom; updateButtonViewLayoutIfNeeded(); } } Loading @@ -562,7 +559,8 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest mDraggableWindowBounds.set(newBounds); } private void updateButtonViewLayoutIfNeeded() { @VisibleForTesting void updateButtonViewLayoutIfNeeded() { if (mIsVisible) { mParams.x = MathUtils.constrain(mParams.x, mDraggableWindowBounds.left, mDraggableWindowBounds.right); Loading packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationSettingsTest.java +36 −1 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import android.annotation.IdRes; import android.content.Context; import android.content.pm.ActivityInfo; import android.database.ContentObserver; import android.graphics.Rect; import android.os.UserHandle; import android.provider.Settings; import android.testing.AndroidTestingRunner; Loading @@ -49,6 +50,7 @@ import android.widget.Button; import android.widget.CompoundButton; import android.widget.LinearLayout; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; import com.android.internal.graphics.SfVsyncFrameCallbackProvider; Loading @@ -65,7 +67,7 @@ import org.mockito.MockitoAnnotations; @SmallTest @RunWith(AndroidTestingRunner.class) @TestableLooper.RunWithLooper(setAsMainLooper = true) @TestableLooper.RunWithLooper public class WindowMagnificationSettingsTest extends SysuiTestCase { private static final int MAGNIFICATION_SIZE_SMALL = 1; Loading Loading @@ -274,6 +276,39 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase { assertThat(magnifierMediumButton.isSelected()).isTrue(); } @Test public void onScreenSizeChanged_resetPositionToRightBottomCorner() { setupMagnificationCapabilityAndMode( /* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_ALL, /* mode= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW); mWindowMagnificationSettings.showSettingPanel(); // move the panel to the center of draggable window bounds mWindowMagnificationSettings.mParams.x = mWindowMagnificationSettings.mDraggableWindowBounds.centerX(); mWindowMagnificationSettings.mParams.y = mWindowMagnificationSettings.mDraggableWindowBounds.centerY(); mWindowMagnificationSettings.updateButtonViewLayoutIfNeeded(); final Rect testWindowBounds = new Rect( mWindowManager.getCurrentWindowMetrics().getBounds()); testWindowBounds.set(testWindowBounds.left, testWindowBounds.top, testWindowBounds.right + 200, testWindowBounds.bottom + 50); mWindowManager.setWindowBounds(testWindowBounds); InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { mWindowMagnificationSettings.onConfigurationChanged(ActivityInfo.CONFIG_SCREEN_SIZE); }); // the panel position should be reset to the bottom-right corner assertEquals( mWindowMagnificationSettings.mParams.x, mWindowMagnificationSettings.mDraggableWindowBounds.right); assertEquals( mWindowMagnificationSettings.mParams.y, mWindowMagnificationSettings.mDraggableWindowBounds.bottom); } @Test public void showSettingsPanel_observerRegistered() { setupMagnificationCapabilityAndMode( Loading Loading
packages/SystemUI/src/com/android/systemui/accessibility/WindowMagnificationSettings.java +10 −12 Original line number Diff line number Diff line Loading @@ -79,7 +79,8 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest private final Runnable mWindowInsetChangeRunnable; private final SfVsyncFrameCallbackProvider mSfVsyncFrameProvider; private final LayoutParams mParams; @VisibleForTesting final LayoutParams mParams; @VisibleForTesting final Rect mDraggableWindowBounds = new Rect(); private boolean mIsVisible = false; Loading Loading @@ -529,7 +530,6 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest // CONFIG_FONT_SCALE: font size change // CONFIG_LOCALE: language change // CONFIG_DENSITY: display size change mParams.accessibilityTitle = getAccessibilityWindowTitle(mContext); boolean showSettingPanelAfterConfigChange = mIsVisible; Loading @@ -541,16 +541,13 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest return; } if ((configDiff & ActivityInfo.CONFIG_ORIENTATION) != 0) { final Rect previousDraggableBounds = new Rect(mDraggableWindowBounds); if ((configDiff & ActivityInfo.CONFIG_ORIENTATION) != 0 || (configDiff & ActivityInfo.CONFIG_SCREEN_SIZE) != 0) { mDraggableWindowBounds.set(getDraggableWindowBounds()); // Keep the Y position with the same height ratio before the window bounds and // draggable bounds are changed. final float windowHeightFraction = (float) (mParams.y - previousDraggableBounds.top) / previousDraggableBounds.height(); mParams.y = (int) (windowHeightFraction * mDraggableWindowBounds.height()) + mDraggableWindowBounds.top; return; // reset the panel position to the right-bottom corner mParams.x = mDraggableWindowBounds.right; mParams.y = mDraggableWindowBounds.bottom; updateButtonViewLayoutIfNeeded(); } } Loading @@ -562,7 +559,8 @@ class WindowMagnificationSettings implements MagnificationGestureDetector.OnGest mDraggableWindowBounds.set(newBounds); } private void updateButtonViewLayoutIfNeeded() { @VisibleForTesting void updateButtonViewLayoutIfNeeded() { if (mIsVisible) { mParams.x = MathUtils.constrain(mParams.x, mDraggableWindowBounds.left, mDraggableWindowBounds.right); Loading
packages/SystemUI/tests/src/com/android/systemui/accessibility/WindowMagnificationSettingsTest.java +36 −1 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import android.annotation.IdRes; import android.content.Context; import android.content.pm.ActivityInfo; import android.database.ContentObserver; import android.graphics.Rect; import android.os.UserHandle; import android.provider.Settings; import android.testing.AndroidTestingRunner; Loading @@ -49,6 +50,7 @@ import android.widget.Button; import android.widget.CompoundButton; import android.widget.LinearLayout; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; import com.android.internal.graphics.SfVsyncFrameCallbackProvider; Loading @@ -65,7 +67,7 @@ import org.mockito.MockitoAnnotations; @SmallTest @RunWith(AndroidTestingRunner.class) @TestableLooper.RunWithLooper(setAsMainLooper = true) @TestableLooper.RunWithLooper public class WindowMagnificationSettingsTest extends SysuiTestCase { private static final int MAGNIFICATION_SIZE_SMALL = 1; Loading Loading @@ -274,6 +276,39 @@ public class WindowMagnificationSettingsTest extends SysuiTestCase { assertThat(magnifierMediumButton.isSelected()).isTrue(); } @Test public void onScreenSizeChanged_resetPositionToRightBottomCorner() { setupMagnificationCapabilityAndMode( /* capability= */ ACCESSIBILITY_MAGNIFICATION_MODE_ALL, /* mode= */ ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW); mWindowMagnificationSettings.showSettingPanel(); // move the panel to the center of draggable window bounds mWindowMagnificationSettings.mParams.x = mWindowMagnificationSettings.mDraggableWindowBounds.centerX(); mWindowMagnificationSettings.mParams.y = mWindowMagnificationSettings.mDraggableWindowBounds.centerY(); mWindowMagnificationSettings.updateButtonViewLayoutIfNeeded(); final Rect testWindowBounds = new Rect( mWindowManager.getCurrentWindowMetrics().getBounds()); testWindowBounds.set(testWindowBounds.left, testWindowBounds.top, testWindowBounds.right + 200, testWindowBounds.bottom + 50); mWindowManager.setWindowBounds(testWindowBounds); InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { mWindowMagnificationSettings.onConfigurationChanged(ActivityInfo.CONFIG_SCREEN_SIZE); }); // the panel position should be reset to the bottom-right corner assertEquals( mWindowMagnificationSettings.mParams.x, mWindowMagnificationSettings.mDraggableWindowBounds.right); assertEquals( mWindowMagnificationSettings.mParams.y, mWindowMagnificationSettings.mDraggableWindowBounds.bottom); } @Test public void showSettingsPanel_observerRegistered() { setupMagnificationCapabilityAndMode( Loading