Search in sources :

Example 11 with EmoticonBean

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;
}
Also used : EmoticonBean(cn.hadcn.keyboard.emoticon.EmoticonBean) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException) Paint(android.graphics.Paint) EmoticonSetBean(cn.hadcn.keyboard.emoticon.EmoticonSetBean)

Example 12 with EmoticonBean

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();
}
Also used : EmoticonBean(cn.hadcn.keyboard.emoticon.EmoticonBean) ArrayList(java.util.ArrayList) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) EmoticonDBHelper(cn.hadcn.keyboard.emoticon.db.EmoticonDBHelper) EmoticonSetBean(cn.hadcn.keyboard.emoticon.EmoticonSetBean)

Aggregations

EmoticonBean (cn.hadcn.keyboard.emoticon.EmoticonBean)12 ArrayList (java.util.ArrayList)6 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 EmoticonSetBean (cn.hadcn.keyboard.emoticon.EmoticonSetBean)4 Cursor (android.database.Cursor)3 IOException (java.io.IOException)3 Paint (android.graphics.Paint)2 LinearLayout (android.widget.LinearLayout)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 ContentValues (android.content.ContentValues)1 SQLiteException (android.database.sqlite.SQLiteException)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Editable (android.text.Editable)1 KeyEvent (android.view.KeyEvent)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1