Commit 397dad4e3ab4f24bcd817635a0b47b099139bcb5
1 parent
7e3f78f1
添加文档
Showing
6 changed files
with
115 additions
and
31 deletions
app/doc/聊天SDK文档.docx
0 → 100644
No preview for this file type
app/libs/libcnliveutil.jar
No preview for this file type
app/src/main/java/com/cnlive/im/CNLiveApplication.java
| ... | ... | @@ -14,7 +14,7 @@ public class CNLiveApplication extends Application { |
| 14 | 14 | @Override |
| 15 | 15 | public void onCreate() { |
| 16 | 16 | super.onCreate(); |
| 17 | - Config.init(this, "60_irn9cdak77", "a425987ebc86e352b3373c25d5bd082d0cc248b4043028"); | |
| 17 | + Config.init(this, " 60_j07o9s9b65", " b0d8df0b4bb3fef43339b1edea4f33f58efe99e26681ca"); | |
| 18 | 18 | } |
| 19 | 19 | } |
| 20 | 20 | ... | ... |
app/src/main/java/com/cnlive/im/ui/ChatRoomActivity.java
| 1 | 1 | package com.cnlive.im.ui; |
| 2 | 2 | |
| 3 | 3 | import android.os.Bundle; |
| 4 | +import android.os.Handler; | |
| 4 | 5 | import android.support.v7.app.AppCompatActivity; |
| 5 | 6 | import android.util.Log; |
| 6 | 7 | import android.view.View; |
| ... | ... | @@ -18,6 +19,7 @@ import com.cnlive.libs.util.chat.model.CNUserInfo; |
| 18 | 19 | |
| 19 | 20 | import java.util.ArrayList; |
| 20 | 21 | |
| 22 | + | |
| 21 | 23 | /** |
| 22 | 24 | * @author 陈硕 |
| 23 | 25 | * @time 2017/3/7 14:36 |
| ... | ... | @@ -34,6 +36,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 34 | 36 | private ListView listViewTwo; |
| 35 | 37 | private Button user_switchBtn, reconnectionBtn, switch_visitorsBtn, foundChatBtn, disconnectBtn; |
| 36 | 38 | private Button creatChat2Btn; |
| 39 | + private Handler mHandler; | |
| 37 | 40 | |
| 38 | 41 | |
| 39 | 42 | @Override |
| ... | ... | @@ -42,6 +45,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 42 | 45 | setContentView(R.layout.activity_groupchat); |
| 43 | 46 | initUI(); |
| 44 | 47 | //设置监听 |
| 48 | + mHandler = new Handler(); | |
| 45 | 49 | ChatUtil.setConnectStatusListener(connectStatusListener); |
| 46 | 50 | ChatUtil.setOnChatRoomActionListener(chatRoomActionListener); |
| 47 | 51 | ChatUtil.setOnReceiveMessageListener(receiveMessageListener); |
| ... | ... | @@ -111,22 +115,28 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 111 | 115 | } |
| 112 | 116 | |
| 113 | 117 | @Override |
| 114 | - public void onSuccess(CNMessage cnMessage) { | |
| 115 | - if (("60_" + roomIdOne).equals(cnMessage.getTargetId())) { | |
| 116 | - groupChatOneListMy.add(cnMessage); | |
| 117 | - chatListAdapterOne.updateItems(groupChatOneListMy); | |
| 118 | - chatListAdapterOne.notifyDataSetChanged(); | |
| 119 | - } | |
| 120 | - Log.v(TAG, "SendMessageListener SUCCESSES" + cnMessage.getTargetId() + cnMessage.getUserInfo().getUserName()); | |
| 121 | - | |
| 122 | - /** | |
| 123 | - * 连接两个聊天室30015 错误 | |
| 124 | - */ | |
| 125 | - if (("60_" + roomIdTwo).equals(cnMessage.getTargetId())) { | |
| 126 | - groupChatTwoListMy.add(cnMessage); | |
| 127 | - chatListAdapterTwo.updateItems(groupChatTwoListMy); | |
| 128 | - chatListAdapterTwo.notifyDataSetChanged(); | |
| 129 | - } | |
| 118 | + public void onSuccess(final CNMessage cnMessage) { | |
| 119 | + mHandler.post(new Runnable() { | |
| 120 | + @Override | |
| 121 | + public void run() { | |
| 122 | + if (("60_" + roomIdOne).equals(cnMessage.getTargetId())) { | |
| 123 | + groupChatOneListMy.add(cnMessage); | |
| 124 | + chatListAdapterOne.updateItems(groupChatOneListMy); | |
| 125 | + chatListAdapterOne.notifyDataSetChanged(); | |
| 126 | + } | |
| 127 | + Log.v(TAG, "SendMessageListener SUCCESSES" + cnMessage.getTargetId() + cnMessage.getUserInfo().getUserName()); | |
| 128 | + | |
| 129 | + /** | |
| 130 | + * 连接两个聊天室30015 错误 | |
| 131 | + */ | |
| 132 | + if (("60_" + roomIdTwo).equals(cnMessage.getTargetId())) { | |
| 133 | + groupChatTwoListMy.add(cnMessage); | |
| 134 | + chatListAdapterTwo.updateItems(groupChatTwoListMy); | |
| 135 | + chatListAdapterTwo.notifyDataSetChanged(); | |
| 136 | + } | |
| 137 | + | |
| 138 | + } | |
| 139 | + }); | |
| 130 | 140 | |
| 131 | 141 | } |
| 132 | 142 | |
| ... | ... | @@ -150,8 +160,30 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 150 | 160 | //接收消息监听 |
| 151 | 161 | private IChat.OnReceiveMessageListener receiveMessageListener = new IChat.OnReceiveMessageListener() { |
| 152 | 162 | @Override |
| 153 | - public void processMessage(CNMessage cnMessage) { | |
| 163 | + public void processMessage(final CNMessage cnMessage) { | |
| 154 | 164 | Log.v(TAG, "receiveMessageListener" + " " + cnMessage.getTargetId() + " " + cnMessage.getContent()); |
| 165 | + mHandler.post(new Runnable() { | |
| 166 | + @Override | |
| 167 | + public void run() { | |
| 168 | + if (("60_" + roomIdOne).equals(cnMessage.getTargetId())) { | |
| 169 | + groupChatOneListMy.add(cnMessage); | |
| 170 | + chatListAdapterOne.updateItems(groupChatOneListMy); | |
| 171 | + chatListAdapterOne.notifyDataSetChanged(); | |
| 172 | + } | |
| 173 | + Log.v(TAG, "SendMessageListener SUCCESSES" + cnMessage.getTargetId() + cnMessage.getUserInfo().getUserName()); | |
| 174 | + | |
| 175 | + /** | |
| 176 | + * 连接两个聊天室30015 错误 | |
| 177 | + */ | |
| 178 | + if (("60_" + roomIdTwo).equals(cnMessage.getTargetId())) { | |
| 179 | + groupChatTwoListMy.add(cnMessage); | |
| 180 | + chatListAdapterTwo.updateItems(groupChatTwoListMy); | |
| 181 | + chatListAdapterTwo.notifyDataSetChanged(); | |
| 182 | + } | |
| 183 | + | |
| 184 | + } | |
| 185 | + }); | |
| 186 | + | |
| 155 | 187 | } |
| 156 | 188 | }; |
| 157 | 189 | |
| ... | ... | @@ -275,5 +307,4 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 275 | 307 | } |
| 276 | 308 | |
| 277 | 309 | |
| 278 | - | |
| 279 | 310 | } | ... | ... |
app/src/main/java/com/cnlive/im/ui/MainActivity.java
| ... | ... | @@ -16,7 +16,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe |
| 16 | 16 | @Override |
| 17 | 17 | protected void onCreate(Bundle savedInstanceState) { |
| 18 | 18 | super.onCreate(savedInstanceState); |
| 19 | - setContentView(R .layout.activity_main); | |
| 19 | + setContentView(R.layout.activity_main); | |
| 20 | 20 | initUI(); |
| 21 | 21 | } |
| 22 | 22 | ... | ... |
app/src/main/java/com/cnlive/im/ui/PrivateChatActivity.java
| 1 | 1 | package com.cnlive.im.ui; |
| 2 | 2 | |
| 3 | 3 | import android.os.Bundle; |
| 4 | +import android.os.Handler; | |
| 4 | 5 | import android.support.v7.app.AppCompatActivity; |
| 5 | 6 | import android.util.Log; |
| 6 | 7 | import android.view.View; |
| ... | ... | @@ -21,6 +22,7 @@ import java.util.ArrayList; |
| 21 | 22 | |
| 22 | 23 | import static com.cnlive.im.R.id.opposite_id_edit; |
| 23 | 24 | |
| 25 | + | |
| 24 | 26 | /** |
| 25 | 27 | * @author 陈硕 |
| 26 | 28 | * @time 2017/3/7 14:36 |
| ... | ... | @@ -44,13 +46,16 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli |
| 44 | 46 | private EditText my_id_edit; |
| 45 | 47 | private String my_id_editID; |
| 46 | 48 | private LinearLayout my_liner_userID; |
| 49 | + private Handler mHandler; | |
| 47 | 50 | |
| 48 | 51 | @Override |
| 49 | 52 | protected void onCreate(Bundle savedInstanceState) { |
| 50 | 53 | super.onCreate(savedInstanceState); |
| 51 | 54 | setContentView(R.layout.activity_private_chat); |
| 52 | 55 | initView(); |
| 56 | + mHandler = new Handler(); | |
| 53 | 57 | ChatUtil.setConnectStatusListener(connectStatusListener); |
| 58 | + ChatUtil.setOnChatRoomActionListener(chatRoomActionListener); | |
| 54 | 59 | ChatUtil.setOnReceiveMessageListener(receiveMessageListener); |
| 55 | 60 | ChatUtil.connect(connectListener); |
| 56 | 61 | |
| ... | ... | @@ -137,18 +142,23 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli |
| 137 | 142 | |
| 138 | 143 | @Override |
| 139 | 144 | public void onAttached(CNMessage cnMessage) { |
| 140 | -Toast.makeText(PrivateChatActivity.this,"onAttached",Toast.LENGTH_LONG).show(); | |
| 145 | + Toast.makeText(PrivateChatActivity.this, "onAttached", Toast.LENGTH_LONG).show(); | |
| 141 | 146 | Log.v(TAG, "私聊SendMessageListener onAttached" + cnMessage.getTargetId() + cnMessage.getUserInfo().getUserName()); |
| 142 | 147 | |
| 143 | 148 | } |
| 144 | 149 | |
| 145 | 150 | @Override |
| 146 | - public void onSuccess(CNMessage cnMessage) { | |
| 147 | - Toast.makeText(PrivateChatActivity.this,"onSuccess",Toast.LENGTH_LONG).show(); | |
| 151 | + public void onSuccess(final CNMessage cnMessage) { | |
| 152 | + Toast.makeText(PrivateChatActivity.this, "onSuccess", Toast.LENGTH_LONG).show(); | |
| 153 | + mHandler.post(new Runnable() { | |
| 154 | + @Override | |
| 155 | + public void run() { | |
| 156 | + messageList.add(cnMessage); | |
| 157 | + chatListAdapter.updateItems(messageList); | |
| 158 | + chatListAdapter.notifyDataSetChanged(); | |
| 159 | + } | |
| 160 | + }); | |
| 148 | 161 | |
| 149 | - messageList.add(cnMessage); | |
| 150 | - chatListAdapter.updateItems(messageList); | |
| 151 | - chatListAdapter.notifyDataSetChanged(); | |
| 152 | 162 | Log.v(TAG, "私聊SendMessageListener SUCCESSES" + cnMessage.getTargetId() + cnMessage.getUserInfo().getUserName()); |
| 153 | 163 | |
| 154 | 164 | |
| ... | ... | @@ -157,7 +167,7 @@ Toast.makeText(PrivateChatActivity.this,"onAttached",Toast.LENGTH_LONG).show(); |
| 157 | 167 | @Override |
| 158 | 168 | public void onError(CNMessage cnMessage, int i, String s) { |
| 159 | 169 | Log.v(TAG, "私聊SendMessageListener 失败 " + i + " s" + s); |
| 160 | - Toast.makeText(PrivateChatActivity.this,"失败",Toast.LENGTH_LONG).show(); | |
| 170 | + Toast.makeText(PrivateChatActivity.this, "失败", Toast.LENGTH_LONG).show(); | |
| 161 | 171 | |
| 162 | 172 | |
| 163 | 173 | } |
| ... | ... | @@ -176,17 +186,60 @@ Toast.makeText(PrivateChatActivity.this,"onAttached",Toast.LENGTH_LONG).show(); |
| 176 | 186 | //接收消息监听 |
| 177 | 187 | private IChat.OnReceiveMessageListener receiveMessageListener = new IChat.OnReceiveMessageListener() { |
| 178 | 188 | @Override |
| 179 | - public void processMessage(CNMessage cnMessage) { | |
| 189 | + public void processMessage(final CNMessage cnMessage) { | |
| 180 | 190 | Log.v(TAG, "私聊receiveMessageListener" + " " + cnMessage.getTargetId() + " " + cnMessage.getContent()); |
| 191 | + mHandler.post(new Runnable() { | |
| 192 | + @Override | |
| 193 | + public void run() { | |
| 194 | + messageList.add(cnMessage); | |
| 195 | + chatListAdapter.updateItems(messageList); | |
| 196 | + chatListAdapter.notifyDataSetChanged(); | |
| 197 | + } | |
| 198 | + }); | |
| 199 | + } | |
| 200 | + }; | |
| 201 | + | |
| 202 | + | |
| 203 | + //聊天室操作 | |
| 204 | + private IChat.OnChatRoomActionListener chatRoomActionListener = new IChat.OnChatRoomActionListener() { | |
| 205 | + @Override | |
| 206 | + public void onJoining(String s) { | |
| 207 | + Log.i(TAG, "私聊chatRoomActionListener" + " onJoined" + s); | |
| 208 | + | |
| 209 | + } | |
| 181 | 210 | |
| 182 | - messageList.add(cnMessage); | |
| 183 | - chatListAdapter.updateItems(messageList); | |
| 184 | - chatListAdapter.notifyDataSetChanged(); | |
| 211 | + @Override | |
| 212 | + public void onJoined(String s) { | |
| 213 | + Log.i(TAG, "私聊chatRoomActionListener " + "onJoined" + s); | |
| 214 | + | |
| 215 | + } | |
| 216 | + | |
| 217 | + @Override | |
| 218 | + public void onQuited(String s) { | |
| 219 | + Log.i(TAG, "私聊chatRoomActionListener " + "onQuited" + s); | |
| 220 | + | |
| 221 | + } | |
| 222 | + | |
| 223 | + @Override | |
| 224 | + public void onError(String s, int i, String s1) { | |
| 225 | + Log.i(TAG, "私聊chatRoomActionListener " + "onError" + s); | |
| 185 | 226 | |
| 186 | 227 | } |
| 187 | 228 | }; |
| 188 | 229 | |
| 189 | 230 | |
| 231 | + //获取历史消息监听 | |
| 232 | +// private IChat.OnLatestMessageListener latestMessageListener = new IChat.OnLatestMessageListener() { | |
| 233 | +// @Override | |
| 234 | +// public void onSuccess(List<CNMessage> list) { | |
| 235 | +// | |
| 236 | +// } | |
| 237 | +// | |
| 238 | +// @Override | |
| 239 | +// public void onError(int i, String s) { | |
| 240 | +// | |
| 241 | +// } | |
| 242 | +// }; | |
| 190 | 243 | |
| 191 | 244 | |
| 192 | 245 | @Override | ... | ... |