Special key font + Esc key

This commit is contained in:
jaguillo 2015-10-13 00:02:34 +02:00
parent 075c55bb5b
commit 6bb257fd75
5 changed files with 78 additions and 48 deletions

BIN
assets/fonts/keys.ttf Normal file

Binary file not shown.

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<keyboard> <keyboard>
<row> <row>
<key key0="a" key2="1" key3="&amp;" /> <key key0="a" key1="esc" key2="1" key3="&amp;" />
<key key0="z" key2="2" key3="accent2" key4="~" /> <key key0="z" key2="2" key3="accent2" key4="~" />
<key key0="e" key2="3" key3="&quot;" key4="\#" /> <key key0="e" key2="3" key3="&quot;" key4="\#" />
<key key0="r" key2="4" key3="'" key4="{" /> <key key0="r" key2="4" key3="'" key4="{" />

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<keyboard> <keyboard>
<row> <row>
<key key0="q" key1="~" key2="1" key3="!" key4="`" /> <key key0="q" key1="esc" key2="1" key3="~" key4="!" />
<key key0="w" key2="2" key3="\@" /> <key key0="w" key2="2" key3="\@" />
<key key0="e" key2="3" key3="\#" /> <key key0="e" key2="3" key3="\#" />
<key key0="r" key2="4" key3="$" /> <key key0="r" key2="4" key3="$" />
@ -13,7 +13,7 @@
<key key0="p" key1="insert" key2="0" /> <key key0="p" key1="insert" key2="0" />
</row> </row>
<row> <row>
<key key0="a" key1="tab" /> <key key0="a" key1="tab" key2="`" />
<key key0="s" key1="accent1" key2="accent2" key4="accent6" /> <key key0="s" key1="accent1" key2="accent2" key4="accent6" />
<key key0="d" key1="accent3" key2="accent4" key3="accent5" /> <key key0="d" key1="accent3" key2="accent4" key3="accent5" />
<key key0="f" /> <key key0="f" />

View File

