Search in sources :

Example 1 with EmoticonSetBean

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

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

the class EmoticonDBHelper method queryEmoticonSet.

public synchronized ArrayList<EmoticonSetBean> queryEmoticonSet(String sql) {
    SQLiteDatabase db = mOpenDbHelper.getReadableDatabase();
    Cursor cursor = null;
    try {
        cursor = db.rawQuery(sql, null);
        int count = cursor.getCount();
        ArrayList<EmoticonSetBean> beanList = new ArrayList<EmoticonSetBean>();
        if (count > 0) {
            cursor.moveToFirst();
            for (int i = 0; i < count; i++) {
                String name = cursor.getString(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.NAME));
                int line = cursor.getInt(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.LINE));
                int row = cursor.getInt(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.ROW));
                String iconUri = cursor.getString(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.ICON_URI));
                boolean isshowdelbtn = cursor.getInt(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.IS_SHOW_DEL_BTN)) == 1;
                int itempadding = cursor.getInt(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.ITEM_PADDING));
                int horizontalspacing = cursor.getInt(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.HORIZONTAL_SPACING));
                int verticalSpacing = cursor.getInt(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.VERTICAL_SPACING));
                boolean isShownName = cursor.getInt(cursor.getColumnIndex(TableColumns.EmoticonSetColumns.IS_SHOWN_NAME)) == 1;
                ArrayList<EmoticonBean> emoticonList = null;
                if (!TextUtils.isEmpty(name)) {
                    String sqlGetEmoticonBean = "select * from " + TABLE_NAME_EMOTICONS + " where " + TableColumns.EmoticonColumns.EMOTICON_SET_NAME + " = '" + name + "'";
                    emoticonList = queryEmoticonBeanList(sqlGetEmoticonBean);
                }
                int pageCount = 0;
                if (emoticonList != null) {
                    int del = isshowdelbtn ? 1 : 0;
                    int everyPageMaxSum = row * line - del;
                    pageCount = (int) Math.ceil((double) emoticonList.size() / everyPageMaxSum);
                }
                EmoticonSetBean bean = new EmoticonSetBean(name, line, row, iconUri, isshowdelbtn, isShownName, itempadding, horizontalspacing, verticalSpacing, emoticonList);
                beanList.add(bean);
                cursor.moveToNext();
            }
            return beanList;
        }
    } catch (SQLiteException e) {
        Log.e(TAG, "query failed", e);
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
Also used : EmoticonBean(cn.hadcn.keyboard.emoticon.EmoticonBean) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException) EmoticonSetBean(cn.hadcn.keyboard.emoticon.EmoticonSetBean)

Example 3 with EmoticonSetBean

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

the class EmoticonsPageView method updateView.

