注册

【环信3.x Android加表情】加表情三部曲,你值得拥有!!!

写在前面:不知道是不是因为这个需求太简单了还是什么原因,我发现这个需求的教程居然少的可怜!!!这让我这种小白如何是好~!!!正好今天实现了,就写出来,希望能帮助到和我这类的小白。
 
首先我实现方式就是仿照官方demo里兔斯基的实现方式,在自带的表情基础上增加一组新表情。所以就很简单了!!!首先就不说如何集成环信demo了,相信有这个需求的人都是已经集成好了的。
  1. 第一部

    首先找到EmojiconExampleGroupData这个类,复制一份照着修改下,我的代码如下:
package com.liancheng.tiantianzhengchong.HuanXin.domain;


import com.hyphenate.easeui.domain.EaseEmojicon;
import com.hyphenate.easeui.domain.EaseEmojicon.Type;
import com.hyphenate.easeui.domain.EaseEmojiconGroupEntity;
import com.liancheng.tiantianzhengchong.R;

import java.util.Arrays;

public class EmojiconSinaGroupData {

private static int[] icons = new int[]{
R.drawable.d_aini,
R.drawable.d_aoteman,
R.drawable.d_baibai,
R.drawable.d_baobao,
R.drawable.d_beishang,
R.drawable.d_bishi,
R.drawable.d_bizui,
R.drawable.d_chanzui,
R.drawable.d_chijing,
R.drawable.d_dahaqi,
R.drawable.d_dalian,
R.drawable.d_ding,
R.drawable.d_doge,
R.drawable.d_erha,
R.drawable.d_feizao,
R.drawable.d_ganmao,
R.drawable.d_guzhang,
R.drawable.d_haha,
R.drawable.d_haixiu,
R.drawable.d_han,
R.drawable.d_hehe,
R.drawable.d_heixian,
R.drawable.d_heng,
R.drawable.d_huaixiao,
R.drawable.d_huaxin,
R.drawable.d_jiyan,
R.drawable.d_keai,
R.drawable.d_kelian,
R.drawable.d_ku,
R.drawable.d_kulou,
R.drawable.d_kun,
R.drawable.d_landelini,
R.drawable.d_lang,
R.drawable.d_lei,
R.drawable.d_miao,
R.drawable.d_nanhaier,
R.drawable.d_nu,
R.drawable.d_numa,
R.drawable.d_nvhaier,
R.drawable.d_qian,
R.drawable.d_qinqin,
R.drawable.d_shayan,
R.drawable.d_shengbing,
R.drawable.d_shenshou,
R.drawable.d_shiwang,
R.drawable.d_shuai,
R.drawable.d_shuijiao,
R.drawable.d_sikao,
R.drawable.d_taikaixin,
R.drawable.d_tanshou,
R.drawable.d_tian,
R.drawable.d_touxiao,
R.drawable.d_tu,
R.drawable.d_tuzi,
R.drawable.d_wabishi,
R.drawable.d_weiqu,
R.drawable.d_wu,
R.drawable.d_xiaoku,
R.drawable.d_xiongmao,
R.drawable.d_xixi,
R.drawable.d_xu,
R.drawable.d_yinxian,
R.drawable.d_yiwen,
R.drawable.d_youhengheng,
R.drawable.d_yun,
R.drawable.d_zhuakuang,
R.drawable.d_zhutou,
R.drawable.d_zuiyou,
R.drawable.d_zuohengheng,

R.drawable.f_geili,
R.drawable.f_hufen,
R.drawable.f_jiong,
R.drawable.f_meng,
R.drawable.f_shenma,
R.drawable.f_v5,
R.drawable.f_xi,
R.drawable.f_zhi,
R.drawable.h_buyao,
R.drawable.h_good,
R.drawable.h_haha,
R.drawable.h_jiayou,
R.drawable.h_lai,
R.drawable.h_ok,
R.drawable.h_quantou,
R.drawable.h_ruo,
R.drawable.h_woshou,
R.drawable.h_ye,
R.drawable.h_zan,
R.drawable.h_zuoyi,
R.drawable.l_shangxin,
R.drawable.l_xin,
R.drawable.lxh_haoaio,
R.drawable.lxh_haoxihuan,
R.drawable.lxh_oye,
R.drawable.lxh_qiuguanzhu,
R.drawable.lxh_toule,
R.drawable.lxh_xiaohaha,
R.drawable.lxh_xiudada,
R.drawable.lxh_zana,
R.drawable.o_dangao,
R.drawable.o_feiji,
R.drawable.o_ganbei,
R.drawable.o_huatong,
R.drawable.o_lazhu,
R.drawable.o_liwu,
R.drawable.o_lvsidai,
R.drawable.o_weibo,
R.drawable.o_weiguan,
R.drawable.o_yinyue,
R.drawable.o_zhaoxiangji,
R.drawable.o_zhong,
R.drawable.w_fuyun,
R.drawable.w_shachenbao,
R.drawable.w_taiyang,
R.drawable.w_weifeng,
R.drawable.w_xianhua,
R.drawable.w_xiayu,
R.drawable.w_yueliang

};

private static String[] icons_name = new String[]{
"[爱你]",
"[奥特曼]",
"[拜拜]",
"[抱抱]",
"[悲伤]",
"[鄙视]",
"[闭嘴]",
"[馋嘴]",
"[吃惊]",
"[打哈气]",
"[打脸]",
"[顶]",
"[doge]",
"[二哈]",
"[肥皂]",
"[感冒]",
"[鼓掌]",
"[哈哈]",
"[害羞]",
"[汗]",
"[呵呵]",
"[黑线]",
"[哼]",
"[坏笑]",
"[花心]",
"[挤眼]",
"[可爱]",
"[可怜]",
"[酷]",
"[骷髅]",
"[困]",
"[懒得理你]",
"[浪]",
"[泪]",
"[喵喵]",
"[男孩儿]",
"[怒]",
"[怒骂]",
"[女孩儿]",
"[钱]",
"[亲亲]",
"[傻眼]",
"[生病]",
"[草泥马]",
"[失望]",
"[衰]",
"[睡觉]",
"[思考]",
"[太开心]",
"[摊手]",
"[舔屏]",
"[偷笑]",
"[吐]",
"[兔子]",
"[挖鼻屎]",
"[委屈]",
"[污]",
"[笑cry]",
"[熊猫]",
"[嘻嘻]",
"[嘘]",
"[阴险]",
"[疑问]",
"[右哼哼]",
"[晕]",
"[抓狂]",
"[猪头]",
"[最右]",
"[左哼哼]",

"[给力]",
"[互粉]",
"[囧]",
"[萌]",
"[神马]",
"[威武]",
"[喜]",
"[织毛线]",
"[NO]",
"[good]",
"[haha]",
"[加油]",
"[来]",
"[ok]",
"[拳头]",
"[弱]",
"[握手]",
"[耶]",
"[赞]",
"[作揖]",
"[伤心]",
"[心]",
"[好爱哦]",
"[好喜欢]",
"[噢耶]",
"[求关注]",
"[偷乐]",
"[笑哈哈]",
"[羞嗒嗒]",
"[赞啊]",
"[蛋糕]",
"[飞机]",
"[干杯]",
"[话筒]",
"[蜡烛]",
"[礼物]",
"[绿丝带]",
"[围脖]",
"[围观]",
"[音乐]",
"[照相机]",
"[钟]",
"[浮云]",
"[沙尘暴]",
"[太阳]",
"[微风]",
"[鲜花]",
"[下雨]",
"[月亮]"
};


private static final EaseEmojiconGroupEntity DATA = createData();

private static EaseEmojiconGroupEntity createData() {
EaseEmojiconGroupEntity emojiconGroupEntity = new EaseEmojiconGroupEntity();
EaseEmojicon[] datas = new EaseEmojicon[icons.length];
for (int i = 0; i < icons.length; i++) {
datas[i] = new EaseEmojicon(icons[i], icons_name[i], Type.BIG_EXPRESSION);
datas[i].setBigIcon(icons[i]);
//you can replace this to any you want
datas[i].setName(icons_name[i]);
datas[i].setIdentityCode("sina" + (1000 + i + 1));
}
emojiconGroupEntity.setEmojiconList(Arrays.asList(datas));
emojiconGroupEntity.setIcon(R.drawable.ee_3);
emojiconGroupEntity.setType(Type.BIG_EXPRESSION);//设置类型,如果是nomal就可以输入输入框
return emojiconGroupEntity;
}


public static EaseEmojiconGroupEntity getData() {
return DATA;
}
}
这里说明下,
datas[i] = new EaseEmojicon(icons[i], icons_name[i], Type.BIG_EXPRESSION);