@ -20,6 +20,8 @@ class KeyValue
public static final int FLAG_NOCHAR = (1 << 5); public static final int FLAG_NOCHAR = (1 << 5);
public static final int FLAG_LOCKED = (1 << 8); public static final int FLAG_LOCKED = (1 << 8);
public static final int FLAG_KEY_FONT = (1 << 12);
public static final int FLAG_ACCENT1 = (1 << 16); public static final int FLAG_ACCENT1 = (1 << 16);
public static final int FLAG_ACCENT2 = (1 << 17); public static final int FLAG_ACCENT2 = (1 << 17);
public static final int FLAG_ACCENT3 = (1 << 18); public static final int FLAG_ACCENT3 = (1 << 18);
@ -170,20 +172,21 @@ class KeyValue
new KeyValue("switch_text", "ABC", CHAR_NONE, EVENT_SWITCH_TEXT, 0); new KeyValue("switch_text", "ABC", CHAR_NONE, EVENT_SWITCH_TEXT, 0);
new KeyValue("switch_numeric", "123+", CHAR_NONE, EVENT_SWITCH_NUMERIC, 0); new KeyValue("switch_numeric", "123+", CHAR_NONE, EVENT_SWITCH_NUMERIC, 0);
new KeyValue("enter", "", CHAR_NONE, KeyEvent.KEYCODE_ENTER, 0); new KeyValue("esc", "Esc", CHAR_NONE, KeyEvent.KEYCODE_ESCAPE, 0);
new KeyValue("up", "", CHAR_NONE, KeyEvent.KEYCODE_DPAD_UP, 0); new KeyValue("enter", "\uE800", CHAR_NONE, KeyEvent.KEYCODE_ENTER, FLAG_KEY_FONT);
new KeyValue("right", "", CHAR_NONE, KeyEvent.KEYCODE_DPAD_RIGHT, 0); new KeyValue("up", "\uE80B", CHAR_NONE, KeyEvent.KEYCODE_DPAD_UP, FLAG_KEY_FONT);
new KeyValue("down", "", CHAR_NONE, KeyEvent.KEYCODE_DPAD_DOWN, 0); new KeyValue("right", "\uE80C", CHAR_NONE, KeyEvent.KEYCODE_DPAD_RIGHT, FLAG_KEY_FONT);
new KeyValue("left", "", CHAR_NONE, KeyEvent.KEYCODE_DPAD_LEFT, 0); new KeyValue("down", "\uE809", CHAR_NONE, KeyEvent.KEYCODE_DPAD_DOWN, FLAG_KEY_FONT);
new KeyValue("page_up", "", CHAR_NONE, KeyEvent.KEYCODE_PAGE_DOWN, 0); new KeyValue("left", "\uE80A", CHAR_NONE, KeyEvent.KEYCODE_DPAD_LEFT, FLAG_KEY_FONT);
new KeyValue("page_down", "", CHAR_NONE, KeyEvent.KEYCODE_PAGE_UP, 0); new KeyValue("page_up", "", CHAR_NONE, KeyEvent.KEYCODE_PAGE_DOWN, 0);
new KeyValue("home", "", CHAR_NONE, KeyEvent.KEYCODE_HOME, 0); new KeyValue("page_down", "", CHAR_NONE, KeyEvent.KEYCODE_PAGE_UP, 0);
new KeyValue("end", "", CHAR_NONE, KeyEvent.KEYCODE_MOVE_END, 0); new KeyValue("home", "", CHAR_NONE, KeyEvent.KEYCODE_HOME, 0);
new KeyValue("backspace", "", CHAR_NONE, KeyEvent.KEYCODE_DEL, 0); new KeyValue("end", "", CHAR_NONE, KeyEvent.KEYCODE_MOVE_END, 0);
new KeyValue("delete", "", CHAR_NONE, KeyEvent.KEYCODE_FORWARD_DEL, 0); new KeyValue("backspace", "", CHAR_NONE, KeyEvent.KEYCODE_DEL, 0);
new KeyValue("insert", "Ins", CHAR_NONE, KeyEvent.KEYCODE_INSERT, 0); new KeyValue("delete", "", CHAR_NONE, KeyEvent.KEYCODE_FORWARD_DEL, 0);
new KeyValue("insert", "Ins", CHAR_NONE, KeyEvent.KEYCODE_INSERT, 0);
new KeyValue("tab", "", '\t', KeyEvent.KEYCODE_TAB, 0); new KeyValue("tab", "", '\t', KeyEvent.KEYCODE_TAB, 0);
new KeyValue("space", null, ' ', KeyEvent.KEYCODE_SPACE, 0); new KeyValue("space", null, ' ', KeyEvent.KEYCODE_SPACE, 0);
} }
} }

View File

