Emoji pane

This commit is contained in:
jaguillo 2015-10-24 16:32:49 +02:00
parent db20d52884
commit 8bd0214e26
12 changed files with 324 additions and 124 deletions

View File

@ -1,7 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<VerticalLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:hardwareAccelerated="false">
<juloo.keyboard2.EmojiGridView
android:background="@color/bg"
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<juloo.keyboard2.EmojiTypeButton
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/emoji_button_bg"
android:padding="0px"
android:text="\uD83D\uDE03"
emoji_type="EMOTICONS"
/>
</VerticalLayout>
<juloo.keyboard2.EmojiTypeButton
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/emoji_button_bg"
android:padding="0px"
android:text="\u2708"
emoji_type="DINGBATS"
/>
<juloo.keyboard2.EmojiTypeButton
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/emoji_button_bg"
android:padding="0px"
android:text="\uD83D\uDE8C"
emoji_type="TRANSPORT"
/>
<juloo.keyboard2.EmojiTypeButton
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/emoji_button_bg"
android:padding="0px"
android:text="\uD83C\uDF4C"
emoji_type="UNCATEGORIZED"
/>
<juloo.keyboard2.EmojiTypeButton
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/emoji_button_bg"
android:padding="0px"
android:text="\uD83C\uDD92"
emoji_type="ENCLOSED_CHARACTERS"
/>
</LinearLayout>
<juloo.keyboard2.EmojiGridView
android:id="@+id/emoji_grid"
android:background="@color/bg"
android:layout_width="fill_parent"
android:layout_height="@dimen/emoji_grid_height"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<juloo.keyboard2.EmojiKeyButton
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/emoji_key_bg"
android:textColor="@color/emoji_key_text"
android:textSize="@dimen/label_text_size"
android:padding="0px"
key="switch_back_emoji"
/>
<juloo.keyboard2.EmojiKeyButton
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="4"
android:background="@color/emoji_key_bg"
android:textColor="@color/emoji_key_text"
android:textSize="@dimen/label_text_size"
android:padding="0px"
key="space"
/>
<juloo.keyboard2.EmojiKeyButton
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/emoji_key_bg"
android:textColor="@color/emoji_key_text"
android:textSize="@dimen/label_text_size"
android:padding="0px"
key="backspace"
/>
<juloo.keyboard2.EmojiKeyButton
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/emoji_key_bg"
android:textColor="@color/emoji_key_text"
android:textSize="@dimen/label_text_size"
android:padding="0px"
key="enter"
/>
</LinearLayout>
</LinearLayout>

View File

@ -6,4 +6,5 @@
<dimen name="key_height">36dp</dimen>
<dimen name="label_text_size">18dp</dimen>
<dimen name="sublabel_text_size">11dp</dimen>
<dimen name="emoji_type_button_height">48dp</dimen>
</resources>

View File

@ -6,4 +6,7 @@
<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>
<item name="emoji_button_bg" type="color">#202020</item>
<item name="emoji_key_bg" type="color">@color/emoji_button_bg</item>
<item name="emoji_key_text" type="color">@color/key_label</item>
</resources>

View File

@ -9,4 +9,6 @@
<dimen name="key_round">4dp</dimen>
<dimen name="label_text_size">16dp</dimen>
<dimen name="sublabel_text_size">10dp</dimen>
<dimen name="emoji_type_button_height">56dp</dimen>
<dimen name="emoji_grid_height">250dp</dimen>
</resources>

View File

@ -39,6 +39,6 @@
<key key0="alt" key1="page_up" key2="end" key3="home" key4="page_down" />
<key width="4.4" key0="space" />
<key key1="up" key2="right" key3="left" key4="down" />
<key width="1.8" key0="enter" key1="config" />
<key width="1.8" key0="enter" key1="config" key2="switch_emoji" />
</row>
</keyboard>

View File

@ -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));
}

View File

@ -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()

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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;
@ -171,6 +173,8 @@ class KeyValue
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);

View File

@ -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)
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);

View File

@ -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);
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);
}