Search in sources :

Example 6 with EmoticonBean

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

the class EmoticonLayout method init.

private void init(Context context) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.keyboard_bottom_emoticons, this);
    ivIndicator = (IndicatorView) findViewById(R.id.emoticon_indicator_view);
    epvContent = (EmoticonsPageView) findViewById(R.id.emoticon_page_view);
    etvToolBar = (EmoticonsToolBarView) findViewById(R.id.emoticon_page_toolbar);
    epvContent.setOnIndicatorListener(this);
    epvContent.setIViewListener(new IView() {

        @Override
        public void onItemClick(EmoticonBean bean) {
            mListener.onEmoticonItemClicked(bean);
        }

        @Override
        public void onPageChangeTo(int position) {
            etvToolBar.setToolBtnSelect(position);
        }
    });
    etvToolBar.setOnToolBarItemClickListener(new EmoticonsToolBarView.OnToolBarItemClickListener() {

        @Override
        public void onToolBarItemClick(int position) {
            epvContent.setPageSelect(position);
        }
    });
}
Also used : EmoticonBean(cn.hadcn.keyboard.emoticon.EmoticonBean) LayoutInflater(android.view.LayoutInflater)

Example 7 with EmoticonBean

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

the class ChatKeyboardLayout method showEmoticons.

public void showEmoticons() {
    btnEmoticon.setVisibility(VISIBLE);
    EmoticonsKeyboardBuilder builder = getBuilder(mContext);
    EmoticonLayout layout = new EmoticonLayout(mContext);
    layout.setContents(builder, new EmoticonLayout.OnEmoticonListener() {

        @Override
        public void onEmoticonItemClicked(EmoticonBean bean) {
            if (etInputArea != null) {
                setEditableState(true);
                if (bean.getEventType() == EmoticonBean.FACE_TYPE_DEL) {
                    int action = KeyEvent.ACTION_DOWN;
                    int code = KeyEvent.KEYCODE_DEL;
                    KeyEvent event = new KeyEvent(action, code);
                    etInputArea.onKeyDown(KeyEvent.KEYCODE_DEL, event);
                    return;
                } else if (bean.getEventType() == EmoticonBean.FACE_TYPE_STICKER) {
                    if (mOnChatKeyBoardListener != null) {
                        mOnChatKeyBoardListener.onUserDefEmoticonClicked(bean.getTag(), bean.getIconUri());
                    }
                    return;
                }
                int index = etInputArea.getSelectionStart();
                Editable editable = etInputArea.getEditableText();
                if (index < 0) {
                    editable.append(bean.getTag());
                } else {
                    editable.insert(index, bean.getTag());
                }
            }
        }
    });
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    lyBottomLayout.addView(layout, params);
    FUNC_EMOTICON_POS = FUNC_ORDER_COUNT;
    ++FUNC_ORDER_COUNT;
}
Also used : KeyEvent(android.view.KeyEvent) EmoticonBean(cn.hadcn.keyboard.emoticon.EmoticonBean) EmoticonsKeyboardBuilder(cn.hadcn.keyboard.emoticon.util.EmoticonsKeyboardBuilder) Editable(android.text.Editable) EmoticonLayout(cn.hadcn.keyboard.emoticon.view.EmoticonLayout) LinearLayout(android.widget.LinearLayout)

Example 8 with EmoticonBean

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

Example 9 with EmoticonBean

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

the class EmoticonsAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if (convertView == null) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.emoticons_item, parent, false);
        convertView.setLayoutParams(new AbsListView.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, mItemHeight));
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(mImgHeight, mImgHeight);
        //params.addRule(RelativeLayout.CENTER_HORIZONTAL);
        viewHolder = new ViewHolder(convertView);
        viewHolder.ivEmoticon.setLayoutParams(params);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
    final EmoticonBean emoticonBean = getItem(position);
    if (emoticonBean != null) {
        // exists some empty block
        viewHolder.ivEmoticon.setBackgroundResource(R.drawable.emoticon_bg);
        if (isDisplayName) {
            viewHolder.tvName.setVisibility(View.VISIBLE);
            viewHolder.tvName.setText(getItem(position).getName());
        } else {
            viewHolder.tvName.setVisibility(View.GONE);
        }
        viewHolder.ivEmoticon.setImageDrawable(EmoticonLoader.getInstance(mContext).getDrawable(emoticonBean.getIconUri()));
        convertView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mOnItemListener != null) {
                    mOnItemListener.onItemClick(emoticonBean);
                }
            }
        });
    }
    return convertView;
}
Also used : EmoticonBean(cn.hadcn.keyboard.emoticon.EmoticonBean) AbsListView(android.widget.AbsListView) ImageView(android.widget.ImageView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) View(android.view.View) LinearLayout(android.widget.LinearLayout)

Example 10 with EmoticonBean

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

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