Search in sources :

Example 1 with VerticalImageSpan

use of cn.hadcn.keyboard.view.VerticalImageSpan in project ChatKeyboard by CPPAlien.

the class EmoticonHandler method setTextFace.

public void setTextFace(String content, Spannable spannable, int start, int size) {
    if (mEmoticonBeans == null) {
        mEmoticonBeans = emoticonDbHelper.queryAllEmoticonBeans();
        emoticonDbHelper.cleanup();
    }
    if (content.length() <= 0) {
        return;
    }
    int keyIndex = start;
    for (EmoticonBean bean : mEmoticonBeans) {
        String key = bean.getTag();
        int keyLength = key.length();
        while (keyIndex >= 0) {
            //when do not find, get -1
            keyIndex = content.indexOf(key, keyIndex);
            if (keyIndex < 0) {
                break;
            }
            Drawable drawable = EmoticonLoader.getInstance(mContext).getDrawable(bean.getIconUri());
            drawable.setBounds(0, 0, size, size);
            VerticalImageSpan imageSpan = new VerticalImageSpan(drawable);
            spannable.setSpan(imageSpan, keyIndex, keyIndex + keyLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            keyIndex += keyLength;
        }
        keyIndex = start;
    }
}
Also used : VerticalImageSpan(cn.hadcn.keyboard.view.VerticalImageSpan) EmoticonBean(cn.hadcn.keyboard.emoticon.EmoticonBean) Drawable(android.graphics.drawable.Drawable)

Aggregations

Drawable (android.graphics.drawable.Drawable)1 EmoticonBean (cn.hadcn.keyboard.emoticon.EmoticonBean)1 VerticalImageSpan (cn.hadcn.keyboard.view.VerticalImageSpan)1