diff options
| author | 2024-06-10 15:43:03 +0000 | |
|---|---|---|
| committer | 2024-06-10 15:43:03 +0000 | |
| commit | e0405511e316ce239ce7a43c1c32f730d4c64ea9 (patch) | |
| tree | af08ef1ac36bd7ca825c5672d8f53a48b57519ae | |
| parent | 7220698aea0b46bc40d11b70f28c751770029f98 (diff) | |
| parent | d02442167be89de1345136378bcd511cdc8da5b6 (diff) | |
Merge "Include IME navigation bar in IME insets" into main
| -rw-r--r-- | core/java/android/inputmethodservice/InputMethodService.java | 1 | ||||
| -rw-r--r-- | core/java/android/inputmethodservice/NavigationBarController.java | 31 |
2 files changed, 32 insertions, 0 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index 278e8631622c..4d694372efaf 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -720,6 +720,7 @@ public class InputMethodService extends AbstractInputMethodService { final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsComputer = info -> { onComputeInsets(mTmpInsets); + mNavigationBarController.updateInsets(mTmpInsets); if (!mViewsCreated) { // The IME views are not ready, keep visible insets untouched. mTmpInsets.visibleTopInsets = 0; diff --git a/core/java/android/inputmethodservice/NavigationBarController.java b/core/java/android/inputmethodservice/NavigationBarController.java index 9c55b0ee0623..de67e06ddda7 100644 --- a/core/java/android/inputmethodservice/NavigationBarController.java +++ b/core/java/android/inputmethodservice/NavigationBarController.java @@ -58,6 +58,10 @@ import java.util.Objects; final class NavigationBarController { private interface Callback { + + default void updateInsets(@NonNull InputMethodService.Insets originalInsets) { + } + default void updateTouchableInsets(@NonNull InputMethodService.Insets originalInsets, @NonNull ViewTreeObserver.InternalInsetsInfo dest) { } @@ -96,6 +100,15 @@ final class NavigationBarController { ? new Impl(inputMethodService) : Callback.NOOP; } + /** + * Update the given insets to be at least as big as the IME navigation bar, when visible. + * + * @param originalInsets the insets to check and modify to include the IME navigation bar. + */ + void updateInsets(@NonNull InputMethodService.Insets originalInsets) { + mImpl.updateInsets(originalInsets); + } + void updateTouchableInsets(@NonNull InputMethodService.Insets originalInsets, @NonNull ViewTreeObserver.InternalInsetsInfo dest) { mImpl.updateTouchableInsets(originalInsets, dest); @@ -270,6 +283,24 @@ final class NavigationBarController { } @Override + public void updateInsets(@NonNull InputMethodService.Insets originalInsets) { + if (!mImeDrawsImeNavBar || mNavigationBarFrame == null + || mNavigationBarFrame.getVisibility() != View.VISIBLE + || mService.isFullscreenMode()) { + return; + } + + final int[] loc = new int[2]; + mNavigationBarFrame.getLocationInWindow(loc); + if (originalInsets.contentTopInsets > loc[1]) { + originalInsets.contentTopInsets = loc[1]; + } + if (originalInsets.visibleTopInsets > loc[1]) { + originalInsets.visibleTopInsets = loc[1]; + } + } + + @Override public void updateTouchableInsets(@NonNull InputMethodService.Insets originalInsets, @NonNull ViewTreeObserver.InternalInsetsInfo dest) { if (!mImeDrawsImeNavBar || mNavigationBarFrame == null) { |