4.实现一个可以让用户选择的表情界面,本人用GridView实现

5.实现点击GridView的每一个item,处理根据item的index查找对应的表情code,然后再把code利用正则把code转换为相对应的表情图片,最后表情插入EditText进行发送。

下面是具体的实现过程

1.把新浪表情图片下载到本地的实现如下:(这个可以建一个java工程进行下载)

Java代码

  1. public void getFriendList() throws Exception {

  2. BlogReleaseServiceImpl service = new BlogReleaseServiceImpl();

  3. List list = service.getEmotion();

  4. for (Emotions emotions : list) {

  5. String path = emotions.getUrl();

  6. String filename = path.substring(path.lastIndexOf("/") + 1,path.length());

  7. URL url =  new URL(path);

  8. HttpURLConnection conn = (HttpURLConnection)url.openConnection();

  9. conn.setRequestMethod(“GET”);

  10. conn.setReadTimeout(5 * 1000);

  11. if(conn.getResponseCode() == 200){

  12. InputStream is = conn.getInputStream();

  13. byte[] data = readStream(is);

  14. File file = new File(“f: \\sina_images\\” + filename);

  15. FileOutputStream fs = new FileOutputStream(file);

  16. fs.write(data);

  17. fs.close();

  18. }else{

  19. System.out.println(“请求失败”);

  20. }

  21. }

  22. }

  23. public byte[] readStream(InputStream is) throws Exception {

  24. ByteArrayOutputStream os = new ByteArrayOutputStream();

  25. byte[] buffer = new byte[2048];

  26. int len = 0;

  27. while((len = is.read(buffer)) != -1){

  28. os.write(buffer,0,len);

  29. }

  30. is.close();

  31. return os.toByteArray();

  32. }

public void getFriendList() throws Exception {

BlogReleaseServiceImpl service = new BlogReleaseServiceImpl();

List list = service.getEmotion();

for (Emotions emotions : list) {

String path = emotions.getUrl();

String filename = path.substring(path.lastIndexOf("/") + 1,path.length());

URL url = new URL(path);

HttpURLConnection conn = (HttpURLConnection)url.openConnection();

conn.setRequestMethod(“GET”);

conn.setReadTimeout(5 * 1000);

if(conn.getResponseCode() == 200){

InputStream is = conn.getInputStream();

byte[] data = readStream(is);

File file = new File(“f: \sina_images\” + filename);

FileOutputStream fs = new FileOutputStream(file);

fs.write(data);

fs.close();

}else{

System.out.println(“请求失败”);

}

}

}

public byte[] readStream(InputStream is) throws Exception {

ByteArrayOutputStream os = new ByteArrayOutputStream();

byte[] buffer = new byte[2048];

int len = 0;

while((len = is.read(buffer)) != -1){

os.write(buffer,0,len);

}

is.close();

return os.toByteArray();

}

2:把本地的表情都放进android的资源文件里----drawable下面(这个就不用多说了,直接选取所有文件复制就行了)

3:

3.1访问新浪的表情接口,把返回的信息如下:

Xml代码

  1. <emotion>

  2. <phrase>[嘻嘻]</phrase>

  3. <type>face</type>

  4. <url>http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/c2/tooth.gif

  5. </url>

  6. <is_hot>false</is_hot>

  7. <is_common>true</is_common>

  8. <order_number>0</order_number>

  9. <category></category>

  10. lt;/emotion>

[嘻嘻]

face

http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/c2/tooth.gif

<is_hot>false</is_hot>

<is_common>true</is_common>

<order_number>0</order_number>

3.2 储存在一个Emotion.java里。Emotion.java代码如下:

Java代码

  1. package com.uim.microblog.model;

  2. import java.io.Serializable;

  3. public class Emotions implements Serializable {

  4. /**

  5. *

  6. */

  7. private static final long serialVersionUID = 1L;

  8. private String phrase;//表情使用的替代文字

  9. private String type;

  10. private String url;//表情图片存放的位置

  11. private String isHot;//是否为热门表情

  12. private String isCommon;//是否属于通用

  13. private String orderNumber;//该表情在系统中的排序号码

  14. private String category;//表情分类

  15. private String imageName;//表情名称

  16. public String getImageName() {

  17. return imageName;

  18. }

  19. public void setImageName(String imageName) {

  20. this.imageName = imageName;

  21. }

  22. public String getPhrase() {

  23. return phrase;

  24. }

  25. public void setPhrase(String phrase) {

  26. this.phrase = phrase;

  27. }

  28. public String getType() {

  29. return type;

  30. }

  31. public void setType(String type) {

  32. this.type = type;

  33. }

  34. public String getUrl() {

  35. return url;

  36. }

  37. public void setUrl(String url) {

  38. this.url = url;

  39. }

  40. public String getIsHot() {

  41. return isHot;

  42. }

  43. public void setIsHot(String isHot) {

  44. this.isHot = isHot;

  45. }

  46. public String getIsCommon() {

  47. return isCommon;

  48. }

  49. public void setIsCommon(String isCommon) {

  50. this.isCommon = isCommon;

  51. }

  52. public String getOrderNumber() {

  53. return orderNumber;

  54. }

  55. public void setOrderNumber(String orderNumber) {

  56. this.orderNumber = orderNumber;

  57. }

  58. public String getCategory() {

  59. return category;

  60. }

  61. public void setCategory(String category) {

  62. this.category = category;

  63. }

  64. }

