4.实现一个可以让用户选择的表情界面,本人用GridView实现
5.实现点击GridView的每一个item,处理根据item的index查找对应的表情code,然后再把code利用正则把code转换为相对应的表情图片,最后表情插入EditText进行发送。
下面是具体的实现过程
1.把新浪表情图片下载到本地的实现如下:(这个可以建一个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访问新浪的表情接口,把返回的信息如下:
-
<emotion>
-
<phrase>[嘻嘻]</phrase>