From 7fb715c4254a8544fec3072d8220d76a5821b189 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Thu, 9 Jan 2020 23:45:41 +0100 Subject: Introduce Window.setContentOnApplyWindowInsetsListener When root-level content containers fit insets, they used to just apply and consume the entire system insets. However, with the new Inset APIs, and with deprecating ADJUST_RESIZE IME flag, we want to give apps an easy way to customize this behavior. For that, we introduce Window.setOnContentApplyWindowInsetsListener that returns what kind of margins/padding should be applied and what should be dispatched to the content views. This is essentially a replacement for SYSTEM_UI_FLAG_LAYOUT_* as well as SOFT_INPUT_ADJUST_RESIZE: It allows apps to choose which insets should be handled on the window level vs view level. For that, we mark the window decor views as FRAMEWORK_OPTIONAL_FIT_SYSTEM_WINDOWS, in order to distinguish the case when support library calls makeOptionalFitSystemWindows(). This is because of two reasons: - We don't want the listener to be invoked twice. - We can not do the compat ping-pong between onApplyWindowInsets and fitSystemWindows. This is because during the ping-pong, the result of the OnContentApplyWindowInsetsListener would be lost. However, we still need to do the compat ping-pong for ActionBarOverlayLayout in the support library (until that gets migrated to use onApplyWindowInsets), so we have this separate dispatching path that only gets used for framework optional fitting views. Test: WindowTest Bug: 118118435 Change-Id: I4b514addd9e094163062d651972f85615b4a35db --- core/java/android/inputmethodservice/InputMethodService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/java/android/inputmethodservice/InputMethodService.java') diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index 8e52ee944c1c..86ff0f4e0dfc 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -1194,7 +1194,7 @@ public class InputMethodService extends AbstractInputMethodService { Context.LAYOUT_INFLATER_SERVICE); mWindow = new SoftInputWindow(this, "InputMethod", mTheme, null, null, mDispatcherState, WindowManager.LayoutParams.TYPE_INPUT_METHOD, Gravity.BOTTOM, false); - mWindow.getWindow().setFitWindowInsetsTypes(WindowInsets.Type.systemBars()); + mWindow.getWindow().getAttributes().setFitWindowInsetsTypes(WindowInsets.Type.systemBars()); mWindow.getWindow().addPrivateFlags(PRIVATE_FLAG_ONLY_DRAW_BOTTOM_BAR_BACKGROUND); mWindow.getWindow().getDecorView().setOnApplyWindowInsetsListener( (v, insets) -> v.onApplyWindowInsets( -- cgit v1.2.3 From 0da8fd165fed21f26b2b10ddcf4bd1a89d9981c3 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Fri, 10 Jan 2020 01:23:21 +0100 Subject: Force non-floating main app windows to not fit anything Since we have a better approach of fitting content instead of setting them on the layout params (Window.setContentOnApplyWindowInsetsListener), we can now simplify forcing of filling the screen: Instead of clearing the fit types when the private flag is set, we unset the types and straight out reject any params when the client would like to fit. Test: DisplayPolicyTests Bug: 118118435 Change-Id: I845e6b1c81e29ab66a770891d03c62a32418e8cc --- .../android/inputmethodservice/InputMethodService.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'core/java/android/inputmethodservice/InputMethodService.java') diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index 86ff0f4e0dfc..82b21f9b266e 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -20,8 +20,8 @@ import static android.view.Display.DEFAULT_DISPLAY; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import static android.view.ViewRootImpl.NEW_INSETS_MODE_NONE; +import static android.view.WindowInsets.Type.navigationBars; import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS; -import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_ONLY_DRAW_BOTTOM_BAR_BACKGROUND; import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage; @@ -1194,16 +1194,15 @@ public class InputMethodService extends AbstractInputMethodService { Context.LAYOUT_INFLATER_SERVICE); mWindow = new SoftInputWindow(this, "InputMethod", mTheme, null, null, mDispatcherState, WindowManager.LayoutParams.TYPE_INPUT_METHOD, Gravity.BOTTOM, false); - mWindow.getWindow().getAttributes().setFitWindowInsetsTypes(WindowInsets.Type.systemBars()); - mWindow.getWindow().addPrivateFlags(PRIVATE_FLAG_ONLY_DRAW_BOTTOM_BAR_BACKGROUND); + mWindow.getWindow().getAttributes().setFitWindowInsetsTypes(WindowInsets.Type.statusBars()); + + // IME layout should always be inset by navigation bar, no matter it's current visibility. mWindow.getWindow().getDecorView().setOnApplyWindowInsetsListener( (v, insets) -> v.onApplyWindowInsets( - new WindowInsets.Builder(insets).setSystemWindowInsets( - android.graphics.Insets.of( - insets.getSystemWindowInsetLeft(), - insets.getSystemWindowInsetTop(), - insets.getSystemWindowInsetRight(), - insets.getStableInsetBottom())).build())); + new WindowInsets.Builder(insets).setInsets( + navigationBars(), insets.getMaxInsets(navigationBars())) + .build())); + // For ColorView in DecorView to work, FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS needs to be set // by default (but IME developers can opt this out later if they want a new behavior). mWindow.getWindow().setFlags( -- cgit v1.2.3