From 6bb257fd752ad13c50ee0ebe848543c442470e61 Mon Sep 17 00:00:00 2001 From: jaguillo Date: Tue, 13 Oct 2015 00:02:34 +0200 Subject: [PATCH] Special key font + Esc key --- assets/fonts/keys.ttf | Bin 0 -> 5852 bytes res/xml/azerty.xml | 2 +- res/xml/qwerty.xml | 4 +- srcs/juloo.keyboard2/KeyValue.java | 31 +++++---- srcs/juloo.keyboard2/Keyboard2View.java | 89 +++++++++++++++--------- 5 files changed, 78 insertions(+), 48 deletions(-) create mode 100644 assets/fonts/keys.ttf diff --git a/assets/fonts/keys.ttf b/assets/fonts/keys.ttf new file mode 100644 index 0000000000000000000000000000000000000000..71107301853594f5aa8ff50bcbff4e30d3925c6a GIT binary patch literal 5852 zcmd^Ddu$xV8K2p`JKx#yD}IFLNSMpUj&rwnj_ueniDR5QKSIL8aUQ)3G`aQN`H|SZ zt9=PcO4Ue(G_pdWD5|L1LP%Q`RjrtFfI@{(D)o^{RH&3vfoLfRQ5T^qLg^ok;N0K0 zyJtIzDHZ>AeY@XpzWL3}Z@&3vb`!=KV`c0lQ(64(-Hpwi4clLW=R@5465~c@cGW-L zV2pR;9!MO`3ixpqzekUu%<%Z>M;?g*US_N$Gi*#{;IBaWEm-&P*zuv>O!*qdl*brT zKORXL$)a~w{GBn^S=6_Uz)|#}`g4?DMtSYXc=lM}9U$gHf2@5hoiK`i>e|d$Q3J}W z$Bknd_UmPBC~rquOc>*-m%r~_h4Ki-_K)y7f& z3ghY;{s?n2w{k*x5uP)a<$q&MTtN@aslvO&)j!meWL>jtwp1OMJH+;@1MJ(NQS7XX z+R=Tp?Yjdds=b*x*alcP{xAY#v(DMlxj7TD*&;$W@tYR+#JG!U|L-p|w(5X#7b{_| z3m%mR164KaHr4o=YilaC)=QTzDfJByTz-&0ZgR8yin@J)TUWHMrLv`xU%7hqyi8ucti1P$y`Ji8 zO4Q^j41I1Q88yDk79)A}>bV(v1?PEA;?=eK@V7#F|C5!<`~OUypE-Bc(zr0LO92lG z@wbUz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+Or#8p9NfLQo?#e;-AjB-->*Tw`rcyvnf;t3t8~d$H$J{Jl79d3BX+2B%M#8)3Fn)OrwC(TjIhAx^jJl#X&c z!n#Ap|GR7h*a^T1+@a5K({m?)>A8zIVN~5s90L8sA+U=$1O|xH39y?u1ojYzz+U1I z*hic$fG-kq;6nhGX0V - + diff --git a/res/xml/qwerty.xml b/res/xml/qwerty.xml index 992eee6..4c5f366 100644 --- a/res/xml/qwerty.xml +++ b/res/xml/qwerty.xml @@ -1,7 +1,7 @@ - + @@ -13,7 +13,7 @@ - + diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java index 33b78aa..ae0ce6c 100644 --- a/srcs/juloo.keyboard2/KeyValue.java +++ b/srcs/juloo.keyboard2/KeyValue.java @@ -20,6 +20,8 @@ class KeyValue public static final int FLAG_NOCHAR = (1 << 5); 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_ACCENT2 = (1 << 17); 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_numeric", "123+", CHAR_NONE, EVENT_SWITCH_NUMERIC, 0); - new KeyValue("enter", "↵", CHAR_NONE, KeyEvent.KEYCODE_ENTER, 0); - new KeyValue("up", "↑", CHAR_NONE, KeyEvent.KEYCODE_DPAD_UP, 0); - new KeyValue("right", "→", CHAR_NONE, KeyEvent.KEYCODE_DPAD_RIGHT, 0); - new KeyValue("down", "↓", CHAR_NONE, KeyEvent.KEYCODE_DPAD_DOWN, 0); - new KeyValue("left", "←", CHAR_NONE, KeyEvent.KEYCODE_DPAD_LEFT, 0); - new KeyValue("page_up", "⇞", CHAR_NONE, KeyEvent.KEYCODE_PAGE_DOWN, 0); - new KeyValue("page_down", "⇟", CHAR_NONE, KeyEvent.KEYCODE_PAGE_UP, 0); - new KeyValue("home", "↖", CHAR_NONE, KeyEvent.KEYCODE_HOME, 0); - new KeyValue("end", "↗", CHAR_NONE, KeyEvent.KEYCODE_MOVE_END, 0); - new KeyValue("backspace", "⌫", CHAR_NONE, KeyEvent.KEYCODE_DEL, 0); - new KeyValue("delete", "⌦", CHAR_NONE, KeyEvent.KEYCODE_FORWARD_DEL, 0); - new KeyValue("insert", "Ins", CHAR_NONE, KeyEvent.KEYCODE_INSERT, 0); + new KeyValue("esc", "Esc", CHAR_NONE, KeyEvent.KEYCODE_ESCAPE, 0); + new KeyValue("enter", "\uE800", CHAR_NONE, KeyEvent.KEYCODE_ENTER, FLAG_KEY_FONT); + new KeyValue("up", "\uE80B", CHAR_NONE, KeyEvent.KEYCODE_DPAD_UP, FLAG_KEY_FONT); + new KeyValue("right", "\uE80C", CHAR_NONE, KeyEvent.KEYCODE_DPAD_RIGHT, FLAG_KEY_FONT); + new KeyValue("down", "\uE809", CHAR_NONE, KeyEvent.KEYCODE_DPAD_DOWN, FLAG_KEY_FONT); + new KeyValue("left", "\uE80A", CHAR_NONE, KeyEvent.KEYCODE_DPAD_LEFT, FLAG_KEY_FONT); + new KeyValue("page_up", "⇞", CHAR_NONE, KeyEvent.KEYCODE_PAGE_DOWN, 0); + new KeyValue("page_down", "⇟", CHAR_NONE, KeyEvent.KEYCODE_PAGE_UP, 0); + new KeyValue("home", "↖", CHAR_NONE, KeyEvent.KEYCODE_HOME, 0); + new KeyValue("end", "↗", CHAR_NONE, KeyEvent.KEYCODE_MOVE_END, 0); + new KeyValue("backspace", "⌫", CHAR_NONE, KeyEvent.KEYCODE_DEL, 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("space", null, ' ', KeyEvent.KEYCODE_SPACE, 0); + new KeyValue("tab", "↹", '\t', KeyEvent.KEYCODE_TAB, 0); + new KeyValue("space", null, ' ', KeyEvent.KEYCODE_SPACE, 0); } } diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index 5d21759..4c7d131 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -5,6 +5,7 @@ import android.content.SharedPreferences; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.RectF; +import android.graphics.Typeface; import android.os.Handler; import android.os.Message; import android.os.Vibrator; @@ -53,10 +54,14 @@ 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); - private Paint _keySubLabelRightPaint = new Paint(Paint.ANTI_ALIAS_FLAG); + private Paint _keyLabelPaint; + private Paint _keyLabelLockedPaint; + private Paint _keySubLabelPaint; + private Paint _keySubLabelRightPaint; + private Paint _specialKeyLabelPaint; + private Paint _specialKeyLabelLockedPaint; + private Paint _specialKeySubLabelPaint; + private Paint _specialKeySubLabelRightPaint; private static RectF _tmpRect = new RectF(); @@ -65,6 +70,7 @@ public class Keyboard2View extends View super(context, attrs); _vibratorService = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); _handler = new Handler(this); + Typeface specialKeysFont = Typeface.createFromAsset(getContext().getAssets(), "fonts/keys.ttf"); _horizontalMargin = getResources().getDimension(R.dimen.horizontal_margin); _marginTop = getResources().getDimension(R.dimen.margin_top); _marginBottom = getResources().getDimension(R.dimen.margin_bottom); @@ -74,21 +80,29 @@ public class Keyboard2View extends View _keyRound = getResources().getDimension(R.dimen.key_round); _keyBgPaint.setColor(getResources().getColor(R.color.key_bg)); _keyDownBgPaint.setColor(getResources().getColor(R.color.key_down_bg)); - _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.setTextAlign(Paint.Align.LEFT); - _keySubLabelPaint.setColor(getResources().getColor(R.color.key_sub_label)); - _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)); + _keyLabelPaint = initLabelPaint(Paint.Align.CENTER, R.color.key_label, R.dimen.label_text_size, null); + _keyLabelLockedPaint = initLabelPaint(Paint.Align.CENTER, R.color.key_label_locked, R.dimen.label_text_size, null); + _keySubLabelPaint = initLabelPaint(Paint.Align.LEFT, R.color.key_sub_label, R.dimen.sublabel_text_size, null); + _keySubLabelRightPaint = initLabelPaint(Paint.Align.RIGHT, R.color.key_sub_label, R.dimen.sublabel_text_size, null); + _specialKeyLabelPaint = initLabelPaint(Paint.Align.CENTER, R.color.key_label, R.dimen.label_text_size, specialKeysFont); + _specialKeyLabelLockedPaint = initLabelPaint(Paint.Align.CENTER, R.color.key_label_locked, R.dimen.label_text_size, specialKeysFont); + _specialKeySubLabelPaint = initLabelPaint(Paint.Align.LEFT, R.color.key_sub_label, R.dimen.sublabel_text_size, specialKeysFont); + _specialKeySubLabelRightPaint = initLabelPaint(Paint.Align.RIGHT, R.color.key_sub_label, R.dimen.sublabel_text_size, specialKeysFont); 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) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ime); @@ -99,9 +113,12 @@ public class Keyboard2View extends View _vibrateDuration = prefs.getInt("vibrate_duration", (int)_vibrateDuration); _longPressTimeout = prefs.getInt("longpress_timeout", (int)_longPressTimeout); _longPressInterval = prefs.getInt("longpress_interval", (int)_longPressInterval); - _marginBottom = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, prefs.getInt("margin_bottom", (int)_marginBottom), 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()); + _marginBottom = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, + prefs.getInt("margin_bottom", (int)_marginBottom), 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(); } @@ -362,29 +379,39 @@ public class Keyboard2View extends View else canvas.drawRoundRect(_tmpRect, _keyRound, _keyRound, _keyBgPaint); if (k.key0 != null) - canvas.drawText(k.key0.getSymbol(_flags), keyW / 2f + x, - (_keyHeight + _keyLabelPaint.getTextSize()) / 2f + y, - (keyDown != null && (keyDown.flags & KeyValue.FLAG_LOCKED) != 0) - ? _keyLabelLockedPaint : _keyLabelPaint); + drawLabel(canvas, k.key0, keyW / 2f + x, (_keyHeight + _keyLabelPaint.getTextSize()) / 2f + y, + (keyDown != null && (keyDown.flags & KeyValue.FLAG_LOCKED) != 0)); float subPadding = _keyBgPadding + _keyPadding; if (k.key1 != null) - canvas.drawText(k.key1.getSymbol(_flags), x + subPadding, - y + subPadding - _keySubLabelPaint.ascent(), _keySubLabelPaint); + drawSubLabel(canvas, k.key1, x + subPadding, y + subPadding - _keySubLabelPaint.ascent(), false); if (k.key3 != null) - canvas.drawText(k.key3.getSymbol(_flags), x + subPadding, - y + _keyHeight - subPadding - _keySubLabelPaint.descent(), _keySubLabelPaint); + drawSubLabel(canvas, k.key3, x + subPadding, y + _keyHeight - subPadding - _keySubLabelPaint.descent(), false); if (k.key2 != null) - canvas.drawText(k.key2.getSymbol(_flags), x + keyW - subPadding, - y + subPadding - _keySubLabelRightPaint.ascent(), _keySubLabelRightPaint); + drawSubLabel(canvas, k.key2, x + keyW - subPadding, y + subPadding - _keySubLabelRightPaint.ascent(), true); if (k.key4 != null) - canvas.drawText(k.key4.getSymbol(_flags), x + keyW - subPadding, - y + _keyHeight - subPadding - _keySubLabelRightPaint.descent(), _keySubLabelRightPaint); + drawSubLabel(canvas, k.key4, x + keyW - subPadding, y + _keyHeight - subPadding - _keySubLabelRightPaint.descent(), true); x += keyW; } 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 { public int pointerId;