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

Commit 85980d54 authored by Georg Veichtlbauer's avatar Georg Veichtlbauer
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.

Change-Id: Ibf81a90a238583084a102af8b70a16f5b894e5a2
parent 91a45bb4
Loading
Loading
Loading
Loading
+21 −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;
@@ -1082,7 +1085,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
    @Override
    public void onWindowShown() {
        super.onWindowShown();
        setNavigationBarVisibility(isInputViewShown());
        updateNavigationBarColor();
    }

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

    void onFinishInputInternal() {
@@ -2027,12 +2029,22 @@ 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() {
        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);
        }
    }
}