diff options
| author | Yohei Yukawa <yukawa@google.com> | 2022-01-27 10:29:33 -0800 |
|---|---|---|
| committer | Yohei Yukawa <yukawa@google.com> | 2022-01-27 10:29:33 -0800 |
| commit | 678ddce11c131a8e6746fe386c40ddc8d99d01c3 (patch) | |
| tree | 0681704cedf5ae4fa1d8a3c1cf88756cc8fd7710 /core/java/android/inputmethodservice/NavigationBarController.java | |
| parent | fd190e8b9a12fd68e6a200c40967137e8cbcc9ec (diff) | |
Support light navigation bar
In order to propagate the information about whether the IME is using
light navigation bar or not from
android.view.ViewRootImpl
to
android.inputmethodservice.NavigationBarController
within the same process, this CL adds a new @hide method to
Window.Callback
as follows.
ViewRootImpl#performTraversals()
-> DecorView#onSystemBarAppearanceChanged()
-> Window.Callback#onSystemBarAppearanceChanged()
-> SoftInputWindow#onSystemBarAppearanceChanged()
-> NavigationBarController#onSystemBarAppearanceChanged()
Button color transition will be implemented in a subsequent CL.
Bug: 215549533
Test: Manually tested with ThemedNavBarKeyboard sample
1. Build aosp_coral-userdebug and flash it
2. adb root
3. adb shell setprop \
persist.sys.ime.can_render_gestural_nav_buttons true
4. adb reboot
5. make -j ThemedNavBarKeyboard
6. adb install -r \
$OUT/system/app/ThemedNavBarKeyboard/ThemedNavBarKeyboard.apk
7. adb shell ime enable \
com.example.android.themednavbarkeyboard/.ThemedNavBarKeyboard
8. adb shell ime set \
com.example.android.themednavbarkeyboard/.ThemedNavBarKeyboard
9. Open the Dialer app
10. Focus in the top edit field.
11. Tap "EXTENDED LIGHT NAVIGARION BAR" mode
12. Make sure that the navigation button color is optimized for light
navigation bar.
13. Tap "STANDARD LIGHT NAVIGARION BAR" mode
14. Make sure that the navigation button color is optimized for light
navigation bar.
Change-Id: I08566034bebfafff6777ce0152cd6ca1f66f6cad
Diffstat (limited to 'core/java/android/inputmethodservice/NavigationBarController.java')
| -rw-r--r-- | core/java/android/inputmethodservice/NavigationBarController.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/core/java/android/inputmethodservice/NavigationBarController.java b/core/java/android/inputmethodservice/NavigationBarController.java index a6e475aeb813..2484cf079c56 100644 --- a/core/java/android/inputmethodservice/NavigationBarController.java +++ b/core/java/android/inputmethodservice/NavigationBarController.java @@ -17,7 +17,9 @@ package android.inputmethodservice; import static android.content.Intent.ACTION_OVERLAY_CHANGED; +import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS; +import android.annotation.FloatRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.StatusBarManager; @@ -40,6 +42,7 @@ import android.view.ViewParent; import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowInsets; +import android.view.WindowInsetsController.Appearance; import android.view.WindowManagerPolicyConstants; import android.widget.FrameLayout; @@ -68,6 +71,9 @@ final class NavigationBarController { default void onDestroy() { } + default void onSystemBarAppearanceChanged(@Appearance int appearance) { + } + default String toDebugString() { return "No-op implementation"; } @@ -100,6 +106,10 @@ final class NavigationBarController { mImpl.onDestroy(); } + void onSystemBarAppearanceChanged(@Appearance int appearance) { + mImpl.onSystemBarAppearanceChanged(appearance); + } + String toDebugString() { return mImpl.toDebugString(); } @@ -120,6 +130,9 @@ final class NavigationBarController { @Nullable private BroadcastReceiver mSystemOverlayChangedReceiver; + @Appearance + private int mAppearance; + Impl(@NonNull InputMethodService inputMethodService) { mService = inputMethodService; } @@ -187,6 +200,8 @@ final class NavigationBarController { } mNavigationBarFrame.setBackground(null); + + setIconTintInternal(calculateTargetDarkIntensity(mAppearance)); } private void uninstallNavigationBarFrameIfNecessary() { @@ -389,9 +404,41 @@ final class NavigationBarController { } @Override + public void onSystemBarAppearanceChanged(@Appearance int appearance) { + if (mDestroyed) { + return; + } + + mAppearance = appearance; + + if (mNavigationBarFrame == null) { + return; + } + + final float targetDarkIntensity = calculateTargetDarkIntensity(mAppearance); + setIconTintInternal(targetDarkIntensity); + } + + private void setIconTintInternal(float darkIntensity) { + final NavigationBarView navigationBarView = + mNavigationBarFrame.findViewByPredicate(NavigationBarView.class::isInstance); + if (navigationBarView == null) { + return; + } + navigationBarView.setDarkIntensity(darkIntensity); + } + + @FloatRange(from = 0.0f, to = 1.0f) + private static float calculateTargetDarkIntensity(@Appearance int appearance) { + final boolean lightNavBar = (appearance & APPEARANCE_LIGHT_NAVIGATION_BARS) != 0; + return lightNavBar ? 1.0f : 0.0f; + } + + @Override public String toDebugString() { return "{mRenderGesturalNavButtons=" + mRenderGesturalNavButtons + " mNavigationBarFrame=" + mNavigationBarFrame + + " mAppearance=0x" + Integer.toHexString(mAppearance) + "}"; } } |
