Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit af1695a7 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Introduce Window.DecorCallback

This is a follow up CL to my previous CL [1], which introduced a
hidden callback method into Window.Callback.

This CL does not change any observable behavior but consolidate that
hidden callback into a newly introduced Window.DecorCallback
interface.  In this approach, we no longer need to worry about
accidental method name collision in Window.Callback implementations
classes.

Here is the new callback chain.

 ViewRootImpl#performTraversals()
  -> DecorView#onSystemBarAppearanceChanged()
   -> Window.dispatchOnSystemBarAppearanceChanged()
    -> NavigationBarController.Impl#onSystemBarAppearanceChanged()

 [1]: I08566034bebfafff6777ce0152cd6ca1f66f6cad
      678ddce1

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: I5168f76dfc9526e925c565dbfa87597b5543fcdc
parent f376ad2d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -475,7 +475,7 @@ public class InputMethodService extends AbstractInputMethodService {
    private InputMethodPrivilegedOperations mPrivOps = new InputMethodPrivilegedOperations();

    @NonNull
    final NavigationBarController mNavigationBarController =
    private final NavigationBarController mNavigationBarController =
            new NavigationBarController(this);

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
@@ -1504,7 +1504,7 @@ public class InputMethodService extends AbstractInputMethodService {
                Context.LAYOUT_INFLATER_SERVICE);
        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.initSoftInputWindow");
        mWindow = new SoftInputWindow(this, mTheme, mDispatcherState);

        mNavigationBarController.onSoftInputWindowCreated(mWindow);
        {
            final Window window = mWindow.getWindow();
            {
+15 −8
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ final class NavigationBarController {
                @NonNull ViewTreeObserver.InternalInsetsInfo dest) {
        }

        default void onSoftInputWindowCreated(@NonNull SoftInputWindow softInputWindow) {
        }

        default void onViewInitialized() {
        }

@@ -78,9 +81,6 @@ final class NavigationBarController {
                boolean shouldShowImeSwitcherWhenImeIsShown) {
        }

        default void onSystemBarAppearanceChanged(@Appearance int appearance) {
        }

        default String toDebugString() {
            return "No-op implementation";
        }
@@ -101,6 +101,10 @@ final class NavigationBarController {
        mImpl.updateTouchableInsets(originalInsets, dest);
    }

    void onSoftInputWindowCreated(@NonNull SoftInputWindow softInputWindow) {
        mImpl.onSoftInputWindowCreated(softInputWindow);
    }

    void onViewInitialized() {
        mImpl.onViewInitialized();
    }
@@ -117,15 +121,11 @@ final class NavigationBarController {
        mImpl.setShouldShowImeSwitcherWhenImeIsShown(shouldShowImeSwitcherWhenImeIsShown);
    }

    void onSystemBarAppearanceChanged(@Appearance int appearance) {
        mImpl.onSystemBarAppearanceChanged(appearance);
    }

    String toDebugString() {
        return mImpl.toDebugString();
    }

    private static final class Impl implements Callback {
    private static final class Impl implements Callback, Window.DecorCallback {
        private static final int DEFAULT_COLOR_ADAPT_TRANSITION_TIME = 1700;

        // Copied from com.android.systemui.animation.Interpolators#LEGACY_DECELERATE
@@ -361,6 +361,13 @@ final class NavigationBarController {
                    == WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
        }

        @Override
        public void onSoftInputWindowCreated(@NonNull SoftInputWindow softInputWindow) {
            final Window window = softInputWindow.getWindow();
            mAppearance = window.getSystemBarAppearance();
            window.setDecorCallback(this);
        }

        @Override
        public void onViewInitialized() {
            if (mDestroyed) {
+0 −6
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.util.proto.ProtoOutputStream;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowInsetsController;
import android.view.WindowManager;

import java.lang.annotation.Retention;
@@ -264,11 +263,6 @@ final class SoftInputWindow extends Dialog {
        }
    }

    @Override
    public void onSystemBarAppearanceChanged(@WindowInsetsController.Appearance int appearance) {
        mService.mNavigationBarController.onSystemBarAppearanceChanged(appearance);
    }

    void dumpDebug(ProtoOutputStream proto, long fieldId) {
        final long token = proto.start(fieldId);
        mBounds.dumpDebug(proto, BOUNDS);
+34 −11
Original line number Diff line number Diff line
@@ -295,6 +295,9 @@ public abstract class Window {
    private OnWindowDismissedCallback mOnWindowDismissedCallback;
    private OnWindowSwipeDismissedCallback mOnWindowSwipeDismissedCallback;
    private WindowControllerCallback mWindowControllerCallback;
    @WindowInsetsController.Appearance
    private int mSystemBarAppearance;
    private DecorCallback mDecorCallback;
    private OnRestrictedCaptionAreaChangedListener mOnRestrictedCaptionAreaChangedListener;
    private Rect mRestrictedCaptionAreaRect;
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
@@ -607,17 +610,6 @@ public abstract class Window {
         * @param hasCapture True if the window has pointer capture.
         */
        default public void onPointerCaptureChanged(boolean hasCapture) { };

        /**
         * Called from
         * {@link com.android.internal.policy.DecorView#onSystemBarAppearanceChanged(int)}.
         *
         * @param appearance The newly applied appearance.
         * @hide
         */
        default void onSystemBarAppearanceChanged(
                @WindowInsetsController.Appearance int appearance) {
        }
    }

    /** @hide */
@@ -672,6 +664,17 @@ public abstract class Window {
        void updateNavigationBarColor(int color);
    }

    /** @hide */
    public interface DecorCallback {
        /**
         * Called from
         * {@link com.android.internal.policy.DecorView#onSystemBarAppearanceChanged(int)}.
         *
         * @param appearance The newly applied appearance.
         */
        void onSystemBarAppearanceChanged(@WindowInsetsController.Appearance int appearance);
    }

    /**
     * Callback for clients that want to be aware of where caption draws content.
     */
@@ -996,6 +999,26 @@ public abstract class Window {
        return mWindowControllerCallback;
    }

    /** @hide */
    public final void setDecorCallback(DecorCallback decorCallback) {
        mDecorCallback = decorCallback;
    }

    /** @hide */
    @WindowInsetsController.Appearance
    public final int getSystemBarAppearance() {
        return mSystemBarAppearance;
    }

    /** @hide */
    public final void dispatchOnSystemBarAppearanceChanged(
            @WindowInsetsController.Appearance int appearance) {
        mSystemBarAppearance = appearance;
        if (mDecorCallback != null) {
            mDecorCallback.onSystemBarAppearanceChanged(appearance);
        }
    }

    /**
     * Set a callback for changes of area where caption will draw its content.
     *
+0 −5
Original line number Diff line number Diff line
@@ -163,10 +163,5 @@ public class WindowCallbackWrapper implements Window.Callback {
    public void onPointerCaptureChanged(boolean hasCapture) {
        mWrapped.onPointerCaptureChanged(hasCapture);
    }

    @Override
    public void onSystemBarAppearanceChanged(@WindowInsetsController.Appearance int appearance) {
        mWrapped.onSystemBarAppearanceChanged(appearance);
    }
}
Loading