abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2
diff options
context:
space:
mode:
authorjaguillo2015-10-24 16:32:49 +0200
committerjaguillo2015-10-24 16:32:49 +0200
commit8bd0214e2695c2a621624967a595a069902e6fdd (patch)
tree909fe80e335069f393c621516391605ac4d2b805 /srcs/juloo.keyboard2
parentdb20d528847fe6b451c19eb0b95eeb12954f98a4 (diff)
downloadunexpected-keyboard-8bd0214e2695c2a621624967a595a069902e6fdd.tar.gz
unexpected-keyboard-8bd0214e2695c2a621624967a595a069902e6fdd.zip
Emoji pane
Diffstat (limited to 'srcs/juloo.keyboard2')
-rw-r--r--srcs/juloo.keyboard2/Emoji.java21
-rw-r--r--srcs/juloo.keyboard2/EmojiGridView.java43
-rw-r--r--srcs/juloo.keyboard2/EmojiKeyButton.java29
-rw-r--r--srcs/juloo.keyboard2/EmojiTypeButton.java48
-rw-r--r--srcs/juloo.keyboard2/KeyValue.java86
-rw-r--r--srcs/juloo.keyboard2/Keyboard2.java41
-rw-r--r--srcs/juloo.keyboard2/Keyboard2View.java69
7 files changed, 215 insertions, 122 deletions
diff --git a/srcs/juloo.keyboard2/Emoji.java b/srcs/juloo.keyboard2/Emoji.java
index ed28603..064ee6c 100644
--- a/srcs/juloo.keyboard2/Emoji.java
+++ b/srcs/juloo.keyboard2/Emoji.java
@@ -2,7 +2,7 @@ package juloo.keyboard2;
import java.util.HashMap;
-public class Emoji
+public class Emoji extends KeyValue
{
public static final int TYPE_EMOTICONS = 1;
public static final int TYPE_DINGBATS = 2;
@@ -10,27 +10,14 @@ public class Emoji
public static final int TYPE_UNCATEGORIZED = 4;
public static final int TYPE_ENCLOSED_CHARACTERS = 5;
- private final String _name;
- private final String _bytecode;
private final String _desc;
- private Emoji(String name, String bytecode, String desc)
+ protected Emoji(String name, String bytecode, String desc)
{
- _name = name;
- _bytecode = bytecode;
+ super(name, bytecode, CHAR_NONE, EVENT_NONE, 0);
_desc = desc;
}
- public String getName()
- {
- return (_name);
- }
-
- public String getBytecode()
- {
- return (_bytecode);
- }
-
public String getDescription()
{
return (_desc);
@@ -38,7 +25,7 @@ public class Emoji
private static final HashMap<Integer, Emoji[]> emoji_type_map = new HashMap<Integer, Emoji[]>();
- public static Emoji[] getEmojiByType(int type)
+ public static Emoji[] getEmojisByType(int type)
{
return (emoji_type_map.get(type));
}
diff --git a/srcs/juloo.keyboard2/EmojiGridView.java b/srcs/juloo.keyboard2/EmojiGridView.java
index f4d2d54..fd94aee 100644
--- a/srcs/juloo.keyboard2/EmojiGridView.java
+++ b/srcs/juloo.keyboard2/EmojiGridView.java
@@ -1,6 +1,8 @@
package juloo.keyboard2;
+import android.content.Context;
import android.graphics.Typeface;
+import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
@@ -13,24 +15,36 @@ public class EmojiGridView extends GridView
implements GridView.OnItemClickListener
{
public static final int COLUMN_WIDTH = 192;
- public static final int EMOJI_PANE_HEIGHT = 720;
- public static final int EMOJI_PANE_BG = 0xFF191919;
public static final float EMOJI_SIZE = 32.f;
- public EmojiGridView(Keyboard2 context)
+ private int _emojiType = Emoji.TYPE_EMOTICONS;
+
+ /*
+ ** TODO: save last emoji type
+ ** TODO: adapt column width and emoji size
+ */
+ public EmojiGridView(Context context, AttributeSet attrs)
{
- super(context);
+ super(context, attrs);
setOnItemClickListener(this);
- EmojiViewAdpater adpater = new EmojiViewAdpater(context);
- adpater.setEmojiSet(Emoji.getEmojiByType(Emoji.TYPE_EMOTICONS));
setColumnWidth(COLUMN_WIDTH);
- setBackgroundColor(EMOJI_PANE_BG);
- setAdapter(adpater);
+ setEmojiType(Emoji.TYPE_EMOTICONS);
+ }
+
+ /*
+ ** TODO: type (-1) for lastest used
+ */
+ public void setEmojiType(int type)
+ {
+ _emojiType = type;
+ setAdapter(new EmojiViewAdpater((Keyboard2)getContext(), type));
}
public void onItemClick(AdapterView<?> parent, View v, int pos, long id)
{
- System.out.println("Lol emoji: " + Emoji.getEmojiByType(Emoji.TYPE_EMOTICONS)[pos].getName());
+ Keyboard2 main = (Keyboard2)getContext();
+
+ main.handleKeyUp(Emoji.getEmojisByType(_emojiType)[pos], 0);
}
@Override
@@ -38,7 +52,6 @@ public class EmojiGridView extends GridView
{
super.onMeasure(wSpec, hSpec);
setNumColumns(getMeasuredWidth() / COLUMN_WIDTH);
- setMeasuredDimension(wSpec, EMOJI_PANE_HEIGHT);
}
private static class EmojiView extends TextView
@@ -57,7 +70,7 @@ public class EmojiGridView extends GridView
public void setEmoji(Emoji emoji)
{
- setText(emoji.getBytecode());
+ setText(emoji.getSymbol(0));
}
}
@@ -67,14 +80,10 @@ public class EmojiGridView extends GridView
private Emoji[] _emojiSet = null;
- public EmojiViewAdpater(Keyboard2 main)
+ public EmojiViewAdpater(Keyboard2 main, int type)
{
_main = main;
- }
-
- public void setEmojiSet(Emoji[] set)
- {
- _emojiSet = set;
+ _emojiSet = Emoji.getEmojisByType(type);
}
public int getCount()
diff --git a/srcs/juloo.keyboard2/EmojiKeyButton.java b/srcs/juloo.keyboard2/EmojiKeyButton.java
new file mode 100644
index 0000000..00a9a69
--- /dev/null
+++ b/srcs/juloo.keyboard2/EmojiKeyButton.java
@@ -0,0 +1,29 @@
+package juloo.keyboard2;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.Button;
+
+public class EmojiKeyButton extends Button
+ implements View.OnClickListener
+{
+ KeyValue _key;
+
+ public EmojiKeyButton(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ setOnClickListener(this);
+ _key = KeyValue.getKeyByName(attrs.getAttributeValue(null, "key"));
+ setText(_key.getSymbol(0));
+ if ((_key.getFlags() & KeyValue.FLAG_KEY_FONT) != 0)
+ setTypeface(((Keyboard2)context).getSpecialKeyFont());
+ }
+
+ public void onClick(View v)
+ {
+ Keyboard2 main = (Keyboard2)getContext();
+
+ main.handleKeyUp(_key, 0);
+ }
+}
diff --git a/srcs/juloo.keyboard2/EmojiTypeButton.java b/srcs/juloo.keyboard2/EmojiTypeButton.java
new file mode 100644
index 0000000..a645823
--- /dev/null
+++ b/srcs/juloo.keyboard2/EmojiTypeButton.java
@@ -0,0 +1,48 @@
+package juloo.keyboard2;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+
+public class EmojiTypeButton extends Button
+ implements View.OnTouchListener
+{
+ private int _emojiType;
+
+ public EmojiTypeButton(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ _emojiType = getTypeByString(attrs.getAttributeValue(null, "emoji_type"));
+ setOnTouchListener(this);
+ }
+
+ public boolean onTouch(View view, MotionEvent event)
+ {
+ EmojiGridView emojiGrid;
+
+ if (event.getAction() != MotionEvent.ACTION_DOWN)
+ return (false);
+ emojiGrid = (EmojiGridView)((ViewGroup)(getParent().getParent())).findViewById(R.id.emoji_grid);
+ emojiGrid.setEmojiType(_emojiType);
+ return (true);
+ }
+
+ public static int getTypeByString(String str)
+ {
+ // caca
+ if (str.equals("EMOTICONS"))
+ return (Emoji.TYPE_EMOTICONS);
+ if (str.equals("DINGBATS"))
+ return (Emoji.TYPE_DINGBATS);
+ if (str.equals("TRANSPORT"))
+ return (Emoji.TYPE_TRANSPORT);
+ if (str.equals("UNCATEGORIZED"))
+ return (Emoji.TYPE_UNCATEGORIZED);
+ if (str.equals("ENCLOSED_CHARACTERS"))
+ return (Emoji.TYPE_ENCLOSED_CHARACTERS);
+ return (-1);
+ }
+}
diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java
index ae0ce6c..f13ad54 100644
--- a/srcs/juloo.keyboard2/KeyValue.java
+++ b/srcs/juloo.keyboard2/KeyValue.java
@@ -10,6 +10,8 @@ class KeyValue
public static final int EVENT_CONFIG = -2;
public static final int EVENT_SWITCH_TEXT = -3;
public static final int EVENT_SWITCH_NUMERIC = -4;
+ public static final int EVENT_SWITCH_EMOJI = -5;
+ public static final int EVENT_SWITCH_BACK_EMOJI = -6;
public static final char CHAR_NONE = '\0';
public static final int FLAG_KEEP_ON = 1;
@@ -94,7 +96,7 @@ class KeyValue
private static HashMap<String, KeyValue> keys = new HashMap<String, KeyValue>();
- private KeyValue(String name, String symbol, char c, int eventCode, int flags)
+ protected KeyValue(String name, String symbol, char c, int eventCode, int flags)
{
_name = name;
_symbol = symbol;
@@ -131,46 +133,48 @@ class KeyValue
new KeyValue("accent5", "\u00B8", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ACCENT5);
new KeyValue("accent6", "\u00A8", CHAR_NONE, EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ACCENT6);
- 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("switch_text", "ABC", CHAR_NONE, EVENT_SWITCH_TEXT, 0);
- new KeyValue("switch_numeric", "123+", CHAR_NONE, EVENT_SWITCH_NUMERIC, 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("switch_text", "ABC", CHAR_NONE, EVENT_SWITCH_TEXT, 0);
+ new KeyValue("switch_numeric", "123+", CHAR_NONE, EVENT_SWITCH_NUMERIC, 0);
+ new KeyValue("switch_emoji", "\uD83D\uDE03", CHAR_NONE, EVENT_SWITCH_EMOJI, 0);
+ new KeyValue("switch_back_emoji", "ABC", CHAR_NONE, EVENT_SWITCH_BACK_EMOJI, 0);
new KeyValue("esc", "Esc", CHAR_NONE, KeyEvent.KEYCODE_ESCAPE, 0);
new KeyValue("enter", "\uE800", CHAR_NONE, KeyEvent.KEYCODE_ENTER, FLAG_KEY_FONT);
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java
index f38d41d..e1e3186 100644
--- a/srcs/juloo.keyboard2/Keyboard2.java
+++ b/srcs/juloo.keyboard2/Keyboard2.java
@@ -3,6 +3,7 @@ package juloo.keyboard2;
import android.content.res.Configuration;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.graphics.Typeface;
import android.inputmethodservice.InputMethodService;
import android.os.Bundle;
import android.text.InputType;
@@ -12,40 +13,35 @@ import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
-/*
-** TODO: move config values in a Config object
-*/
public class Keyboard2 extends InputMethodService
implements SharedPreferences.OnSharedPreferenceChangeListener
{
private Keyboard2View _keyboardView;
- private ViewGroup _emojiPane = null;
private KeyboardData _textKeyboard = null;
private KeyboardData _numericKeyboard = null;
+ private ViewGroup _emojiPane = null;
+ private Typeface _specialKeyFont = null;
@Override
public void onCreate()
{
super.onCreate();
+ _specialKeyFont = Typeface.createFromAsset(getAssets(), "fonts/keys.ttf");
PreferenceManager.setDefaultValues(this, R.xml.settings, false);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
updateConfig();
_keyboardView = (Keyboard2View)getLayoutInflater().inflate(R.layout.keyboard, null);
- _keyboardView.reset_prefs(this);
+ _keyboardView.reset_prefs();
}
- private View getEmojiPane()
+ public Typeface getSpecialKeyFont()
{
- if (_emojiPane == null)
- {
- }
- return (_emojiPane);
+ return (_specialKeyFont);
}
@Override
public View onCreateInputView()
{
- // return (new EmojiGridView(this)); // TMP
ViewGroup parent = (ViewGroup)_keyboardView.getParent();
if (parent != null)
@@ -66,7 +62,7 @@ public class Keyboard2 extends InputMethodService
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
{
updateConfig();
- _keyboardView.reset_prefs(this);
+ _keyboardView.reset_prefs();
}
@Override
@@ -92,6 +88,7 @@ public class Keyboard2 extends InputMethodService
xmlRes = R.xml.azerty;
_textKeyboard = new KeyboardData(getResources().getXml(xmlRes));
_numericKeyboard = new KeyboardData(getResources().getXml(R.xml.numeric));
+ _emojiPane = null;
}
public void handleKeyUp(KeyValue key, int flags)
@@ -111,18 +108,34 @@ public class Keyboard2 extends InputMethodService
_keyboardView.setKeyboard(_textKeyboard);
else if (eventCode == KeyValue.EVENT_SWITCH_NUMERIC)
_keyboardView.setKeyboard(_numericKeyboard);
+ else if (eventCode == KeyValue.EVENT_SWITCH_EMOJI)
+ setInputView(getEmojiPane());
+ else if (eventCode == KeyValue.EVENT_SWITCH_BACK_EMOJI)
+ setInputView(_keyboardView);
else if ((flags & (KeyValue.FLAG_CTRL | KeyValue.FLAG_ALT)) != 0)
handleMetaKeyUp(key, flags);
// else if (eventCode == KeyEvent.KEYCODE_DEL)
// handleDelKey(1, 0);
// else if (eventCode == KeyEvent.KEYCODE_FORWARD_DEL)
// handleDelKey(0, 1);
- else if (keyChar == KeyValue.CHAR_NONE && eventCode != KeyValue.EVENT_NONE)
- handleMetaKeyUp(key, flags);
+ else if (keyChar == KeyValue.CHAR_NONE)
+ {
+ if (eventCode != KeyValue.EVENT_NONE)
+ handleMetaKeyUp(key, flags);
+ else
+ getCurrentInputConnection().commitText(key.getSymbol(flags), 1);
+ }
else if (keyChar != KeyValue.CHAR_NONE)
sendKeyChar(keyChar);
}
+ private ViewGroup getEmojiPane()
+ {
+ if (_emojiPane == null)
+ _emojiPane = (ViewGroup)getLayoutInflater().inflate(R.layout.emoji_pane, null);
+ return (_emojiPane);
+ }
+
// private void handleDelKey(int before, int after)
// {
// CharSequence selection = getCurrentInputConnection().getSelectedText(0);
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java
index 9bb743a..dc61977 100644
--- a/srcs/juloo.keyboard2/Keyboard2View.java
+++ b/srcs/juloo.keyboard2/Keyboard2View.java
@@ -24,7 +24,6 @@ public class Keyboard2View extends View
private static final long VIBRATE_MIN_INTERVAL = 100;
- private Keyboard2 _ime;
private KeyboardData _keyboard;
private ArrayList<KeyDown> _downKeys = new ArrayList<KeyDown>();
@@ -37,6 +36,9 @@ public class Keyboard2View extends View
private Handler _handler;
private static int _currentWhat = 0;
+ /*
+ ** TODO: move config values in a Config object
+ */
private float _marginTop;
private float _keyWidth;
private float _keyPadding;
@@ -52,16 +54,16 @@ public class Keyboard2View extends View
private float _keyHeight;
private float _horizontalMargin;
- private Paint _keyBgPaint = new Paint();
- private Paint _keyDownBgPaint = new Paint();
- 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 Paint _keyBgPaint = new Paint();
+ private static Paint _keyDownBgPaint = new Paint();
+ private static Paint _keyLabelPaint;
+ private static Paint _keyLabelLockedPaint;
+ private static Paint _keySubLabelPaint;
+ private static Paint _keySubLabelRightPaint;
+ private static Paint _specialKeyLabelPaint;
+ private static Paint _specialKeyLabelLockedPaint;
+ private static Paint _specialKeySubLabelPaint;
+ private static Paint _specialKeySubLabelRightPaint;
private static RectF _tmpRect = new RectF();
@@ -70,7 +72,6 @@ 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);
@@ -80,34 +81,36 @@ 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 = 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);
+ _keyLabelPaint = initLabelPaint(_keyLabelPaint, Paint.Align.CENTER, R.color.key_label, R.dimen.label_text_size, null);
+ _keyLabelLockedPaint = initLabelPaint(_keyLabelLockedPaint, Paint.Align.CENTER, R.color.key_label_locked, R.dimen.label_text_size, null);
+ _keySubLabelPaint = initLabelPaint(_keySubLabelPaint, Paint.Align.LEFT, R.color.key_sub_label, R.dimen.sublabel_text_size, null);
+ _keySubLabelRightPaint = initLabelPaint(_keySubLabelRightPaint, Paint.Align.RIGHT, R.color.key_sub_label, R.dimen.sublabel_text_size, null);
+ Typeface specialKeysFont = ((Keyboard2)getContext()).getSpecialKeyFont();
+ _specialKeyLabelPaint = initLabelPaint(_specialKeyLabelPaint, Paint.Align.CENTER, R.color.key_label, R.dimen.label_text_size, specialKeysFont);
+ _specialKeyLabelLockedPaint = initLabelPaint(_specialKeyLabelLockedPaint, Paint.Align.CENTER, R.color.key_label_locked, R.dimen.label_text_size, specialKeysFont);
+ _specialKeySubLabelPaint = initLabelPaint(_specialKeySubLabelPaint, Paint.Align.LEFT, R.color.key_sub_label, R.dimen.sublabel_text_size, specialKeysFont);
+ _specialKeySubLabelRightPaint = initLabelPaint(_specialKeySubLabelRightPaint, 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)
+ private Paint initLabelPaint(Paint paint, 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);
+ if (paint == null)
+ {
+ 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()
{
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ime);
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
- _ime = ime;
_subValueDist = prefs.getFloat("sub_value_dist", _subValueDist);
_vibrateEnabled = prefs.getBoolean("vibrate_enabled", _vibrateEnabled);
_vibrateDuration = prefs.getInt("vibrate_duration", (int)_vibrateDuration);
@@ -291,7 +294,7 @@ public class Keyboard2View extends View
downKey.flags ^= KeyValue.FLAG_KEEP_ON;
}
if (k.value != null && (k.flags & (KeyValue.FLAG_LOCKED | KeyValue.FLAG_NOCHAR)) == 0)
- _ime.handleKeyUp(k.value, _flags);
+ ((Keyboard2)getContext()).handleKeyUp(k.value, _flags);
_downKeys.remove(k);
updateFlags();
invalidate();
@@ -335,7 +338,7 @@ public class Keyboard2View extends View
if (key.timeoutWhat == msg.what)
{
_handler.sendEmptyMessageDelayed(msg.what, _longPressInterval);
- _ime.handleKeyUp(key.value, _flags);
+ ((Keyboard2)getContext()).handleKeyUp(key.value, _flags);
vibrate();
return (true);
}