fix(magnification thumbnail): fix thumbnail not refreshing when orientation changes or IME opens
Fix: b/279538599 Fix: b/279538852 Fix: b/279527264 Test: manual Change-Id: Idb0855b78a867d120ac0911fba1b5f8c66da1c13
This commit is contained in:
@@ -319,6 +319,10 @@ public class FullScreenMagnificationController implements
|
|||||||
FullScreenMagnificationController::onUserContextChanged,
|
FullScreenMagnificationController::onUserContextChanged,
|
||||||
FullScreenMagnificationController.this, mDisplayId);
|
FullScreenMagnificationController.this, mDisplayId);
|
||||||
mControllerCtx.getHandler().sendMessage(m);
|
mControllerCtx.getHandler().sendMessage(m);
|
||||||
|
|
||||||
|
synchronized (mLock) {
|
||||||
|
refreshThumbnail();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -344,7 +348,7 @@ public class FullScreenMagnificationController implements
|
|||||||
mMagnificationRegion.set(magnified);
|
mMagnificationRegion.set(magnified);
|
||||||
mMagnificationRegion.getBounds(mMagnificationBounds);
|
mMagnificationRegion.getBounds(mMagnificationBounds);
|
||||||
|
|
||||||
refreshThumbnail(getScale(), getCenterX(), getCenterY());
|
refreshThumbnail();
|
||||||
|
|
||||||
// It's possible that our magnification spec is invalid with the new bounds.
|
// It's possible that our magnification spec is invalid with the new bounds.
|
||||||
// Adjust the current spec's offsets if necessary.
|
// Adjust the current spec's offsets if necessary.
|
||||||
@@ -602,13 +606,13 @@ public class FullScreenMagnificationController implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
void refreshThumbnail(float scale, float centerX, float centerY) {
|
void refreshThumbnail() {
|
||||||
if (mMagnificationThumbnail != null) {
|
if (mMagnificationThumbnail != null) {
|
||||||
mMagnificationThumbnail.setThumbnailBounds(
|
mMagnificationThumbnail.setThumbnailBounds(
|
||||||
mMagnificationBounds,
|
mMagnificationBounds,
|
||||||
scale,
|
getScale(),
|
||||||
centerX,
|
getCenterX(),
|
||||||
centerY
|
getCenterY()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -627,7 +631,7 @@ public class FullScreenMagnificationController implements
|
|||||||
// We call refreshThumbnail when the thumbnail is just created to set current
|
// We call refreshThumbnail when the thumbnail is just created to set current
|
||||||
// magnification bounds to thumbnail. It to prevent the thumbnail size has not yet
|
// magnification bounds to thumbnail. It to prevent the thumbnail size has not yet
|
||||||
// updated properly and thus shows with huge size. (b/276314641)
|
// updated properly and thus shows with huge size. (b/276314641)
|
||||||
refreshThumbnail(getScale(), getCenterX(), getCenterY());
|
refreshThumbnail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,15 +99,17 @@ public class MagnificationThumbnail {
|
|||||||
Log.d(LOG_TAG, "setThumbnailBounds " + currentBounds);
|
Log.d(LOG_TAG, "setThumbnailBounds " + currentBounds);
|
||||||
}
|
}
|
||||||
mHandler.post(() -> {
|
mHandler.post(() -> {
|
||||||
mWindowBounds = currentBounds;
|
refreshBackgroundBounds(currentBounds);
|
||||||
setBackgroundBounds();
|
|
||||||
if (mVisible) {
|
if (mVisible) {
|
||||||
updateThumbnailMainThread(scale, centerX, centerY);
|
updateThumbnailMainThread(scale, centerX, centerY);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBackgroundBounds() {
|
@MainThread
|
||||||
|
private void refreshBackgroundBounds(Rect currentBounds) {
|
||||||
|
mWindowBounds = currentBounds;
|
||||||
|
|
||||||
Point magnificationBoundary = getMagnificationThumbnailPadding(mContext);
|
Point magnificationBoundary = getMagnificationThumbnailPadding(mContext);
|
||||||
mThumbnailWidth = (int) (mWindowBounds.width() / BG_ASPECT_RATIO);
|
mThumbnailWidth = (int) (mWindowBounds.width() / BG_ASPECT_RATIO);
|
||||||
mThumbnailHeight = (int) (mWindowBounds.height() / BG_ASPECT_RATIO);
|
mThumbnailHeight = (int) (mWindowBounds.height() / BG_ASPECT_RATIO);
|
||||||
@@ -117,6 +119,10 @@ public class MagnificationThumbnail {
|
|||||||
mBackgroundParams.height = mThumbnailHeight;
|
mBackgroundParams.height = mThumbnailHeight;
|
||||||
mBackgroundParams.x = initX;
|
mBackgroundParams.x = initX;
|
||||||
mBackgroundParams.y = initY;
|
mBackgroundParams.y = initY;
|
||||||
|
|
||||||
|
if (mVisible) {
|
||||||
|
mWindowManager.updateViewLayout(mThumbnailLayout, mBackgroundParams);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainThread
|
@MainThread
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import static org.mockito.ArgumentMatchers.any;
|
|||||||
import static org.mockito.ArgumentMatchers.anyFloat;
|
import static org.mockito.ArgumentMatchers.anyFloat;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.atLeastOnce;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
@@ -202,6 +203,7 @@ public class FullScreenMagnificationControllerTest {
|
|||||||
assertFalse(mFullScreenMagnificationController.isRegistered(DISPLAY_0));
|
assertFalse(mFullScreenMagnificationController.isRegistered(DISPLAY_0));
|
||||||
assertFalse(mFullScreenMagnificationController.isRegistered(DISPLAY_1));
|
assertFalse(mFullScreenMagnificationController.isRegistered(DISPLAY_1));
|
||||||
|
|
||||||
|
// Once for each display on unregister
|
||||||
verify(mMockThumbnail, times(2)).hideThumbnail();
|
verify(mMockThumbnail, times(2)).hideThumbnail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -543,7 +545,11 @@ public class FullScreenMagnificationControllerTest {
|
|||||||
// The first time is triggered when the thumbnail is just created.
|
// The first time is triggered when the thumbnail is just created.
|
||||||
// The second time is triggered when the magnification region changed.
|
// The second time is triggered when the magnification region changed.
|
||||||
verify(mMockThumbnail, times(2)).setThumbnailBounds(
|
verify(mMockThumbnail, times(2)).setThumbnailBounds(
|
||||||
any(), anyFloat(), anyFloat(), anyFloat());
|
/* currentBounds= */ any(),
|
||||||
|
/* scale= */ anyFloat(),
|
||||||
|
/* centerX= */ anyFloat(),
|
||||||
|
/* centerY= */ anyFloat()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -681,6 +687,9 @@ public class FullScreenMagnificationControllerTest {
|
|||||||
checkActivatedAndMagnifying(/* activated= */ true, /* magnifying= */ true, displayId);
|
checkActivatedAndMagnifying(/* activated= */ true, /* magnifying= */ true, displayId);
|
||||||
assertTrue(mFullScreenMagnificationController.resetIfNeeded(displayId, SERVICE_ID_2));
|
assertTrue(mFullScreenMagnificationController.resetIfNeeded(displayId, SERVICE_ID_2));
|
||||||
checkActivatedAndMagnifying(/* activated= */ false, /* magnifying= */ false, displayId);
|
checkActivatedAndMagnifying(/* activated= */ false, /* magnifying= */ false, displayId);
|
||||||
|
|
||||||
|
// Once on init before it's activated and once for reset
|
||||||
|
verify(mMockThumbnail, times(2)).hideThumbnail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -783,6 +792,9 @@ public class FullScreenMagnificationControllerTest {
|
|||||||
mMessageCapturingHandler.sendAllMessages();
|
mMessageCapturingHandler.sendAllMessages();
|
||||||
checkActivatedAndMagnifying(/* activated= */ false, /* magnifying= */ false, DISPLAY_0);
|
checkActivatedAndMagnifying(/* activated= */ false, /* magnifying= */ false, DISPLAY_0);
|
||||||
checkActivatedAndMagnifying(/* activated= */ false, /* magnifying= */ false, DISPLAY_1);
|
checkActivatedAndMagnifying(/* activated= */ false, /* magnifying= */ false, DISPLAY_1);
|
||||||
|
|
||||||
|
// Twice for each display: once on init before it's activated and once for screen off
|
||||||
|
verify(mMockThumbnail, times(4)).hideThumbnail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -847,6 +859,15 @@ public class FullScreenMagnificationControllerTest {
|
|||||||
mMessageCapturingHandler.sendAllMessages();
|
mMessageCapturingHandler.sendAllMessages();
|
||||||
checkActivatedAndMagnifying(
|
checkActivatedAndMagnifying(
|
||||||
/* activated= */ expectedActivated, /* magnifying= */ false, displayId);
|
/* activated= */ expectedActivated, /* magnifying= */ false, displayId);
|
||||||
|
|
||||||
|
if (expectedActivated) {
|
||||||
|
verify(mMockThumbnail, times(2)).setThumbnailBounds(
|
||||||
|
/* currentBounds= */ any(),
|
||||||
|
/* scale= */ anyFloat(),
|
||||||
|
/* centerX= */ anyFloat(),
|
||||||
|
/* centerY= */ anyFloat()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -950,6 +971,13 @@ public class FullScreenMagnificationControllerTest {
|
|||||||
INITIAL_BOUNDS_LOWER_RIGHT_2X_CENTER, scale);
|
INITIAL_BOUNDS_LOWER_RIGHT_2X_CENTER, scale);
|
||||||
assertThat(endSpec, closeTo(getMagnificationSpec(scale, expectedOffsets)));
|
assertThat(endSpec, closeTo(getMagnificationSpec(scale, expectedOffsets)));
|
||||||
verify(mMockWindowManager).setMagnificationSpec(eq(displayId), argThat(closeTo(endSpec)));
|
verify(mMockWindowManager).setMagnificationSpec(eq(displayId), argThat(closeTo(endSpec)));
|
||||||
|
|
||||||
|
verify(mMockThumbnail, atLeastOnce()).setThumbnailBounds(
|
||||||
|
/* currentBounds= */ any(),
|
||||||
|
eq(scale),
|
||||||
|
/* centerX= */ anyFloat(),
|
||||||
|
/* centerY= */ anyFloat()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -984,6 +1012,13 @@ public class FullScreenMagnificationControllerTest {
|
|||||||
INITIAL_BOUNDS_LOWER_RIGHT_2X_CENTER, scale);
|
INITIAL_BOUNDS_LOWER_RIGHT_2X_CENTER, scale);
|
||||||
assertThat(endSpec, closeTo(getMagnificationSpec(scale, expectedOffsets)));
|
assertThat(endSpec, closeTo(getMagnificationSpec(scale, expectedOffsets)));
|
||||||
verify(mMockWindowManager).setMagnificationSpec(eq(displayId), argThat(closeTo(endSpec)));
|
verify(mMockWindowManager).setMagnificationSpec(eq(displayId), argThat(closeTo(endSpec)));
|
||||||
|
|
||||||
|
verify(mMockThumbnail, atLeastOnce()).setThumbnailBounds(
|
||||||
|
/* currentBounds= */ any(),
|
||||||
|
eq(scale),
|
||||||
|
/* centerX= */ anyFloat(),
|
||||||
|
/* centerY= */ anyFloat()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1246,6 +1281,13 @@ public class FullScreenMagnificationControllerTest {
|
|||||||
callbacks.onImeWindowVisibilityChanged(true);
|
callbacks.onImeWindowVisibilityChanged(true);
|
||||||
mMessageCapturingHandler.sendAllMessages();
|
mMessageCapturingHandler.sendAllMessages();
|
||||||
verify(mRequestObserver).onImeWindowVisibilityChanged(eq(DISPLAY_0), eq(true));
|
verify(mRequestObserver).onImeWindowVisibilityChanged(eq(DISPLAY_0), eq(true));
|
||||||
|
|
||||||
|
verify(mMockThumbnail, atLeastOnce()).setThumbnailBounds(
|
||||||
|
/* currentBounds= */ any(),
|
||||||
|
/* scale= */ anyFloat(),
|
||||||
|
/* centerX= */ anyFloat(),
|
||||||
|
/* centerY= */ anyFloat()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1270,6 +1312,15 @@ public class FullScreenMagnificationControllerTest {
|
|||||||
mFullScreenMagnificationController.onUserContextChanged(DISPLAY_0);
|
mFullScreenMagnificationController.onUserContextChanged(DISPLAY_0);
|
||||||
|
|
||||||
verify(mRequestObserver).onFullScreenMagnificationActivationState(eq(DISPLAY_0), eq(false));
|
verify(mRequestObserver).onFullScreenMagnificationActivationState(eq(DISPLAY_0), eq(false));
|
||||||
|
verify(mMockThumbnail).setThumbnailBounds(
|
||||||
|
/* currentBounds= */ any(),
|
||||||
|
/* scale= */ anyFloat(),
|
||||||
|
/* centerX= */ anyFloat(),
|
||||||
|
/* centerY= */ anyFloat()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Once on init before it's activated and once for reset
|
||||||
|
verify(mMockThumbnail, times(2)).hideThumbnail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1281,6 +1332,12 @@ public class FullScreenMagnificationControllerTest {
|
|||||||
|
|
||||||
assertEquals(1.0f, mFullScreenMagnificationController.getScale(DISPLAY_0), 0);
|
assertEquals(1.0f, mFullScreenMagnificationController.getScale(DISPLAY_0), 0);
|
||||||
assertTrue(mFullScreenMagnificationController.isActivated(DISPLAY_0));
|
assertTrue(mFullScreenMagnificationController.isActivated(DISPLAY_0));
|
||||||
|
verify(mMockThumbnail).setThumbnailBounds(
|
||||||
|
/* currentBounds= */ any(),
|
||||||
|
/* scale= */ anyFloat(),
|
||||||
|
/* centerX= */ anyFloat(),
|
||||||
|
/* centerY= */ anyFloat()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setScaleToMagnifying() {
|
private void setScaleToMagnifying() {
|
||||||
|
|||||||
@@ -187,6 +187,29 @@ public class MagnificationThumbnailTest {
|
|||||||
.addView(eq(mMagnificationThumbnail.mThumbnailLayout), any());
|
.addView(eq(mMagnificationThumbnail.mThumbnailLayout), any());
|
||||||
verify(mMockWindowManager, never())
|
verify(mMockWindowManager, never())
|
||||||
.removeView(eq(mMagnificationThumbnail.mThumbnailLayout));
|
.removeView(eq(mMagnificationThumbnail.mThumbnailLayout));
|
||||||
|
verify(mMockWindowManager, never())
|
||||||
|
.updateViewLayout(eq(mMagnificationThumbnail.mThumbnailLayout), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenVisible_setBoundsUpdatesLayout() throws InterruptedException {
|
||||||
|
runOnMainSync(() -> mMagnificationThumbnail.updateThumbnail(
|
||||||
|
/* scale= */ 2f,
|
||||||
|
/* centerX= */ 5,
|
||||||
|
/* centerY= */ 10
|
||||||
|
));
|
||||||
|
runOnMainSync(() -> mMagnificationThumbnail.setThumbnailBounds(
|
||||||
|
new Rect(),
|
||||||
|
/* scale= */ 2f,
|
||||||
|
/* centerX= */ 5,
|
||||||
|
/* centerY= */ 10
|
||||||
|
));
|
||||||
|
idle();
|
||||||
|
|
||||||
|
verify(mMockWindowManager).updateViewLayout(
|
||||||
|
eq(mMagnificationThumbnail.mThumbnailLayout),
|
||||||
|
/* params= */ any()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void idle() {
|
private static void idle() {
|
||||||
|
|||||||
Reference in New Issue
Block a user