emojiconGroupEntity.setType(Type.BIG_EXPRESSION);

主要是这里要设置下type类型,这里以BIG_EXPRESSION形式,如何设置成nomal的话,发出来的是纯文字的,不能显示表情的,需要用的话,得修改easeui里的东西,不推荐。一般需要加新表情都是已大图形式的,如果需要纯文字,可以加在默认的(第一组)表情里!
  2.第二部
   找到ChatFragment,找到((EaseEmojiconMenu)inputMenu.getEmojiconMenu()).addEmojiconGroup(EmojiconExampleGroupData.getData());
复制一份,修改成
((EaseEmojiconMenu) inputMenu.getEmojiconMenu()).addEmojiconGroup(EmojiconSinaGroupData.getData());
加在这句后面。
  3.第三部
   找到DemoHelper,找到easeUI.setEmojiconInfoProvider,写成如下:
  //set emoji icon provider
easeUI.setEmojiconInfoProvider(new EaseEmojiconInfoProvider() {

@Override
public EaseEmojicon getEmojiconInfo(String emojiconIdentityCode) {
//第一种表情
EaseEmojiconGroupEntity data = EmojiconExampleGroupData.getData();
for (EaseEmojicon emojicon : data.getEmojiconList()) {
if (emojicon.getIdentityCode().equals(emojiconIdentityCode)) {
return emojicon;
}
}
//新增的第二种表情
EaseEmojiconGroupEntity data_sina = EmojiconSinaGroupData.getData();
for (EaseEmojicon emojicon : data_sina.getEmojiconList()) {
if (emojicon.getIdentityCode().equals(emojiconIdentityCode)) {
return emojicon;
}
}
return null;
}

@Override
public Map<String, Object> getTextEmojiconMapping() {
return null;
}
});
   最后写完了,希望能帮到和我这样的小白!!!
 
 

2 个评论

厉害了我的哥!我要给你赞赏。
谢谢!!!

要回复文章请先登录注册