forked from extern/Unexpected-Keyboard
Lockable keys
This commit is contained in:
parent
1115a34a19
commit
12a04ae2c7
@ -4,5 +4,6 @@
|
||||
<item name="key_bg" type="color">#282828</item>
|
||||
<item name="key_down_bg" type="color">#1B1B1B</item>
|
||||
<item name="key_label" type="color">#DDDDDD</item>
|
||||
<item name="key_label_locked" type="color">#229933</item>
|
||||
<item name="key_sub_label" type="color">#BDBDBD</item>
|
||||
</resources>
|
||||
|
@ -10,9 +10,12 @@ class KeyValue
|
||||
public static final int EVENT_DELETE = -3;
|
||||
|
||||
public static final int FLAG_KEEP_ON = 1;
|
||||
public static final int FLAG_CTRL = (1 << 1);
|
||||
public static final int FLAG_SHIFT = (1 << 2);
|
||||
public static final int FLAG_ALT = (1 << 3);
|
||||
public static final int FLAG_LOCK = (1 << 1);
|
||||
public static final int FLAG_CTRL = (1 << 2);
|
||||
public static final int FLAG_SHIFT = (1 << 3);
|
||||
public static final int FLAG_ALT = (1 << 4);
|
||||
public static final int FLAG_NOCHAR = (1 << 5);
|
||||
public static final int FLAG_LOCKED = (1 << 8);
|
||||
|
||||
private String _name;
|
||||
private String _symbol;
|
||||
@ -92,9 +95,9 @@ class KeyValue
|
||||
for (int i = 0; i < chars.length(); i++)
|
||||
new KeyValue(chars.substring(i, i + 1));
|
||||
|
||||
new KeyValue("shift", "⇧", '\0', EVENT_NONE, FLAG_KEEP_ON | FLAG_SHIFT);
|
||||
new KeyValue("ctrl", "Ctrl", '\0', EVENT_NONE, FLAG_KEEP_ON | FLAG_CTRL);
|
||||
new KeyValue("alt", "Alt", '\0', EVENT_NONE, FLAG_KEEP_ON | FLAG_ALT);
|
||||
new KeyValue("shift", "⇧", 'S', EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_LOCK | FLAG_SHIFT);
|
||||
new KeyValue("ctrl", "Ctrl", 'C', EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_CTRL);
|
||||
new KeyValue("alt", "Alt", 'A', EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ALT);
|
||||
|
||||
new KeyValue("backspace", "⌫", EVENT_BACKSPACE);
|
||||
new KeyValue("delete", "⌦", EVENT_DELETE);
|
||||
|
@ -33,6 +33,7 @@ public class Keyboard2View extends View
|
||||
private Paint _keyBgPaint = new Paint();
|
||||
private Paint _keyDownBgPaint = new Paint();
|
||||
private Paint _keyLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
private Paint _keyLabelLockedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
private Paint _keySubLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
|
||||
public Keyboard2View(Context context, AttributeSet attrs)
|
||||
@ -51,6 +52,9 @@ public class Keyboard2View extends View
|
||||
_keyLabelPaint.setColor(getResources().getColor(R.color.key_label));
|
||||
_keyLabelPaint.setTextSize(getResources().getDimension(R.dimen.label_text_size));
|
||||
_keyLabelPaint.setTextAlign(Paint.Align.CENTER);
|
||||
_keyLabelLockedPaint.setColor(getResources().getColor(R.color.key_label_locked));
|
||||
_keyLabelLockedPaint.setTextSize(getResources().getDimension(R.dimen.label_text_size));
|
||||
_keyLabelLockedPaint.setTextAlign(Paint.Align.CENTER);
|
||||
_keySubLabelPaint.setColor(getResources().getColor(R.color.key_sub_label));
|
||||
_keySubLabelPaint.setTextSize(getResources().getDimension(R.dimen.sublabel_text_size));
|
||||
_keySubLabelPaint.setTextAlign(Paint.Align.CENTER);
|
||||
@ -141,7 +145,12 @@ public class Keyboard2View extends View
|
||||
KeyDown down = getKeyDown(key);
|
||||
if (down != null)
|
||||
{
|
||||
if (down.pointerId == -1)
|
||||
if ((down.flags & KeyValue.FLAG_LOCK) != 0)
|
||||
{
|
||||
down.flags ^= KeyValue.FLAG_LOCK;
|
||||
down.flags |= KeyValue.FLAG_LOCKED;
|
||||
}
|
||||
else if (down.pointerId == -1)
|
||||
down.pointerId = pointerId;
|
||||
}
|
||||
else
|
||||
@ -170,12 +179,12 @@ public class Keyboard2View extends View
|
||||
for (int i = 0; i < _downKeys.size(); i++)
|
||||
{
|
||||
KeyDown downKey = _downKeys.get(i);
|
||||
if (downKey.pointerId == -1)
|
||||
if (downKey.pointerId == -1 && (downKey.flags & KeyValue.FLAG_LOCKED) == 0)
|
||||
_downKeys.remove(i--);
|
||||
else if ((downKey.flags & KeyValue.FLAG_KEEP_ON) != 0)
|
||||
downKey.flags ^= KeyValue.FLAG_KEEP_ON;
|
||||
}
|
||||
if (k.value != null)
|
||||
if (k.value != null && (k.flags & (KeyValue.FLAG_LOCKED | KeyValue.FLAG_NOCHAR)) == 0)
|
||||
_ime.handleKeyUp(k.value, _flags);
|
||||
_downKeys.remove(k);
|
||||
updateFlags();
|
||||
@ -218,7 +227,8 @@ public class Keyboard2View extends View
|
||||
for (KeyboardData.Key k : row)
|
||||
{
|
||||
float keyW = _keyWidth * k.width;
|
||||
if (getKeyDown(k) != null)
|
||||
KeyDown keyDown = getKeyDown(k);
|
||||
if (keyDown != null)
|
||||
canvas.drawRect(x + _keyBgPadding, y + _keyBgPadding,
|
||||
x + keyW - _keyBgPadding, y + _keyHeight - _keyBgPadding, _keyDownBgPaint);
|
||||
else
|
||||
@ -226,7 +236,9 @@ public class Keyboard2View extends View
|
||||
x + keyW - _keyBgPadding, y + _keyHeight - _keyBgPadding), _keyRound, _keyRound, _keyBgPaint);
|
||||
if (k.key0 != null)
|
||||
canvas.drawText(k.key0.getSymbol(upperCase), keyW / 2 + x,
|
||||
(_keyHeight + _keyLabelPaint.getTextSize()) / 2 + y, _keyLabelPaint);
|
||||
(_keyHeight + _keyLabelPaint.getTextSize()) / 2 + y,
|
||||
(keyDown != null && (keyDown.flags & KeyValue.FLAG_LOCKED) != 0)
|
||||
? _keyLabelLockedPaint : _keyLabelPaint);
|
||||
float textOffsetY = _keySubLabelPaint.getTextSize() / 2;
|
||||
float subPadding = _keyPadding + _keyBgPadding;
|
||||
if (k.key1 != null)
|
||||
|
Loading…
Reference in New Issue
Block a user