Skip to content

Commit

Permalink
Different color for action keys and space bar
Browse files Browse the repository at this point in the history
Keys can be made darker or dimmer individually in layouts.
This is done by setting the new 'role' attributes. Roles are "normal",
"action" and "space_bar".

The "action" role is intended to be used for keys like shift, backspace
and other keys from the bottom row.

Themes and special layouts are updated.
  • Loading branch information
Julow committed Feb 3, 2025
1 parent 545fb38 commit 76736af
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 52 deletions.
33 changes: 32 additions & 1 deletion res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<attr name="colorKey" format="color"/>
<!-- Background of the keys when pressed -->
<attr name="colorKeyActivated" format="color"/>
<!-- Adjust the lightness of keys depending on their role. -->
<attr name="colorKeyAction" format="color"/>
<attr name="colorKeySpaceBar" format="color"/>
<!-- Label colors -->
<attr name="colorLabel" format="color"/>
<attr name="colorLabelActivated" format="color"/>
Expand All @@ -19,6 +22,8 @@
<attr name="keyBorderRadius" format="dimension"/>
<attr name="keyBorderWidth" format="dimension"/>
<attr name="keyBorderWidthActivated" format="dimension"/>
<attr name="keyBorderWidthAction" format="dimension"/>
<attr name="keyBorderWidthSpaceBar" format="dimension"/>
<attr name="keyBorderColorLeft" format="color"/>
<attr name="keyBorderColorTop" format="color"/>
<attr name="keyBorderColorRight" format="color"/>
Expand All @@ -42,6 +47,8 @@
<item name="keyBorderRadius">5dp</item>
<item name="keyBorderWidth">0dp</item>
<item name="keyBorderWidthActivated">0dp</item>
<item name="keyBorderWidthAction">?attr/keyBorderWidth</item>
<item name="keyBorderWidthSpaceBar">?attr/keyBorderWidth</item>
<item name="secondaryDimming">0.25</item>
<item name="greyedDimming">0.5</item>
<item name="emoji_key_bg" type="color">?attr/emoji_button_bg</item>
Expand All @@ -54,8 +61,12 @@
<item name="colorKeyboard">#1b1b1b</item>
<item name="colorKey">#333333</item>
<item name="colorKeyActivated">#1b1b1b</item>
<item name="colorKeyAction">#262626</item>
<item name="colorKeySpaceBar">#2b2b2b</item>
<item name="keyBorderWidth">1.2dp</item>
<item name="keyBorderWidthActivated">0dp</item>
<item name="keyBorderWidthAction">0dp</item>
<item name="keyBorderWidthSpaceBar">0dp</item>
<item name="keyBorderColorBottom">#404040</item>
<item name="colorLabel">#ffffff</item>
<item name="colorLabelActivated">#3399ff</item>
Expand All @@ -69,8 +80,12 @@
<item name="colorKeyboard">#e3e3e3</item>
<item name="colorKey">#cccccc</item>
<item name="colorKeyActivated">#e3e3e3</item>
<item name="colorKeyAction">#d9d9d9</item>
<item name="colorKeySpaceBar">#dedede</item>
<item name="keyBorderWidth">0.6dp</item>
<item name="keyBorderWidthActivated">0dp</item>
<item name="keyBorderWidthAction">0dp</item>
<item name="keyBorderWidthSpaceBar">0dp</item>
<item name="keyBorderColorLeft">#cccccc</item>
<item name="keyBorderColorTop">#eeeeee</item>
<item name="keyBorderColorRight">#cccccc</item>
Expand All @@ -87,6 +102,8 @@
<item name="colorKeyboard">#000000</item>
<item name="colorKey">#000000</item>
<item name="colorKeyActivated">#333333</item>
<item name="colorKeyAction">#000000</item>
<item name="colorKeySpaceBar">#000000</item>
<item name="keyBorderWidth">0dp</item>
<item name="keyBorderWidthActivated">1dp</item>
<item name="keyBorderColorLeft">#2a2a2a</item>
Expand All @@ -108,6 +125,8 @@
<item name="android:isLightTheme">true</item>
<item name="colorKeyboard">#ffffff</item>
<item name="colorKey">#ffffff</item>
<item name="colorKeyAction">#ffffff</item>
<item name="colorKeySpaceBar">#ffffff</item>
<item name="keyBorderWidth">1dp</item>
<item name="keyBorderWidthActivated">1dp</item>
<item name="keyBorderColorLeft">#f0f0f0</item>
Expand All @@ -127,6 +146,8 @@
<item name="android:isLightTheme">true</item>
<item name="colorKeyboard">#ffffff</item>
<item name="colorKey">#ffffff</item>
<item name="colorKeyAction">#ffffff</item>
<item name="colorKeySpaceBar">#ffffff</item>
<item name="keyBorderWidth">2dp</item>
<item name="keyBorderWidthActivated">5dp</item>
<item name="keyBorderColorLeft">#000000</item>
Expand All @@ -148,6 +169,8 @@
<item name="colorKeyboard">#ffe0b2</item>
<item name="colorKey">#fff3e0</item>
<item name="colorKeyActivated">#ffcc80</item>
<item name="colorKeyAction">#ffe9c6</item>
<item name="colorKeySpaceBar">#ffedd0</item>
<item name="colorLabel">#000000</item>
<item name="colorLabelActivated">#ffffff</item>
<item name="colorLabelLocked">#e65100</item>
Expand All @@ -166,6 +189,8 @@
<item name="colorKeyboard">#4db6ac</item>
<item name="colorKey">#e0f2f1</item>
<item name="colorKeyActivated">#00695c</item>
<item name="colorKeyAction">#b8e3de</item>
<item name="colorKeySpaceBar">#c3e7e3</item>
<item name="colorLabel">#000000</item>
<item name="colorLabelActivated">#ffffff</item>
<item name="colorLabelLocked">#64ffda</item>
Expand All @@ -184,6 +209,8 @@
<item name="colorKeyboard">@android:color/system_accent1_100</item>
<item name="colorKey">@android:color/system_accent1_0</item>
<item name="colorKeyActivated">@android:color/system_accent1_300</item>
<item name="colorKeyAction">@android:color/system_accent1_100</item>
<item name="colorKeySpaceBar">@android:color/system_accent1_200</item>
<item name="colorLabel">@android:color/system_accent1_1000</item>
<item name="colorLabelActivated">@android:color/system_accent1_1000</item>
<item name="colorLabelLocked">@android:color/system_accent1_500</item>
Expand All @@ -195,7 +222,9 @@
<item name="android:isLightTheme">false</item>
<item name="colorKeyboard">@android:color/system_neutral1_900</item>
<item name="colorKey">@android:color/system_accent2_800</item>
<item name="colorKeyActivated">@android:color/system_accent1_800</item>
<item name="colorKeyActivated">@android:color/system_accent1_700</item>
<item name="colorKeyAction">@android:color/system_accent2_900</item>
<item name="colorKeySpaceBar">@android:color/system_accent2_900</item>
<item name="colorLabel">@android:color/system_neutral1_0</item>
<item name="colorLabelActivated">@android:color/system_accent1_400</item>
<item name="colorLabelLocked">@android:color/system_accent1_100</item>
Expand All @@ -208,6 +237,8 @@
<item name="colorKeyboard">#191724</item>
<item name="colorKey">#26233a</item>
<item name="colorKeyActivated">#403d52</item>
<item name="colorKeyAction">#2a2740</item>
<item name="colorKeySpaceBar">#2e2b47</item>
<item name="keyBorderWidth">0dp</item>
<item name="keyBorderWidthActivated">1dp</item>
<item name="keyBorderColorLeft">#6e6a86</item>
Expand Down
10 changes: 5 additions & 5 deletions res/xml/bottom_row.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<row height="0.95">
<key width="1.7" key0="ctrl" key1="loc switch_greekmath" key2="loc meta" key3="loc switch_clipboard" key4="switch_numeric"/>
<key width="1.1" key0="fn" key1="loc alt" key2="loc change_method" key3="switch_emoji" key4="config"/>
<key width="4.4" key0="space" key7="switch_forward" key8="switch_backward" key5="cursor_left" key6="cursor_right"/>
<key width="1.1" key0="loc compose" key7="up" key6="right" key5="left" key8="down" key1="loc home" key2="loc page_up" key3="loc end" key4="loc page_down"/>
<key width="1.7" key0="enter" key1="loc voice_typing" key2="action"/>
<key width="1.7" role="action" key0="ctrl" key1="loc switch_greekmath" key2="loc meta" key3="loc switch_clipboard" key4="switch_numeric"/>
<key width="1.1" role="action" key0="fn" key1="loc alt" key2="loc change_method" key3="switch_emoji" key4="config"/>
<key width="4.4" role="space_bar" key0="space" key7="switch_forward" key8="switch_backward" key5="cursor_left" key6="cursor_right"/>
<key width="1.1" role="action" key0="loc compose" key7="up" key6="right" key5="left" key8="down" key1="loc home" key2="loc page_up" key3="loc end" key4="loc page_down"/>
<key width="1.7" role="action" key0="enter" key1="loc voice_typing" key2="action"/>
</row>
8 changes: 4 additions & 4 deletions res/xml/clipboard_bottom_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- The bottom row used in the clipboard history pane. -->
<keyboard bottom_row="false">
<row height="0.95">
<key key0="switch_back_clipboard"/>
<key width="3" key0="space" key5="cursor_left" key6="cursor_right"/>
<key key0="backspace" key2="delete"/>
<key key0="enter" key2="action"/>
<key role="action" key0="switch_back_clipboard"/>
<key width="3" role="space_bar" key0="space" key5="cursor_left" key6="cursor_right"/>
<key role="action" key0="backspace" key2="delete"/>
<key role="action" key0="enter" key2="action"/>
</row>
</keyboard>
8 changes: 4 additions & 4 deletions res/xml/emoji_bottom_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- The bottom row used in the emoji pane. -->
<keyboard bottom_row="false">
<row height="0.95">
<key key0="switch_back_emoji"/>
<key width="3" key0="space" key5="cursor_left" key6="cursor_right"/>
<key key0="backspace" key2="delete"/>
<key key0="enter" key2="action"/>
<key role="action" key0="switch_back_emoji"/>
<key role="space_bar" width="3" key0="space" key5="cursor_left" key6="cursor_right"/>
<key role="action" key0="backspace" key2="delete"/>
<key role="action" key0="enter" key2="action"/>
</row>
</keyboard>
18 changes: 9 additions & 9 deletions res/xml/greekmath.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@
<key key0="ϡ" key1=""/>
</row>
<row>
<key width="1.5" key0="shift" key2="loc capslock"/>
<key width="1.5" role="action" key0="shift" key2="loc capslock"/>
<key key0="ζ" key3="" key4=""/>
<key key0="χ" key3="accent_arrow_right" key4=""/>
<key key0="ϛ" key4=""/>
<key key0="ϟ" key3="" key4=""/>
<key key0="β" key1="" key3="" key4="1"/>
<key key0="ν" key1="" key3="" key4="2"/>
<key key0="μ" key1="" key3="×" key4="3"/>
<key width="1.5" key0="backspace" key3="delete"/>
<key width="1.5" role="action" key0="backspace" key3="delete"/>
</row>
<row height="0.95">
<key width="1.2" key0="switch_text" key2="loc esc"/>
<key width="1.2" key0="switch_numeric" key2="loc tab"/>
<key width="1.2" key0="fn"/>
<key width="2.8" key0="space" key1="superscript" key3="subscript"/>
<key width="1.2" key0="0" key2="."/>
<key width="1.2" key0="loc compose" key7="up" key6="right" key5="left" key8="down"/>
<key width="1.2" key0="enter" key1="=" key2="action"/>
<key width="1.2" role="action" key0="switch_text" key2="loc esc"/>
<key width="1.2" role="action" key0="switch_numeric" key2="loc tab"/>
<key width="1.2" role="action" key0="fn"/>
<key width="2.8" role="space_bar" key0="space" key1="superscript" key3="subscript"/>
<key width="1.2" role="action" key0="0" key2="."/>
<key width="1.2" role="action" key0="loc compose" key7="up" key6="right" key5="left" key8="down"/>
<key width="1.2" role="action" key0="enter" key1="=" key2="action"/>
</row>
</keyboard>
10 changes: 5 additions & 5 deletions res/xml/numeric.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
<key width="0.75" key0="-" key1="^"/>
</row>
<row>
<key width="0.75" key0="switch_greekmath"/>
<key width="0.75" key0="shift" key2="fn" key4="loc alt"/>
<key width="0.75" role="action" key0="switch_greekmath"/>
<key width="0.75" role="action" key0="shift" key2="fn" key4="loc alt"/>
<key key0="1" key1="superscript" key2="ordinal" key3="subscript"/>
<key key0="2"/>
<key key0="3"/>
<key width="1.5" key0="backspace" key2="delete"/>
<key width="1.5" role="action" key0="backspace" key2="delete"/>
</row>
<row height="0.95">
<key width="1.5" key0="switch_text" key2="ctrl"/>
<key width="1.5" role="action" key0="switch_text" key2="ctrl"/>
<key width="1.5" key0="0"/>
<key width="0.75" key0="." key1=":" key2="," key3=";"/>
<key width="0.75" key0="space" key1="&quot;" key2="'" key3="loc compose" key4="_"/>
<key width="1.5" key0="enter" key1="±" key2="action" key3="="/>
<key width="1.5" role="action" key0="enter" key1="±" key2="action" key3="="/>
</row>
</keyboard>
12 changes: 6 additions & 6 deletions res/xml/pin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
<key shift="1.0" key0="1"/>
<key key0="2" indication="ABC"/>
<key key0="3" indication="DEF"/>
<key key0="backspace" key2="delete"/>
<key role="action" key0="backspace" key2="delete"/>
</row>
<row>
<key shift="1.0" key0="4" indication="GHI"/>
<key key0="5" indication="JKL"/>
<key key0="6" indication="MNO"/>
<key key0="(" key1="paste" key2="=" key3=":" key4="-"/>
<key role="action" key0="(" key1="paste" key2="=" key3=":" key4="-"/>
</row>
<row>
<key shift="1.0" key0="7" indication="PQRS"/>
<key key0="8" indication="TUV"/>
<key key0="9" indication="WXYZ"/>
<key key0=")" key2="," key3="/" key4="."/>
<key role="action" key0=")" key2="," key3="/" key4="."/>
</row>
<row>
<key shift="1.0" key0="*" key1="switch_text" key3="switch_numeric"/>
<key role="action" shift="1.0" key0="*" key1="switch_text" key3="switch_numeric"/>
<key key0="0" key3="+" key4="space"/>
<key key0="\#" key7="up" key6="right" key5="left" key8="down"/>
<key key0="action" key2="enter"/>
<key role="action" key0="\#" key7="up" key6="right" key5="left" key8="down"/>
<key role="action" key0="action" key2="enter"/>
</row>
</keyboard>
12 changes: 11 additions & 1 deletion srcs/juloo.keyboard2/Keyboard2View.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,17 @@ protected void onDraw(Canvas canvas)
x += k.shift * _keyWidth;
float keyW = _keyWidth * k.width - _tc.horizontal_margin;
boolean isKeyDown = _pointers.isKeyDown(k);
Theme.Computed.Key tc_key = isKeyDown ? _tc.key_activated : _tc.key;
Theme.Computed.Key tc_key;
if (isKeyDown)
tc_key = _tc.key_activated;
else
switch (k.role)
{
case Action: tc_key = _tc.key_action; break;
case Space_bar: tc_key = _tc.key_space_bar; break;
default:
case Normal: tc_key = _tc.key; break;
}
drawKeyFrame(canvas, x, y, keyW, keyH, tc_key);
if (k.keys[0] != null)
drawLabel(canvas, k.keys[0], keyW / 2f + x, y, keyH, isKeyDown, tc_key);
Expand Down
34 changes: 28 additions & 6 deletions srcs/juloo.keyboard2/KeyboardData.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,19 +403,22 @@ public static class Key
public final float shift;
/** String printed on the keys. It has no other effect. */
public final String indication;
/** Keys are rendered differently according to their role. */
public final Role role;

