Merge "Ensure notifying when only caption insets changed"

This commit is contained in:
Yunfan Chen
2021-01-18 05:24:47 +00:00
committed by Android (Google) Code Review
3 changed files with 28 additions and 6 deletions

View File

@@ -642,7 +642,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
updateState(state);
applyLocalVisibilityOverride();
if (!mState.equals(lastState, true /* excludingCaptionInsets */,
if (!mState.equals(lastState, false /* excludingCaptionInsets */,
true /* excludeInvisibleIme */)) {
if (DEBUG) Log.d(TAG, "onStateChanged, notifyInsetsChanged");
mHost.notifyInsetsChanged();
@@ -672,16 +672,14 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
getSourceConsumer(type).updateSource(source, animationType);
}
for (@InternalInsetsType int type = 0; type < InsetsState.SIZE; type++) {
// Only update the server side insets here.
if (type == ITYPE_CAPTION_BAR) continue;
InsetsSource source = mState.peekSource(type);
if (source == null) continue;
if (newState.peekSource(type) == null) {
mState.removeSource(type);
}
}
if (mCaptionInsetsHeight != 0) {
mState.getSource(ITYPE_CAPTION_BAR).setFrame(new Rect(mFrame.left, mFrame.top,
mFrame.right, mFrame.top + mCaptionInsetsHeight));
}
updateDisabledUserAnimationTypes(disabledUserAnimationTypes);
@@ -1488,7 +1486,16 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
@Override
public void setCaptionInsetsHeight(int height) {
mCaptionInsetsHeight = height;
if (mCaptionInsetsHeight != height) {
mCaptionInsetsHeight = height;
if (mCaptionInsetsHeight != 0) {
mState.getSource(ITYPE_CAPTION_BAR).setFrame(new Rect(mFrame.left, mFrame.top,
mFrame.right, mFrame.top + mCaptionInsetsHeight));
} else {
mState.removeSource(ITYPE_CAPTION_BAR);
}
mHost.notifyInsetsChanged();
}
}
@Override

View File

@@ -2019,6 +2019,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
if (getForeground() != null) {
drawableChanged();
}
notifyCaptionHeightChanged();
}
}

View File

@@ -45,6 +45,7 @@ import static org.mockito.ArgumentMatchers.notNull;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -680,6 +681,19 @@ public class InsetsControllerTest {
});
}
@Test
public void testNotifyCaptionInsetsOnlyChange() {
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
final InsetsState state = new InsetsState(mController.getState(), true);
reset(mTestHost);
mController.setCaptionInsetsHeight(100);
verify(mTestHost).notifyInsetsChanged();
reset(mTestHost);
mController.setCaptionInsetsHeight(0);
verify(mTestHost).notifyInsetsChanged();
});
}
@Test
public void testRequestedState() {
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {