use of cn.hadcn.keyboard.emoticon.EmoticonBean in project ChatKeyboard by CPPAlien.
the class Utils method ParseEmoticons.
public static EmoticonSetBean ParseEmoticons(Context context, String path, EmoticonBase.Scheme scheme) throws IOException, XmlPullParserException {
String arrayParentKey = "EmoticonBean";
EmoticonSetBean emoticonSetBean = new EmoticonSetBean();
ArrayList<EmoticonBean> emoticonList = new ArrayList<>();
emoticonSetBean.setEmoticonList(emoticonList);
EmoticonBean emoticonBeanTemp = null;
EmoticonLoader emoticonLoader = EmoticonLoader.getInstance(context);
InputStream inStream = emoticonLoader.getConfigStream(path, scheme);
if (inStream == null) {
throw new IOException("Read config.xml in emoticon directory failed");
}
boolean isChildCheck = false;
XmlPullParser pullParser = Xml.newPullParser();
pullParser.setInput(inStream, "UTF-8");
int event = pullParser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
if (event == XmlPullParser.START_TAG) {
String sKeyName = pullParser.getName();
if (isChildCheck) {
switch(sKeyName) {
case "eventType":
{
String value = pullParser.nextText();
emoticonBeanTemp.setEventType(Integer.parseInt(value));
break;
}
case "iconUri":
{
String value = pullParser.nextText();
emoticonBeanTemp.setIconUri(scheme.toUri(path + "/" + value));
break;
}
case "msgUri":
{
String value = pullParser.nextText();
emoticonBeanTemp.setMsgUri(scheme.toUri(path + "/" + value));
break;
}
case "tag":
{
String value = pullParser.nextText();
emoticonBeanTemp.setTag(value);
break;
}
case "name":
{
String value = pullParser.nextText();
emoticonBeanTemp.setName(value);
break;
}
}
} else {
switch(sKeyName) {
case "name":
{
String value = pullParser.nextText();
emoticonSetBean.setName(value);
break;
}
case "line":
{
String value = pullParser.nextText();
emoticonSetBean.setLine(Integer.parseInt(value));
break;
}
case "row":
{
String value = pullParser.nextText();
emoticonSetBean.setRow(Integer.parseInt(value));
break;
}
case "iconUri":
{
String value = pullParser.nextText();
emoticonSetBean.setIconUri(scheme.toUri(path + "/" + value));
break;
}
case "isShowDelBtn":
{
String value = pullParser.nextText();
emoticonSetBean.setShowDelBtn(Integer.parseInt(value) == 1);
break;
}
case "itemPadding":
{
String value = pullParser.nextText();
emoticonSetBean.setItemPadding(Integer.parseInt(value));
break;
}
case "horizontalSpacing":
{
String value = pullParser.nextText();
emoticonSetBean.setHorizontalSpacing(Integer.parseInt(value));
break;
}
case "verticalSpacing":
{
String value = pullParser.nextText();
emoticonSetBean.setVerticalSpacing(Integer.parseInt(value));
break;
}
case "isShowName":
{
String value = pullParser.nextText();
emoticonSetBean.setIsShownName(Integer.parseInt(value) == 1);
break;
}
}
}
if (sKeyName.equals(arrayParentKey)) {
isChildCheck = true;
emoticonBeanTemp = new EmoticonBean();
}
} else if (event == XmlPullParser.END_TAG) {
String ekeyName = pullParser.getName();
if (isChildCheck && ekeyName.equals(arrayParentKey)) {
isChildCheck = false;
emoticonList.add(emoticonBeanTemp);
}
}
event = pullParser.next();
}
return emoticonSetBean;
}
use of cn.hadcn.keyboard.emoticon.EmoticonBean in project ChatKeyboard by CPPAlien.
the class ChatKeyboardLayout method initEmoticonsDB.
public static void initEmoticonsDB(final Context context, final boolean isShowEmoji, final List<EmoticonEntity> emoticonEntities) {
new Thread(new Runnable() {
@Override
public void run() {
EmoticonDBHelper emoticonDbHelper = EmoticonHandler.getInstance(context).getEmoticonDbHelper();
if (isShowEmoji) {
List<EmoticonBean> emojiArray = Utils.parseData(DefEmoticons.emojiArray, EmoticonBean.FACE_TYPE_NORMAL, EmoticonBase.Scheme.DRAWABLE);
EmoticonSetBean emojiEmoticonSetBean = new EmoticonSetBean("emoji", 3, 7);
emojiEmoticonSetBean.setIconUri("drawable://icon_emoji");
emojiEmoticonSetBean.setItemPadding(25);
emojiEmoticonSetBean.setVerticalSpacing(10);
emojiEmoticonSetBean.setShowDelBtn(true);
emojiEmoticonSetBean.setEmoticonList(emojiArray);
emoticonDbHelper.insertEmoticonSet(emojiEmoticonSetBean);
}
List<EmoticonSetBean> emoticonSetBeans = new ArrayList<>();
for (EmoticonEntity entity : emoticonEntities) {
try {
EmoticonSetBean bean = Utils.ParseEmoticons(context, entity.getPath(), entity.getScheme());
emoticonSetBeans.add(bean);
} catch (IOException e) {
HadLog.e(String.format("read %s config.xml error", entity.getPath()), e);
} catch (XmlPullParserException e) {
HadLog.e(String.format("parse %s config.xml error", entity.getPath()), e);
}
}
for (EmoticonSetBean setBean : emoticonSetBeans) {
emoticonDbHelper.insertEmoticonSet(setBean);
}
emoticonDbHelper.cleanup();
if (emoticonSetBeans.size() == emoticonEntities.size()) {
Utils.setIsInitDb(context, true);
}
}
}).start();
}
Aggregations