Commit 8ee1b9a780bbd0a533b70ec25d715e339c319454

Authored by 王琳
1 parent 44327355

优化demo代码,添加注释

.idea/vcs.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="VcsDirectoryMappings">
  4 + <mapping directory="$PROJECT_DIR$" vcs="Git" />
  5 + </component>
  6 +</project>
0 \ No newline at end of file 7 \ No newline at end of file
IMLib/build/intermediates/bundles/release/classes.jar
No preview for this file type
IMLib/build/intermediates/classes/release/io/rong/imlib/Chat.class
No preview for this file type
IMLib/build/intermediates/incremental/mergeDebugAndroidTestResources/compile-file-map.properties
1 -#Wed Feb 22 10:05:11 CST 2017 1 +#Wed Feb 22 15:18:03 CST 2017
IMLib/build/intermediates/incremental/mergeDebugResources/compile-file-map.properties
1 -#Wed Feb 22 10:05:09 CST 2017 1 +#Wed Feb 22 15:18:02 CST 2017
IMLib/build/intermediates/incremental/mergeReleaseResources/compile-file-map.properties
1 -#Wed Feb 22 10:05:31 CST 2017 1 +#Wed Feb 22 15:18:18 CST 2017
IMLib/build/intermediates/incremental/packageDebugResources/compile-file-map.properties
1 -#Wed Feb 22 10:05:11 CST 2017 1 +#Wed Feb 22 15:18:03 CST 2017
IMLib/build/intermediates/incremental/packageReleaseResources/compile-file-map.properties
1 -#Wed Feb 22 10:05:11 CST 2017 1 +#Wed Feb 22 15:18:03 CST 2017
IMLib/build/intermediates/res/resources-debug-androidTest.ap_
No preview for this file type
IMLib/build/intermediates/transforms/proguard/release/jars/3/3/main.jar
No preview for this file type
IMLib/build/outputs/aar/IMLib-debug.aar
No preview for this file type
IMLib/build/outputs/aar/IMLib-release.aar
No preview for this file type
IMLib/build/outputs/mapping/release/dump.txt
@@ -6603,7 +6603,7 @@ Constant Pool (count = 426): @@ -6603,7 +6603,7 @@ Constant Pool (count = 426):
6603 + Methodref [android/util/Log.e (Ljava/lang/String;Ljava/lang/String;)I] 6603 + Methodref [android/util/Log.e (Ljava/lang/String;Ljava/lang/String;)I]
6604 + Methodref [io/rong/imlib/Chat.<init> ()V] 6604 + Methodref [io/rong/imlib/Chat.<init> ()V]
6605 + Methodref [io/rong/imlib/Chat.cnMessage (Lio/rong/imlib/model/Message;)Lio/rong/imlib/model/CNMessage;] 6605 + Methodref [io/rong/imlib/Chat.cnMessage (Lio/rong/imlib/model/Message;)Lio/rong/imlib/model/CNMessage;]
6606 - + Methodref [io/rong/imlib/Chat.getToken (Lio/rong/imlib/model/UserInfo;Lio/rong/imlib/network/HttpUtil$OnResponse;)V] 6606 + + Methodref [io/rong/imlib/Chat.getToken (Lio/rong/imlib/model/CNUserInfo;Lio/rong/imlib/network/HttpUtil$OnResponse;)V]
6607 + Methodref [io/rong/imlib/Chat.sendChatRoomMessage (Lio/rong/imlib/model/MessageContent;)V] 6607 + Methodref [io/rong/imlib/Chat.sendChatRoomMessage (Lio/rong/imlib/model/MessageContent;)V]
6608 + Methodref [io/rong/imlib/Chat.setChatRoomActionListener (Lio/rong/imlib/RongIMClient$ChatRoomActionListener;)V] 6608 + Methodref [io/rong/imlib/Chat.setChatRoomActionListener (Lio/rong/imlib/RongIMClient$ChatRoomActionListener;)V]
6609 + Methodref [io/rong/imlib/Chat.setConnectStatusListener (Lio/rong/imlib/RongIMClient$ConnectionStatusListener;)V] 6609 + Methodref [io/rong/imlib/Chat.setConnectStatusListener (Lio/rong/imlib/RongIMClient$ConnectionStatusListener;)V]
@@ -6691,7 +6691,7 @@ Constant Pool (count = 426): @@ -6691,7 +6691,7 @@ Constant Pool (count = 426):
6691 + NameAndType [getName ()Ljava/lang/String;] 6691 + NameAndType [getName ()Ljava/lang/String;]
6692 + NameAndType [getPortraitUri ()Landroid/net/Uri;] 6692 + NameAndType [getPortraitUri ()Landroid/net/Uri;]
6693 + NameAndType [getRcHeader (Ljava/lang/String;Ljava/lang/String;)Lio/rong/imlib/network/HttpUtil$Header;] 6693 + NameAndType [getRcHeader (Ljava/lang/String;Ljava/lang/String;)Lio/rong/imlib/network/HttpUtil$Header;]
6694 - + NameAndType [getToken (Lio/rong/imlib/model/UserInfo;Lio/rong/imlib/network/HttpUtil$OnResponse;)V] 6694 + + NameAndType [getToken (Lio/rong/imlib/model/CNUserInfo;Lio/rong/imlib/network/HttpUtil$OnResponse;)V]
6695 + NameAndType [getUserId ()Ljava/lang/String;] 6695 + NameAndType [getUserId ()Ljava/lang/String;]
6696 + NameAndType [getUserInfo ()Lio/rong/imlib/model/UserInfo;] 6696 + NameAndType [getUserInfo ()Lio/rong/imlib/model/UserInfo;]
6697 + NameAndType [getUserName ()Ljava/lang/String;] 6697 + NameAndType [getUserName ()Ljava/lang/String;]
@@ -6760,12 +6760,12 @@ Constant Pool (count = 426): @@ -6760,12 +6760,12 @@ Constant Pool (count = 426):
6760 + Utf8 [(Lio/rong/imlib/base/IChat$OnResultListener;)V] 6760 + Utf8 [(Lio/rong/imlib/base/IChat$OnResultListener;)V]
6761 + Utf8 [(Lio/rong/imlib/base/IChat$OnSendMessageListener;)V] 6761 + Utf8 [(Lio/rong/imlib/base/IChat$OnSendMessageListener;)V]
6762 + Utf8 [(Lio/rong/imlib/model/CNUserInfo;)V] 6762 + Utf8 [(Lio/rong/imlib/model/CNUserInfo;)V]
  6763 + + Utf8 [(Lio/rong/imlib/model/CNUserInfo;Lio/rong/imlib/network/HttpUtil$OnResponse;)V]
