Search in sources :

Example 6 with EmoticonPageSetEntity

use of sj.keyboard.data.EmoticonPageSetEntity in project XhsEmoticonsKeyboard by w446108264.

the class XmlUtil method ParserXml.

public EmoticonPageSetEntity<EmoticonEntity> ParserXml(String filePath, InputStream inStream) {
    String arrayParentKey = "EmoticonBean";
    boolean isChildCheck = false;
    EmoticonPageSetEntity.Builder<EmoticonEntity> emoticonPageSetEntity = new EmoticonPageSetEntity.Builder<>();
    ArrayList<EmoticonEntity> emoticonList = new ArrayList<>();
    emoticonPageSetEntity.setEmoticonList(emoticonList);
    EmoticonEntity emoticonBeanTemp = null;
    if (null != inStream) {
        XmlPullParser pullParser = Xml.newPullParser();
        try {
            pullParser.setInput(inStream, "UTF-8");
            int event = pullParser.getEventType();
            while (event != XmlPullParser.END_DOCUMENT) {
                switch(event) {
                    case XmlPullParser.START_DOCUMENT:
                        break;
                    case XmlPullParser.START_TAG:
                        String skeyName = pullParser.getName();
                        /**
                             * EmoticonBeans data
                             */
                        if (isChildCheck && emoticonBeanTemp != null) {
                            if (skeyName.equals("eventType")) {
                                try {
                                    String value = pullParser.nextText();
                                    emoticonBeanTemp.setEventType(Integer.parseInt(value));
                                } catch (NumberFormatException e) {
                                }
                            } else if (skeyName.equals("iconUri")) {
                                String value = pullParser.nextText();
                                emoticonBeanTemp.setIconUri("file://" + filePath + "/" + value);
                            } else if (skeyName.equals("content")) {
                                String value = pullParser.nextText();
                                emoticonBeanTemp.setContent(value);
                            }
                        } else /**
                             * EmoticonSet data
                             */
                        {
                            try {
                                if (skeyName.equals("name")) {
                                    String value = pullParser.nextText();
                                    emoticonPageSetEntity.setSetName(value);
                                } else if (skeyName.equals("line")) {
                                    String value = pullParser.nextText();
                                    emoticonPageSetEntity.setLine(Integer.parseInt(value));
                                } else if (skeyName.equals("row")) {
                                    String value = pullParser.nextText();
                                    emoticonPageSetEntity.setRow(Integer.parseInt(value));
                                } else if (skeyName.equals("iconUri")) {
                                    String value = pullParser.nextText();
                                    emoticonPageSetEntity.setIconUri(value);
                                } else if (skeyName.equals("isShowDelBtn")) {
                                    String value = pullParser.nextText();
                                    EmoticonPageEntity.DelBtnStatus delBtnStatus;
                                    if (Integer.parseInt(value) == 1) {
                                        delBtnStatus = EmoticonPageEntity.DelBtnStatus.FOLLOW;
                                    } else if (Integer.parseInt(value) == 2) {
                                        delBtnStatus = EmoticonPageEntity.DelBtnStatus.LAST;
                                    } else {
                                        delBtnStatus = EmoticonPageEntity.DelBtnStatus.GONE;
                                    }
                                    emoticonPageSetEntity.setShowDelBtn(delBtnStatus);
                                }
                            } catch (NumberFormatException e) {
                                e.printStackTrace();
                            }
                        }
                        if (skeyName.equals(arrayParentKey)) {
                            isChildCheck = true;
                            emoticonBeanTemp = new EmoticonEntity();
                        }
                        break;
                    case XmlPullParser.END_TAG:
                        String ekeyName = pullParser.getName();
                        if (isChildCheck && ekeyName.equals(arrayParentKey)) {
                            isChildCheck = false;
                            emoticonList.add(emoticonBeanTemp);
                        }
                        break;
                    default:
                        break;
                }
                event = pullParser.next();
            }
            return new EmoticonPageSetEntity(emoticonPageSetEntity);
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return new EmoticonPageSetEntity(emoticonPageSetEntity);
}
Also used : EmoticonEntity(sj.keyboard.data.EmoticonEntity) ArrayList(java.util.ArrayList) XmlPullParser(org.xmlpull.v1.XmlPullParser) EmoticonPageEntity(sj.keyboard.data.EmoticonPageEntity) IOException(java.io.IOException) EmoticonPageSetEntity(sj.keyboard.data.EmoticonPageSetEntity) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 7 with EmoticonPageSetEntity

use of sj.keyboard.data.EmoticonPageSetEntity in project XhsEmoticonsKeyboard by w446108264.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final XhsEmoticonsKeyBoard ek_bar = (XhsEmoticonsKeyBoard) findViewById(R.id.ek_bar);
    // source data
    ArrayList<EmojiBean> emojiArray = new ArrayList<>();
    Collections.addAll(emojiArray, DefEmoticons.getDefEmojiArray());
    // emoticon click
    final EmoticonClickListener emoticonClickListener = new EmoticonClickListener() {

        @Override
        public void onEmoticonClick(Object o, int actionType, boolean isDelBtn) {
            if (isDelBtn) {
                int action = KeyEvent.ACTION_DOWN;
                int code = KeyEvent.KEYCODE_DEL;
                KeyEvent event = new KeyEvent(action, code);
                ek_bar.getEtChat().onKeyDown(KeyEvent.KEYCODE_DEL, event);
            } else {
                if (o == null) {
                    return;
                }
                String content = null;
                if (o instanceof EmojiBean) {
                    content = ((EmojiBean) o).emoji;
                }
                int index = ek_bar.getEtChat().getSelectionStart();
                Editable editable = ek_bar.getEtChat().getText();
                editable.insert(index, content);
            }
        }
    };
    // emoticon instantiate
    final EmoticonDisplayListener emoticonDisplayListener = new EmoticonDisplayListener() {

        @Override
        public void onBindView(int i, ViewGroup viewGroup, EmoticonsAdapter.ViewHolder viewHolder, Object object, final boolean isDelBtn) {
            final EmojiBean emojiBean = (EmojiBean) object;
            if (emojiBean == null && !isDelBtn) {
                return;
            }
            viewHolder.ly_root.setBackgroundResource(com.keyboard.view.R.drawable.bg_emoticon);
            if (isDelBtn) {
                viewHolder.iv_emoticon.setImageResource(R.mipmap.icon_del);
            } else {
                viewHolder.iv_emoticon.setImageResource(emojiBean.icon);
            }
            viewHolder.rootView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    emoticonClickListener.onEmoticonClick(emojiBean, 0, isDelBtn);
                }
            });
        }
    };
    //  page instantiate
    PageViewInstantiateListener pageViewInstantiateListener = new PageViewInstantiateListener<EmoticonPageEntity>() {

        @Override
        public View instantiateItem(ViewGroup viewGroup, int i, EmoticonPageEntity pageEntity) {
            if (pageEntity.getRootView() == null) {
                EmoticonPageView pageView = new EmoticonPageView(viewGroup.getContext());
                pageView.setNumColumns(pageEntity.getRow());
                pageEntity.setRootView(pageView);
                try {
                    EmoticonsAdapter adapter = new EmoticonsAdapter(viewGroup.getContext(), pageEntity, null);
                    // emoticon instantiate
                    adapter.setOnDisPlayListener(emoticonDisplayListener);
                    pageView.getEmoticonsGridView().setAdapter(adapter);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return pageEntity.getRootView();
        }
    };
    // build
    EmoticonPageSetEntity xhsPageSetEntity = new EmoticonPageSetEntity.Builder().setLine(3).setRow(7).setEmoticonList(emojiArray).setIPageViewInstantiateItem(pageViewInstantiateListener).setShowDelBtn(EmoticonPageEntity.DelBtnStatus.LAST).setIconUri(R.mipmap.ic_launcher).build();
    PageSetAdapter pageSetAdapter = new PageSetAdapter();
    pageSetAdapter.add(xhsPageSetEntity);
    ek_bar.setAdapter(pageSetAdapter);
    class EmojiFilter extends EmoticonFilter {

        private int emojiSize = -1;

        @Override
        public void filter(EditText editText, CharSequence text, int start, int lengthBefore, int lengthAfter) {
            emojiSize = emojiSize == -1 ? EmoticonsKeyboardUtils.getFontHeight(editText) : emojiSize;
            clearSpan(editText.getText(), start, text.toString().length());
            Matcher m = EmojiDisplay.getMatcher(text.toString().substring(start, text.toString().length()));
            if (m != null) {
                while (m.find()) {
                    String emojiHex = Integer.toHexString(Character.codePointAt(m.group(), 0));
                    Drawable drawable = getDrawable(editText.getContext(), EmojiDisplay.HEAD_NAME + emojiHex);
                    if (drawable != null) {
                        int itemHeight;
                        int itemWidth;
                        if (emojiSize == EmojiDisplay.WRAP_DRAWABLE) {
                            itemHeight = drawable.getIntrinsicHeight();
                            itemWidth = drawable.getIntrinsicWidth();
                        } else {
                            itemHeight = emojiSize;
                            itemWidth = emojiSize;
                        }
                        drawable.setBounds(0, 0, itemHeight, itemWidth);
                        EmojiSpan imageSpan = new EmojiSpan(drawable);
                        editText.getText().setSpan(imageSpan, start + m.start(), start + m.end(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                    }
                }
            }
        }

        private void clearSpan(Spannable spannable, int start, int end) {
            if (start == end) {
                return;
            }
            EmojiSpan[] oldSpans = spannable.getSpans(start, end, EmojiSpan.class);
            for (int i = 0; i < oldSpans.length; i++) {
                spannable.removeSpan(oldSpans[i]);
            }
        }
    }
    // add a filter
    ek_bar.getEtChat().addEmoticonFilter(new EmojiFilter());
}
Also used : PageViewInstantiateListener(sj.keyboard.interfaces.PageViewInstantiateListener) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) EmoticonPageEntity(sj.keyboard.data.EmoticonPageEntity) KeyEvent(android.view.KeyEvent) EmoticonClickListener(sj.keyboard.interfaces.EmoticonClickListener) EmojiBean(com.sj.emoji.EmojiBean) Editable(android.text.Editable) XhsEmoticonsKeyBoard(sj.keyboard.XhsEmoticonsKeyBoard) EditText(android.widget.EditText) EmoticonsAdapter(sj.keyboard.adpater.EmoticonsAdapter) ViewGroup(android.view.ViewGroup) EmojiSpan(com.sj.emoji.EmojiSpan) Drawable(android.graphics.drawable.Drawable) View(android.view.View) EmoticonPageView(sj.keyboard.widget.EmoticonPageView) EmoticonPageSetEntity(sj.keyboard.data.EmoticonPageSetEntity) EmoticonFilter(sj.keyboard.interfaces.EmoticonFilter) EmoticonPageView(sj.keyboard.widget.EmoticonPageView) PageSetAdapter(sj.keyboard.adpater.PageSetAdapter) EmoticonDisplayListener(sj.keyboard.interfaces.EmoticonDisplayListener) Spannable(android.text.Spannable)

Example 8 with EmoticonPageSetEntity

use of sj.keyboard.data.EmoticonPageSetEntity in project XhsEmoticonsKeyboard by w446108264.

the class SimpleCommonUtils method addKaomojiPageSetEntity.

/**
     * 插入颜文字表情集
     *
     * @param pageSetAdapter
     * @param context
     * @param emoticonClickListener
     */
public static void addKaomojiPageSetEntity(PageSetAdapter pageSetAdapter, Context context, EmoticonClickListener emoticonClickListener) {
    EmoticonPageSetEntity kaomojiPageSetEntity = new EmoticonPageSetEntity.Builder().setLine(3).setRow(3).setEmoticonList(ParseDataUtils.parseKaomojiData(context)).setIPageViewInstantiateItem(getEmoticonPageViewInstantiateItem(TextEmoticonsAdapter.class, emoticonClickListener)).setIconUri(ImageBase.Scheme.DRAWABLE.toUri("icon_kaomoji")).build();
    pageSetAdapter.add(kaomojiPageSetEntity);
}
Also used : TextEmoticonsAdapter(com.xhsemoticonskeyboard.common.adapter.emoticonadapter.TextEmoticonsAdapter) SpannableStringBuilder(android.text.SpannableStringBuilder) EmoticonPageSetEntity(sj.keyboard.data.EmoticonPageSetEntity)

Aggregations

EmoticonPageSetEntity (sj.keyboard.data.EmoticonPageSetEntity)8 SpannableStringBuilder (android.text.SpannableStringBuilder)3 ViewGroup (android.view.ViewGroup)3 ArrayList (java.util.ArrayList)3 EmoticonsAdapter (sj.keyboard.adpater.EmoticonsAdapter)3 EmoticonEntity (sj.keyboard.data.EmoticonEntity)3 EmoticonPageEntity (sj.keyboard.data.EmoticonPageEntity)3 EmoticonPageView (sj.keyboard.widget.EmoticonPageView)3 View (android.view.View)2 EmojiBean (com.sj.emoji.EmojiBean)2 BigEmoticonsAdapter (com.xhsemoticonskeyboard.common.adapter.emoticonadapter.BigEmoticonsAdapter)2 TextEmoticonsAdapter (com.xhsemoticonskeyboard.common.adapter.emoticonadapter.TextEmoticonsAdapter)2 IOException (java.io.IOException)2 PageViewInstantiateListener (sj.keyboard.interfaces.PageViewInstantiateListener)2 Drawable (android.graphics.drawable.Drawable)1 Editable (android.text.Editable)1 Spannable (android.text.Spannable)1 KeyEvent (android.view.KeyEvent)1 EditText (android.widget.EditText)1 TextView (android.widget.TextView)1