From 022b18263468282979e84fd8864bee4f67919f2d Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Wed, 12 Jun 2019 08:44:09 -0700 Subject: [PATCH] Updating consumed insets when dispatching to child views Bug: 134963243 Change-Id: I4fa072128398cfd22b906037c6c444495781c9d0 --- .../android/launcher3/LauncherRootView.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/com/android/launcher3/LauncherRootView.java b/src/com/android/launcher3/LauncherRootView.java index 49b380b41f..f964b8d9ee 100644 --- a/src/com/android/launcher3/LauncherRootView.java +++ b/src/com/android/launcher3/LauncherRootView.java @@ -8,18 +8,22 @@ import android.app.ActivityManager; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.Insets; import android.graphics.Paint; import android.graphics.Rect; import android.os.Build; import android.util.AttributeSet; import android.view.View; import android.view.ViewDebug; +import android.view.WindowInsets; import java.util.Collections; import java.util.List; public class LauncherRootView extends InsettableFrameLayout { + private final Rect mTempRect = new Rect(); + private final Launcher mLauncher; private final Paint mOpaquePaint; @@ -56,9 +60,7 @@ public class LauncherRootView extends InsettableFrameLayout { super.onFinishInflate(); } - @TargetApi(23) - @Override - protected boolean fitSystemWindows(Rect insets) { + private void handleSystemWindowInsets(Rect insets) { mConsumedInsets.setEmpty(); boolean drawInsetBar = false; if (mLauncher.isInMultiWindowMode() @@ -66,13 +68,13 @@ public class LauncherRootView extends InsettableFrameLayout { mConsumedInsets.left = insets.left; mConsumedInsets.right = insets.right; mConsumedInsets.bottom = insets.bottom; - insets = new Rect(0, insets.top, 0, 0); + insets.set(0, insets.top, 0, 0); drawInsetBar = true; } else if ((insets.right > 0 || insets.left > 0) && getContext().getSystemService(ActivityManager.class).isLowRamDevice()) { mConsumedInsets.left = insets.left; mConsumedInsets.right = insets.right; - insets = new Rect(0, insets.top, 0, insets.bottom); + insets.set(0, insets.top, 0, insets.bottom); drawInsetBar = true; } @@ -99,8 +101,19 @@ public class LauncherRootView extends InsettableFrameLayout { if (resetState) { mLauncher.getStateManager().reapplyState(true /* cancelCurrentAnimation */); } + } - return false; // Let children get the full insets + @Override + public WindowInsets onApplyWindowInsets(WindowInsets insets) { + mTempRect.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), + insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); + handleSystemWindowInsets(mTempRect); + if (Utilities.ATLEAST_Q) { + return insets.inset(mConsumedInsets.left, mConsumedInsets.top, + mConsumedInsets.right, mConsumedInsets.bottom); + } else { + return insets.replaceSystemWindowInsets(mTempRect); + } } @Override