6763 + Utf8 [(Lio/rong/imlib/model/Conversation$ConversationType;Ljava/lang/String;ILio/rong/imlib/RongIMClient$ResultCallback;)V] 6764 + Utf8 [(Lio/rong/imlib/model/Conversation$ConversationType;Ljava/lang/String;ILio/rong/imlib/RongIMClient$ResultCallback;)V]
6764 + Utf8 [(Lio/rong/imlib/model/Message;)Lio/rong/imlib/model/CNMessage;] 6765 + Utf8 [(Lio/rong/imlib/model/Message;)Lio/rong/imlib/model/CNMessage;]
6765 + Utf8 [(Lio/rong/imlib/model/Message;Ljava/lang/String;Ljava/lang/String;Lio/rong/imlib/RongIMClient$SendMessageCallback;Lio/rong/imlib/RongIMClient$ResultCallback;)V] 6766 + Utf8 [(Lio/rong/imlib/model/Message;Ljava/lang/String;Ljava/lang/String;Lio/rong/imlib/RongIMClient$SendMessageCallback;Lio/rong/imlib/RongIMClient$ResultCallback;)V]
6766 + Utf8 [(Lio/rong/imlib/model/MessageContent;)V] 6767 + Utf8 [(Lio/rong/imlib/model/MessageContent;)V]
6767 + Utf8 [(Lio/rong/imlib/model/UserInfo;)V] 6768 + Utf8 [(Lio/rong/imlib/model/UserInfo;)V]
6768 - + Utf8 [(Lio/rong/imlib/model/UserInfo;Lio/rong/imlib/network/HttpUtil$OnResponse;)V]  
6769 + Utf8 [(Ljava/lang/Object;)Ljava/lang/StringBuilder;] 6769 + Utf8 [(Ljava/lang/Object;)Ljava/lang/StringBuilder;]
6770 + Utf8 [(Ljava/lang/String;)Landroid/net/Uri;] 6770 + Utf8 [(Ljava/lang/String;)Landroid/net/Uri;]
6771 + Utf8 [(Ljava/lang/String;)Lio/rong/message/TextMessage;] 6771 + Utf8 [(Ljava/lang/String;)Lio/rong/message/TextMessage;]
@@ -7098,7 +7098,7 @@ Methods (count = 37): @@ -7098,7 +7098,7 @@ Methods (count = 37):
7098 Access flags: 0x1 7098 Access flags: 0x1
7099 = public void connect(io.rong.imlib.model.CNUserInfo) 7099 = public void connect(io.rong.imlib.model.CNUserInfo)
7100 Class member attributes (count = 1): 7100 Class member attributes (count = 1):
7101 - + Code attribute instructions (code length = 118, locals = 5, stack = 5): 7101 + + Code attribute instructions (code length = 116, locals = 5, stack = 5):
7102 [0] aload_1 v1 7102 [0] aload_1 v1
7103 [1] invokevirtual #116 7103 [1] invokevirtual #116
7104 + Methodref [io/rong/imlib/model/CNUserInfo.getUserId ()Ljava/lang/String;] 7104 + Methodref [io/rong/imlib/model/CNUserInfo.getUserId ()Ljava/lang/String;]
@@ -7170,17 +7170,16 @@ Methods (count = 37): @@ -7170,17 +7170,16 @@ Methods (count = 37):
7170 + Methodref [io/rong/imlib/model/UserInfo.<init> (Ljava/lang/String;Ljava/lang/String;Landroid/net/Uri;)V] 7170 + Methodref [io/rong/imlib/model/UserInfo.<init> (Ljava/lang/String;Ljava/lang/String;Landroid/net/Uri;)V]
7171 [100] putstatic #64 7171 [100] putstatic #64
7172 + Fieldref [io/rong/imlib/Chat.currentUser Lio/rong/imlib/model/UserInfo;] 7172 + Fieldref [io/rong/imlib/Chat.currentUser Lio/rong/imlib/model/UserInfo;]
7173 - [103] getstatic #64  
7174 - + Fieldref [io/rong/imlib/Chat.currentUser Lio/rong/imlib/model/UserInfo;]  
7175 - [106] new #12 7173 + [103] aload_1 v1
  7174 + [104] new #12
7176 + Class [io/rong/imlib/Chat$1] 7175 + Class [io/rong/imlib/Chat$1]
7177 - [109] dup  
7178 - [110] aload_0 v0  
7179 - [111] invokespecial #86 7176 + [107] dup
  7177 + [108] aload_0 v0
  7178 + [109] invokespecial #86
7180 + Methodref [io/rong/imlib/Chat$1.<init> (Lio/rong/imlib/Chat;)V] 7179 + Methodref [io/rong/imlib/Chat$1.<init> (Lio/rong/imlib/Chat;)V]
7181 - [114] invokestatic #81  
7182 - + Methodref [io/rong/imlib/Chat.getToken (Lio/rong/imlib/model/UserInfo;Lio/rong/imlib/network/HttpUtil$OnResponse;)V]  
7183 - [117] return 7180 + [112] invokestatic #81
  7181 + + Methodref [io/rong/imlib/Chat.getToken (Lio/rong/imlib/model/CNUserInfo;Lio/rong/imlib/network/HttpUtil$OnResponse;)V]
  7182 + [115] return
7184 Code attribute exceptions (count = 0): 7183 Code attribute exceptions (count = 0):
7185 Code attribute attributes (attribute count = 1): 7184 Code attribute attributes (attribute count = 1):
7186 + Line number table attribute (count = 7) 7185 + Line number table attribute (count = 7)
@@ -7190,12 +7189,12 @@ Methods (count = 37): @@ -7190,12 +7189,12 @@ Methods (count = 37):
7190 [52] -> line 74 7189 [52] -> line 74
7191 [86] -> line 75 7190 [86] -> line 75
7192 [103] -> line 76 7191 [103] -> line 76
7193 - [117] -> line 91  
7194 - + Method: getToken(Lio/rong/imlib/model/UserInfo;Lio/rong/imlib/network/HttpUtil$OnResponse;)V 7192 + [115] -> line 91
  7193 + + Method: getToken(Lio/rong/imlib/model/CNUserInfo;Lio/rong/imlib/network/HttpUtil$OnResponse;)V
