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

View File

@ -9,4 +9,13 @@
<item name="android:textColor">@color/emoji_key_text</item>
<item name="android:textSize">@dimen/label_text_size</item>
</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>

View File

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