package com.uim.microblog.model;

import java.io.Serializable;

public class Emotions implements Serializable {

/**

*/

private static final long serialVersionUID = 1L;

private String phrase;//表情使用的替代文字

private String type;

private String url;//表情图片存放的位置

private String isHot;//是否为热门表情

private String isCommon;//是否属于通用

private String orderNumber;//该表情在系统中的排序号码

private String category;//表情分类

private String imageName;//表情名称

public String getImageName() {

return imageName;

}

public void setImageName(String imageName) {

this.imageName = imageName;

}

public String getPhrase() {

return phrase;

}

public void setPhrase(String phrase) {

this.phrase = phrase;

}

public String getType() {

return type;

}

public void setType(String type) {

this.type = type;

}

public String getUrl() {

return url;

}

public void setUrl(String url) {

this.url = url;

}

public String getIsHot() {

return isHot;

}

public void setIsHot(String isHot) {

this.isHot = isHot;

}

public String getIsCommon() {

return isCommon;

}

public void setIsCommon(String isCommon) {

this.isCommon = isCommon;

}

public String getOrderNumber() {

return orderNumber;

}

public void setOrderNumber(String orderNumber) {

this.orderNumber = orderNumber;

}

public String getCategory() {

return category;

}

public void setCategory(String category) {

this.category = category;

}

}

3.3xm sax解析l的handler如下:

Java代码

  1. package com.uim.microblog.net.handler;

  2. import java.util.ArrayList;

  3. import java.util.List;

  4. import org.xml.sax.Attributes;

  5. import org.xml.sax.SAXException;

  6. import org.xml.sax.helpers.DefaultHandler;

  7. import com.uim.microblog.model.Emotions;

  8. import com.uim.microblog.model.ResponseResult;

  9. public class BlogEmotionsHandler extends DefaultHandler {

  10. private List list;

  11. private Emotions emotions;

  12. private ResponseResult responseresult;

  13. private String tag = null;//正在解析的元素

  14. public List getEmotionsList(){

  15. return list;

  16. }

  17. @Override

  18. public void characters(char[] ch, int start, int length)

  19. throws SAXException {

  20. if (tag != null) {

  21. String textArea = new String(ch,start,length);

  22. /**开始解析表情数据*/

  23. if (“phrase”.equals(tag)) {

  24. emotions.setPhrase(textArea);

  25. } else if (“type”.equals(tag)) {

  26. emotions.setType(textArea);

  27. } else if (“url”.equals(tag)) {

  28. try {

  29. emotions.setUrl(textArea);

  30. String imageName = textArea.substring(textArea.lastIndexOf("/") + 1,textArea.length() - 4);

  31. emotions.setImageName(imageName);

  32. } catch (Exception e) {

  33. e.printStackTrace();

  34. }

  35. } else if (“is_hot”.equals(tag)) {

  36. emotions.setIsHot(textArea);

  37. } else if (“is_common”.equals(tag)) {

  38. emotions.setIsCommon(textArea);

  39. } else if (“order_number”.equals(tag)) {

  40. emotions.setOrderNumber(textArea);

  41. } else if (“category”.equals(tag)) {

  42. emotions.setCategory(textArea);

  43. } else if (“retn”.equals(tag)) {

  44. responseresult.setRetn(textArea);

  45. } else if (“desc”.equals(tag)) {

  46. responseresult.setDesc(textArea);

  47. }

  48. }

  49. }

  50. @Override

  51. public void endDocument() throws SAXException {

  52. super.endDocument();

  53. }

  54. @Override

  55. public void endElement(String uri, String localName, String qName)

  56. throws SAXException {

  57. tag = null;

  58. if (“mb”.equals(localName)) {

  59. } else if (“emotions”.equals(localName)) {

  60. responseresult =null;

  61. } else if (“emotion”.equals(localName)) {

  62. list.add(emotions);

  63. emotions = null;

  64. }

  65. }

  66. @Override

  67. public void startDocument() throws SAXException {

  68. list = new ArrayList();

  69. }

  70. @Override

  71. public void startElement(String uri, String localName, String qName,

  72. Attributes attributes) throws SAXException {

  73. if (“mb”.equals(localName)) {

  74. responseresult = new ResponseResult();

  75. } else if (“emotions”.equals(localName)) {

  76. } else if (“emotion”.equals(localName)) {

  77. emotions = new Emotions();

  78. }

  79. tag = localName;

  80. }

  81. }

