abouttreesummaryrefslogcommitdiff
diff options
context:
space:
mode:
authorJules Aguillon2022-05-07 23:51:00 +0200
committerJules Aguillon2022-05-07 23:51:00 +0200
commit7da7a5082dc28a434776bb7f127b00955d7098f0 (patch)
tree8b76e3776a3294003be269ac96b1682731f97039
parent80600ed65906a87b190a3424fa1b279073fa1164 (diff)
downloadunexpected-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.
-rw-r--r--res/values/themes.xml36
-rw-r--r--srcs/juloo.keyboard2/Keyboard2View.java29
-rw-r--r--srcs/juloo.keyboard2/Theme.java5
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 @@
<attr name="emoji_color" type="color" format="color"/>
<attr name="emoji_key_bg" type="color" format="color"/>
<attr name="emoji_key_text" type="color" format="color"/>
+ <!-- System integration -->
+ <attr name="navigationBarColor" format="color"/>
+ <attr name="windowLightNavigationBar" format="boolean"/>
</declare-styleable>
- <style name="Dark">
- <item name="android:isLightTheme">false</item>
+ <style name="BaseTheme">
<item name="android:forceDarkAllowed">false</item>
+ <item name="navigationBarColor">?attr/colorKeyboard</item>
+ <item name="windowLightNavigationBar">?attr/android:isLightTheme</item>
+ <item name="keyBorderRadius">5dp</item>
+ <item name="emoji_key_bg" type="color">?attr/emoji_button_bg</item>
+ <item name="emoji_key_text" type="color">?attr/colorLabel</item>
+ </style>
+ <style name="Dark" parent="BaseTheme">
+ <item name="android:isLightTheme">false</item>
<item name="colorKeyboard">#1b1b1b</item>
<item name="colorKey">#333333</item>
<item name="colorKeyActivated">#1b1b1b</item>
@@ -31,15 +41,11 @@
<item name="colorLabelActivated">#3399ff</item>
<item name="colorLabelLocked">#33cc33</item>
<item name="colorSubLabel">#cccccc</item>
- <item name="keyBorderRadius">5dp</item>
<item name="emoji_button_bg" type="color">#202020</item>
<item name="emoji_color" type="color">#ffffff</item>
- <item name="emoji_key_bg" type="color">?attr/emoji_button_bg</item>
- <item name="emoji_key_text" type="color">?attr/colorLabel</item>
</style>
- <style name="Light">
+ <style name="Light" parent="BaseTheme">
<item name="android:isLightTheme">true</item>
- <item name="android:forceDarkAllowed">false</item>
<item name="colorKeyboard">#e3e3e3</item>
<item name="colorKey">#cccccc</item>
<item name="colorKeyActivated">#e3e3e3</item>
@@ -47,15 +53,11 @@
<item name="colorLabelActivated">#0066cc</item>
<item name="colorLabelLocked">#33cc33</item>
<item name="colorSubLabel">#333333</item>
- <item name="keyBorderRadius">5dp</item>
- <item name="emoji_button_bg" type="color">#dedede</item>
- <item name="emoji_color" type="color">#000000</item>
- <item name="emoji_key_bg" type="color">?attr/emoji_button_bg</item>
- <item name="emoji_key_text" type="color">?attr/colorLabel</item>
+ <item name="emoji_button_bg">#dedede</item>
+ <item name="emoji_color">#000000</item>
</style>
- <style name="Black">
+ <style name="Black" parent="BaseTheme">
<item name="android:isLightTheme">false</item>
- <item name="android:forceDarkAllowed">false</item>
<item name="colorKeyboard">#000000</item>
<item name="colorKey">#000000</item>
<item name="colorKeyActivated">#333333</item>
@@ -64,9 +66,7 @@
<item name="colorLabelLocked">#00ff26</item>
<item name="colorSubLabel">#bbbbbb</item>
<item name="keyBorderRadius">1dp</item>
- <item name="emoji_button_bg" type="color">#000000</item>
- <item name="emoji_color" type="color">#ffffff</item>
- <item name="emoji_key_bg" type="color">?attr/emoji_button_bg</item>
- <item name="emoji_key_text" type="color">?attr/colorLabel</item>
+ <item name="emoji_button_bg">#000000</item>
+ <item name="emoji_color">#ffffff</item>
</style>
</resources>
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);