7195 Access flags: 0x9 7194 Access flags: 0x9
7196 - = public static void getToken(io.rong.imlib.model.UserInfo,io.rong.imlib.network.HttpUtil$OnResponse) 7195 + = public static void getToken(io.rong.imlib.model.CNUserInfo,io.rong.imlib.network.HttpUtil$OnResponse)
7197 Class member attributes (count = 1): 7196 Class member attributes (count = 1):
7198 - + Code attribute instructions (code length = 82, locals = 6, stack = 5): 7197 + + Code attribute instructions (code length = 85, locals = 6, stack = 5):
7199 [0] ldc #7 7198 [0] ldc #7
7200 + String [https://api.cn.ronghub.com/user/getToken.json] 7199 + String [https://api.cn.ronghub.com/user/getToken.json]
7201 [2] astore_2 v2 7200 [2] astore_2 v2
@@ -7216,8 +7215,8 @@ Methods (count = 37): @@ -7216,8 +7215,8 @@ Methods (count = 37):
7216 [22] invokevirtual #139 7215 [22] invokevirtual #139
7217 + Methodref [java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;] 7216 + Methodref [java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;]
7218 [25] aload_0 v0 7217 [25] aload_0 v0
7219 - [26] invokevirtual #128  
7220 - + Methodref [io/rong/imlib/model/UserInfo.getUserId ()Ljava/lang/String;] 7218 + [26] invokevirtual #116
  7219 + + Methodref [io/rong/imlib/model/CNUserInfo.getUserId ()Ljava/lang/String;]
7221 [29] invokevirtual #139 7220 [29] invokevirtual #139
7222 + Methodref [java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;] 7221 + Methodref [java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;]
7223 [32] ldc #3 7222 [32] ldc #3
@@ -7225,8 +7224,8 @@ Methods (count = 37): @@ -7225,8 +7224,8 @@ Methods (count = 37):
7225 [34] invokevirtual #139 7224 [34] invokevirtual #139
7226 + Methodref [java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;] 7225 + Methodref [java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;]
7227 [37] aload_0 v0 7226 [37] aload_0 v0
7228 - [38] invokevirtual #126  
7229 - + Methodref [io/rong/imlib/model/UserInfo.getName ()Ljava/lang/String;] 7227 + [38] invokevirtual #117
  7228 + + Methodref [io/rong/imlib/model/CNUserInfo.getUserName ()Ljava/lang/String;]
7230 [41] invokevirtual #139 7229 [41] invokevirtual #139
7231 + Methodref [java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;] 7230 + Methodref [java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;]
7232 [44] ldc #4 7231 [44] ldc #4
@@ -7234,37 +7233,39 @@ Methods (count = 37): @@ -7234,37 +7233,39 @@ Methods (count = 37):
7234 [46] invokevirtual #139 7233 [46] invokevirtual #139
7235 + Methodref [java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;] 7234 + Methodref [java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;]
7236 [49] aload_0 v0 7235 [49] aload_0 v0
7237 - [50] invokevirtual #127  
7238 - + Methodref [io/rong/imlib/model/UserInfo.getPortraitUri ()Landroid/net/Uri;]  
7239 - [53] invokevirtual #138 7236 + [50] invokevirtual #115
  7237 + + Methodref [io/rong/imlib/model/CNUserInfo.getHeadUrl ()Ljava/lang/String;]
  7238 + [53] invokestatic #76
  7239 + + Methodref [android/net/Uri.parse (Ljava/lang/String;)Landroid/net/Uri;]
  7240 + [56] invokevirtual #138
7240 + Methodref [java/lang/StringBuilder.append (Ljava/lang/Object;)Ljava/lang/StringBuilder;] 7241 + Methodref [java/lang/StringBuilder.append (Ljava/lang/Object;)Ljava/lang/StringBuilder;]
7241 - [56] invokevirtual #140 7242 + [59] invokevirtual #140
7242 + Methodref [java/lang/StringBuilder.toString ()Ljava/lang/String;] 7243 + Methodref [java/lang/StringBuilder.toString ()Ljava/lang/String;]
7243 - [59] astore v4  
7244 - [61] new #50 7244 + [62] astore v4
  7245 + [64] new #50
7245 + Class [io/rong/imlib/network/HttpUtil] 7246 + Class [io/rong/imlib/network/HttpUtil]
7246 - [64] dup  
7247 - [65] invokespecial #129 7247 + [67] dup
  7248 + [68] invokespecial #129
7248 + Methodref [io/rong/imlib/network/HttpUtil.<init> ()V] 7249 + Methodref [io/rong/imlib/network/HttpUtil.<init> ()V]
7249 - [68] astore v5  
7250 - [70] aload v5  
7251 - [72] ldc #7 7250 + [71] astore v5
  7251 + [73] aload v5
  7252 + [75] ldc #7
7252 + String [https://api.cn.ronghub.com/user/getToken.json] 7253 + String [https://api.cn.ronghub.com/user/getToken.json]
7253 - [74] aload_3 v3  
7254 - [75] aload v4  
7255 - [77] aload_1 v1  
7256 - [78] invokevirtual #131 7254 + [77] aload_3 v3
  7255 + [78] aload v4
  7256 + [80] aload_1 v1
  7257 + [81] invokevirtual #131
7257 + Methodref [io/rong/imlib/network/HttpUtil.post (Ljava/lang/String;Lio/rong/imlib/network/HttpUtil$Header;Ljava/lang/String;Lio/rong/imlib/network/HttpUtil$OnResponse;)V] 7258 + Methodref [io/rong/imlib/network/HttpUtil.post (Ljava/lang/String;Lio/rong/imlib/network/HttpUtil$Header;Ljava/lang/String;Lio/rong/imlib/network/HttpUtil$OnResponse;)V]
7258 - [81] return 7259 + [84] return
7259 Code attribute exceptions (count = 0): 7260 Code attribute exceptions (count = 0):
7260 Code attribute attributes (attribute count = 1): 7261 Code attribute attributes (attribute count = 1):
7261 + Line number table attribute (count = 6) 7262 + Line number table attribute (count = 6)
7262 [0] -> line 95 7263 [0] -> line 95
7263 [3] -> line 96 7264 [3] -> line 96
7264 [13] -> line 97 7265 [13] -> line 97
7265 - [61] -> line 98  
7266 - [70] -> line 99  
7267 - [81] -> line 100 7266 + [64] -> line 98
  7267 + [73] -> line 99
  7268 + [84] -> line 100
7268 + Method: connect(Ljava/lang/String;)V 7269 + Method: connect(Ljava/lang/String;)V
7269 Access flags: 0x1 7270 Access flags: 0x1
7270 = public void connect(java.lang.String) 7271 = public void connect(java.lang.String)
IMLib/build/outputs/mapping/release/mapping.txt
@@ -149,7 +149,7 @@ io.rong.imlib.Chat -&gt; io.rong.imlib.Chat: @@ -149,7 +149,7 @@ io.rong.imlib.Chat -&gt; io.rong.imlib.Chat:
149 58:324:void <init>() -> <init> 149 58:324:void <init>() -> <init>
150 65:68:void init(android.content.Context,java.lang.String,java.lang.String) -> init 150 65:68:void init(android.content.Context,java.lang.String,java.lang.String) -> init
151 71:91:void connect(io.rong.imlib.model.CNUserInfo) -> connect 151 71:91:void connect(io.rong.imlib.model.CNUserInfo) -> connect
152 - 95:100:void getToken(io.rong.imlib.model.UserInfo,io.rong.imlib.network.HttpUtil$OnResponse) -> getToken 152 + 95:100:void getToken(io.rong.imlib.model.CNUserInfo,io.rong.imlib.network.HttpUtil$OnResponse) -> getToken
153 104:124:void connect(java.lang.String) -> connect 153 104:124:void connect(java.lang.String) -> connect
154 128:130:void disconnect(boolean) -> disconnect 154 128:130:void disconnect(boolean) -> disconnect
155 134:148:void joinChatRoom(java.lang.String,int) -> joinChatRoom 155 134:148:void joinChatRoom(java.lang.String,int) -> joinChatRoom
IMLib/build/outputs/mapping/release/seeds.txt
@@ -149,7 +149,7 @@ io.rong.imlib.Chat: io.rong.imlib.Chat getInstance() @@ -149,7 +149,7 @@ io.rong.imlib.Chat: io.rong.imlib.Chat getInstance()
149 io.rong.imlib.Chat: Chat() 149 io.rong.imlib.Chat: Chat()
150 io.rong.imlib.Chat: void init(android.content.Context,java.lang.String,java.lang.String) 150 io.rong.imlib.Chat: void init(android.content.Context,java.lang.String,java.lang.String)
151 io.rong.imlib.Chat: void connect(io.rong.imlib.model.CNUserInfo) 151 io.rong.imlib.Chat: void connect(io.rong.imlib.model.CNUserInfo)
152 -io.rong.imlib.Chat: void getToken(io.rong.imlib.model.UserInfo,io.rong.imlib.network.HttpUtil$OnResponse) 152 +io.rong.imlib.Chat: void getToken(io.rong.imlib.model.CNUserInfo,io.rong.imlib.network.HttpUtil$OnResponse)
153 io.rong.imlib.Chat: void connect(java.lang.String) 153 io.rong.imlib.Chat: void connect(java.lang.String)
154 io.rong.imlib.Chat: void disconnect(boolean) 154 io.rong.imlib.Chat: void disconnect(boolean)
155 io.rong.imlib.Chat: void joinChatRoom(java.lang.String,int) 155 io.rong.imlib.Chat: void joinChatRoom(java.lang.String,int)
IMLib/src/main/java/io.rong.imlib/Chat.java
@@ -73,7 +73,7 @@ public class Chat implements IChat { @@ -73,7 +73,7 @@ public class Chat implements IChat {
73 String headUrl = cnUserInfo.getHeadUrl() == null ? "" : cnUserInfo.getHeadUrl(); 73 String headUrl = cnUserInfo.getHeadUrl() == null ? "" : cnUserInfo.getHeadUrl();
74 Log.e("DemoView", userId + " : " + userName + " : "); 74 Log.e("DemoView", userId + " : " + userName + " : ");
75 currentUser = new UserInfo(userId, userName, Uri.parse(headUrl)); 75 currentUser = new UserInfo(userId, userName, Uri.parse(headUrl));
76 - getToken(currentUser, new HttpUtil.OnResponse() { 76 + getToken(cnUserInfo, new HttpUtil.OnResponse() {
77 @Override 77 @Override
78 public void onResponse(int code, String body) { 78 public void onResponse(int code, String body) {
79 if (code != 200) return; 79 if (code != 200) return;
@@ -91,10 +91,10 @@ public class Chat implements IChat { @@ -91,10 +91,10 @@ public class Chat implements IChat {
91 } 91 }
92 92
93 //获得token 93 //获得token
94 - public static void getToken(UserInfo user, HttpUtil.OnResponse callback) { 94 + public static void getToken(CNUserInfo user, HttpUtil.OnResponse callback) {
95 final String HTTP_GET_TOKEN = "https://api.cn.ronghub.com/user/getToken.json"; 95 final String HTTP_GET_TOKEN = "https://api.cn.ronghub.com/user/getToken.json";
96 HttpUtil.Header header = HttpUtil.getRcHeader(APP_KEY, APP_SECRET); 96 HttpUtil.Header header = HttpUtil.getRcHeader(APP_KEY, APP_SECRET);
97 - String body = "userId=" + user.getUserId() + "&name=" + user.getName() + "&portraitUri=" + user.getPortraitUri(); 97 + String body = "userId=" + user.getUserId() + "&name=" + user.getUserName() + "&portraitUri=" + Uri.parse(user.getHeadUrl());
98 HttpUtil httpUtil = new HttpUtil(); 98 HttpUtil httpUtil = new HttpUtil();
99 httpUtil.post(HTTP_GET_TOKEN, header, body, callback); 99 httpUtil.post(HTTP_GET_TOKEN, header, body, callback);
100 } 100 }
@@ -415,5 +415,4 @@ public class Chat implements IChat { @@ -415,5 +415,4 @@ public class Chat implements IChat {
415 public void setCurrentUser(UserInfo user) { 415 public void setCurrentUser(UserInfo user) {
416 currentUser = user; 416 currentUser = user;
417 } 417 }
418 -  
419 } 418 }
app/src/main/AndroidManifest.xml
@@ -18,11 +18,16 @@ @@ -18,11 +18,16 @@
18 <category android:name="android.intent.category.LAUNCHER" /> 18 <category android:name="android.intent.category.LAUNCHER" />
19 </intent-filter> 19 </intent-filter>
20 </activity> 20 </activity>
21 - <activity android:name=".ui.ChatRoomActivity" /> 21 + <activity
  22 + android:name=".ui.ChatRoomActivity"
  23 + android:launchMode="singleTop"
  24 + android:screenOrientation="portrait"
  25 + android:windowSoftInputMode="adjustResize" />
22 <activity 26 <activity
23 android:name=".ui.PrivateChatActivity" 27 android:name=".ui.PrivateChatActivity"
24 android:launchMode="singleTop" 28 android:launchMode="singleTop"
25 - android:screenOrientation="portrait"> 29 + android:screenOrientation="portrait"
  30 + android:windowSoftInputMode="adjustResize">
26 <intent-filter> 31 <intent-filter>
27 <action android:name="android.intent.action.VIEW" /> 32 <action android:name="android.intent.action.VIEW" />
28 33
app/src/main/java/com/cnlive/chat/receiver/CNPushMessageReceiver.java
@@ -13,11 +13,13 @@ public class CNPushMessageReceiver extends SealNotificationReceiver { @@ -13,11 +13,13 @@ public class CNPushMessageReceiver extends SealNotificationReceiver {
13 13
14 @Override 14 @Override
15 public boolean onNotificationMessageArrived(Context var1, CNNotificationMessage var2) { 15 public boolean onNotificationMessageArrived(Context var1, CNNotificationMessage var2) {
  16 + //返回false,会弹出SDK默认的通知;返回true,SDK不会弹出通知,通知需要您自定义
16 return false; 17 return false;
17 } 18 }
18 19
19 @Override 20 @Override
20 public boolean onNotificationMessageClicked(Context var1, CNNotificationMessage var2) { 21 public boolean onNotificationMessageClicked(Context var1, CNNotificationMessage var2) {
  22 + //返回false,会走SDK默认的处理逻辑,即点击该通知则会打开会话列表或会话界面;返回true,则由您自定义处理逻辑
21 return false; 23 return false;
22 } 24 }
23 } 25 }
app/src/main/java/com/cnlive/chat/ui/ChatRoomActivity.java
1 package com.cnlive.chat.ui; 1 package com.cnlive.chat.ui;
2 2
3 -import android.content.Intent;  
4 -import android.net.Uri;  
5 import android.os.Handler; 3 import android.os.Handler;
6 import android.support.v7.app.AppCompatActivity; 4 import android.support.v7.app.AppCompatActivity;
7 import android.os.Bundle; 5 import android.os.Bundle;
@@ -15,24 +13,22 @@ import com.cnlive.chat.R; @@ -15,24 +13,22 @@ import com.cnlive.chat.R;
15 import com.cnlive.chat.adapter.ChatListAdapter; 13 import com.cnlive.chat.adapter.ChatListAdapter;
16 14
17 import java.util.ArrayList; 15 import java.util.ArrayList;
18 -import java.util.StringTokenizer;  
19 16
20 -import io.rong.imlib.Chat;  
21 import io.rong.imlib.model.CNMessage; 17 import io.rong.imlib.model.CNMessage;
22 import io.rong.imlib.ChatUtil; 18 import io.rong.imlib.ChatUtil;
23 import io.rong.imlib.base.IChat; 19 import io.rong.imlib.base.IChat;
24 import io.rong.imlib.model.CNUserInfo; 20 import io.rong.imlib.model.CNUserInfo;
25 -import io.rong.imlib.model.UserInfo;  
26 21
27 -public class ChatRoomActivity extends AppCompatActivity implements View.OnClickListener, IChat.OnMessageListener, IChat.OnConnectStatusListener, IChat.OnChatRoomActionListener { 22 +public class ChatRoomActivity extends AppCompatActivity implements View.OnClickListener {
28 23
29 private static final String TAG = "ChatRoomActivity"; 24 private static final String TAG = "ChatRoomActivity";
30 private ListView chatListView; 25 private ListView chatListView;
31 private EditText messageContent; 26 private EditText messageContent;
32 private Button sendMessageBtn; 27 private Button sendMessageBtn;
33 - private Button changeUserInfo; 28 +// private Button changeUserInfo;
34 29
35 private String roomId; 30 private String roomId;
  31 + private CNUserInfo userInfo;
36 32
37 private ChatListAdapter chatListAdapter; 33 private ChatListAdapter chatListAdapter;
38 private ArrayList<CNMessage> messageList = new ArrayList<>(); 34 private ArrayList<CNMessage> messageList = new ArrayList<>();
@@ -44,15 +40,21 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL @@ -44,15 +40,21 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
44 protected void onCreate(Bundle savedInstanceState) { 40 protected void onCreate(Bundle savedInstanceState) {
45 super.onCreate(savedInstanceState); 41 super.onCreate(savedInstanceState);
46 setContentView(R.layout.activity_chat_room); 42 setContentView(R.layout.activity_chat_room);
  43 +
  44 + ChatUtil.setOnConnectionListener(onConnectListener);
  45 + userInfo = new CNUserInfo("2017010102", "J", "http://7xs9j5.com1.z0.glb.clouddn.com/liveapp/guojunwang.jpg");
  46 + //连接服务器
  47 + ChatUtil.connect(userInfo);
  48 +
47 mHandler = new Handler(this.getMainLooper()); 49 mHandler = new Handler(this.getMainLooper());
48 initView(); 50 initView();
49 ChatUtil.setOnSendMessageListener(onSendMessageListener); 51 ChatUtil.setOnSendMessageListener(onSendMessageListener);
50 ChatUtil.setOnOperationListener(onOperationListener); 52 ChatUtil.setOnOperationListener(onOperationListener);
51 ChatUtil.setOnResultListener(onResultListener); 53 ChatUtil.setOnResultListener(onResultListener);
52 joinChatRoom(); 54 joinChatRoom();
53 - ChatUtil.setOnMessageListener(this);  
54 - ChatUtil.setConnectStatusListener(this);  
55 - ChatUtil.setOnChatRoomActionListener(this); 55 + ChatUtil.setOnMessageListener(onMessageListener);
  56 + ChatUtil.setConnectStatusListener(onConnectStatusListener);
  57 + ChatUtil.setOnChatRoomActionListener(onChatRoomActionListener);
56 } 58 }
57 59
58 private void initView() { 60 private void initView() {
@@ -62,8 +64,8 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL @@ -62,8 +64,8 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
62 messageContent = (EditText) findViewById(R.id.message_content); 64 messageContent = (EditText) findViewById(R.id.message_content);
63 sendMessageBtn = (Button) findViewById(R.id.send_message); 65 sendMessageBtn = (Button) findViewById(R.id.send_message);
64 sendMessageBtn.setOnClickListener(this); 66 sendMessageBtn.setOnClickListener(this);
65 - changeUserInfo = (Button) findViewById(R.id.change_user_info);  
66 - changeUserInfo.setOnClickListener(this); 67 +// changeUserInfo = (Button) findViewById(R.id.change_user_info);
  68 +// changeUserInfo.setOnClickListener(this);
67 } 69 }
68 70
69 //加入聊天室 71 //加入聊天室
@@ -80,60 +82,26 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL @@ -80,60 +82,26 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
80 public void onClick(View v) { 82 public void onClick(View v) {
81 switch (v.getId()) { 83 switch (v.getId()) {
82 case R.id.send_message: 84 case R.id.send_message:
  85 + //发送聊天室消息
83 ChatUtil.sendChatRoomMessage(messageContent.getText().toString()); 86 ChatUtil.sendChatRoomMessage(messageContent.getText().toString());
84 messageContent.setText(""); 87 messageContent.setText("");
85 break; 88 break;
86 - case R.id.change_user_info:  
87 - ChatUtil.currentUser().setName("Ha");  
88 - break; 89 +// case R.id.change_user_info:
  90 +// ChatUtil.currentUser().setName("Ha");
  91 +// break;
89 } 92 }
90 } 93 }
91 94
92 - @Override  
93 - public void processMessage(final CNMessage message) {  
94 -  
95 - Log.e("DemoView", message.getUserInfo().getUserName() + " : " + message.getContent());  
96 -  
97 - mHandler.post(new Runnable() {  
98 - @Override  
99 - public void run() {  
100 - messageList.add(message);  
101 - chatListAdapter.updateItems(messageList);  
102 - chatListAdapter.notifyDataSetChanged();  
103 - }  
104 - });  
105 - }  
106 -  
107 - @Override  
108 - public void onConnectStatus(int what, String extra) {  
109 - Log.e(TAG, "status : what " + what + " extra : " + extra);  
110 - }  
111 -  
112 - @Override  
113 - public void onJoining(String s) {  
114 - Log.e("DemoView", "onJoining + : " + s);  
115 - }  
116 -  
117 - @Override  
118 - public void onJoined(String s) {  
119 - Log.e("DemoView", "onJoined + : " + s);  
120 - }  
121 -  
122 - @Override  
123 - public void onQuited(String s) {  
124 - Log.e(TAG, "onQuited + : " + s);  
125 - }  
126 -  
127 - @Override  
128 - public void onError(String s, int errorCode, String errorMessage) {  
129 - Log.e("DemoView", "onError + : " + s);  
130 - }  
131 95
  96 + /**
  97 + * 发送消息监听
  98 + */
132 private IChat.OnSendMessageListener onSendMessageListener = new IChat.OnSendMessageListener() { 99 private IChat.OnSendMessageListener onSendMessageListener = new IChat.OnSendMessageListener() {
133 @Override 100 @Override
134 public void onSuccess(Integer integer) { 101 public void onSuccess(Integer integer) {
135 Log.i(TAG, "SendMessageListener SUCCESS"); 102 Log.i(TAG, "SendMessageListener SUCCESS");
136 //聊天SDK屏蔽用户自己发送的消息,所以在发送消息成功的时候需要根据需要处理自己的消息 103 //聊天SDK屏蔽用户自己发送的消息,所以在发送消息成功的时候需要根据需要处理自己的消息
  104 + //本demo操作是在发送消息成功后,将发送消息结果监听中的message添加到listview中
137 105
138 mHandler.post(new Runnable() { 106 mHandler.post(new Runnable() {
139 @Override 107 @Override
@@ -151,6 +119,26 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL @@ -151,6 +119,26 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
151 } 119 }
152 }; 120 };
153 121
  122 + /**
  123 + * 发送消息结果监听
  124 + * 在onSuccess中返回发送的消息体
  125 + */
  126 + private IChat.OnResultListener onResultListener = new IChat.OnResultListener() {
  127 + @Override
  128 + public void onSuccess(CNMessage message) {
  129 + Log.i(TAG, "ResultListener SUCCESS " + message.getContent());
  130 + cnMessage = message;
  131 + }
  132 +
  133 + @Override
  134 + public void onError(int what, String extra) {
  135 + Log.e(TAG, "ResultListener errorCode : " + what + " errorMessage : " + extra);
  136 + }
  137 + };
  138 +
  139 + /**
  140 + * 加入或退出聊天室监听
  141 + */
154 private IChat.OnOperationListener onOperationListener = new IChat.OnOperationListener() { 142 private IChat.OnOperationListener onOperationListener = new IChat.OnOperationListener() {
155 @Override 143 @Override
156 public void onSuccess(int what, String extra) { 144 public void onSuccess(int what, String extra) {
@@ -160,6 +148,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL @@ -160,6 +148,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
160 break; 148 break;
161 case IChat.SUCCESS_QUIT_CHATROOM: 149 case IChat.SUCCESS_QUIT_CHATROOM:
162 Log.i(TAG, "退出聊天室成功"); 150 Log.i(TAG, "退出聊天室成功");
  151 + //断开连接
163 ChatUtil.disconnect(false); 152 ChatUtil.disconnect(false);
164 break; 153 break;
165 } 154 }
@@ -171,16 +160,104 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL @@ -171,16 +160,104 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
171 } 160 }
172 }; 161 };
173 162
174 - private IChat.OnResultListener onResultListener = new IChat.OnResultListener() { 163 + /**
  164 + * 接收消息监听
  165 + */
  166 + private IChat.OnMessageListener onMessageListener = new IChat.OnMessageListener() {
175 @Override 167 @Override
176 - public void onSuccess(CNMessage message) {  
177 - Log.i(TAG, "ResultListener SUCCESS " + message.getContent());  
178 - cnMessage = message; 168 + public void processMessage(final CNMessage message) {
  169 + Log.e(TAG, message.getUserInfo().getUserName() + " : " + message.getContent());
  170 +
  171 + mHandler.post(new Runnable() {
  172 + @Override
  173 + public void run() {
  174 + messageList.add(message);
  175 + chatListAdapter.updateItems(messageList);
  176 + chatListAdapter.notifyDataSetChanged();
  177 + }
  178 + });
  179 + }
  180 + };
  181 +
  182 + /**
  183 + * 连接状态监听
  184 + */
  185 + private IChat.OnConnectStatusListener onConnectStatusListener = new IChat.OnConnectStatusListener() {
  186 + @Override
  187 + public void onConnectStatus(int what, String extra) {
  188 + Log.e(TAG, "errorCode : " + what + " errorMessage : " + extra);
  189 + switch (what) {
  190 + case IChat.CONNECTED:
  191 + //连接成功
  192 + break;
  193 + case IChat.CONNECTING:
  194 + //连接中
  195 + break;
  196 + case IChat.DISCONNECTED:
  197 + //断开连接
  198 + break;
  199 + case IChat.NETWORK_UNAVAILABLE:
  200 + //网络不可以
  201 + break;
  202 + case IChat.ERROR_TOKEN_INCORRECT:
  203 + //Token错误
  204 + break;
  205 + case IChat.SERVER_INVALID:
  206 + //服务器无效
  207 + break;
  208 + case IChat.KICKED_OFFLINE_BY_OTHER_CLIENT:
  209 + //用户在其他设备登录,本机会被踢掉线
  210 + break;
  211 + }
  212 + }
  213 + };
  214 +
  215 + /**
  216 + * 聊天室动作监听
  217 + */
  218 + private IChat.OnChatRoomActionListener onChatRoomActionListener = new IChat.OnChatRoomActionListener() {
  219 + @Override
  220 + public void onJoining(String s) {
  221 + //加入中。。。
  222 + Log.i(TAG, s);
  223 + }
  224 +
  225 + @Override
  226 + public void onJoined(String s) {
  227 + //成功加入聊天室
  228 + Log.i(TAG, s);
  229 + }
  230 +
  231 + @Override
  232 + public void onQuited(String s) {
  233 + //退出聊天室
  234 + Log.i(TAG, s);
  235 + }
  236 +
  237 + @Override
  238 + public void onError(String s, int errorCode, String errorMessage) {
  239 + Log.e(TAG, s + " errorCode : " + errorCode + " errorMessage : " + errorMessage);
  240 + }
  241 + };
  242 +
  243 + /**
  244 + * 连接服务器监听
  245 + */
  246 + protected IChat.OnConnectListener onConnectListener = new IChat.OnConnectListener() {
  247 + @Override
  248 + public void onTokenIncorrect() {
  249 + //Token错误
  250 + Log.e(TAG, "ConnectListener TokenIncorrect");
  251 + }
  252 +
  253 + @Override
  254 + public void onSuccess(String s) {
  255 + Log.i(TAG, "ConnectListener " + s);
179 } 256 }
180 257
181 @Override 258 @Override
182 public void onError(int what, String extra) { 259 public void onError(int what, String extra) {
183 - Log.e(TAG, "ResultListener errorCode : " + what + " errorMessage : " + extra); 260 + Log.e(TAG, "ConnectListener errorCode : " + what + " : errorMessage : " + extra);
184 } 261 }
185 }; 262 };
186 263
@@ -192,6 +269,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL @@ -192,6 +269,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL
192 @Override 269 @Override
193 public void onBackPressed() { 270 public void onBackPressed() {
194 super.onBackPressed(); 271 super.onBackPressed();
  272 + //退出聊天室
195 ChatUtil.quitChatRoom(); 273 ChatUtil.quitChatRoom();
196 } 274 }
197 } 275 }
app/src/main/java/com/cnlive/chat/ui/MainActivity.java
@@ -21,15 +21,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe @@ -21,15 +21,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
21 21
22 private Button chatRoom; 22 private Button chatRoom;
23 private Button privateChat; 23 private Button privateChat;
24 - private CNUserInfo userInfo;  
25 24
26 @Override 25 @Override
27 protected void onCreate(Bundle savedInstanceState) { 26 protected void onCreate(Bundle savedInstanceState) {
28 super.onCreate(savedInstanceState); 27 super.onCreate(savedInstanceState);
29 setContentView(R.layout.activity_main); 28 setContentView(R.layout.activity_main);
30 - ChatUtil.setOnConnectionListener(onConnectListener);  
31 -// ChatUtil.connect("WAkcsLgCj23M30nGybKzncw4SBtlLkK9SlzzuzBtTglso17GA6CGh1e++CukcOkNsdtWdRpLlYwva7BX3uQS5g==");  
32 - userInfo = new CNUserInfo("2017010102", "J", "http://7xs9j5.com1.z0.glb.clouddn.com/liveapp/guojunwang.jpg");  
33 initView(); 29 initView();
34 } 30 }
35 31
@@ -45,8 +41,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe @@ -45,8 +41,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
45 public void onClick(View v) { 41 public void onClick(View v) {
46 switch (v.getId()) { 42 switch (v.getId()) {
47 case R.id.chat_room: 43 case R.id.chat_room:
48 - ChatUtil.connect(userInfo);  
49 -  
50 Intent intent = new Intent(this, ChatRoomActivity.class); 44 Intent intent = new Intent(this, ChatRoomActivity.class);
51 startActivity(intent); 45 startActivity(intent);
52 break; 46 break;
@@ -56,21 +50,4 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe @@ -56,21 +50,4 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
56 break; 50 break;
57 } 51 }
58 } 52 }
59 -  
60 - protected IChat.OnConnectListener onConnectListener = new IChat.OnConnectListener() {  
61 - @Override  
62 - public void onTokenIncorrect() {  
63 - Log.e(TAG, "ConnectListener TokenIncorrect");  
64 - }  
65 -  
66 - @Override  
67 - public void onSuccess(String s) {  
68 - Log.i(TAG, "ConnectListener " + s);  
69 - }  
70 -  
71 - @Override  
72 - public void onError(int what, String extra) {  
73 - Log.e(TAG, "ConnectListener errorCode : " + what + " : errorMessage : " + extra);  
74 - }  
75 - };  
76 } 53 }
app/src/main/java/com/cnlive/chat/ui/PrivateChatActivity.java
1 package com.cnlive.chat.ui; 1 package com.cnlive.chat.ui;
2 2
3 -import android.content.Intent;  
4 -import android.net.Uri;  
5 import android.os.Handler; 3 import android.os.Handler;
6 import android.support.v7.app.AppCompatActivity; 4 import android.support.v7.app.AppCompatActivity;
7 import android.os.Bundle; 5 import android.os.Bundle;
8 -import android.support.v7.widget.ListViewCompat;  
9 import android.util.Log; 6 import android.util.Log;
10 import android.view.View; 7 import android.view.View;
11 import android.widget.Button; 8 import android.widget.Button;
@@ -19,14 +16,12 @@ import java.util.ArrayList; @@ -19,14 +16,12 @@ import java.util.ArrayList;
19 import java.util.Collections; 16 import java.util.Collections;
20 import java.util.List; 17 import java.util.List;
21 18
22 -import io.rong.imlib.RongIMClient;  
23 import io.rong.imlib.model.CNMessage; 19 import io.rong.imlib.model.CNMessage;
24 import io.rong.imlib.ChatUtil; 20 import io.rong.imlib.ChatUtil;
25 import io.rong.imlib.base.IChat; 21 import io.rong.imlib.base.IChat;
26 import io.rong.imlib.model.CNUserInfo; 22 import io.rong.imlib.model.CNUserInfo;
27 -import io.rong.imlib.model.UserInfo;  
28 23
29 -public class PrivateChatActivity extends AppCompatActivity implements View.OnClickListener, IChat.OnMessageListener, IChat.OnConnectStatusListener { 24 +public class PrivateChatActivity extends AppCompatActivity implements View.OnClickListener {
30 25
31 private static final String TAG = "PrivateChatActivity"; 26 private static final String TAG = "PrivateChatActivity";
32 private ListView chatListView; 27 private ListView chatListView;
@@ -46,9 +41,10 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli @@ -46,9 +41,10 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
46 @Override 41 @Override
47 protected void onCreate(Bundle savedInstanceState) { 42 protected void onCreate(Bundle savedInstanceState) {
48 super.onCreate(savedInstanceState); 43 super.onCreate(savedInstanceState);
49 - setContentView(R.layout.activity_chat_room); 44 + setContentView(R.layout.activity_private_chat);
50 45
51 userInfo = new CNUserInfo("2017010102", "J", "http://7xs9j5.com1.z0.glb.clouddn.com/liveapp/guojunwang.jpg"); 46 userInfo = new CNUserInfo("2017010102", "J", "http://7xs9j5.com1.z0.glb.clouddn.com/liveapp/guojunwang.jpg");
  47 + //连接服务器
52 ChatUtil.connect(userInfo); 48 ChatUtil.connect(userInfo);
53 49
54 targetId = "2017010101"; 50 targetId = "2017010101";
@@ -56,17 +52,17 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli @@ -56,17 +52,17 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
56 ChatUtil.setOnResultListener(onResultListener); 52 ChatUtil.setOnResultListener(onResultListener);
57 ChatUtil.setOnSendMessageListener(onSendMessageListener); 53 ChatUtil.setOnSendMessageListener(onSendMessageListener);
58 ChatUtil.setOnLatestMessageListener(latestMessageListener); 54 ChatUtil.setOnLatestMessageListener(latestMessageListener);
59 - ChatUtil.getLatestMessages(targetId, 20);  
60 initView(); 55 initView();
61 - ChatUtil.setOnMessageListener(this);  
62 - ChatUtil.setConnectStatusListener(this); 56 + ChatUtil.setOnMessageListener(onMessageListener);
  57 + ChatUtil.setConnectStatusListener(onConnectStatusListener);
  58 + ChatUtil.setOnConnectionListener(onConnectListener);
63 // Intent intent = getIntent(); 59 // Intent intent = getIntent();
64 // getPushMessage(intent); 60 // getPushMessage(intent);
65 } 61 }
66 62
67 63
68 private void initView() { 64 private void initView() {
69 - chatListView = (ListView) findViewById(R.id.chat_list_view); 65 + chatListView = (ListView) findViewById(R.id.private_list_view);
70 chatListAdapter = new ChatListAdapter(this); 66 chatListAdapter = new ChatListAdapter(this);
71 chatListView.setAdapter(chatListAdapter); 67 chatListView.setAdapter(chatListAdapter);
72 messageContent = (EditText) findViewById(R.id.message_content); 68 messageContent = (EditText) findViewById(R.id.message_content);
@@ -84,22 +80,21 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli @@ -84,22 +80,21 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
84 public void onClick(View v) { 80 public void onClick(View v) {
85 switch (v.getId()) { 81 switch (v.getId()) {
86 case R.id.send_message: 82 case R.id.send_message:
  83 + //发送私聊消息,需要传入目标ID与发送的消息内容
87 ChatUtil.sendPrivateMessage(targetId, messageContent.getText().toString()); 84 ChatUtil.sendPrivateMessage(targetId, messageContent.getText().toString());
88 messageContent.setText(""); 85 messageContent.setText("");
89 break; 86 break;
90 } 87 }
91 } 88 }
92 89
93 - @Override  
94 - public void onConnectStatus(int what, String extra) {  
95 - Log.e("DemoView", "errorCode : " + what + " errorMessage : " + extra);  
96 -  
97 - }  
98 - 90 + /**
  91 + * 发送消息监听
  92 + */
99 private IChat.OnSendMessageListener onSendMessageListener = new IChat.OnSendMessageListener() { 93 private IChat.OnSendMessageListener onSendMessageListener = new IChat.OnSendMessageListener() {
100 @Override 94 @Override
101 public void onSuccess(Integer integer) { 95 public void onSuccess(Integer integer) {
102 - 96 + //聊天SDK屏蔽用户自己发送的消息,所以在发送消息成功的时候需要根据需要处理自己的消息
  97 + //本demo操作是在发送消息成功后,将发送消息结果监听中的message添加到listview中
103 mHandler.post(new Runnable() { 98 mHandler.post(new Runnable() {
104 @Override 99 @Override
105 public void run() { 100 public void run() {
@@ -108,7 +103,6 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli @@ -108,7 +103,6 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
108 chatListAdapter.notifyDataSetChanged(); 103 chatListAdapter.notifyDataSetChanged();
109 } 104 }
110 }); 105 });
111 - Log.i(TAG, "SendMessageListener SUCCESS");  
112 } 106 }
113 107
114 @Override 108 @Override
@@ -117,6 +111,10 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli @@ -117,6 +111,10 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
117 } 111 }
118 }; 112 };
119 113
  114 + /**
  115 + * 发送消息结果监听
  116 + * 在onSuccess中返回发送的消息体
  117 + */
120 private IChat.OnResultListener onResultListener = new IChat.OnResultListener() { 118 private IChat.OnResultListener onResultListener = new IChat.OnResultListener() {
121 @Override 119 @Override
122 public void onSuccess(CNMessage message) { 120 public void onSuccess(CNMessage message) {
@@ -130,7 +128,9 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli @@ -130,7 +128,9 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
130 } 128 }
131 }; 129 };
132 130
133 - //单聊的历史消息,按照时间顺序从新到旧排列 131 + /**
  132 + * 获取单聊的历史消息监听,消息按照时间顺序从新到旧排列
  133 + */
134 private IChat.OnLatestMessageListener latestMessageListener = new IChat.OnLatestMessageListener() { 134 private IChat.OnLatestMessageListener latestMessageListener = new IChat.OnLatestMessageListener() {
135 @Override 135 @Override
136 public void onSuccess(final List<CNMessage> messages) { 136 public void onSuccess(final List<CNMessage> messages) {
@@ -155,19 +155,79 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli @@ -155,19 +155,79 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
155 } 155 }
156 }; 156 };
157 157
158 - @Override  
159 - public void processMessage(final CNMessage message) {  
160 - Log.e("DemoView", message.getContent());  
161 -  
162 - mHandler.post(new Runnable() {  
163 - @Override  
164 - public void run() {  
165 - messageList.add(message);  
166 - chatListAdapter.updateItems(messageList);  
167 - chatListAdapter.notifyDataSetChanged(); 158 + /**
  159 + * 连接服务器监听
  160 + */
  161 + protected IChat.OnConnectListener onConnectListener = new IChat.OnConnectListener() {
  162 + @Override
  163 + public void onTokenIncorrect() {
  164 + Log.e(TAG, "ConnectListener TokenIncorrect");
  165 + }
  166 +
  167 + @Override
  168 + public void onSuccess(String s) {
  169 + Log.i(TAG, "ConnectListener " + s);
  170 + //聊天SDK若想获得聊天历史,需要调用此方法,需要传入目标ID与获取消息数量
  171 + ChatUtil.getLatestMessages(targetId, 20);
  172 + }
  173 +
  174 + @Override
  175 + public void onError(int what, String extra) {
  176 + Log.e(TAG, "ConnectListener errorCode : " + what + " : errorMessage : " + extra);
  177 + }
  178 + };
  179 +
  180 + /**
  181 + * 接收消息监听
  182 + */
  183 + private IChat.OnMessageListener onMessageListener = new IChat.OnMessageListener() {
  184 + @Override
  185 + public void processMessage(final CNMessage message) {
  186 + Log.e(TAG, message.getContent());
  187 +
  188 + mHandler.post(new Runnable() {
  189 + @Override
  190 + public void run() {
  191 + messageList.add(message);
  192 + chatListAdapter.updateItems(messageList);
  193 + chatListAdapter.notifyDataSetChanged();
  194 + }
  195 + });
  196 + }
  197 + };
  198 +
  199 + /**
  200 + * 连接状态监听
  201 + */
  202 + private IChat.OnConnectStatusListener onConnectStatusListener = new IChat.OnConnectStatusListener() {
  203 + @Override
  204 + public void onConnectStatus(int what, String extra) {
  205 + Log.e(TAG, "errorCode : " + what + " errorMessage : " + extra);
  206 + switch (what) {
  207 + case IChat.CONNECTED:
  208 + //连接成功
  209 + break;
  210 + case IChat.CONNECTING:
  211 + //连接中
  212 + break;
  213 + case IChat.DISCONNECTED:
  214 + //断开连接
  215 + break;
  216 + case IChat.NETWORK_UNAVAILABLE:
  217 + //网络不可以
  218 + break;
  219 + case IChat.ERROR_TOKEN_INCORRECT:
  220 + //Token错误
  221 + break;
  222 + case IChat.SERVER_INVALID:
  223 + //服务器无效
  224 + break;
  225 + case IChat.KICKED_OFFLINE_BY_OTHER_CLIENT:
  226 + //用户在其他设备登录,本机会被踢掉线
  227 + break;
168 } 228 }
169 - });  
170 - } 229 + }
  230 + };
171 231
172 @Override 232 @Override
173 protected void onDestroy() { 233 protected void onDestroy() {
@@ -191,6 +251,7 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli @@ -191,6 +251,7 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli
191 @Override 251 @Override
192 public void onBackPressed() { 252 public void onBackPressed() {
193 super.onBackPressed(); 253 super.onBackPressed();
  254 + //断开连接 传入true时,可以接收push消息;传入false时,不能接收push消息
194 ChatUtil.disconnect(true); 255 ChatUtil.disconnect(true);
195 } 256 }
196 } 257 }
app/src/main/res/layout/activity_chat_room.xml
@@ -14,19 +14,13 @@ @@ -14,19 +14,13 @@
14 android:id="@+id/chat_list_view" 14 android:id="@+id/chat_list_view"
15 android:layout_width="match_parent" 15 android:layout_width="match_parent"
16 android:layout_height="300dp" 16 android:layout_height="300dp"
  17 + android:layout_above="@+id/edit_layout"
17 android:divider="@null" 18 android:divider="@null"
18 android:scrollbars="none" 19 android:scrollbars="none"
19 android:transcriptMode="alwaysScroll" /> 20 android:transcriptMode="alwaysScroll" />
20 21
21 - <Button  
22 - android:id="@+id/change_user_info"  
23 - android:layout_width="match_parent"  
24 - android:layout_height="wrap_content"  
25 - android:layout_below="@id/chat_list_view"  
26 - android:layout_marginTop="10dp"  
27 - android:text="更新用户信息" />  
28 -  
29 <LinearLayout 22 <LinearLayout
  23 + android:id="@+id/edit_layout"
30 android:layout_width="match_parent" 24 android:layout_width="match_parent"
31 android:layout_height="wrap_content" 25 android:layout_height="wrap_content"
32 android:layout_alignParentBottom="true" 26 android:layout_alignParentBottom="true"
@@ -48,4 +42,11 @@ @@ -48,4 +42,11 @@
48 android:text="发送" /> 42 android:text="发送" />
49 </LinearLayout> 43 </LinearLayout>
50 44
  45 + <!--<Button-->
  46 + <!--android:id="@+id/change_user_info"-->
  47 + <!--android:layout_width="match_parent"-->
  48 + <!--android:layout_height="wrap_content"-->
  49 + <!--android:layout_above="@+id/chat_list_view"-->
  50 + <!--android:text="更新用户信息" />-->
  51 +
51 </RelativeLayout> 52 </RelativeLayout>
app/src/main/res/layout/activity_private_chat.xml
@@ -10,10 +10,36 @@ @@ -10,10 +10,36 @@
10 android:paddingTop="@dimen/activity_vertical_margin" 10 android:paddingTop="@dimen/activity_vertical_margin"
11 tools:context="com.cnlive.chat.ui.PrivateChatActivity"> 11 tools:context="com.cnlive.chat.ui.PrivateChatActivity">
12 12
13 - <TextView  
14 - android:layout_width="wrap_content" 13 + <ListView
  14 + android:id="@+id/private_list_view"
  15 + android:layout_width="match_parent"
  16 + android:layout_height="300dp"
  17 + android:layout_above="@+id/edit_layout"
  18 + android:divider="@null"
  19 + android:scrollbars="none"
  20 + android:transcriptMode="alwaysScroll" />
  21 +
  22 + <LinearLayout
  23 + android:id="@+id/edit_layout"
  24 + android:layout_width="match_parent"
15 android:layout_height="wrap_content" 25 android:layout_height="wrap_content"
16 - android:layout_centerInParent="true"  
17 - android:text="我是单聊" /> 26 + android:layout_alignParentBottom="true"
  27 + android:orientation="horizontal">
  28 +
  29 + <EditText
  30 + android:id="@+id/message_content"
  31 + android:layout_width="0dp"
  32 + android:layout_height="wrap_content"
  33 + android:layout_gravity="center"
  34 + android:layout_weight="0.7" />
  35 +
  36 + <Button
  37 + android:id="@+id/send_message"
  38 + android:layout_width="0dp"
  39 + android:layout_height="wrap_content"
  40 + android:layout_gravity="center"
  41 + android:layout_weight="0.2"
  42 + android:text="发送" />
  43 + </LinearLayout>
18 44
19 </RelativeLayout> 45 </RelativeLayout>