Improve init of emoji pane

This commit is contained in:
jaguillo 2015-10-27 15:05:50 +01:00
parent 1044daefb4
commit 8716801261
3 changed files with 53 additions and 61 deletions

View File

@ -9,53 +9,43 @@
> >
<juloo.keyboard2.EmojiTypeButton <juloo.keyboard2.EmojiTypeButton
style="@style/emojiTypeButton" style="@style/emojiTypeButton"
android:text="\uD83D\uDD59"
emoji_type="LAST_USE" emoji_type="LAST_USE"
/> />
<juloo.keyboard2.EmojiTypeButton <juloo.keyboard2.EmojiTypeButton
style="@style/emojiTypeButton" style="@style/emojiTypeButton"
android:text="\uD83D\uDE03"
emoji_type="EMOTICONS" emoji_type="EMOTICONS"
/> />
<juloo.keyboard2.EmojiTypeButton <juloo.keyboard2.EmojiTypeButton
style="@style/emojiTypeButton" style="@style/emojiTypeButton"
android:text="\uD83D\uDE8C"
emoji_type="TRANSPORT" emoji_type="TRANSPORT"
/> />
<juloo.keyboard2.EmojiTypeButton <juloo.keyboard2.EmojiTypeButton
style="@style/emojiTypeButton" style="@style/emojiTypeButton"
emoji_type="FOOD" emoji_type="FOOD"
android:text="\uD83C\uDF55"
/> />
<juloo.keyboard2.EmojiTypeButton <juloo.keyboard2.EmojiTypeButton
style="@style/emojiTypeButton" style="@style/emojiTypeButton"
emoji_type="NATURE" emoji_type="NATURE"
android:text="\uD83C\uDF37"
/> />
<juloo.keyboard2.EmojiTypeButton <juloo.keyboard2.EmojiTypeButton
style="@style/emojiTypeButton" style="@style/emojiTypeButton"
emoji_type="FEST" emoji_type="FEST"
android:text="\uD83C\uDF88"
/> />
<juloo.keyboard2.EmojiTypeButton <juloo.keyboard2.EmojiTypeButton
style="@style/emojiTypeButton" style="@style/emojiTypeButton"
emoji_type="ANIMAL" emoji_type="ANIMAL"
android:text="\uD83D\uDC31"
/> />
<juloo.keyboard2.EmojiTypeButton <juloo.keyboard2.EmojiTypeButton
style="@style/emojiTypeButton" style="@style/emojiTypeButton"
emoji_type="HUMAN" emoji_type="HUMAN"
android:text="\uD83D\uDC9C"
/> />
<juloo.keyboard2.EmojiTypeButton <juloo.keyboard2.EmojiTypeButton
style="@style/emojiTypeButton" style="@style/emojiTypeButton"
emoji_type="UNCATEGORIZED" emoji_type="UNCATEGORIZED"
android:text="\uD83D\uDCA5"
/> />
<juloo.keyboard2.EmojiTypeButton <juloo.keyboard2.EmojiTypeButton
style="@style/emojiTypeButton" style="@style/emojiTypeButton"
emoji_type="DINGBATS" emoji_type="DINGBATS"
android:text="\u2705"
/> />
</LinearLayout> </LinearLayout>
<juloo.keyboard2.EmojiGridView <juloo.keyboard2.EmojiGridView
@ -71,43 +61,20 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
> >
<juloo.keyboard2.EmojiKeyButton <juloo.keyboard2.EmojiKeyButton
android:layout_width="0px" style="@style/emojiKeyButton"
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" key="switch_back_emoji"
/> />
<juloo.keyboard2.EmojiKeyButton <juloo.keyboard2.EmojiKeyButton
android:layout_width="0px" style="@style/emojiKeyButton"
android:layout_height="wrap_content"
android:layout_weight="4" 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" key="space"
/> />
<juloo.keyboard2.EmojiKeyButton <juloo.keyboard2.EmojiKeyButton
android:layout_width="0px" style="@style/emojiKeyButton"
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" key="backspace"
/> />
<juloo.keyboard2.EmojiKeyButton <juloo.keyboard2.EmojiKeyButton
android:layout_width="0px" style="@style/emojiKeyButton"
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" key="enter"
/> />
</LinearLayout> </LinearLayout>

View File

