android 新浪微博客户端的表情功能的实现,flutter教程pdf
4.实现一个可以让用户选择的表情界面,本人用GridView实现
5.实现点击GridView的每一个item,处理根据item的index查找对应的表情code,然后再把code利用正则把code转换为相对应的表情图片,最后表情插入EditText进行发送。
下面是具体的实现过程
1.把新浪表情图片下载到本地的实现如下:(这个可以建一个java工程进行下载)
Java代码
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();
}
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代码
<emotion>
<phrase>[嘻嘻]</phrase>
<type>face</type>
<url>http://img.t.sinajs.cn/t35/style/images/common/face/ext/normal/c2/tooth.gif
</url>
<is_hot>false</is_hot>
<is_common>true</is_common>
<order_number>0</order_number>
<category></category>
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代码
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;
}
}
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代码
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;
}
}
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代码
public List getEmotion(){
BlogGetData getdata = new BlogGetData();
String result = getdata.blogEmotionsServlet();
try {
//生成SAX解析对象
parser = SAXParserFactory.newInstance().newSAXParser();
//生成xml读取器
reader = parser.getXMLReader();
BlogEmotionsHandler handler = new BlogEmotionsHandler();
//设置Handler
reader.setContentHandler(handler);
//指定文件,进行解析
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代码
public List getEmotion(){
BlogGetData getdata = new BlogGetData();
String result = getdata.blogEmotionsServlet();
try {
//生成SAX解析对象
parser = SAXParserFactory.newInstance().newSAXParser();
//生成xml读取器
reader = parser.getXMLReader();
BlogEmotionsHandler handler = new BlogEmotionsHandler();
//设置Handler
reader.setContentHandler(handler);
//指定文件,进行解析
reader.parse(new InputSource(new StringReader(result)));
android 新浪微博客户端的表情功能的实现,flutter教程pdf相关推荐
- android 新浪微博客户端的表情功能的实现
这是一篇好文章,我转来收藏,技术的最高境界是分享. 最近在搞android 新浪微博客户端,有一些心得分享 弄android客户端表情功能可以用以下思路 1.首页把新浪的表情下载到本地一文件夹种,表情 ...
- android 新浪微博客户端开发
[转载]android开发新浪微博客户端 完整攻略 分类: android 2011-04-23 22:45 3193人阅读 评论(4) 收藏 举报 开始接触学习android已经有3个礼拜了,一直都 ...
- android新浪微博客户端毕业设计课题背景
原本天真地以为毕业设计课题选个做项目的就不用弄这些形形式式的文档了,结果导师告诉我:不要抱有侥幸心理! 然后就按部就班地花了近两小时写课题背景,奈何各种原因又要更换选题,为了资源的再利 ...
- android 4个button 田字布局,android新浪微博客户端开发.docx
玄傲三菽境探 」 < N I.■ \ 1% I fi % l 1 1 安徽三联学院 ANHUI SANLIAN UNIVERSITY 本科毕业论文 论文题目基于An droid手机微博客户端的开 ...
- Android 新浪微博客户端
大家好,很高兴来到CSDN博客,很高兴能在这个地方发表自己的一些见解,希望能够互相帮助,共同提高. 我是一名大学生,普普通通的一个二本学校,我就不说了.我是计算机专业的,学校开的课程实在是-- ...
- android开发我的新浪微博客户端-登录页面功能篇(4.2)
上一篇中完成了如上图的UI部分的实现,现在继续来讲功能的实现,用户登录操作主要就是账号列表显示和选择账号登录两个功能其他的都是些简单的辅助功能,首先是点击id为iconSelectBtn的ImageB ...
- android开发我的新浪微博客户端-登录页面功能篇
首先是从数据库中获取所有的账户记录然后设置默认选中的用户账号代码如下: private void initUser(){//获取账号列表dbHelper=new DataHelper(this);us ...
- Android新浪微博客户端的logo界面
为了简化步骤,这一步只需要一张logo,颜色渐深,三秒显示后跳入下一个activity,同时去掉标题栏与状态栏.代码如下:logo.java中 package com.ding.ui; import ...
- android新浪微博客户端 开机Logo动画实现
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //全屏显示 th ...
- 云豹app直播源码Android 端获取相册图片功能的具体实现教程
app直播源码开发时,关于动态功能的实现,通常采用类似于朋友圈式图文+视频模式,这就需要通过访问手机相册获取用户图片进行下一步操作,接下来就请跟随小编一起,从app直播源码角度探究云豹直播系统在这个功 ...
最新文章
- 商务之路有多远,贿赂就有多远吗? 续一
- doctype的三种类型
- 命令提示符中的几个重要的命令
- android关于获取摄像头帧数据转成图片
- bigdecimal 设置_BigDecimal 使用方法详解
- bzoj2431:[HAOI2009]逆序对数列
- Easyui datebox单击文本框显示日期选择
- bootstrap模态框和select2合用时input无法获取焦点
- 华为手机怎么使用读卡器_华为G7手机OTG功能详细使用教程
- 中国3月份采购经理人指数回升
- python 读bin文件_Python学习 | Python 读写文件-bin文件打开
- 服务器名称 历史修改记录,清除 SQL Server Management Studio 服务器名称历史记录
- 情感分析的一些专业术语
- 万物流变:从辩证法看互联网架构和人生
- Android R 11 后台定位权限没有 始终允许选项的解决方法
- 网页设计实验二( 格式化文本、段落与列表)
- linux mint安装金山快盘
- 消息称人人车破产 回应:纯属造谣
- Python-MongoDB
- 2019最新泰牛PHP大牛班(基础+高级+实战+全套课件)