/** Whether a key was declared with the 'loc' prefix. */
public static final int F_LOC = 1;
public static final int ALL_FLAGS = F_LOC;

protected Key(KeyValue[] ks, KeyValue antic, int f, float w, float s, String i)
protected Key(KeyValue[] ks, KeyValue antic, int f, float w, float s, String i, Role role_)
{
keys = ks;
anticircle = antic;
keysflags = f;
width = Math.max(w, 0f);
shift = Math.max(s, 0f);
indication = i;
role = role_;
}

/** Read a key value attribute that have a synonym. Having both synonyms
Expand Down Expand Up @@ -484,9 +487,11 @@ public static Key parse(XmlPullParser parser) throws Exception
float width = attribute_float(parser, "width", 1f);
float shift = attribute_float(parser, "shift", 0.f);
String indication = parser.getAttributeValue(null, "indication");
String role_str = parser.getAttributeValue(null, "role");
Role role = (role_str == null) ? Role.Normal : Role.parse(role_str);
while (parser.next() != XmlPullParser.END_TAG)
continue;
return new Key(ks, anticircle, keysflags, width, shift, indication);
return new Key(ks, anticircle, keysflags, width, shift, indication, role);
}

/** Whether key at [index] as [flag]. */
Expand All @@ -498,7 +503,7 @@ public boolean keyHasFlag(int index, int flag)
/** New key with the width multiplied by 's'. */
public Key scaleWidth(float s)
{
return new Key(keys, anticircle, keysflags, width * s, shift, indication);
return new Key(keys, anticircle, keysflags, width * s, shift, indication, role);
}

