From 7da7a5082dc28a434776bb7f127b00955d7098f0 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sat, 7 May 2022 23:51:00 +0200 Subject: [PATCH] Set the color of the navigation bar Since SDK 21, applications can set the background color of the navigation bar. This is normally simply an item in a theme but it is more complicated for keyboards. --- res/values/themes.xml | 36 ++++++++++++------------- srcs/juloo.keyboard2/Keyboard2View.java | 29 ++++++++++++++++++++ srcs/juloo.keyboard2/Theme.java | 5 ++++ 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/res/values/themes.xml b/res/values/themes.xml index 048d59e..8aa27d7 100644 --- a/res/values/themes.xml +++ b/res/values/themes.xml @@ -20,10 +20,20 @@ + + + - + - - diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index 1b08cf3..9234366 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -1,15 +1,19 @@ package juloo.keyboard2; import android.content.Context; +import android.content.ContextWrapper; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.RectF; +import android.inputmethodservice.InputMethodService; +import android.os.Build.VERSION; import android.os.Vibrator; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; +import android.view.Window; public class Keyboard2View extends View implements View.OnTouchListener, Pointers.IPointerEventHandler @@ -49,10 +53,35 @@ public class Keyboard2View extends View _theme = new Theme(getContext(), attrs); _config = Config.globalConfig(); _pointers = new Pointers(this, _config); + refresh_navigation_bar(context); setOnTouchListener(this); reset(); } + private Window getParentWindow(Context context) + { + if (context instanceof InputMethodService) + return ((InputMethodService)context).getWindow().getWindow(); + if (context instanceof ContextWrapper) + return getParentWindow(((ContextWrapper)context).getBaseContext()); + return null; + } + + public void refresh_navigation_bar(Context context) + { + if (VERSION.SDK_INT < 21) + return; + // The intermediate Window is a [Dialog]. + Window w = getParentWindow(context); + int uiFlags = getSystemUiVisibility(); + if (_theme.isLightNavBar) + uiFlags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; + else + uiFlags &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; + w.setNavigationBarColor(_theme.colorNavBar); + setSystemUiVisibility(uiFlags); + } + public void setKeyboard(KeyboardData kw) { _keyboard = _config.modify_layout(kw); diff --git a/srcs/juloo.keyboard2/Theme.java b/srcs/juloo.keyboard2/Theme.java index 548e291..1461389 100644 --- a/srcs/juloo.keyboard2/Theme.java +++ b/srcs/juloo.keyboard2/Theme.java @@ -18,6 +18,9 @@ public class Theme public final float keyBorderRadius; + public final int colorNavBar; + public final boolean isLightNavBar; + private final Paint _keyLabelPaint; private final Paint _specialKeyLabelPaint; private final Paint _keySubLabelPaint; @@ -29,6 +32,8 @@ public class Theme keyBgPaint.setColor(s.getColor(R.styleable.keyboard_colorKey, 0)); keyDownBgPaint.setColor(s.getColor(R.styleable.keyboard_colorKeyActivated, 0)); // colorKeyboard = s.getColor(R.styleable.keyboard_colorKeyboard, 0); + colorNavBar = s.getColor(R.styleable.keyboard_navigationBarColor, 0); + isLightNavBar = s.getBoolean(R.styleable.keyboard_windowLightNavigationBar, false); labelColor = s.getColor(R.styleable.keyboard_colorLabel, 0); activatedColor = s.getColor(R.styleable.keyboard_colorLabelActivated, 0); lockedColor = s.getColor(R.styleable.keyboard_colorLabelLocked, 0);