Search in sources :

Example 1 with EmoticonDBHelper

use of cn.hadcn.keyboard.emoticon.db.EmoticonDBHelper in project ChatKeyboard by CPPAlien.

the class ChatKeyboardLayout method getBuilder.

private EmoticonsKeyboardBuilder getBuilder(Context context) {
    if (context == null) {
        throw new RuntimeException("Context is null, cannot create db helper");
    }
    EmoticonDBHelper emoticonDbHelper = new EmoticonDBHelper(context);
    ArrayList<EmoticonSetBean> mEmoticonSetBeanList = emoticonDbHelper.queryAllEmoticonSet();
    emoticonDbHelper.cleanup();
    return new EmoticonsKeyboardBuilder.Builder().setEmoticonSetBeanList(mEmoticonSetBeanList).build();
}
Also used : EmoticonsKeyboardBuilder(cn.hadcn.keyboard.emoticon.util.EmoticonsKeyboardBuilder) EmoticonDBHelper(cn.hadcn.keyboard.emoticon.db.EmoticonDBHelper) EmoticonSetBean(cn.hadcn.keyboard.emoticon.EmoticonSetBean)

Example 2 with EmoticonDBHelper

use of cn.hadcn.keyboard.emoticon.db.EmoticonDBHelper 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

EmoticonSetBean (cn.hadcn.keyboard.emoticon.EmoticonSetBean)2 EmoticonDBHelper (cn.hadcn.keyboard.emoticon.db.EmoticonDBHelper)2 EmoticonBean (cn.hadcn.keyboard.emoticon.EmoticonBean)1 EmoticonsKeyboardBuilder (cn.hadcn.keyboard.emoticon.util.EmoticonsKeyboardBuilder)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1