@ -5,6 +5,7 @@ import android.content.SharedPreferences;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.RectF; import android.graphics.RectF;
import android.graphics.Typeface;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.Vibrator; import android.os.Vibrator;
@ -53,10 +54,14 @@ public class Keyboard2View extends View
private Paint _keyBgPaint = new Paint(); private Paint _keyBgPaint = new Paint();
private Paint _keyDownBgPaint = new Paint(); private Paint _keyDownBgPaint = new Paint();
private Paint _keyLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG); private Paint _keyLabelPaint;
private Paint _keyLabelLockedPaint = new Paint(Paint.ANTI_ALIAS_FLAG); private Paint _keyLabelLockedPaint;
private Paint _keySubLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG); private Paint _keySubLabelPaint;
private Paint _keySubLabelRightPaint = new Paint(Paint.ANTI_ALIAS_FLAG); private Paint _keySubLabelRightPaint;
private Paint _specialKeyLabelPaint;
private Paint _specialKeyLabelLockedPaint;
private Paint _specialKeySubLabelPaint;
private Paint _specialKeySubLabelRightPaint;
private static RectF _tmpRect = new RectF(); private static RectF _tmpRect = new RectF();
@ -65,6 +70,7 @@ public class Keyboard2View extends View
super(context, attrs); super(context, attrs);
_vibratorService = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); _vibratorService = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
_handler = new Handler(this); _handler = new Handler(this);
Typeface specialKeysFont = Typeface.createFromAsset(getContext().getAssets(), "fonts/keys.ttf");
_horizontalMargin = getResources().getDimension(R.dimen.horizontal_margin); _horizontalMargin = getResources().getDimension(R.dimen.horizontal_margin);
_marginTop = getResources().getDimension(R.dimen.margin_top); _marginTop = getResources().getDimension(R.dimen.margin_top);
_marginBottom = getResources().getDimension(R.dimen.margin_bottom); _marginBottom = getResources().getDimension(R.dimen.margin_bottom);
@ -74,21 +80,29 @@ public class Keyboard2View extends View
_keyRound = getResources().getDimension(R.dimen.key_round); _keyRound = getResources().getDimension(R.dimen.key_round);
_keyBgPaint.setColor(getResources().getColor(R.color.key_bg)); _keyBgPaint.setColor(getResources().getColor(R.color.key_bg));
_keyDownBgPaint.setColor(getResources().getColor(R.color.key_down_bg)); _keyDownBgPaint.setColor(getResources().getColor(R.color.key_down_bg));
_keyLabelPaint.setColor(getResources().getColor(R.color.key_label)); _keyLabelPaint = initLabelPaint(Paint.Align.CENTER, R.color.key_label, R.dimen.label_text_size, null);
_keyLabelPaint.setTextSize(getResources().getDimension(R.dimen.label_text_size)); _keyLabelLockedPaint = initLabelPaint(Paint.Align.CENTER, R.color.key_label_locked, R.dimen.label_text_size, null);
_keyLabelPaint.setTextAlign(Paint.Align.CENTER); _keySubLabelPaint = initLabelPaint(Paint.Align.LEFT, R.color.key_sub_label, R.dimen.sublabel_text_size, null);
_keyLabelLockedPaint.setColor(getResources().getColor(R.color.key_label_locked)); _keySubLabelRightPaint = initLabelPaint(Paint.Align.RIGHT, R.color.key_sub_label, R.dimen.sublabel_text_size, null);
_keyLabelLockedPaint.setTextSize(getResources().getDimension(R.dimen.label_text_size)); _specialKeyLabelPaint = initLabelPaint(Paint.Align.CENTER, R.color.key_label, R.dimen.label_text_size, specialKeysFont);
_keyLabelLockedPaint.setTextAlign(Paint.Align.CENTER); _specialKeyLabelLockedPaint = initLabelPaint(Paint.Align.CENTER, R.color.key_label_locked, R.dimen.label_text_size, specialKeysFont);
_keySubLabelPaint.setTextAlign(Paint.Align.LEFT); _specialKeySubLabelPaint = initLabelPaint(Paint.Align.LEFT, R.color.key_sub_label, R.dimen.sublabel_text_size, specialKeysFont);
_keySubLabelPaint.setColor(getResources().getColor(R.color.key_sub_label)); _specialKeySubLabelRightPaint = initLabelPaint(Paint.Align.RIGHT, R.color.key_sub_label, R.dimen.sublabel_text_size, specialKeysFont);
_keySubLabelPaint.setTextSize(getResources().getDimension(R.dimen.sublabel_text_size));
_keySubLabelRightPaint.setTextAlign(Paint.Align.RIGHT);
_keySubLabelRightPaint.setColor(getResources().getColor(R.color.key_sub_label));
_keySubLabelRightPaint.setTextSize(getResources().getDimension(R.dimen.sublabel_text_size));
setOnTouchListener(this); setOnTouchListener(this);
} }
private Paint initLabelPaint(Paint.Align align, int color, int size, Typeface font)
{
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTextAlign(align);
paint.setColor(getResources().getColor(color));
paint.setTextSize(getResources().getDimension(size));
if (font != null)
paint.setTypeface(font);
return (paint);
}
public void reset_prefs(Keyboard2 ime) public void reset_prefs(Keyboard2 ime)
{ {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ime); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ime);
@ -99,9 +113,12 @@ public class Keyboard2View extends View
_vibrateDuration = prefs.getInt("vibrate_duration", (int)_vibrateDuration); _vibrateDuration = prefs.getInt("vibrate_duration", (int)_vibrateDuration);
_longPressTimeout = prefs.getInt("longpress_timeout", (int)_longPressTimeout); _longPressTimeout = prefs.getInt("longpress_timeout", (int)_longPressTimeout);
_longPressInterval = prefs.getInt("longpress_interval", (int)_longPressInterval); _longPressInterval = prefs.getInt("longpress_interval", (int)_longPressInterval);
_marginBottom = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, prefs.getInt("margin_bottom", (int)_marginBottom), getResources().getDisplayMetrics()); _marginBottom = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
_keyHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, prefs.getInt("key_height", (int)_keyHeight), getResources().getDisplayMetrics()); prefs.getInt("margin_bottom", (int)_marginBottom), getResources().getDisplayMetrics());
_horizontalMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, prefs.getInt("horizontal_margin", (int)_horizontalMargin), getResources().getDisplayMetrics()); _keyHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
prefs.getInt("key_height", (int)_keyHeight), getResources().getDisplayMetrics());
_horizontalMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
prefs.getInt("horizontal_margin", (int)_horizontalMargin), getResources().getDisplayMetrics());
reset(); reset();
} }
@ -362,29 +379,39 @@ public class Keyboard2View extends View
else else
canvas.drawRoundRect(_tmpRect, _keyRound, _keyRound, _keyBgPaint); canvas.drawRoundRect(_tmpRect, _keyRound, _keyRound, _keyBgPaint);
if (k.key0 != null) if (k.key0 != null)
canvas.drawText(k.key0.getSymbol(_flags), keyW / 2f + x, drawLabel(canvas, k.key0, keyW / 2f + x, (_keyHeight + _keyLabelPaint.getTextSize()) / 2f + y,
(_keyHeight + _keyLabelPaint.getTextSize()) / 2f + y, (keyDown != null && (keyDown.flags & KeyValue.FLAG_LOCKED) != 0));
(keyDown != null && (keyDown.flags & KeyValue.FLAG_LOCKED) != 0)
? _keyLabelLockedPaint : _keyLabelPaint);
float subPadding = _keyBgPadding + _keyPadding; float subPadding = _keyBgPadding + _keyPadding;
if (k.key1 != null) if (k.key1 != null)
canvas.drawText(k.key1.getSymbol(_flags), x + subPadding, drawSubLabel(canvas, k.key1, x + subPadding, y + subPadding - _keySubLabelPaint.ascent(), false);
y + subPadding - _keySubLabelPaint.ascent(), _keySubLabelPaint);
if (k.key3 != null) if (k.key3 != null)
canvas.drawText(k.key3.getSymbol(_flags), x + subPadding, drawSubLabel(canvas, k.key3, x + subPadding, y + _keyHeight - subPadding - _keySubLabelPaint.descent(), false);
y + _keyHeight - subPadding - _keySubLabelPaint.descent(), _keySubLabelPaint);
if (k.key2 != null) if (k.key2 != null)
canvas.drawText(k.key2.getSymbol(_flags), x + keyW - subPadding, drawSubLabel(canvas, k.key2, x + keyW - subPadding, y + subPadding - _keySubLabelRightPaint.ascent(), true);
y + subPadding - _keySubLabelRightPaint.ascent(), _keySubLabelRightPaint);
if (k.key4 != null) if (k.key4 != null)
canvas.drawText(k.key4.getSymbol(_flags), x + keyW - subPadding, drawSubLabel(canvas, k.key4, x + keyW - subPadding, y + _keyHeight - subPadding - _keySubLabelRightPaint.descent(), true);
y + _keyHeight - subPadding - _keySubLabelRightPaint.descent(), _keySubLabelRightPaint);
x += keyW; x += keyW;
} }
y += _keyHeight; y += _keyHeight;
} }
} }
private void drawLabel(Canvas canvas, KeyValue k, float x, float y, boolean locked)
{
if ((k.getFlags() & KeyValue.FLAG_KEY_FONT) != 0)
canvas.drawText(k.getSymbol(_flags), x, y, locked ? _specialKeyLabelLockedPaint : _specialKeyLabelPaint);
else
canvas.drawText(k.getSymbol(_flags), x, y, locked ? _keyLabelLockedPaint : _keyLabelPaint);
}
private void drawSubLabel(Canvas canvas, KeyValue k, float x, float y, boolean right)
{
if ((k.getFlags() & KeyValue.FLAG_KEY_FONT) != 0)
canvas.drawText(k.getSymbol(_flags), x, y, right ? _specialKeySubLabelRightPaint : _specialKeySubLabelPaint);
else
canvas.drawText(k.getSymbol(_flags), x, y, right ? _keySubLabelRightPaint : _keySubLabelPaint);
}
private class KeyDown private class KeyDown
{ {
public int pointerId; public int pointerId;