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

本文介绍了如何在Android应用中实现新浪微博客户端的表情功能,包括从服务器下载表情图片,将图片放入资源文件,使用SAX解析XML获取表情信息,并在用户界面展示和插入编辑框。
摘要由CSDN通过智能技术生成

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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值