This commit is contained in:
juloo 2015-08-18 01:25:47 +02:00
parent 8f3d1a4d38
commit d81509d7ec
4 changed files with 89 additions and 61 deletions

View File

@ -14,8 +14,8 @@
</row>
<row>
<key key0="a" key1="tab" />
<key key0="s" />
<key key0="d" />
<key key0="s" key1="accent1" key2="accent2" />
<key key0="d" key1="accent3" key2="accent4" key3="accent5" />
<key key0="f" />
<key key0="g" key2="-" key3="_" />
<key key0="h" key2="=" key3="+" />

View File

@ -1,5 +1,6 @@
package juloo.keyboard2;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import java.util.HashMap;
@ -17,6 +18,12 @@ class KeyValue
public static final int FLAG_NOCHAR = (1 << 5);
public static final int FLAG_LOCKED = (1 << 8);
public static final int FLAG_ACCENT1 = (1 << 16);
public static final int FLAG_ACCENT2 = (1 << 17);
public static final int FLAG_ACCENT3 = (1 << 18);
public static final int FLAG_ACCENT4 = (1 << 19);
public static final int FLAG_ACCENT5 = (1 << 20);
private String _name;
private String _symbol;
private char _char;
@ -28,17 +35,33 @@ class KeyValue
return (_name);
}
public String getSymbol(boolean upperCase)
public String getSymbol(int flags)
{
if (upperCase)
return (_symbol.toUpperCase());
if (_symbol == null)
return (String.valueOf(getChar(flags)));
return (_symbol);
}
public char getChar(boolean upperCase)
public char getChar(int flags)
{
if (upperCase)
return (Character.toUpperCase(_char));
if (flags != 0)
{
char c = _char;
if ((flags & FLAG_SHIFT) != 0)
c = Character.toUpperCase(_char);
if ((flags & FLAG_ACCENT1) != 0)
c = (char)KeyCharacterMap.getDeadChar('\u02CB', (int)c);
if ((flags & FLAG_ACCENT2) != 0)
c = (char)KeyCharacterMap.getDeadChar('\u00B4', (int)c);
if ((flags & FLAG_ACCENT3) != 0)
c = (char)KeyCharacterMap.getDeadChar('\u02C6', (int)c);
if ((flags & FLAG_ACCENT4) != 0)
c = (char)KeyCharacterMap.getDeadChar('\u02DC', (int)c);
if ((flags & FLAG_ACCENT5) != 0)
c = (char)KeyCharacterMap.getDeadChar('\u00B8', (int)c);
if (c != 0)
return (c);
}
return (_char);
}
@ -71,10 +94,9 @@ class KeyValue
static
{
String chars = "àçéèêë<>"
+ "\"'(-_)=°+"
String chars = "<>&\"'(-_)=°+"
+ "~#{[|`\\^@]}"
+ "^$ù*,;:!¨£%µ?./§";
+ "^$*,;:!£%µ?./§";
for (int i = 0; i < chars.length(); i++)
{
String key = chars.substring(i, i + 1);
@ -84,43 +106,48 @@ class KeyValue
new KeyValue("shift", "", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_LOCK | FLAG_SHIFT);
new KeyValue("ctrl", "Ctrl", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_CTRL);
new KeyValue("alt", "Alt", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ALT);
new KeyValue("accent1", "\u02CB", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ACCENT1);
new KeyValue("accent2", "\u00B4", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ACCENT2);
new KeyValue("accent3", "\u02C6", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ACCENT3);
new KeyValue("accent4", "\u02DC", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ACCENT4);
new KeyValue("accent5", "\u00B8", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ACCENT5);
new KeyValue("a", "a", 'a', KeyEvent.KEYCODE_A, 0);
new KeyValue("b", "b", 'b', KeyEvent.KEYCODE_B, 0);
new KeyValue("c", "c", 'c', KeyEvent.KEYCODE_C, 0);
new KeyValue("d", "d", 'd', KeyEvent.KEYCODE_D, 0);
new KeyValue("e", "e", 'e', KeyEvent.KEYCODE_E, 0);
new KeyValue("f", "f", 'f', KeyEvent.KEYCODE_F, 0);
new KeyValue("g", "g", 'g', KeyEvent.KEYCODE_G, 0);
new KeyValue("h", "h", 'h', KeyEvent.KEYCODE_H, 0);
new KeyValue("i", "i", 'i', KeyEvent.KEYCODE_I, 0);
new KeyValue("j", "j", 'j', KeyEvent.KEYCODE_J, 0);
new KeyValue("k", "k", 'k', KeyEvent.KEYCODE_K, 0);
new KeyValue("l", "l", 'l', KeyEvent.KEYCODE_L, 0);
new KeyValue("m", "m", 'm', KeyEvent.KEYCODE_M, 0);
new KeyValue("n", "n", 'n', KeyEvent.KEYCODE_N, 0);
new KeyValue("o", "o", 'o', KeyEvent.KEYCODE_O, 0);
new KeyValue("p", "p", 'p', KeyEvent.KEYCODE_P, 0);
new KeyValue("q", "q", 'q', KeyEvent.KEYCODE_Q, 0);
new KeyValue("r", "r", 'r', KeyEvent.KEYCODE_R, 0);
new KeyValue("s", "s", 's', KeyEvent.KEYCODE_S, 0);
new KeyValue("t", "t", 't', KeyEvent.KEYCODE_T, 0);
new KeyValue("u", "u", 'u', KeyEvent.KEYCODE_U, 0);
new KeyValue("v", "v", 'v', KeyEvent.KEYCODE_V, 0);
new KeyValue("w", "w", 'w', KeyEvent.KEYCODE_W, 0);
new KeyValue("x", "x", 'x', KeyEvent.KEYCODE_X, 0);
new KeyValue("y", "y", 'y', KeyEvent.KEYCODE_Y, 0);
new KeyValue("z", "z", 'z', KeyEvent.KEYCODE_Z, 0);
new KeyValue("0", "0", '0', KeyEvent.KEYCODE_0, 0);
new KeyValue("1", "1", '1', KeyEvent.KEYCODE_1, 0);
new KeyValue("2", "2", '2', KeyEvent.KEYCODE_2, 0);
new KeyValue("3", "3", '3', KeyEvent.KEYCODE_3, 0);
new KeyValue("4", "4", '4', KeyEvent.KEYCODE_4, 0);
new KeyValue("5", "5", '5', KeyEvent.KEYCODE_5, 0);
new KeyValue("6", "6", '6', KeyEvent.KEYCODE_6, 0);
new KeyValue("7", "7", '7', KeyEvent.KEYCODE_7, 0);
new KeyValue("8", "8", '8', KeyEvent.KEYCODE_8, 0);
new KeyValue("9", "9", '9', KeyEvent.KEYCODE_9, 0);
new KeyValue("a", null, 'a', KeyEvent.KEYCODE_A, 0);
new KeyValue("b", null, 'b', KeyEvent.KEYCODE_B, 0);
new KeyValue("c", null, 'c', KeyEvent.KEYCODE_C, 0);
new KeyValue("d", null, 'd', KeyEvent.KEYCODE_D, 0);
new KeyValue("e", null, 'e', KeyEvent.KEYCODE_E, 0);
new KeyValue("f", null, 'f', KeyEvent.KEYCODE_F, 0);
new KeyValue("g", null, 'g', KeyEvent.KEYCODE_G, 0);
new KeyValue("h", null, 'h', KeyEvent.KEYCODE_H, 0);
new KeyValue("i", null, 'i', KeyEvent.KEYCODE_I, 0);
new KeyValue("j", null, 'j', KeyEvent.KEYCODE_J, 0);
new KeyValue("k", null, 'k', KeyEvent.KEYCODE_K, 0);
new KeyValue("l", null, 'l', KeyEvent.KEYCODE_L, 0);
new KeyValue("m", null, 'm', KeyEvent.KEYCODE_M, 0);
new KeyValue("n", null, 'n', KeyEvent.KEYCODE_N, 0);
new KeyValue("o", null, 'o', KeyEvent.KEYCODE_O, 0);
new KeyValue("p", null, 'p', KeyEvent.KEYCODE_P, 0);
new KeyValue("q", null, 'q', KeyEvent.KEYCODE_Q, 0);
new KeyValue("r", null, 'r', KeyEvent.KEYCODE_R, 0);
new KeyValue("s", null, 's', KeyEvent.KEYCODE_S, 0);
new KeyValue("t", null, 't', KeyEvent.KEYCODE_T, 0);
new KeyValue("u", null, 'u', KeyEvent.KEYCODE_U, 0);
new KeyValue("v", null, 'v', KeyEvent.KEYCODE_V, 0);
new KeyValue("w", null, 'w', KeyEvent.KEYCODE_W, 0);
new KeyValue("x", null, 'x', KeyEvent.KEYCODE_X, 0);
new KeyValue("y", null, 'y', KeyEvent.KEYCODE_Y, 0);
new KeyValue("z", null, 'z', KeyEvent.KEYCODE_Z, 0);
new KeyValue("0", null, '0', KeyEvent.KEYCODE_0, 0);
new KeyValue("1", null, '1', KeyEvent.KEYCODE_1, 0);
new KeyValue("2", null, '2', KeyEvent.KEYCODE_2, 0);
new KeyValue("3", null, '3', KeyEvent.KEYCODE_3, 0);
new KeyValue("4", null, '4', KeyEvent.KEYCODE_4, 0);
new KeyValue("5", null, '5', KeyEvent.KEYCODE_5, 0);
new KeyValue("6", null, '6', KeyEvent.KEYCODE_6, 0);
new KeyValue("7", null, '7', KeyEvent.KEYCODE_7, 0);
new KeyValue("8", null, '8', KeyEvent.KEYCODE_8, 0);
new KeyValue("9", null, '9', KeyEvent.KEYCODE_9, 0);
new KeyValue("config", "Conf", CHAR_NONE, EVENT_CONFIG, 0);
new KeyValue("enter", "", CHAR_NONE, KeyEvent.KEYCODE_ENTER, 0);
@ -137,6 +164,6 @@ class KeyValue
new KeyValue("insert", "Ins", CHAR_NONE, KeyEvent.KEYCODE_INSERT, 0);
new KeyValue("tab", "", '\t', KeyEvent.KEYCODE_TAB, 0);
new KeyValue("space", " ", ' ', KeyEvent.KEYCODE_SPACE, 0);
new KeyValue("space", null, ' ', KeyEvent.KEYCODE_SPACE, 0);
}
}