private void updateView() {
    if (mEmoticonSetBeanList == null)
        return;
    if (mEmoticonsViewPagerAdapter == null) {
        mEmoticonsViewPagerAdapter = new EmoticonsViewPagerAdapter();
        setAdapter(mEmoticonsViewPagerAdapter);
        setOnPageChangeListener(new PageChangeListener());
    }
    int screenWidth = Utils.getDisplayWidthPixels(mContext);
    int maxPagerHeight = mHeight;
    mEmoticonPageViews.clear();
    mEmoticonsViewPagerAdapter.notifyDataSetChanged();
    for (EmoticonSetBean bean : mEmoticonSetBeanList) {
        List<EmoticonBean> emoticonList = bean.getEmoticonList();
        if (emoticonList != null) {
            int emoticonSetSum = emoticonList.size();
            int row = bean.getRow();
            int line = bean.getLine();
            int del = bean.isShowDelBtn() ? 1 : 0;
            int everyPageMaxSum = row * line - del;
            int pageCount = getPageCount(bean);
            mMaxEmoticonSetPageCount = Math.max(mMaxEmoticonSetPageCount, pageCount);
            int start = 0;
            int end = everyPageMaxSum > emoticonSetSum ? emoticonSetSum : everyPageMaxSum;
            RelativeLayout.LayoutParams gridParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            gridParams.addRule(SoftListenLayout.CENTER_VERTICAL);
            int itemHeight = Math.min((screenWidth - (bean.getRow() - 1) * Utils.dip2px(mContext, bean.getHorizontalSpacing())) / bean.getRow(), (maxPagerHeight - (bean.getLine() - 1) * Utils.dip2px(mContext, bean.getVerticalSpacing())) / bean.getLine());
            for (int i = 0; i < pageCount; i++) {
                RelativeLayout rl = new RelativeLayout(mContext);
                GridView gridView = new GridView(mContext);
                gridView.setNumColumns(bean.getRow());
                gridView.setBackgroundColor(Color.TRANSPARENT);
                gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
                gridView.setCacheColorHint(0);
                gridView.setHorizontalSpacing(Utils.dip2px(mContext, bean.getHorizontalSpacing()));
                gridView.setVerticalSpacing(Utils.dip2px(mContext, bean.getVerticalSpacing()));
                gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
                gridView.setGravity(Gravity.CENTER);
                gridView.setVerticalScrollBarEnabled(false);
                List<EmoticonBean> list = new ArrayList<>();
                for (int j = start; j < end; j++) {
                    list.add(emoticonList.get(j));
                }
                if (bean.isShowDelBtn()) {
                    int count = bean.getLine() * bean.getRow();
                    while (list.size() < count - 1) {
                        list.add(null);
                    }
                    list.add(new EmoticonBean(EmoticonBean.FACE_TYPE_DEL, "drawable://icon_del", null, null));
                } else {
                    int count = bean.getLine() * bean.getRow();
                    while (list.size() < count) {
                        list.add(null);
                    }
                }
                EmoticonsAdapter adapter = new EmoticonsAdapter(mContext, list, bean.isShownName());
                adapter.setHeight(itemHeight, Utils.dip2px(mContext, bean.getItemPadding()));
                gridView.setAdapter(adapter);
                rl.addView(gridView, gridParams);
                mEmoticonPageViews.add(rl);
                adapter.setOnItemListener(this);
                start = everyPageMaxSum + i * everyPageMaxSum;
                end = everyPageMaxSum + (i + 1) * everyPageMaxSum;
                if (end >= emoticonSetSum) {
                    end = emoticonSetSum;
                }
            }
        }
    }
    mEmoticonsViewPagerAdapter.notifyDataSetChanged();
}
Also used : EmoticonBean(cn.hadcn.keyboard.emoticon.EmoticonBean) ArrayList(java.util.ArrayList) EmoticonSetBean(cn.hadcn.keyboard.emoticon.EmoticonSetBean) ColorDrawable(android.graphics.drawable.ColorDrawable) RelativeLayout(android.widget.RelativeLayout) GridView(android.widget.GridView)

Example 4 with EmoticonSetBean

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

the class EmoticonsToolBarView method setEmoticonContents.

public void setEmoticonContents(EmoticonsKeyboardBuilder builder) {
    mEmoticonSetBeanList = builder.builder == null ? null : builder.builder.getEmoticonSetBeanList();
    if (mEmoticonSetBeanList == null) {
        return;
    }
    int i = 0;
    for (EmoticonSetBean bean : mEmoticonSetBeanList) {
        View toolBtnView = inflate(mContext, R.layout.emoticonstoolbar_item, null);
        ImageView iv_icon = (ImageView) toolBtnView.findViewById(R.id.iv_icon);
        LinearLayout.LayoutParams imgParams = new LinearLayout.LayoutParams(Utils.dip2px(mContext, mBtnWidth), LayoutParams.MATCH_PARENT);
        iv_icon.setLayoutParams(imgParams);
        ly_tool.addView(toolBtnView);
        iv_icon.setImageDrawable(EmoticonLoader.getInstance(mContext).getDrawable(bean.getIconUri()));
        mToolBtnList.add(iv_icon);
        final int finalI = i;
        iv_icon.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                if (mItemClickListeners != null && !mItemClickListeners.isEmpty()) {
                    for (OnToolBarItemClickListener listener : mItemClickListeners) {
                        listener.onToolBarItemClick(finalI);
                    }
                }
            }
        });
        i++;
    }
    setToolBtnSelect(0);
}
Also used : ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) LinearLayout(android.widget.LinearLayout) EmoticonSetBean(cn.hadcn.keyboard.emoticon.EmoticonSetBean)

Example 5 with EmoticonSetBean

use of cn.hadcn.keyboard.emoticon.EmoticonSetBean 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)

Aggregations

EmoticonSetBean (cn.hadcn.keyboard.emoticon.EmoticonSetBean)6 EmoticonBean (cn.hadcn.keyboard.emoticon.EmoticonBean)4 ArrayList (java.util.ArrayList)4 EmoticonDBHelper (cn.hadcn.keyboard.emoticon.db.EmoticonDBHelper)2 IOException (java.io.IOException)2 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 SQLiteException (android.database.sqlite.SQLiteException)1 Paint (android.graphics.Paint)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 View (android.view.View)1 GridView (android.widget.GridView)1 HorizontalScrollView (android.widget.HorizontalScrollView)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 RelativeLayout (android.widget.RelativeLayout)1 EmoticonsKeyboardBuilder (cn.hadcn.keyboard.emoticon.util.EmoticonsKeyboardBuilder)1 InputStream (java.io.InputStream)1 XmlPullParser (org.xmlpull.v1.XmlPullParser)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1