public void getKeys(Map<KeyValue, KeyPos> dst, int row, int col)
Expand All @@ -519,12 +524,12 @@ public Key withKeyValue(int i, KeyValue kv)
for (int j = 0; j < keys.length; j++) ks[j] = keys[j];
ks[i] = kv;
int flags = (keysflags & ~(ALL_FLAGS << i));
return new Key(ks, anticircle, flags, width, shift, indication);
return new Key(ks, anticircle, flags, width, shift, indication, role);
}

public Key withShift(float s)
{
return new Key(keys, anticircle, keysflags, width, s, indication);
return new Key(keys, anticircle, keysflags, width, s, indication, role);
}

public boolean hasValue(KeyValue kv)
Expand All @@ -534,6 +539,23 @@ public boolean hasValue(KeyValue kv)
return true;
return false;
}

public static enum Role
{
Normal,
Action, // Generally Shift, Delete and keys on the bottom row
Space_bar;

public static Role parse(String str)
{
switch (str)
{
case "action": return Action;
case "space_bar": return Space_bar;
default: case "normal": return Normal;
}
}
}
}

// Not using Function<KeyValue, KeyValue> to keep compatibility with Android 6.
Expand All @@ -550,7 +572,7 @@ public Key apply(Key k)
for (int i = 0; i < ks.length; i++)
if (k.keys[i] != null)
ks[i] = apply(k.keys[i], k.keyHasFlag(i, Key.F_LOC));
return new Key(ks, k.anticircle, k.keysflags, k.width, k.shift, k.indication);
return new Key(ks, k.anticircle, k.keysflags, k.width, k.shift, k.indication, k.role);
}
}

Expand Down
Loading

0 comments on commit 76736af

Please sign in to comment.