View File

@ -56,10 +56,10 @@ public class Keyboard2 extends InputMethodService
handleDelKey(1, 0);
else if (key.getEventCode() == KeyEvent.KEYCODE_FORWARD_DEL)
handleDelKey(0, 1);
else if (key.getChar(false) == KeyValue.CHAR_NONE && key.getEventCode() != KeyValue.EVENT_NONE)
else if (key.getChar(flags) == KeyValue.CHAR_NONE && key.getEventCode() != KeyValue.EVENT_NONE)
handleMetaKeyUp(key, flags);
else if (key.getChar(false) != KeyValue.CHAR_NONE)
sendKeyChar(key.getChar((flags & KeyValue.FLAG_SHIFT) != 0));
else if (key.getChar(flags) != KeyValue.CHAR_NONE)
sendKeyChar(key.getChar(flags));
}
private void handleDelKey(int before, int after)

View File

@ -183,11 +183,13 @@ public class Keyboard2View extends View
if (key.timeoutWhat != -1)
{
_handler.removeMessages(key.timeoutWhat);
if ((newValue.getFlags() & KeyValue.FLAG_NOCHAR) == 0)
_handler.sendEmptyMessageDelayed(key.timeoutWhat, _longPressTimeout);
}
key.value = newValue;
key.flags = newValue.getFlags();
updateFlags();
invalidate();
vibrate();
}
}
@ -337,7 +339,6 @@ public class Keyboard2View extends View
{
float x;
float y;
boolean upperCase = ((_flags & KeyValue.FLAG_SHIFT) != 0);
y = _marginTop;
for (KeyboardData.Row row : _keyboard.getRows())
@ -354,24 +355,24 @@ public class Keyboard2View extends View
canvas.drawRoundRect(new RectF(x + _keyBgPadding, y + _keyBgPadding,
x + keyW - _keyBgPadding, y + _keyHeight - _keyBgPadding), _keyRound, _keyRound, _keyBgPaint);
if (k.key0 != null)
canvas.drawText(k.key0.getSymbol(upperCase), keyW / 2f + x,
canvas.drawText(k.key0.getSymbol(_flags), keyW / 2f + x,
(_keyHeight + _keyLabelPaint.getTextSize()) / 2f + y,
(keyDown != null && (keyDown.flags & KeyValue.FLAG_LOCKED) != 0)
? _keyLabelLockedPaint : _keyLabelPaint);
float subPadding = _keyBgPadding + _keyPadding;
_keySubLabelPaint.setTextAlign(Paint.Align.LEFT);
if (k.key1 != null)
canvas.drawText(k.key1.getSymbol(upperCase), x + subPadding,
canvas.drawText(k.key1.getSymbol(_flags), x + subPadding,
y + subPadding - _keySubLabelPaint.ascent(), _keySubLabelPaint);
if (k.key3 != null)
canvas.drawText(k.key3.getSymbol(upperCase), x + subPadding,
canvas.drawText(k.key3.getSymbol(_flags), x + subPadding,
y + _keyHeight - subPadding - _keySubLabelPaint.descent(), _keySubLabelPaint);
_keySubLabelPaint.setTextAlign(Paint.Align.RIGHT);
if (k.key2 != null)
canvas.drawText(k.key2.getSymbol(upperCase), x + keyW - subPadding,
canvas.drawText(k.key2.getSymbol(_flags), x + keyW - subPadding,
y + subPadding - _keySubLabelPaint.ascent(), _keySubLabelPaint);
if (k.key4 != null)
canvas.drawText(k.key4.getSymbol(upperCase), x + keyW - subPadding,
canvas.drawText(k.key4.getSymbol(_flags), x + keyW - subPadding,
y + _keyHeight - subPadding - _keySubLabelPaint.descent(), _keySubLabelPaint);
x += keyW;
}