Merge "Insets: Fix DecorView consuming of insets" into rvc-dev am: 3d670ae046 am: d39dcca7f1

Change-Id: Iec68c92727d0275adcf0342e7b84c7b366154839
This commit is contained in:
Adrian Roos
2020-04-09 10:43:36 +00:00
committed by Automerger Merge Worker
2 changed files with 17 additions and 25 deletions

View File

@@ -68,7 +68,6 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable; import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.LayerDrawable;
import android.os.Build.VERSION_CODES;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.Pair; import android.util.Pair;
@@ -120,7 +119,6 @@ import com.android.internal.widget.DecorCaptionView;
import com.android.internal.widget.FloatingToolbar; import com.android.internal.widget.FloatingToolbar;
import java.util.List; import java.util.List;
import java.util.function.Function;
/** @hide */ /** @hide */
public class DecorView extends FrameLayout implements RootViewSurfaceTaker, WindowCallbacks { public class DecorView extends FrameLayout implements RootViewSurfaceTaker, WindowCallbacks {
@@ -283,11 +281,6 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
private Insets mLastBackgroundInsets = Insets.NONE; private Insets mLastBackgroundInsets = Insets.NONE;
private boolean mDrawLegacyNavigationBarBackground; private boolean mDrawLegacyNavigationBarBackground;
/**
* Whether the app targets an SDK that uses the new insets APIs.
*/
private boolean mUseNewInsetsApi;
private PendingInsetsController mPendingInsetsController = new PendingInsetsController(); private PendingInsetsController mPendingInsetsController = new PendingInsetsController();
DecorView(Context context, int featureId, PhoneWindow window, DecorView(Context context, int featureId, PhoneWindow window,
@@ -319,7 +312,6 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
initResizingPaints(); initResizingPaints();
mLegacyNavigationBarBackgroundPaint.setColor(Color.BLACK); mLegacyNavigationBarBackgroundPaint.setColor(Color.BLACK);
mUseNewInsetsApi = context.getApplicationInfo().targetSdkVersion >= VERSION_CODES.R;
} }
void setBackgroundFallback(@Nullable Drawable fallbackDrawable) { void setBackgroundFallback(@Nullable Drawable fallbackDrawable) {
@@ -1189,23 +1181,23 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
// these flags wouldn't make the window draw behind the navigation bar, unless // these flags wouldn't make the window draw behind the navigation bar, unless
// LAYOUT_HIDE_NAVIGATION was set. // LAYOUT_HIDE_NAVIGATION was set.
// //
// Note: Once the app targets R+, we no longer do this logic because we can't rely on // Note: Once the app uses the R+ Window.setDecorFitsSystemWindows(false) API we no longer
// SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION to indicate whether the app wants to handle it by // consume insets because they might no longer set SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION.
// themselves.
boolean hideNavigation = (sysUiVisibility & SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 boolean hideNavigation = (sysUiVisibility & SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
|| !(controller == null || controller.isRequestedVisible(ITYPE_NAVIGATION_BAR)); || !(controller == null || controller.isRequestedVisible(ITYPE_NAVIGATION_BAR));
boolean decorFitsSystemWindows = mWindow.mDecorFitsSystemWindows;
boolean forceConsumingNavBar = (mForceWindowDrawsBarBackgrounds boolean forceConsumingNavBar = (mForceWindowDrawsBarBackgrounds
&& (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
&& (sysUiVisibility & SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) == 0 && (sysUiVisibility & SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) == 0
&& decorFitsSystemWindows
&& !hideNavigation) && !hideNavigation)
|| (mLastShouldAlwaysConsumeSystemBars && hideNavigation); || (mLastShouldAlwaysConsumeSystemBars && hideNavigation);
boolean consumingNavBar = boolean consumingNavBar =
((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0 ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
&& (sysUiVisibility & SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) == 0 && (sysUiVisibility & SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) == 0
&& !hideNavigation && decorFitsSystemWindows
// TODO IME wrap_content windows need to have margin to work properly && !hideNavigation)
&& (!mUseNewInsetsApi || isImeWindow))
|| forceConsumingNavBar; || forceConsumingNavBar;
// If we didn't request fullscreen layout, but we still got it because of the // If we didn't request fullscreen layout, but we still got it because of the
@@ -1216,6 +1208,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
|| (attrs.flags & FLAG_FULLSCREEN) != 0 || (attrs.flags & FLAG_FULLSCREEN) != 0
|| !(controller == null || controller.isRequestedVisible(ITYPE_STATUS_BAR)); || !(controller == null || controller.isRequestedVisible(ITYPE_STATUS_BAR));
boolean consumingStatusBar = (sysUiVisibility & SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) == 0 boolean consumingStatusBar = (sysUiVisibility & SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) == 0
&& decorFitsSystemWindows
&& (attrs.flags & FLAG_LAYOUT_IN_SCREEN) == 0 && (attrs.flags & FLAG_LAYOUT_IN_SCREEN) == 0
&& (attrs.flags & FLAG_LAYOUT_INSET_DECOR) == 0 && (attrs.flags & FLAG_LAYOUT_INSET_DECOR) == 0
&& mForceWindowDrawsBarBackgrounds && mForceWindowDrawsBarBackgrounds

View File

@@ -343,8 +343,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
/** @see ViewRootImpl#mActivityConfigCallback */ /** @see ViewRootImpl#mActivityConfigCallback */
private ActivityConfigCallback mActivityConfigCallback; private ActivityConfigCallback mActivityConfigCallback;
private OnContentApplyWindowInsetsListener mPendingOnContentApplyWindowInsetsListener = boolean mDecorFitsSystemWindows = true;
sDefaultContentInsetsApplier;
static class WindowManagerHolder { static class WindowManagerHolder {
static final IWindowManager sWindowManager = IWindowManager.Stub.asInterface( static final IWindowManager sWindowManager = IWindowManager.Stub.asInterface(
@@ -2138,9 +2137,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
/** Notify when decor view is attached to window and {@link ViewRootImpl} is available. */ /** Notify when decor view is attached to window and {@link ViewRootImpl} is available. */
void onViewRootImplSet(ViewRootImpl viewRoot) { void onViewRootImplSet(ViewRootImpl viewRoot) {
viewRoot.setActivityConfigCallback(mActivityConfigCallback); viewRoot.setActivityConfigCallback(mActivityConfigCallback);
viewRoot.setOnContentApplyWindowInsetsListener( applyDecorFitsSystemWindows();
mPendingOnContentApplyWindowInsetsListener);
mPendingOnContentApplyWindowInsetsListener = null;
} }
static private final String FOCUSED_ID_TAG = "android:focusedViewId"; static private final String FOCUSED_ID_TAG = "android:focusedViewId";
@@ -3907,14 +3904,16 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
@Override @Override
public void setDecorFitsSystemWindows(boolean decorFitsSystemWindows) { public void setDecorFitsSystemWindows(boolean decorFitsSystemWindows) {
mDecorFitsSystemWindows = decorFitsSystemWindows;
applyDecorFitsSystemWindows();
}
private void applyDecorFitsSystemWindows() {
ViewRootImpl impl = getViewRootImplOrNull(); ViewRootImpl impl = getViewRootImplOrNull();
OnContentApplyWindowInsetsListener listener = decorFitsSystemWindows
? sDefaultContentInsetsApplier
: null;
if (impl != null) { if (impl != null) {
impl.setOnContentApplyWindowInsetsListener(listener); impl.setOnContentApplyWindowInsetsListener(mDecorFitsSystemWindows
} else { ? sDefaultContentInsetsApplier
mPendingOnContentApplyWindowInsetsListener = listener; : null);
} }
} }
} }