diff options
| author | Jules Aguillon | 2022-05-07 23:51:00 +0200 |
|---|---|---|
| committer | Jules Aguillon | 2022-05-07 23:51:00 +0200 |
| commit | 7da7a5082dc28a434776bb7f127b00955d7098f0 (patch) | |
| tree | 8b76e3776a3294003be269ac96b1682731f97039 /srcs | |
| parent | 80600ed65906a87b190a3424fa1b279073fa1164 (diff) | |
| download | unexpected-keyboard-7da7a5082dc28a434776bb7f127b00955d7098f0.tar.gz unexpected-keyboard-7da7a5082dc28a434776bb7f127b00955d7098f0.zip | |
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.
Diffstat (limited to 'srcs')
| -rw-r--r-- | srcs/juloo.keyboard2/Keyboard2View.java | 29 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/Theme.java | 5 |
2 files changed, 34 insertions, 0 deletions
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); |
