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

Unverified Commit 08ff39a1 authored by Georg Veichtlbauer's avatar Georg Veichtlbauer Committed by Michael Bestas
Browse files

LatinIME: Set navigation bar color to KB background

Black navbar is especially irritating in light mode. We have to use
the deprecated API because with the new one the close and IME switcher
icons in the navbar don't get drawn in the correct colors.

Includes Id0e624c590166dd4537c5bec218b8acd4842fa64.

Change-Id: Ibf81a90a238583084a102af8b70a16f5b894e5a2
parent 3c666441
Loading
Loading
Loading
Loading
+25 −9
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.inputmethod.latin;

import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
import static com.android.inputmethod.latin.common.Constants.ImeOption.FORCE_ASCII;
import static com.android.inputmethod.latin.common.Constants.ImeOption.NO_MICROPHONE;
import static com.android.inputmethod.latin.common.Constants.ImeOption.NO_MICROPHONE_COMPAT;
@@ -31,7 +33,8 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.inputmethodservice.InputMethodService;
import android.media.AudioManager;
import android.os.Build;
@@ -1097,7 +1100,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
    @Override
    public void onWindowShown() {
        super.onWindowShown();
        setNavigationBarVisibility(isInputViewShown());
        updateNavigationBarColor();
    }

    @Override
@@ -1107,7 +1110,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
        if (mainKeyboardView != null) {
            mainKeyboardView.closing();
        }
        setNavigationBarVisibility(false);
    }

    void onFinishInputInternal() {
@@ -2042,12 +2044,26 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
        return mRichImm.shouldOfferSwitchingToNextInputMethod(token, fallbackValue);
    }

    private void setNavigationBarVisibility(final boolean visible) {
        if (BuildCompatUtils.EFFECTIVE_SDK_INT > Build.VERSION_CODES.M) {
            // For N and later, IMEs can specify Color.TRANSPARENT to make the navigation bar
            // transparent.  For other colors the system uses the default color.
            getWindow().getWindow().setNavigationBarColor(
                    visible ? Color.BLACK : Color.TRANSPARENT);
    /** @noinspection deprecation*/
    private void updateNavigationBarColor() {
        // This may happen for devices with a physical keyboard
        if (mInputView == null)
            return;

        if (BuildCompatUtils.EFFECTIVE_SDK_INT > Build.VERSION_CODES.R) {
            Drawable bg = mInputView.findViewById(R.id.keyboard_view).getBackground();
            Window w = getWindow().getWindow();
            if (bg instanceof ColorDrawable) {
                w.setNavigationBarColor(((ColorDrawable) bg).getColor());
            }

            int nightModeFlags = mDisplayContext.getResources().getConfiguration().uiMode &
                    Configuration.UI_MODE_NIGHT_MASK;
            int flags = FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
            if (nightModeFlags != Configuration.UI_MODE_NIGHT_YES) {
                flags |= APPEARANCE_LIGHT_NAVIGATION_BARS;
            }
            w.getDecorView().setSystemUiVisibility(flags);
        }
    }
}