Factor out to NavigationBarController#scheduleRelayout()

This is a mechanical refactoring CL so that we can avoid code
duplicate later.

Bug: 215550296
Test: Manually verified that there is no behavior change
Change-Id: I14d2c7609e156b9e627b26471d392cb47b14163b
This commit is contained in:
Yohei Yukawa
2022-01-25 20:55:46 -08:00
parent b7f55ec599
commit 4dd61edf09

View File

@@ -266,34 +266,50 @@ final class NavigationBarController {
}
final boolean insetChanged = !Objects.equals(systemInsets, mLastInsets);
if (zOrderChanged || insetChanged) {
final NavigationBarFrame that = mNavigationBarFrame;
that.post(() -> {
if (!that.isAttachedToWindow()) {
return;
}
final Insets currentSystemInsets = getSystemInsets();
if (!Objects.equals(currentSystemInsets, mLastInsets)) {
that.setLayoutParams(
new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
currentSystemInsets.bottom, Gravity.BOTTOM));
mLastInsets = currentSystemInsets;
}
if (decor instanceof ViewGroup) {
ViewGroup decorGroup = (ViewGroup) decor;
final View navbarBackgroundView =
window.getNavigationBarBackgroundView();
if (navbarBackgroundView != null
&& decorGroup.indexOfChild(navbarBackgroundView)
> decorGroup.indexOfChild(that)) {
decorGroup.bringChildToFront(that);
}
}
});
scheduleRelayout();
}
}
}
private void scheduleRelayout() {
// Capture the current frame object in case the object is replaced or cleared later.
final NavigationBarFrame frame = mNavigationBarFrame;
frame.post(() -> {
if (mDestroyed) {
return;
}
if (!frame.isAttachedToWindow()) {
return;
}
final Window window = mService.mWindow.getWindow();
if (window == null) {
return;
}
final View decor = window.peekDecorView();
if (decor == null) {
return;
}
if (!(decor instanceof ViewGroup)) {
return;
}
final ViewGroup decorGroup = (ViewGroup) decor;
final Insets currentSystemInsets = getSystemInsets();
if (!Objects.equals(currentSystemInsets, mLastInsets)) {
frame.setLayoutParams(new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
currentSystemInsets.bottom, Gravity.BOTTOM));
mLastInsets = currentSystemInsets;
}
final View navbarBackgroundView =
window.getNavigationBarBackgroundView();
if (navbarBackgroundView != null
&& decorGroup.indexOfChild(navbarBackgroundView)
> decorGroup.indexOfChild(frame)) {
decorGroup.bringChildToFront(frame);
}
});
}
private boolean isGesturalNavigationEnabled() {
final Resources resources = mService.getResources();
if (resources == null) {