package com.uim.microblog.net.handler;

import java.util.ArrayList;

import java.util.List;

import org.xml.sax.Attributes;

import org.xml.sax.SAXException;

import org.xml.sax.helpers.DefaultHandler;

import com.uim.microblog.model.Emotions;

import com.uim.microblog.model.ResponseResult;

public class BlogEmotionsHandler extends DefaultHandler {

private List list;

private Emotions emotions;

private ResponseResult responseresult;

private String tag = null;//正在解析的元素

public List getEmotionsList(){

return list;

}

@Override

public void characters(char[] ch, int start, int length)

throws SAXException {

if (tag != null) {

String textArea = new String(ch,start,length);

/*开始解析表情数据/

if (“phrase”.equals(tag)) {

emotions.setPhrase(textArea);

} else if (“type”.equals(tag)) {

emotions.setType(textArea);

} else if (“url”.equals(tag)) {

try {

emotions.setUrl(textArea);

String imageName = textArea.substring(textArea.lastIndexOf("/") + 1,textArea.length() - 4);

emotions.setImageName(imageName);

} catch (Exception e) {

e.printStackTrace();

}

} else if (“is_hot”.equals(tag)) {

emotions.setIsHot(textArea);

} else if (“is_common”.equals(tag)) {

emotions.setIsCommon(textArea);

} else if (“order_number”.equals(tag)) {

emotions.setOrderNumber(textArea);

} else if (“category”.equals(tag)) {

emotions.setCategory(textArea);

} else if (“retn”.equals(tag)) {

responseresult.setRetn(textArea);

} else if (“desc”
.equals(tag)) {

responseresult.setDesc(textArea);

}

}

}

@Override

public void endDocument() throws SAXException {

super.endDocument();

}

@Override

public void endElement(String uri, String localName, String qName)

throws SAXException {

tag = null;

if (“mb”.equals(localName)) {

} else if (“emotions”.equals(localName)) {

responseresult =null;

} else if (“emotion”.equals(localName)) {

list.add(emotions);

emotions = null;

}

}

@Override

public void startDocument() throws SAXException {

list = new ArrayList();

}

@Override

public void startElement(String uri, String localName, String qName,

Attributes attributes) throws SAXException {

if (“mb”.equals(localName)) {

responseresult = new ResponseResult();

} else if (“emotions”.equals(localName)) {

} else if (“emotion”.equals(localName)) {

emotions = new Emotions();

}

tag = localName;

}

}

3.4sax解析

Java代码

  1. public List getEmotion(){

  2. BlogGetData getdata = new BlogGetData();

  3. String result = getdata.blogEmotionsServlet();

  4. try {

  5. //生成SAX解析对象

  6. parser = SAXParserFactory.newInstance().newSAXParser();

  7. //生成xml读取器

  8. reader = parser.getXMLReader();

  9. BlogEmotionsHandler handler = new BlogEmotionsHandler();

  10. //设置Handler

  11. reader.setContentHandler(handler);

  12. //指定文件,进行解析

  13. reader.parse(new InputSource(new StringReader(result)));   
    quals(localName)) {

responseresult = new ResponseResult();

} else if (“emotions”.equals(localName)) {

} else if (“emotion”.equals(localName)) {

emotions = new Emotions();

}

tag = localName;

}

}

3.4sax解析

Java代码

  1. public List getEmotion(){

  2. BlogGetData getdata = new BlogGetData();

  3. String result = getdata.blogEmotionsServlet();

  4. try {

  5. //生成SAX解析对象

  6. parser = SAXParserFactory.newInstance().newSAXParser();

  7. //生成xml读取器

  8. reader = parser.getXMLReader();

  9. BlogEmotionsHandler handler = new BlogEmotionsHandler();

  10. //设置Handler

  11. reader.setContentHandler(handler);

  12. //指定文件,进行解析

  13. reader.parse(new InputSource(new StringReader(result)));

android 新浪微博客户端的表情功能的实现,flutter教程pdf相关推荐

  1. android 新浪微博客户端的表情功能的实现

    这是一篇好文章,我转来收藏,技术的最高境界是分享. 最近在搞android 新浪微博客户端,有一些心得分享 弄android客户端表情功能可以用以下思路 1.首页把新浪的表情下载到本地一文件夹种,表情 ...

  2. android 新浪微博客户端开发

    [转载]android开发新浪微博客户端 完整攻略 分类: android 2011-04-23 22:45 3193人阅读 评论(4) 收藏 举报 开始接触学习android已经有3个礼拜了,一直都 ...

  3. android新浪微博客户端毕业设计课题背景

        原本天真地以为毕业设计课题选个做项目的就不用弄这些形形式式的文档了,结果导师告诉我:不要抱有侥幸心理!     然后就按部就班地花了近两小时写课题背景,奈何各种原因又要更换选题,为了资源的再利 ...

  4. android 4个button 田字布局,android新浪微博客户端开发.docx

    玄傲三菽境探 」 < N I.■ \ 1% I fi % l 1 1 安徽三联学院 ANHUI SANLIAN UNIVERSITY 本科毕业论文 论文题目基于An droid手机微博客户端的开 ...

  5. Android 新浪微博客户端

    大家好,很高兴来到CSDN博客,很高兴能在这个地方发表自己的一些见解,希望能够互相帮助,共同提高.     我是一名大学生,普普通通的一个二本学校,我就不说了.我是计算机专业的,学校开的课程实在是-- ...

  6. android开发我的新浪微博客户端-登录页面功能篇(4.2)

    上一篇中完成了如上图的UI部分的实现,现在继续来讲功能的实现,用户登录操作主要就是账号列表显示和选择账号登录两个功能其他的都是些简单的辅助功能,首先是点击id为iconSelectBtn的ImageB ...

  7. android开发我的新浪微博客户端-登录页面功能篇

    首先是从数据库中获取所有的账户记录然后设置默认选中的用户账号代码如下: private void initUser(){//获取账号列表dbHelper=new DataHelper(this);us ...

  8. Android新浪微博客户端的logo界面

    为了简化步骤,这一步只需要一张logo,颜色渐深,三秒显示后跳入下一个activity,同时去掉标题栏与状态栏.代码如下:logo.java中 package com.ding.ui; import ...

  9. android新浪微博客户端 开机Logo动画实现

    protected void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState); //全屏显示 th ...

  10. 云豹app直播源码Android 端获取相册图片功能的具体实现教程

    app直播源码开发时,关于动态功能的实现,通常采用类似于朋友圈式图文+视频模式,这就需要通过访问手机相册获取用户图片进行下一步操作,接下来就请跟随小编一起,从app直播源码角度探究云豹直播系统在这个功 ...

最新文章

  1. 商务之路有多远,贿赂就有多远吗? 续一
  2. doctype的三种类型
  3. 命令提示符中的几个重要的命令
  4. android关于获取摄像头帧数据转成图片
  5. bigdecimal 设置_BigDecimal 使用方法详解
  6. bzoj2431:[HAOI2009]逆序对数列
  7. Easyui datebox单击文本框显示日期选择
  8. bootstrap模态框和select2合用时input无法获取焦点
  9. 华为手机怎么使用读卡器_华为G7手机OTG功能详细使用教程
  10. 中国3月份采购经理人指数回升
  11. python 读bin文件_Python学习 | Python 读写文件-bin文件打开
  12. 服务器名称 历史修改记录,清除 SQL Server Management Studio 服务器名称历史记录
  13. 情感分析的一些专业术语
  14. 万物流变:从辩证法看互联网架构和人生
  15. Android R 11 后台定位权限没有 始终允许选项的解决方法
  16. 网页设计实验二( 格式化文本、段落与列表)
  17. linux mint安装金山快盘
  18. 消息称人人车破产 回应:纯属造谣
  19. Python-MongoDB
  20. 2019最新泰牛PHP大牛班(基础+高级+实战+全套课件)

热门文章

  1. 使用Python在指定文件夹新建一个文本文档(其他类型文件也可)
  2. 2022电工杯A题利用启发式算法寻优
  3. Thinkpad x200 X201拆机换风扇教程 实图
  4. MAC OS(U盘启动教程)
  5. python基础教程解压密码_python学习手册视频教程压缩包解压密码?
  6. python上的表白代码_用Python实现表白代码
  7. 互动教程 for Excel 2016
  8. 智慧城市是啥?能少点雾霾吗?
  9. 图片太模糊?这几个工具可以将图片变清晰
  10. Aha!设计模式(96)-观察者模式(1)