fix(#MagSettingsPanel): fix panel position not correct after unfold/rotation

In WindowMagnificationSettings#onConfigurationChanged, for case CONFIG_SCREEN_SIZE/CONFIG_ORIENTATION, we change to directly reset the panel position to the default bottom-right corner. Originally it would try to keep the same Y ratio in bounds, but the new calculated might be not proper in some case. Therefore, we just reset the panel position to the default.

Bug: 279544895
Bug: 279565372
Test: manually
      atest WindowMagnificationSettingsTest
Change-Id: If57f685b3ce8309c74541dd33a0f9b5902d95ae5
This commit is contained in:
Roy Chou
2023-05-15 07:57:35 +00:00
parent bd8568ac11
commit 5d5d8b3724
2 changed files with 46 additions and 13 deletions

View File

@@ -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;
@@ -521,7 +522,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;
@@ -533,16 +533,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();
}
}
@@ -554,7 +551,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);

View File

@@ -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;
@@ -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;
@@ -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;
@@ -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(