@ -9,4 +9,13 @@
<item name="android:textColor">@color/emoji_key_text</item> <item name="android:textColor">@color/emoji_key_text</item>
<item name="android:textSize">@dimen/label_text_size</item> <item name="android:textSize">@dimen/label_text_size</item>
</style> </style>
<style name="emojiKeyButton">
<item name="android:layout_width">0px</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:padding">0px</item>
<item name="android:background">@color/emoji_key_bg</item>
<item name="android:textColor">@color/emoji_key_text</item>
<item name="android:textSize">@dimen/label_text_size</item>
</style>
</resources> </resources>

View File

@ -7,6 +7,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import java.util.HashMap;
public class EmojiTypeButton extends Button public class EmojiTypeButton extends Button
implements View.OnTouchListener implements View.OnTouchListener
@ -16,8 +17,11 @@ public class EmojiTypeButton extends Button
public EmojiTypeButton(Context context, AttributeSet attrs) public EmojiTypeButton(Context context, AttributeSet attrs)
{ {
super(context, attrs); super(context, attrs);
EmojiTypeDef def = _types.get(attrs.getAttributeValue(null, "emoji_type"));
_emojiType = def.getTypeId();
setText(def.getButtonText());
setOnTouchListener(this); setOnTouchListener(this);
_emojiType = getTypeByString(attrs.getAttributeValue(null, "emoji_type"));
} }
public boolean onTouch(View view, MotionEvent event) public boolean onTouch(View view, MotionEvent event)
@ -31,29 +35,41 @@ public class EmojiTypeButton extends Button
return (true); return (true);
} }
public static int getTypeByString(String str) private static HashMap<String, EmojiTypeDef> _types = new HashMap<String, EmojiTypeDef>();
static
{ {
// caca _types.put("LAST_USE", new EmojiTypeDef(EmojiGridView.TYPE_LAST_USE, "\uD83D\uDD59"));
if (str.equals("LAST_USE")) _types.put("EMOTICONS", new EmojiTypeDef(Emoji.TYPE_EMOTICONS, "\uD83D\uDE03"));
return (EmojiGridView.TYPE_LAST_USE); _types.put("TRANSPORT", new EmojiTypeDef(Emoji.TYPE_TRANSPORT, "\uD83D\uDE8C"));
if (str.equals("EMOTICONS")) _types.put("FOOD", new EmojiTypeDef(Emoji.TYPE_FOOD, "\uD83C\uDF55"));
return (Emoji.TYPE_EMOTICONS); _types.put("NATURE", new EmojiTypeDef(Emoji.TYPE_NATURE, "\uD83C\uDF37"));
if (str.equals("TRANSPORT")) _types.put("FEST", new EmojiTypeDef(Emoji.TYPE_FEST, "\uD83C\uDF88"));
return (Emoji.TYPE_TRANSPORT); _types.put("ANIMAL", new EmojiTypeDef(Emoji.TYPE_ANIMAL, "\uD83D\uDC31"));
if (str.equals("FOOD")) _types.put("HUMAN", new EmojiTypeDef(Emoji.TYPE_HUMAN, "\uD83D\uDC9C"));
return (Emoji.TYPE_FOOD); _types.put("UNCATEGORIZED", new EmojiTypeDef(Emoji.TYPE_UNCATEGORIZED, "\uD83D\uDCA5"));
if (str.equals("NATURE")) _types.put("DINGBATS", new EmojiTypeDef(Emoji.TYPE_DINGBATS, "\u2705"));
return (Emoji.TYPE_NATURE); }
if (str.equals("FEST"))
return (Emoji.TYPE_FEST); private static class EmojiTypeDef
if (str.equals("ANIMAL")) {
return (Emoji.TYPE_ANIMAL); private int _typeId;
if (str.equals("HUMAN")) private String _buttonText;
return (Emoji.TYPE_HUMAN);
if (str.equals("UNCATEGORIZED")) public EmojiTypeDef(int typeId, String buttonText)
return (Emoji.TYPE_UNCATEGORIZED); {
if (str.equals("DINGBATS")) _typeId = typeId;
return (Emoji.TYPE_DINGBATS); _buttonText = buttonText;
return (-1); }
public int getTypeId()
{
return (_typeId);
}
public String getButtonText()
{
return (_buttonText);
}
} }
} }