# XhsEmoticonsKeyboard **Repository Path**: eebb_ldx/XhsEmoticonsKeyboard ## Basic Information - **Project Name**: XhsEmoticonsKeyboard - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-04-12 - **Last Updated**: 2024-11-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # XhsEmoticonsKeyboard > j.s 🇨🇳 最良心的开源表情键盘解决方案。 # Features * API > 9 * 表情键盘支持无闪烁自跟随系统软键盘高度,及支持自定义高度 * 表情支持自定义格式,支持任意来源 * 组件支持完全自定义,样式支持任意更改 * 支持全屏 * 默认微信键盘样式 * 赠QQ键盘高仿,不谢 ![Art](https://github.com/w446108264/XhsEmoticonsKeyboard/raw/master/output/show.gif) # Screen Recrod # Emoji a lib about emoji -> 「[w446108264/AndroidEmoji](https://github.com/w446108264/AndroidEmoji)」 # Samples APK You can [download a sample APK](https://github.com/w446108264/XhsEmoticonsKeyboard/raw/master/output/simple.apk) or [Simple2 APK](https://github.com/w446108264/XhsEmoticonsKeyboard/raw/master/output/simple2.apk) # Gradle Dependency Users of your library will need add the jitpack.io repository: ```xml allprojects { repositories { jcenter() maven { url "https://jitpack.io" } } } ``` and: ```xml dependencies { compile 'com.github.w446108264:XhsEmoticonsKeyboard:2.0.4' } ``` # Samples Usage ```xml ``` demo -> [Demo](https://github.com/w446108264/XhsEmoticonsKeyboard/blob/master/Simple2/app/src/main/java/com/simple2/MainActivity.java) ```java // simple // https://github.com/w446108264/XhsEmoticonsKeyboard/blob/master/Simple2/app/src/main/java/com/simple2/MainActivity.java // https://github.com/w446108264/XhsEmoticonsKeyboard/blob/master/XhsEmoticonsKeyboard/app/src/main/java/com/xhsemoticonskeyboard/common/SimpleCommonUtils.java // dot't forget // compile 'com.github.w446108264:AndroidEmoji:1.0.0' final XhsEmoticonsKeyBoard ek_bar = (XhsEmoticonsKeyBoard) findViewById(R.id.ek_bar); // source data ArrayList emojiArray = new ArrayList<>(); Collections.addAll(emojiArray, DefEmoticons.sEmojiArray); // 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() { @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(ImageBase.Scheme.DRAWABLE.toUri("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)); EmojiDisplay.emojiDisplay(editText.getContext(), editText.getText(), emojiHex, emojiSize, start + m.start(), start + m.end()); } } } 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()); ``` # Else if you want to change the System status bar ```java // like this getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); // this if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } ``` you should add a Layout on the outside , demo -> [SimpleTranslucentChatActivity](https://github.com/w446108264/XhsEmoticonsKeyboard/blob/master/XhsEmoticonsKeyboard/app/src/main/java/com/xhsemoticonskeyboard/activity/SimpleTranslucentChatActivity.java) ```xml ``` # Simple Default Keyboard Layout Tree 「 [SVG high definition](http://www.shengjun.red/treeview.svg) 」 # Contact & Help Please fell free to contact me if there is any problem when using the library. * email: shengjun8486@gmail.com # License ``` MIT License Copyright (c) 2017 w446108264 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ```