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

Commit 666324ec authored by Yohei Yukawa's avatar Yohei Yukawa Committed by Android (Google) Code Review
Browse files

Merge "Support light navigation bar"

parents 1e4e6962 678ddce1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -475,7 +475,7 @@ public class InputMethodService extends AbstractInputMethodService {
    private InputMethodPrivilegedOperations mPrivOps = new InputMethodPrivilegedOperations();

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

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
+47 −0
Original line number Diff line number Diff line
@@ -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() {
@@ -388,10 +403,42 @@ 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)
                    + "}";
        }
    }
+12 −4
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static java.lang.annotation.RetentionPolicy.SOURCE;

import android.annotation.IntDef;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Rect;
import android.os.Debug;
import android.os.IBinder;
@@ -32,6 +31,7 @@ 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;
@@ -47,6 +47,7 @@ final class SoftInputWindow extends Dialog {

    private final KeyEvent.DispatcherState mDispatcherState;
    private final Rect mBounds = new Rect();
    private final InputMethodService mService;

    @Retention(SOURCE)
    @IntDef(value = {WindowState.TOKEN_PENDING, WindowState.TOKEN_SET,
@@ -120,7 +121,7 @@ final class SoftInputWindow extends Dialog {
    /**
     * Create a SoftInputWindow that uses a custom style.
     *
     * @param context The Context in which the DockWindow should run. In
     * @param service The {@link InputMethodService} in which the DockWindow should run. In
     *        particular, it uses the window manager and theme from this context
     *        to present its UI.
     * @param theme A style resource describing the theme to use for the window.
@@ -129,8 +130,10 @@ final class SoftInputWindow extends Dialog {
     *        using styles. This theme is applied on top of the current theme in
     *        <var>context</var>. If 0, the default dialog theme will be used.
     */
    SoftInputWindow(Context context, int theme, KeyEvent.DispatcherState dispatcherState) {
        super(context, theme);
    SoftInputWindow(InputMethodService service, int theme,
            KeyEvent.DispatcherState dispatcherState) {
        super(service, theme);
        mService = service;
        mDispatcherState = dispatcherState;
    }

@@ -261,6 +264,11 @@ 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);
+11 −0
Original line number Diff line number Diff line
@@ -607,6 +607,17 @@ 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 */
+5 −0
Original line number Diff line number Diff line
@@ -163,5 +163,10 @@ 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