mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2024-11-21 23:03:11 +01:00
compose: Grey out keys that are not in sequence
Keys that are not in the pending compose sequence are greyed out with the new 'FLAG_GREYED' flag.
This commit is contained in:
parent
065d9520e5
commit
146d520325
@ -12,6 +12,7 @@
|
||||
<attr name="colorLabelActivated" format="color"/>
|
||||
<attr name="colorLabelLocked" format="color"/>
|
||||
<attr name="secondaryDimming" format="float"/>
|
||||
<attr name="greyedDimming" format="float"/>
|
||||
<!-- Corner labels -->
|
||||
<attr name="colorSubLabel" format="color"/>
|
||||
<!-- Borders -->
|
||||
@ -39,6 +40,7 @@
|
||||
<item name="keyBorderWidth">0dp</item>
|
||||
<item name="keyBorderWidthActivated">0dp</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>
|
||||
<item name="emoji_key_text" type="color">?attr/colorLabel</item>
|
||||
</style>
|
||||
|
@ -14,7 +14,7 @@ public final class ComposeKey
|
||||
KeyValue res = apply(state, kv.getChar());
|
||||
// Dim characters not part of any sequence instead of removing them.
|
||||
if (res == null)
|
||||
return kv.withFlags(kv.getFlags() | KeyValue.FLAG_SECONDARY);
|
||||
return kv.withFlags(kv.getFlags() | KeyValue.FLAG_GREYED);
|
||||
return res;
|
||||
/* These keys must not be removed. */
|
||||
case Event:
|
||||
@ -25,7 +25,7 @@ public final class ComposeKey
|
||||
case Keyevent:
|
||||
case Editing:
|
||||
case Placeholder:
|
||||
return kv.withFlags(kv.getFlags() | KeyValue.FLAG_SECONDARY);
|
||||
return kv.withFlags(kv.getFlags() | KeyValue.FLAG_GREYED);
|
||||
case Compose_pending: return null;
|
||||
}
|
||||
return null;
|
||||
|
@ -101,7 +101,9 @@ public final class KeyValue
|
||||
public static final int FLAG_LOCK = (1 << FLAGS_OFFSET << 1);
|
||||
// Special keys are not repeated and don't clear latched modifiers.
|
||||
public static final int FLAG_SPECIAL = (1 << FLAGS_OFFSET << 2);
|
||||
// Free flag: (1 << FLAGS_OFFSET << 3);
|
||||
// Whether the symbol should be greyed out. For example, keys that are not
|
||||
// part of the pending compose sequence.
|
||||
public static final int FLAG_GREYED = (1 << FLAGS_OFFSET << 3);
|
||||
// Rendering flags.
|
||||
public static final int FLAG_KEY_FONT = (1 << FLAGS_OFFSET << 4); // special font file
|
||||
public static final int FLAG_SMALLER_FONT = (1 << FLAGS_OFFSET << 5); // 25% smaller symbols
|
||||
@ -112,8 +114,8 @@ public final class KeyValue
|
||||
|
||||
// Ranges for the different components
|
||||
private static final int FLAGS_BITS =
|
||||
FLAG_LATCH | FLAG_LOCK | FLAG_SPECIAL | FLAG_KEY_FONT | FLAG_SMALLER_FONT |
|
||||
FLAG_SECONDARY | FLAG_LOCKED | FLAG_FAKE_PTR;
|
||||
FLAG_LATCH | FLAG_LOCK | FLAG_SPECIAL | FLAG_GREYED | FLAG_KEY_FONT |
|
||||
FLAG_SMALLER_FONT | FLAG_SECONDARY | FLAG_LOCKED | FLAG_FAKE_PTR;
|
||||
private static final int KIND_BITS = (0b1111 << KIND_OFFSET); // 4 bits wide
|
||||
private static final int VALUE_BITS = ~(FLAGS_BITS | KIND_BITS); // 20 bits wide
|
||||
|
||||
@ -140,9 +142,9 @@ public final class KeyValue
|
||||
return (_code & FLAGS_BITS);
|
||||
}
|
||||
|
||||
public boolean hasFlags(int has)
|
||||
public boolean hasFlagsAny(int has)
|
||||
{
|
||||
return ((_code & has) == has);
|
||||
return ((_code & has) != 0);
|
||||
}
|
||||
|
||||
/** The string to render on the keyboard.
|
||||
|
@ -411,8 +411,12 @@ public class Keyboard2View extends View
|
||||
return _theme.activatedColor;
|
||||
}
|
||||
}
|
||||
if (k.hasFlags(KeyValue.FLAG_SECONDARY))
|
||||
if (k.hasFlagsAny(KeyValue.FLAG_SECONDARY | KeyValue.FLAG_GREYED))
|
||||
{
|
||||
if (k.hasFlagsAny(KeyValue.FLAG_GREYED))
|
||||
return _theme.greyedLabelColor;
|
||||
return _theme.secondaryLabelColor;
|
||||
}
|
||||
return sublabel ? _theme.subLabelColor : _theme.labelColor;
|
||||
}
|
||||
|
||||
@ -422,7 +426,7 @@ public class Keyboard2View extends View
|
||||
if (kv == null)
|
||||
return;
|
||||
float textSize = scaleTextSize(kv, _config.labelTextSize, keyH);
|
||||
Paint p = _theme.labelPaint(kv.hasFlags(KeyValue.FLAG_KEY_FONT));
|
||||
Paint p = _theme.labelPaint(kv.hasFlagsAny(KeyValue.FLAG_KEY_FONT));
|
||||
p.setColor(labelColor(kv, isKeyDown, false));
|
||||
p.setAlpha(_config.labelBrightness);
|
||||
p.setTextSize(textSize);
|
||||
@ -438,7 +442,7 @@ public class Keyboard2View extends View
|
||||
if (kv == null)
|
||||
return;
|
||||
float textSize = scaleTextSize(kv, _config.sublabelTextSize, keyH);
|
||||
Paint p = _theme.subLabelPaint(kv.hasFlags(KeyValue.FLAG_KEY_FONT), a);
|
||||
Paint p = _theme.subLabelPaint(kv.hasFlagsAny(KeyValue.FLAG_KEY_FONT), a);
|
||||
p.setColor(labelColor(kv, isKeyDown, true));
|
||||
p.setAlpha(_config.labelBrightness);
|
||||
p.setTextSize(textSize);
|
||||
@ -472,7 +476,7 @@ public class Keyboard2View extends View
|
||||
|
||||
private float scaleTextSize(KeyValue k, float rel_size, float keyH)
|
||||
{
|
||||
float smaller_font = k.hasFlags(KeyValue.FLAG_SMALLER_FONT) ? 0.75f : 1.f;
|
||||
float smaller_font = k.hasFlagsAny(KeyValue.FLAG_SMALLER_FONT) ? 0.75f : 1.f;
|
||||
return keyH * rel_size * smaller_font * _config.characterSize;
|
||||
}
|
||||
}
|
||||
|
@ -391,7 +391,7 @@ public final class Pointers implements Handler.Callback
|
||||
return true;
|
||||
}
|
||||
// Stop repeating: Special keys
|
||||
if (kv.hasFlags(KeyValue.FLAG_SPECIAL))
|
||||
if (kv.hasFlagsAny(KeyValue.FLAG_SPECIAL))
|
||||
return false;
|
||||
_handler.onPointerHold(kv, ptr.modifiers);
|
||||
return true;
|
||||
|
@ -17,6 +17,7 @@ public class Theme
|
||||
public final int labelColor;
|
||||
public final int subLabelColor;
|
||||
public final int secondaryLabelColor;
|
||||
public final int greyedLabelColor;
|
||||
|
||||
public final float keyBorderRadius;
|
||||
public final float keyBorderWidth;
|
||||
@ -50,6 +51,8 @@ public class Theme
|
||||
subLabelColor = s.getColor(R.styleable.keyboard_colorSubLabel, 0);
|
||||
secondaryLabelColor = adjustLight(labelColor,
|
||||
s.getFloat(R.styleable.keyboard_secondaryDimming, 0.25f));
|
||||
greyedLabelColor = adjustLight(labelColor,
|
||||
s.getFloat(R.styleable.keyboard_greyedDimming, 0.5f));
|
||||
keyBorderRadius = s.getDimension(R.styleable.keyboard_keyBorderRadius, 0);
|
||||
keyBorderWidth = s.getDimension(R.styleable.keyboard_keyBorderWidth, 0);
|
||||
keyBorderWidthActivated = s.getDimension(R.styleable.keyboard_keyBorderWidthActivated, 0);
|
||||
|
@ -166,7 +166,7 @@ public class ExtraKeysPreference extends PreferenceCategory
|
||||
setKey(pref_key_of_key_name(key_name));
|
||||
setDefaultValue(default_checked);
|
||||
setTitle(title);
|
||||
_key_font = kv.hasFlags(KeyValue.FLAG_KEY_FONT);
|
||||
_key_font = kv.hasFlagsAny(KeyValue.FLAG_KEY_FONT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user