Commit 2ee02cec859f70d06fad2209d8b41d20b23e3cde
1 parent
34477381
修改3.0demo
Showing
2 changed files
with
186 additions
and
293 deletions
app/src/main/java/com/cnlive/im/ui/ChatRoom3Activity.java
| @@ -37,7 +37,6 @@ import android.widget.Toast; | @@ -37,7 +37,6 @@ import android.widget.Toast; | ||
| 37 | 37 | ||
| 38 | import com.cnlive.im.R; | 38 | import com.cnlive.im.R; |
| 39 | import com.cnlive.im.adapter.ChatRoom3Adpter; | 39 | import com.cnlive.im.adapter.ChatRoom3Adpter; |
| 40 | -import com.cnlive.im.adapter.ChatRoomAdpter; | ||
| 41 | import com.cnlive.im.adapter.base.ItemClickListener; | 40 | import com.cnlive.im.adapter.base.ItemClickListener; |
| 42 | import com.cnlive.im.mode.ImagMessage; | 41 | import com.cnlive.im.mode.ImagMessage; |
| 43 | import com.cnlive.im.mode.StringMessage; | 42 | import com.cnlive.im.mode.StringMessage; |
| @@ -75,6 +74,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -75,6 +74,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 75 | 74 | ||
| 76 | private ArrayList<String> msgIds = new ArrayList<>(); | 75 | private ArrayList<String> msgIds = new ArrayList<>(); |
| 77 | private String roomIdOne = "ChatRoom05"; | 76 | private String roomIdOne = "ChatRoom05"; |
| 77 | + | ||
| 78 | private EditText editText; | 78 | private EditText editText; |
| 79 | private Button send_messageOneBtn; | 79 | private Button send_messageOneBtn; |
| 80 | private RecyclerView listViewOne; | 80 | private RecyclerView listViewOne; |
| @@ -87,7 +87,6 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -87,7 +87,6 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 87 | private ImageView ima_send; | 87 | private ImageView ima_send; |
| 88 | private Button sendVoice; | 88 | private Button sendVoice; |
| 89 | 89 | ||
| 90 | - private Context context; | ||
| 91 | private AudioRecordUtil mAudioRecordUtil; | 90 | private AudioRecordUtil mAudioRecordUtil; |
| 92 | private PopupWindowFactory mPop; | 91 | private PopupWindowFactory mPop; |
| 93 | private ImageView mImageView; | 92 | private ImageView mImageView; |
| @@ -118,14 +117,12 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -118,14 +117,12 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 118 | super.onCreate(savedInstanceState); | 117 | super.onCreate(savedInstanceState); |
| 119 | //取消状态栏 | 118 | //取消状态栏 |
| 120 | setContentView(R.layout.activity_groupchat_3); | 119 | setContentView(R.layout.activity_groupchat_3); |
| 121 | - context = this; | ||
| 122 | initUI(); | 120 | initUI(); |
| 123 | mAudioRecordUtil = new AudioRecordUtil(); | 121 | mAudioRecordUtil = new AudioRecordUtil(); |
| 124 | mAudioRecordUtil.setOnAudioStatusUpdateListener(onAudioStatusUpdateListener); | 122 | mAudioRecordUtil.setOnAudioStatusUpdateListener(onAudioStatusUpdateListener); |
| 125 | //设置监听 | 123 | //设置监听 |
| 126 | mHandler = new Handler(); | 124 | mHandler = new Handler(); |
| 127 | ChatUtil.setOnConnectStatusListener(connectStatusListener); | 125 | ChatUtil.setOnConnectStatusListener(connectStatusListener); |
| 128 | - ChatUtil.setOnChatRoomActionListener(chatRoomActionListener); | ||
| 129 | ChatUtil.setOnReceiveChatroomMessageListener(receiveMessageListener); | 126 | ChatUtil.setOnReceiveChatroomMessageListener(receiveMessageListener); |
| 130 | ChatUtil.setUploadProgressListener(uploadProgressListener); | 127 | ChatUtil.setUploadProgressListener(uploadProgressListener); |
| 131 | ChatUtil.setKickedOfflineListener(onKickedOfflineListener); | 128 | ChatUtil.setKickedOfflineListener(onKickedOfflineListener); |
| @@ -136,12 +133,10 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -136,12 +133,10 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 136 | ChatUtil.login(new CNUserInfo(user_id_string, user_name_string, ""), connectListener); | 133 | ChatUtil.login(new CNUserInfo(user_id_string, user_name_string, ""), connectListener); |
| 137 | else ChatUtil.logOut(connectListener); | 134 | else ChatUtil.logOut(connectListener); |
| 138 | requestPermission(); | 135 | requestPermission(); |
| 139 | - | ||
| 140 | } | 136 | } |
| 141 | 137 | ||
| 142 | 138 | ||
| 143 | private void initUI() { | 139 | private void initUI() { |
| 144 | - | ||
| 145 | final View view = View.inflate(this, R.layout.layout_microphone, null); | 140 | final View view = View.inflate(this, R.layout.layout_microphone, null); |
| 146 | mPop = new PopupWindowFactory(this, view); | 141 | mPop = new PopupWindowFactory(this, view); |
| 147 | mImageView = (ImageView) view.findViewById(R.id.iv_recording_icon); | 142 | mImageView = (ImageView) view.findViewById(R.id.iv_recording_icon); |
| @@ -150,9 +145,6 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -150,9 +145,6 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 150 | cancelSendLayout = (LinearLayout) view.findViewById(R.id.cancel_send_layout); | 145 | cancelSendLayout = (LinearLayout) view.findViewById(R.id.cancel_send_layout); |
| 151 | ima_send = (ImageView) findViewById(R.id.ima_send); | 146 | ima_send = (ImageView) findViewById(R.id.ima_send); |
| 152 | exit_chat1 = (Button) findViewById(R.id.exit_chat1); | 147 | exit_chat1 = (Button) findViewById(R.id.exit_chat1); |
| 153 | -// user_id = (EditText) findViewById(R.id.user_ID); | ||
| 154 | -// user_name = (EditText) findViewById(R.id.user_name); | ||
| 155 | -// lin_user = (LinearLayout) findViewById(R.id.lin_user); | ||
| 156 | re_chat = (RelativeLayout) findViewById(R.id.re_chat); | 148 | re_chat = (RelativeLayout) findViewById(R.id.re_chat); |
| 157 | foundChatBtn = (Button) findViewById(R.id.creatChat); | 149 | foundChatBtn = (Button) findViewById(R.id.creatChat); |
| 158 | listViewOne = (RecyclerView) findViewById(R.id.chat_list_viewOne); | 150 | listViewOne = (RecyclerView) findViewById(R.id.chat_list_viewOne); |
| @@ -167,25 +159,18 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -167,25 +159,18 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 167 | chatListAdapterOne.setonVoiceItemClickListener(this); | 159 | chatListAdapterOne.setonVoiceItemClickListener(this); |
| 168 | listViewOne.setLayoutManager(new LinearLayoutManager(ChatRoom3Activity.this)); | 160 | listViewOne.setLayoutManager(new LinearLayoutManager(ChatRoom3Activity.this)); |
| 169 | listViewOne.setAdapter(chatListAdapterOne); | 161 | listViewOne.setAdapter(chatListAdapterOne); |
| 170 | - | ||
| 171 | sendVoice = (Button) findViewById(R.id.send_voice); | 162 | sendVoice = (Button) findViewById(R.id.send_voice); |
| 172 | re_chat = (RelativeLayout) findViewById(R.id.activity_chat_room); | 163 | re_chat = (RelativeLayout) findViewById(R.id.activity_chat_room); |
| 173 | keybordBtn = (ImageView) findViewById(R.id.keybord); | 164 | keybordBtn = (ImageView) findViewById(R.id.keybord); |
| 174 | keybordBtn.setOnClickListener(this); | 165 | keybordBtn.setOnClickListener(this); |
| 175 | - | ||
| 176 | findViewById(R.id.videoBtn).setOnClickListener(this); | 166 | findViewById(R.id.videoBtn).setOnClickListener(this); |
| 177 | findViewById(R.id.ugcVideoBtn).setOnClickListener(this); | 167 | findViewById(R.id.ugcVideoBtn).setOnClickListener(this); |
| 178 | 168 | ||
| 179 | - | ||
| 180 | StartListener(); | 169 | StartListener(); |
| 181 | - | ||
| 182 | - | ||
| 183 | } | 170 | } |
| 184 | 171 | ||
| 185 | 172 | ||
| 186 | - /** | ||
| 187 | - * 发送消息监听 | ||
| 188 | - */ | 173 | + //发送消息监听 |
| 189 | private IChat.OnSendMessageListener sendMessageListener = new IChat.OnSendMessageListener() { | 174 | private IChat.OnSendMessageListener sendMessageListener = new IChat.OnSendMessageListener() { |
| 190 | @Override | 175 | @Override |
| 191 | public void onAttached(CNBaseMessage o) { | 176 | public void onAttached(CNBaseMessage o) { |
| @@ -211,7 +196,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -211,7 +196,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 211 | } | 196 | } |
| 212 | }; | 197 | }; |
| 213 | 198 | ||
| 214 | - | 199 | + //接收消息监听 |
| 215 | private IChat.OnReceiveMessageListener receiveMessageListener = new IChat.OnReceiveMessageListener() { | 200 | private IChat.OnReceiveMessageListener receiveMessageListener = new IChat.OnReceiveMessageListener() { |
| 216 | @Override | 201 | @Override |
| 217 | public void processMessage(final CNBaseMessage o) { | 202 | public void processMessage(final CNBaseMessage o) { |
| @@ -220,6 +205,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -220,6 +205,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 220 | } | 205 | } |
| 221 | }; | 206 | }; |
| 222 | 207 | ||
| 208 | + //更新上传进度 | ||
| 223 | private IChat.OnUploadProgressListener uploadProgressListener = new IChat.OnUploadProgressListener() { | 209 | private IChat.OnUploadProgressListener uploadProgressListener = new IChat.OnUploadProgressListener() { |
| 224 | @Override | 210 | @Override |
| 225 | public void onMessagesUpdate(CNBaseMessage message, int elemIdx, int taskId, int progress) { | 211 | public void onMessagesUpdate(CNBaseMessage message, int elemIdx, int taskId, int progress) { |
| @@ -228,6 +214,51 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -228,6 +214,51 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 228 | } | 214 | } |
| 229 | }; | 215 | }; |
| 230 | 216 | ||
| 217 | + //被踢下线状态 | ||
| 218 | + private IChat.OnKickedOfflineListener onKickedOfflineListener = new IChat.OnKickedOfflineListener() { | ||
| 219 | + @Override | ||
| 220 | + public void disconnected(int what, final String extra) { | ||
| 221 | + Log.e(TAG, what + " : " + extra); | ||
| 222 | + Toast.makeText(ChatRoom3Activity.this, extra, Toast.LENGTH_SHORT).show(); | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + @Override | ||
| 226 | + public void conByDevId(final int what, final String extra) { | ||
| 227 | + Log.e(TAG, what + " : " + extra); | ||
| 228 | + Toast.makeText(ChatRoom3Activity.this, extra, Toast.LENGTH_SHORT).show(); | ||
| 229 | + } | ||
| 230 | + }; | ||
| 231 | + | ||
| 232 | + // 加入聊天室监听 | ||
| 233 | + private IChat.OnOperationListener onOperationListener = new IChat.OnOperationListener() { | ||
| 234 | + @Override | ||
| 235 | + public void onSuccess(int what, final String extra) { | ||
| 236 | + Log.v(TAG, +what + extra); | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + @Override | ||
| 240 | + public void onError(int what, String extra) { | ||
| 241 | + Log.v(TAG, "加入聊天室" + what + extra); | ||
| 242 | + } | ||
| 243 | + }; | ||
| 244 | + | ||
| 245 | + //连接监听 | ||
| 246 | + private IChat.OnConnectListener connectListener = new IChat.OnConnectListener() { | ||
| 247 | + @Override | ||
| 248 | + public void onTokenIncorrect(String s) { | ||
| 249 | + Log.e(TAG, "ConnectListener TokenIncorrect"); | ||
| 250 | + } | ||
| 251 | + | ||
| 252 | + @Override | ||
| 253 | + public void onSuccess(final String s) { | ||
| 254 | + Log.e(TAG, "ConnectListener 连接监听" + s); | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + @Override | ||
| 258 | + public void onError(int i, final String s) { | ||
| 259 | + Log.e(TAG, "ConnectListener errorCode : " + i + " : errorMessage : " + s); | ||
| 260 | + } | ||
| 261 | + }; | ||
| 231 | 262 | ||
| 232 | /** | 263 | /** |
| 233 | * 更新消息 | 264 | * 更新消息 |
| @@ -288,205 +319,6 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -288,205 +319,6 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 288 | } | 319 | } |
| 289 | 320 | ||
| 290 | 321 | ||
| 291 | - //聊天室操作 | ||
| 292 | - private IChat.OnChatRoomActionListener chatRoomActionListener = new IChat.OnChatRoomActionListener() { | ||
| 293 | - @Override | ||
| 294 | - public void onJoining(String s) { | ||
| 295 | - Log.i(TAG, "chatRoomActionListener" + " onJoining" + s); | ||
| 296 | - } | ||
| 297 | - | ||
| 298 | - @Override | ||
| 299 | - public void onJoined(String s) { | ||
| 300 | - Log.i(TAG, "chatRoomActionListener " + "onJoined" + s); | ||
| 301 | - } | ||
| 302 | - | ||
| 303 | - @Override | ||
| 304 | - public void onQuited(String s) { | ||
| 305 | - Log.i(TAG, "chatRoomActionListener " + "onQuited" + s); | ||
| 306 | - } | ||
| 307 | - | ||
| 308 | - @Override | ||
| 309 | - public void onError(String s, int i, String s1) { | ||
| 310 | - Log.i(TAG, "chatRoomActionListener " + "onError" + s); | ||
| 311 | - | ||
| 312 | - } | ||
| 313 | - }; | ||
| 314 | - | ||
| 315 | - //被踢下线状态 | ||
| 316 | - private IChat.OnKickedOfflineListener onKickedOfflineListener = new IChat.OnKickedOfflineListener() { | ||
| 317 | - @Override | ||
| 318 | - public void disconnected(int what, final String extra) { | ||
| 319 | - Log.e(TAG, what + " : " + extra); | ||
| 320 | - mHandler.post(new Runnable() { | ||
| 321 | - @Override | ||
| 322 | - public void run() { | ||
| 323 | - Toast.makeText(ChatRoom3Activity.this, extra, Toast.LENGTH_SHORT).show(); | ||
| 324 | - } | ||
| 325 | - }); | ||
| 326 | - } | ||
| 327 | - | ||
| 328 | - @Override | ||
| 329 | - public void conByDevId(final int what, final String extra) { | ||
| 330 | - Log.e(TAG, what + " : " + extra); | ||
| 331 | - mHandler.post(new Runnable() { | ||
| 332 | - @Override | ||
| 333 | - public void run() { | ||
| 334 | - Toast.makeText(ChatRoom3Activity.this, extra, Toast.LENGTH_SHORT).show(); | ||
| 335 | - | ||
| 336 | - } | ||
| 337 | - }); | ||
| 338 | - } | ||
| 339 | - }; | ||
| 340 | - | ||
| 341 | - | ||
| 342 | - // 加入聊天室监听 | ||
| 343 | - private IChat.OnOperationListener onOperationListener = new IChat.OnOperationListener() { | ||
| 344 | - @Override | ||
| 345 | - public void onSuccess(int what, final String extra) { | ||
| 346 | - Log.v(TAG, +what + extra); | ||
| 347 | - | ||
| 348 | - | ||
| 349 | - } | ||
| 350 | - | ||
| 351 | - @Override | ||
| 352 | - public void onError(int what, String extra) { | ||
| 353 | - Log.v(TAG, "加入聊天室" + what + extra); | ||
| 354 | - | ||
| 355 | - } | ||
| 356 | - }; | ||
| 357 | - | ||
| 358 | - @Override | ||
| 359 | - public void onClick(View view) { | ||
| 360 | - switch (view.getId()) { | ||
| 361 | - //向聊天室1发送消息 | ||
| 362 | - case R.id.send_messageOne: | ||
| 363 | - //发送聊天室消息 | ||
| 364 | - if (editText.getText().toString().isEmpty()) { | ||
| 365 | - Toast.makeText(this, "不能发送空消息呦~", Toast.LENGTH_SHORT).show(); | ||
| 366 | - } else { | ||
| 367 | - ChatUtil.sendMessage(IChat.CHATROOM, roomIdOne, editText.getText().toString(), sendMessageListener); | ||
| 368 | - editText.setText(""); | ||
| 369 | - } | ||
| 370 | - break; | ||
| 371 | - case R.id.creatChat: | ||
| 372 | - ChatUtil.joinChatRoom(roomIdOne, -1, onOperationListener); | ||
| 373 | - break; | ||
| 374 | - case R.id.exit_chat1: | ||
| 375 | - ChatUtil.quitChatRoom(roomIdOne, onOperationListener); | ||
| 376 | - break; | ||
| 377 | - case R.id.ima_send: | ||
| 378 | - fromPicture(); | ||
| 379 | - break; | ||
| 380 | - case R.id.keybord: | ||
| 381 | - if (!isVoiceBtnVisible) { | ||
| 382 | - editText.setVisibility(View.GONE); | ||
| 383 | - sendVoice.setVisibility(View.VISIBLE); | ||
| 384 | - keybordBtn.setImageResource(R.drawable.keybord); | ||
| 385 | - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); | ||
| 386 | - imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); | ||
| 387 | - isVoiceBtnVisible = true; | ||
| 388 | - } else { | ||
| 389 | - sendVoice.setVisibility(View.GONE); | ||
| 390 | - editText.setVisibility(View.VISIBLE); | ||
| 391 | - keybordBtn.setImageResource(R.drawable.voice); | ||
| 392 | - isVoiceBtnVisible = false; | ||
| 393 | - } | ||
| 394 | - break; | ||
| 395 | - case R.id.videoBtn: | ||
| 396 | - openSystemRecorder(); | ||
| 397 | - break; | ||
| 398 | - case R.id.ugcVideoBtn: | ||
| 399 | - openSystemRecorder(); | ||
| 400 | - break; | ||
| 401 | - } | ||
| 402 | - } | ||
| 403 | - | ||
| 404 | - private void openSystemRecorder() { | ||
| 405 | - // 创建拍照Intent并将控制权返回给调用的程序 | ||
| 406 | - Intent intent = new Intent(); | ||
| 407 | - intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE); | ||
| 408 | - intent.addCategory(Intent.CATEGORY_DEFAULT); | ||
| 409 | - | ||
| 410 | - // 保存录像到指定的路径 | ||
| 411 | - File file = new File("/sdcard/video.mp4"); | ||
| 412 | - Uri uri = Uri.fromFile(file); | ||
| 413 | - intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); | ||
| 414 | - | ||
| 415 | - // 启动图像捕获Intent | ||
| 416 | - startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE); | ||
| 417 | - } | ||
| 418 | - | ||
| 419 | - | ||
| 420 | - public void fromPicture() { | ||
| 421 | - if (Build.VERSION.SDK_INT >= 23) { | ||
| 422 | - int checkCallPhonePermission = ContextCompat.checkSelfPermission(ChatRoom3Activity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE); | ||
| 423 | - if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) { | ||
| 424 | - requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PICTURE_REQUEST_CODE); | ||
| 425 | - return; | ||
| 426 | - } else { | ||
| 427 | - toIntentPicture(); | ||
| 428 | - } | ||
| 429 | - } else { | ||
| 430 | - toIntentPicture(); | ||
| 431 | - } | ||
| 432 | - } | ||
| 433 | - | ||
| 434 | - | ||
| 435 | - private void toIntentPicture() { | ||
| 436 | - Intent intent = new Intent(); | ||
| 437 | - intent.setType("image/*"); | ||
| 438 | - intent.setAction(Intent.ACTION_PICK); | ||
| 439 | - startActivityForResult(Intent.createChooser(intent, "Complete action using"), IMG_FROM_PICTURE); | ||
| 440 | - } | ||
| 441 | - | ||
| 442 | - | ||
| 443 | - @Override | ||
| 444 | - public void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
| 445 | - super.onActivityResult(requestCode, resultCode, data); | ||
| 446 | - if (resultCode == Activity.RESULT_OK) { | ||
| 447 | - switch (requestCode) { | ||
| 448 | - case IMG_FROM_PICTURE: | ||
| 449 | - Uri selectedImage = data.getData(); | ||
| 450 | - String picturePath = UploadImageUtils.getPath(this, selectedImage); | ||
| 451 | - Uri uri = Uri.parse("file://" + picturePath); | ||
| 452 | - ChatUtil.sendImaMessage(IChat.CHATROOM, roomIdOne, uri, uri, sendMessageListener); | ||
| 453 | - break; | ||
| 454 | - case CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE: | ||
| 455 | - String videoPath = data.getData().getPath(); | ||
| 456 | - Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Images.Thumbnails.FULL_SCREEN_KIND); | ||
| 457 | - String imgPath = FileUtil.createFile(bitmap, System.currentTimeMillis() + ""); | ||
| 458 | - ChatUtil.sendVideoMessage(IChat.CHATROOM, roomIdOne, videoPath, imgPath, MediaUtil.getInstance().getDuration(videoPath), sendMessageListener); | ||
| 459 | - break; | ||
| 460 | - default: | ||
| 461 | - break; | ||
| 462 | - } | ||
| 463 | - } | ||
| 464 | - } | ||
| 465 | - | ||
| 466 | - | ||
| 467 | - private IChat.OnConnectListener connectListener = new IChat.OnConnectListener() { | ||
| 468 | - | ||
| 469 | - | ||
| 470 | - @Override | ||
| 471 | - public void onTokenIncorrect(String s) { | ||
| 472 | - Log.e(TAG, "ConnectListener TokenIncorrect"); | ||
| 473 | - | ||
| 474 | - } | ||
| 475 | - | ||
| 476 | - @Override | ||
| 477 | - public void onSuccess(final String s) { | ||
| 478 | - Log.e(TAG, "ConnectListener 连接监听" + s); | ||
| 479 | - | ||
| 480 | - } | ||
| 481 | - | ||
| 482 | - @Override | ||
| 483 | - public void onError(int i, final String s) { | ||
| 484 | - Log.e(TAG, "ConnectListener errorCode : " + i + " : errorMessage : " + s); | ||
| 485 | - | ||
| 486 | - | ||
| 487 | - } | ||
| 488 | - }; | ||
| 489 | - | ||
| 490 | /** | 322 | /** |
| 491 | * 播放语音文件 | 323 | * 播放语音文件 |
| 492 | * | 324 | * |
| @@ -525,13 +357,13 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -525,13 +357,13 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 525 | if (FileUtil.isCacheFileExist(voiceUuid)) { | 357 | if (FileUtil.isCacheFileExist(voiceUuid)) { |
| 526 | File file = new File(voicePath); | 358 | File file = new File(voicePath); |
| 527 | if (file.length() < voiceMessage.getCnVoiceMessage().getDataSize()) { | 359 | if (file.length() < voiceMessage.getCnVoiceMessage().getDataSize()) { |
| 528 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 360 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 529 | return; | 361 | return; |
| 530 | } | 362 | } |
| 531 | startVoice(voicePath, animationDrawable); | 363 | startVoice(voicePath, animationDrawable); |
| 532 | } else { | 364 | } else { |
| 533 | if (voiceMessage.isDownloading()) { | 365 | if (voiceMessage.isDownloading()) { |
| 534 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 366 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 535 | } else { | 367 | } else { |
| 536 | voiceMessage.setDownloading(true); | 368 | voiceMessage.setDownloading(true); |
| 537 | voiceMessage.getCnVoiceMessage().getVoice(voicePath, new IChat.OnDownloadListener() { | 369 | voiceMessage.getCnVoiceMessage().getVoice(voicePath, new IChat.OnDownloadListener() { |
| @@ -563,7 +395,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -563,7 +395,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 563 | if (FileUtil.isCacheFileExist(videoUuid)) { | 395 | if (FileUtil.isCacheFileExist(videoUuid)) { |
| 564 | File file = new File(videoPath); | 396 | File file = new File(videoPath); |
| 565 | if (file.length() < videoMessage.getCnVideoMessage().getVideo().getSize()) { | 397 | if (file.length() < videoMessage.getCnVideoMessage().getVideo().getSize()) { |
| 566 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 398 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 567 | return; | 399 | return; |
| 568 | } | 400 | } |
| 569 | Intent intent = new Intent(ChatRoom3Activity.this, VideoActivity.class); | 401 | Intent intent = new Intent(ChatRoom3Activity.this, VideoActivity.class); |
| @@ -571,7 +403,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -571,7 +403,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 571 | startActivity(intent); | 403 | startActivity(intent); |
| 572 | } else { | 404 | } else { |
| 573 | if (videoMessage.isDownloading()) { | 405 | if (videoMessage.isDownloading()) { |
| 574 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 406 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 575 | } else { | 407 | } else { |
| 576 | videoMessage.setDownloading(true); | 408 | videoMessage.setDownloading(true); |
| 577 | videoMessage.getCnVideoMessage().getVideo().getVideo(videoPath, new IChat.OnDownloadListener() { | 409 | videoMessage.getCnVideoMessage().getVideo().getVideo(videoPath, new IChat.OnDownloadListener() { |
| @@ -606,7 +438,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -606,7 +438,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 606 | if (FileUtil.isCacheFileExist(videoUuid)) { | 438 | if (FileUtil.isCacheFileExist(videoUuid)) { |
| 607 | File file = new File(videoPath); | 439 | File file = new File(videoPath); |
| 608 | if (file.length() < ugcVideoMessage.getCnUgcMessage().getVideo().getSize()) { | 440 | if (file.length() < ugcVideoMessage.getCnUgcMessage().getVideo().getSize()) { |
| 609 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 441 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 610 | return; | 442 | return; |
| 611 | } | 443 | } |
| 612 | Intent intent = new Intent(ChatRoom3Activity.this, VideoActivity.class); | 444 | Intent intent = new Intent(ChatRoom3Activity.this, VideoActivity.class); |
| @@ -614,7 +446,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -614,7 +446,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 614 | startActivity(intent); | 446 | startActivity(intent); |
| 615 | } else { | 447 | } else { |
| 616 | if (ugcVideoMessage.isDownloading()) { | 448 | if (ugcVideoMessage.isDownloading()) { |
| 617 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 449 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 618 | } else { | 450 | } else { |
| 619 | ugcVideoMessage.setDownloading(true); | 451 | ugcVideoMessage.setDownloading(true); |
| 620 | ugcVideoMessage.getCnUgcMessage().getVideo().getVideo(videoPath, new IChat.OnDownloadListener() { | 452 | ugcVideoMessage.getCnUgcMessage().getVideo().getVideo(videoPath, new IChat.OnDownloadListener() { |
| @@ -648,7 +480,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -648,7 +480,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 648 | if (FileUtil.isCacheFileExist(remoteUuid)) { | 480 | if (FileUtil.isCacheFileExist(remoteUuid)) { |
| 649 | File file = new File(imagePath); | 481 | File file = new File(imagePath); |
| 650 | if (file.length() < imagMessage.getCnImgMessage().getRemoteSize()) { | 482 | if (file.length() < imagMessage.getCnImgMessage().getRemoteSize()) { |
| 651 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 483 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 652 | return; | 484 | return; |
| 653 | } | 485 | } |
| 654 | Intent intent = new Intent(ChatRoom3Activity.this, ImageViewActivity.class); | 486 | Intent intent = new Intent(ChatRoom3Activity.this, ImageViewActivity.class); |
| @@ -656,7 +488,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -656,7 +488,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 656 | startActivity(intent); | 488 | startActivity(intent); |
| 657 | } else { | 489 | } else { |
| 658 | if (imagMessage.isDownloading()) { | 490 | if (imagMessage.isDownloading()) { |
| 659 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 491 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 660 | } else { | 492 | } else { |
| 661 | imagMessage.setDownloading(true); | 493 | imagMessage.setDownloading(true); |
| 662 | imagMessage.getCnImgMessage().getRemoteImage(imagePath, new IChat.OnDownloadListener() { | 494 | imagMessage.getCnImgMessage().getRemoteImage(imagePath, new IChat.OnDownloadListener() { |
| @@ -671,7 +503,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -671,7 +503,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 671 | @Override | 503 | @Override |
| 672 | public void onError(int i, String s) { | 504 | public void onError(int i, String s) { |
| 673 | imagMessage.setDownloading(false); | 505 | imagMessage.setDownloading(false); |
| 674 | - Toast.makeText(context, "下载失败", Toast.LENGTH_SHORT).show(); | 506 | + Toast.makeText(ChatRoom3Activity.this, "下载失败", Toast.LENGTH_SHORT).show(); |
| 675 | } | 507 | } |
| 676 | }); | 508 | }); |
| 677 | } | 509 | } |
| @@ -679,6 +511,112 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -679,6 +511,112 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 679 | } | 511 | } |
| 680 | } | 512 | } |
| 681 | 513 | ||
| 514 | + @Override | ||
| 515 | + public void onClick(View view) { | ||
| 516 | + switch (view.getId()) { | ||
| 517 | + //向聊天室1发送消息 | ||
| 518 | + case R.id.send_messageOne: | ||
| 519 | + //发送聊天室消息 | ||
| 520 | + if (editText.getText().toString().isEmpty()) { | ||
| 521 | + Toast.makeText(this, "不能发送空消息呦~", Toast.LENGTH_SHORT).show(); | ||
| 522 | + } else { | ||
| 523 | + ChatUtil.sendMessage(IChat.CHATROOM, roomIdOne, editText.getText().toString(), sendMessageListener); | ||
| 524 | + editText.setText(""); | ||
| 525 | + } | ||
| 526 | + break; | ||
| 527 | + case R.id.creatChat: | ||
| 528 | + ChatUtil.joinChatRoom(roomIdOne, -1, onOperationListener); | ||
| 529 | + break; | ||
| 530 | + case R.id.exit_chat1: | ||
| 531 | + ChatUtil.quitChatRoom(roomIdOne, onOperationListener); | ||
| 532 | + break; | ||
| 533 | + case R.id.ima_send: | ||
| 534 | + fromPicture(); | ||
| 535 | + break; | ||
| 536 | + case R.id.keybord: | ||
| 537 | + if (!isVoiceBtnVisible) { | ||
| 538 | + editText.setVisibility(View.GONE); | ||
| 539 | + sendVoice.setVisibility(View.VISIBLE); | ||
| 540 | + keybordBtn.setImageResource(R.drawable.keybord); | ||
| 541 | + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); | ||
| 542 | + imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); | ||
| 543 | + isVoiceBtnVisible = true; | ||
| 544 | + } else { | ||
| 545 | + sendVoice.setVisibility(View.GONE); | ||
| 546 | + editText.setVisibility(View.VISIBLE); | ||
| 547 | + keybordBtn.setImageResource(R.drawable.voice); | ||
| 548 | + isVoiceBtnVisible = false; | ||
| 549 | + } | ||
| 550 | + break; | ||
| 551 | + case R.id.videoBtn: | ||
| 552 | + openSystemRecorder(); | ||
| 553 | + break; | ||
| 554 | + case R.id.ugcVideoBtn: | ||
| 555 | + openSystemRecorder(); | ||
| 556 | + break; | ||
| 557 | + } | ||
| 558 | + } | ||
| 559 | + | ||
| 560 | + private void openSystemRecorder() { | ||
| 561 | + // 创建拍照Intent并将控制权返回给调用的程序 | ||
| 562 | + Intent intent = new Intent(); | ||
| 563 | + intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE); | ||
| 564 | + intent.addCategory(Intent.CATEGORY_DEFAULT); | ||
| 565 | + // 保存录像到指定的路径 | ||
| 566 | + File file = new File("/sdcard/video.mp4"); | ||
| 567 | + Uri uri = Uri.fromFile(file); | ||
| 568 | + intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); | ||
| 569 | + // 启动图像捕获Intent | ||
| 570 | + startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE); | ||
| 571 | + } | ||
| 572 | + | ||
| 573 | + | ||
| 574 | + public void fromPicture() { | ||
| 575 | + if (Build.VERSION.SDK_INT >= 23) { | ||
| 576 | + int checkCallPhonePermission = ContextCompat.checkSelfPermission(ChatRoom3Activity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE); | ||
| 577 | + if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) { | ||
| 578 | + requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PICTURE_REQUEST_CODE); | ||
| 579 | + return; | ||
| 580 | + } else { | ||
| 581 | + toIntentPicture(); | ||
| 582 | + } | ||
| 583 | + } else { | ||
| 584 | + toIntentPicture(); | ||
| 585 | + } | ||
| 586 | + } | ||
| 587 | + | ||
| 588 | + | ||
| 589 | + private void toIntentPicture() { | ||
| 590 | + Intent intent = new Intent(); | ||
| 591 | + intent.setType("image/*"); | ||
| 592 | + intent.setAction(Intent.ACTION_PICK); | ||
| 593 | + startActivityForResult(Intent.createChooser(intent, "Complete action using"), IMG_FROM_PICTURE); | ||
| 594 | + } | ||
| 595 | + | ||
| 596 | + | ||
| 597 | + @Override | ||
| 598 | + public void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
| 599 | + super.onActivityResult(requestCode, resultCode, data); | ||
| 600 | + if (resultCode == Activity.RESULT_OK) { | ||
| 601 | + switch (requestCode) { | ||
| 602 | + case IMG_FROM_PICTURE: | ||
| 603 | + Uri selectedImage = data.getData(); | ||
| 604 | + String picturePath = UploadImageUtils.getPath(this, selectedImage); | ||
| 605 | + Uri uri = Uri.parse("file://" + picturePath); | ||
| 606 | + ChatUtil.sendImaMessage(IChat.CHATROOM, roomIdOne, uri, uri, sendMessageListener); | ||
| 607 | + break; | ||
| 608 | + case CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE: | ||
| 609 | + String videoPath = data.getData().getPath(); | ||
| 610 | + Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Images.Thumbnails.FULL_SCREEN_KIND); | ||
| 611 | + String imgPath = FileUtil.createFile(bitmap, System.currentTimeMillis() + ""); | ||
| 612 | + ChatUtil.sendVideoMessage(IChat.CHATROOM, roomIdOne, videoPath, imgPath, MediaUtil.getInstance().getDuration(videoPath), sendMessageListener); | ||
| 613 | + break; | ||
| 614 | + default: | ||
| 615 | + break; | ||
| 616 | + } | ||
| 617 | + } | ||
| 618 | + } | ||
| 619 | + | ||
| 682 | 620 | ||
| 683 | /**************************************************************************/ | 621 | /**************************************************************************/ |
| 684 | 622 | ||
| @@ -687,18 +625,18 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -687,18 +625,18 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 687 | */ | 625 | */ |
| 688 | private void requestPermission() { | 626 | private void requestPermission() { |
| 689 | //判断是否开启摄像头权限 | 627 | //判断是否开启摄像头权限 |
| 690 | - if ((ContextCompat.checkSelfPermission(context, | 628 | + if ((ContextCompat.checkSelfPermission(this, |
| 691 | Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) && | 629 | Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) && |
| 692 | - (ContextCompat.checkSelfPermission(context, | 630 | + (ContextCompat.checkSelfPermission(this, |
| 693 | Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) | 631 | Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) |
| 694 | - && (ContextCompat.checkSelfPermission(context, | 632 | + && (ContextCompat.checkSelfPermission(this, |
| 695 | Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)) { | 633 | Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)) { |
| 696 | StartListener(); | 634 | StartListener(); |
| 697 | 635 | ||
| 698 | //判断是否开启语音权限 | 636 | //判断是否开启语音权限 |
| 699 | } else { | 637 | } else { |
| 700 | //请求获取摄像头权限 | 638 | //请求获取摄像头权限 |
| 701 | - ActivityCompat.requestPermissions((Activity) context, | 639 | + ActivityCompat.requestPermissions(this, |
| 702 | new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA}, VOICE_REQUEST_CODE); | 640 | new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA}, VOICE_REQUEST_CODE); |
| 703 | } | 641 | } |
| 704 | } | 642 | } |
| @@ -710,7 +648,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -710,7 +648,7 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 710 | if ((grantResults[0] == PackageManager.PERMISSION_GRANTED) && (grantResults[1] == PackageManager.PERMISSION_GRANTED)) { | 648 | if ((grantResults[0] == PackageManager.PERMISSION_GRANTED) && (grantResults[1] == PackageManager.PERMISSION_GRANTED)) { |
| 711 | StartListener(); | 649 | StartListener(); |
| 712 | } else { | 650 | } else { |
| 713 | - Toast.makeText(context, "已拒绝权限!", Toast.LENGTH_SHORT).show(); | 651 | + Toast.makeText(this, "已拒绝权限!", Toast.LENGTH_SHORT).show(); |
| 714 | } | 652 | } |
| 715 | } | 653 | } |
| 716 | } | 654 | } |
| @@ -738,7 +676,6 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | @@ -738,7 +676,6 @@ public class ChatRoom3Activity extends AppCompatActivity implements View.OnClick | ||
| 738 | 676 | ||
| 739 | case MotionEvent.ACTION_DOWN: | 677 | case MotionEvent.ACTION_DOWN: |
| 740 | mPop.showAtLocation(re_chat, Gravity.CENTER, 0, 0); | 678 | mPop.showAtLocation(re_chat, Gravity.CENTER, 0, 0); |
| 741 | - | ||
| 742 | sendVoice.setText("松开发送"); | 679 | sendVoice.setText("松开发送"); |
| 743 | mAudioRecordUtil.startRecord(); | 680 | mAudioRecordUtil.startRecord(); |
| 744 | downX = event.getX(); | 681 | downX = event.getX(); |
app/src/main/java/com/cnlive/im/ui/Private3Activity.java
| @@ -38,7 +38,6 @@ import android.widget.Toast; | @@ -38,7 +38,6 @@ import android.widget.Toast; | ||
| 38 | 38 | ||
| 39 | import com.cnlive.im.R; | 39 | import com.cnlive.im.R; |
| 40 | import com.cnlive.im.adapter.ChatRoom3Adpter; | 40 | import com.cnlive.im.adapter.ChatRoom3Adpter; |
| 41 | -import com.cnlive.im.adapter.ChatRoomAdpter; | ||
| 42 | import com.cnlive.im.adapter.base.ItemClickListener; | 41 | import com.cnlive.im.adapter.base.ItemClickListener; |
| 43 | import com.cnlive.im.mode.CNMessageModole; | 42 | import com.cnlive.im.mode.CNMessageModole; |
| 44 | import com.cnlive.im.mode.ImagMessage; | 43 | import com.cnlive.im.mode.ImagMessage; |
| @@ -88,7 +87,6 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -88,7 +87,6 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 88 | }; | 87 | }; |
| 89 | 88 | ||
| 90 | public static final int IMG_FROM_PICTURE = 0x1001; | 89 | public static final int IMG_FROM_PICTURE = 0x1001; |
| 91 | - public static final int VOICE = 0x1002; | ||
| 92 | public static final int PICTURE_REQUEST_CODE = 0x1003; | 90 | public static final int PICTURE_REQUEST_CODE = 0x1003; |
| 93 | public static final int VOICE_REQUEST_CODE = 0x1004; | 91 | public static final int VOICE_REQUEST_CODE = 0x1004; |
| 94 | 92 | ||
| @@ -96,12 +94,12 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -96,12 +94,12 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 96 | public static final String STRING_MESSAGE = "string_message"; | 94 | public static final String STRING_MESSAGE = "string_message"; |
| 97 | public static final String VOICE_MESSAGE = "voice_message"; | 95 | public static final String VOICE_MESSAGE = "voice_message"; |
| 98 | 96 | ||
| 97 | + private ArrayList<String> msgIds = new ArrayList<>(); | ||
| 98 | + | ||
| 99 | private RecyclerView chatListView; | 99 | private RecyclerView chatListView; |
| 100 | private EditText messageContent; | 100 | private EditText messageContent; |
| 101 | private Button sendMessageBtn; | 101 | private Button sendMessageBtn; |
| 102 | private ChatRoom3Adpter chatListAdapter; | 102 | private ChatRoom3Adpter chatListAdapter; |
| 103 | - private ArrayList<String> msgIds = new ArrayList<>(); | ||
| 104 | - // private CNMessage cnMessage; | ||
| 105 | private LinearLayout linearLayoutUseID; | 103 | private LinearLayout linearLayoutUseID; |
| 106 | private EditText user_id_edit; | 104 | private EditText user_id_edit; |
| 107 | private Button userId_btn_top; | 105 | private Button userId_btn_top; |
| @@ -115,7 +113,6 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -115,7 +113,6 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 115 | private Button agree_btn; | 113 | private Button agree_btn; |
| 116 | private Button reject_btn; | 114 | private Button reject_btn; |
| 117 | private LinearLayout agree_reject_lin; | 115 | private LinearLayout agree_reject_lin; |
| 118 | - boolean isCanSendMeaasge = false; | ||
| 119 | private Button vistor_btn; | 116 | private Button vistor_btn; |
| 120 | 117 | ||
| 121 | private ImageView keybordBtn; | 118 | private ImageView keybordBtn; |
| @@ -132,13 +129,11 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -132,13 +129,11 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 132 | 129 | ||
| 133 | private boolean isVoiceBtnVisible = false; | 130 | private boolean isVoiceBtnVisible = false; |
| 134 | private int duration; | 131 | private int duration; |
| 135 | - private Context context; | ||
| 136 | 132 | ||
| 137 | @Override | 133 | @Override |
| 138 | protected void onCreate(Bundle savedInstanceState) { | 134 | protected void onCreate(Bundle savedInstanceState) { |
| 139 | super.onCreate(savedInstanceState); | 135 | super.onCreate(savedInstanceState); |
| 140 | setContentView(R.layout.activity_private_chat_3); | 136 | setContentView(R.layout.activity_private_chat_3); |
| 141 | - context = this; | ||
| 142 | initView(); | 137 | initView(); |
| 143 | mAudioRecordUtil = new AudioRecordUtil(); | 138 | mAudioRecordUtil = new AudioRecordUtil(); |
| 144 | mAudioRecordUtil.setOnAudioStatusUpdateListener(onAudioStatusUpdateListener); | 139 | mAudioRecordUtil.setOnAudioStatusUpdateListener(onAudioStatusUpdateListener); |
| @@ -150,19 +145,15 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -150,19 +145,15 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 150 | } | 145 | } |
| 151 | 146 | ||
| 152 | private void initView() { | 147 | private void initView() { |
| 153 | - | ||
| 154 | final View view = View.inflate(this, R.layout.layout_microphone, null); | 148 | final View view = View.inflate(this, R.layout.layout_microphone, null); |
| 155 | mPop = new PopupWindowFactory(this, view); | 149 | mPop = new PopupWindowFactory(this, view); |
| 156 | sendMsgLayout = (LinearLayout) view.findViewById(R.id.send_layout); | 150 | sendMsgLayout = (LinearLayout) view.findViewById(R.id.send_layout); |
| 157 | cancelSendLayout = (LinearLayout) view.findViewById(R.id.cancel_send_layout); | 151 | cancelSendLayout = (LinearLayout) view.findViewById(R.id.cancel_send_layout); |
| 158 | mTextView = (TextView) view.findViewById(R.id.tv_recording_time); | 152 | mTextView = (TextView) view.findViewById(R.id.tv_recording_time); |
| 159 | mImageView = (ImageView) view.findViewById(R.id.iv_recording_icon); | 153 | mImageView = (ImageView) view.findViewById(R.id.iv_recording_icon); |
| 160 | - | ||
| 161 | opposite_name_edit = (EditText) findViewById(R.id.opposite_name_edit); | 154 | opposite_name_edit = (EditText) findViewById(R.id.opposite_name_edit); |
| 162 | chatListView = (RecyclerView) findViewById(R.id.private_list_view); | 155 | chatListView = (RecyclerView) findViewById(R.id.private_list_view); |
| 163 | - | ||
| 164 | privateLayout = (RelativeLayout) findViewById(R.id.activity_private_chat); | 156 | privateLayout = (RelativeLayout) findViewById(R.id.activity_private_chat); |
| 165 | - | ||
| 166 | messageContent = (EditText) findViewById(R.id.message_content); | 157 | messageContent = (EditText) findViewById(R.id.message_content); |
| 167 | messageContent.addTextChangedListener(textWatcher); | 158 | messageContent.addTextChangedListener(textWatcher); |
| 168 | sendMessageBtn = (Button) findViewById(R.id.send_message); | 159 | sendMessageBtn = (Button) findViewById(R.id.send_message); |
| @@ -182,20 +173,15 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -182,20 +173,15 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 182 | agree_reject_lin = (LinearLayout) findViewById(R.id.agree_reject_lin); | 173 | agree_reject_lin = (LinearLayout) findViewById(R.id.agree_reject_lin); |
| 183 | vistor_btn = (Button) findViewById(R.id.vistor_Btn); | 174 | vistor_btn = (Button) findViewById(R.id.vistor_Btn); |
| 184 | vistor_btn.setOnClickListener(this); | 175 | vistor_btn.setOnClickListener(this); |
| 185 | - | ||
| 186 | keybordBtn = (ImageView) findViewById(R.id.keybord); | 176 | keybordBtn = (ImageView) findViewById(R.id.keybord); |
| 187 | keybordBtn.setOnClickListener(this); | 177 | keybordBtn.setOnClickListener(this); |
| 188 | - | ||
| 189 | ima_send = (ImageView) findViewById(R.id.ima_send); | 178 | ima_send = (ImageView) findViewById(R.id.ima_send); |
| 190 | ima_send.setOnClickListener(this); | 179 | ima_send.setOnClickListener(this); |
| 191 | - | ||
| 192 | sendVoice = (Button) findViewById(R.id.send_voice); | 180 | sendVoice = (Button) findViewById(R.id.send_voice); |
| 193 | - | ||
| 194 | chatListAdapter = new ChatRoom3Adpter(this, true); | 181 | chatListAdapter = new ChatRoom3Adpter(this, true); |
| 195 | chatListAdapter.setonVoiceItemClickListener(this); | 182 | chatListAdapter.setonVoiceItemClickListener(this); |
| 196 | chatListView.setLayoutManager(new LinearLayoutManager(Private3Activity.this)); | 183 | chatListView.setLayoutManager(new LinearLayoutManager(Private3Activity.this)); |
| 197 | chatListView.setAdapter(chatListAdapter); | 184 | chatListView.setAdapter(chatListAdapter); |
| 198 | - | ||
| 199 | findViewById(R.id.videoBtn).setOnClickListener(this); | 185 | findViewById(R.id.videoBtn).setOnClickListener(this); |
| 200 | findViewById(R.id.ugcVideoBtn).setOnClickListener(this); | 186 | findViewById(R.id.ugcVideoBtn).setOnClickListener(this); |
| 201 | 187 | ||
| @@ -204,13 +190,10 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -204,13 +190,10 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 204 | 190 | ||
| 205 | @Override | 191 | @Override |
| 206 | public void onClick(View v) { | 192 | public void onClick(View v) { |
| 207 | - | ||
| 208 | switch (v.getId()) { | 193 | switch (v.getId()) { |
| 209 | case R.id.send_message: | 194 | case R.id.send_message: |
| 210 | sendMessage(STRING_MESSAGE); | 195 | sendMessage(STRING_MESSAGE); |
| 211 | - | ||
| 212 | break; | 196 | break; |
| 213 | - | ||
| 214 | case R.id.userId_btn_top: | 197 | case R.id.userId_btn_top: |
| 215 | //发送私聊消息,需要传入目标ID与发送的消息内容 | 198 | //发送私聊消息,需要传入目标ID与发送的消息内容 |
| 216 | if (user_id_edit.getText().toString().isEmpty()) { | 199 | if (user_id_edit.getText().toString().isEmpty()) { |
| @@ -218,36 +201,28 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -218,36 +201,28 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 218 | } else if (opposite_name_edit.getText().toString().isEmpty()) { | 201 | } else if (opposite_name_edit.getText().toString().isEmpty()) { |
| 219 | Toast.makeText(this, "对方name不能为空", Toast.LENGTH_SHORT).show(); | 202 | Toast.makeText(this, "对方name不能为空", Toast.LENGTH_SHORT).show(); |
| 220 | } else { | 203 | } else { |
| 221 | - | ||
| 222 | oppositeID = user_id_edit.getText().toString(); | 204 | oppositeID = user_id_edit.getText().toString(); |
| 223 | linearLayoutUseID.setVisibility(View.INVISIBLE); | 205 | linearLayoutUseID.setVisibility(View.INVISIBLE); |
| 224 | edit_layout.setVisibility(View.VISIBLE); | 206 | edit_layout.setVisibility(View.VISIBLE); |
| 225 | chatListView.setVisibility(View.VISIBLE); | 207 | chatListView.setVisibility(View.VISIBLE); |
| 226 | CNUserInfo cnName = new CNUserInfo(user_id_string, user_name_string, ""); | 208 | CNUserInfo cnName = new CNUserInfo(user_id_string, user_name_string, ""); |
| 227 | ChatUtil.login(cnName, connectListener); | 209 | ChatUtil.login(cnName, connectListener); |
| 228 | - | ||
| 229 | } | 210 | } |
| 230 | - | ||
| 231 | break; | 211 | break; |
| 232 | - | ||
| 233 | case R.id.agree_btn: | 212 | case R.id.agree_btn: |
| 234 | String objToJsonString = ToStringUtils.objToJsonString(new CNMessageModole("同意", "3")); | 213 | String objToJsonString = ToStringUtils.objToJsonString(new CNMessageModole("同意", "3")); |
| 235 | ChatUtil.sendMessage(IChat.PRIVATE, oppositeID, objToJsonString, sendMessageListener); | 214 | ChatUtil.sendMessage(IChat.PRIVATE, oppositeID, objToJsonString, sendMessageListener); |
| 236 | agree_reject_lin.setVisibility(View.GONE); | 215 | agree_reject_lin.setVisibility(View.GONE); |
| 237 | break; | 216 | break; |
| 238 | - | ||
| 239 | case R.id.reject_btn: | 217 | case R.id.reject_btn: |
| 240 | String objToJsonStringDis = ToStringUtils.objToJsonString(new CNMessageModole("拒绝", "3"));//私聊 | 218 | String objToJsonStringDis = ToStringUtils.objToJsonString(new CNMessageModole("拒绝", "3"));//私聊 |
| 241 | - | ||
| 242 | ChatUtil.sendMessage(IChat.PRIVATE, oppositeID, objToJsonStringDis, sendMessageListener); | 219 | ChatUtil.sendMessage(IChat.PRIVATE, oppositeID, objToJsonStringDis, sendMessageListener); |
| 243 | agree_reject_lin.setVisibility(View.GONE); | 220 | agree_reject_lin.setVisibility(View.GONE); |
| 244 | break; | 221 | break; |
| 245 | case R.id.vistor_Btn: | 222 | case R.id.vistor_Btn: |
| 246 | String objToJsonStringInvt = ToStringUtils.objToJsonString(new CNMessageModole("你好我们可以进行私聊吗", "3"));//私聊 | 223 | String objToJsonStringInvt = ToStringUtils.objToJsonString(new CNMessageModole("你好我们可以进行私聊吗", "3"));//私聊 |
| 247 | ChatUtil.sendMessage(IChat.PRIVATE, oppositeID, objToJsonStringInvt, sendMessageListener); | 224 | ChatUtil.sendMessage(IChat.PRIVATE, oppositeID, objToJsonStringInvt, sendMessageListener); |
| 248 | - | ||
| 249 | break; | 225 | break; |
| 250 | - | ||
| 251 | case R.id.keybord: | 226 | case R.id.keybord: |
| 252 | if (!isVoiceBtnVisible) { | 227 | if (!isVoiceBtnVisible) { |
| 253 | messageContent.setVisibility(View.GONE); | 228 | messageContent.setVisibility(View.GONE); |
| @@ -280,12 +255,10 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -280,12 +255,10 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 280 | Intent intent = new Intent(); | 255 | Intent intent = new Intent(); |
| 281 | intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE); | 256 | intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE); |
| 282 | intent.addCategory(Intent.CATEGORY_DEFAULT); | 257 | intent.addCategory(Intent.CATEGORY_DEFAULT); |
| 283 | - | ||
| 284 | // 保存录像到指定的路径 | 258 | // 保存录像到指定的路径 |
| 285 | File file = new File("/sdcard/video.mp4"); | 259 | File file = new File("/sdcard/video.mp4"); |
| 286 | Uri uri = Uri.fromFile(file); | 260 | Uri uri = Uri.fromFile(file); |
| 287 | intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); | 261 | intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); |
| 288 | - | ||
| 289 | // 启动图像捕获Intent | 262 | // 启动图像捕获Intent |
| 290 | startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE); | 263 | startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE); |
| 291 | } | 264 | } |
| @@ -294,10 +267,8 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -294,10 +267,8 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 294 | private void sendMessage(String type) { | 267 | private void sendMessage(String type) { |
| 295 | if (sendInfo == 2) { | 268 | if (sendInfo == 2) { |
| 296 | Toast.makeText(this, "等待对方接受邀请", Toast.LENGTH_SHORT).show(); | 269 | Toast.makeText(this, "等待对方接受邀请", Toast.LENGTH_SHORT).show(); |
| 297 | - | ||
| 298 | } else if (sendInfo == 4) { | 270 | } else if (sendInfo == 4) { |
| 299 | Toast.makeText(this, "对方已经拒绝不能发送", Toast.LENGTH_SHORT).show(); | 271 | Toast.makeText(this, "对方已经拒绝不能发送", Toast.LENGTH_SHORT).show(); |
| 300 | - | ||
| 301 | } else if (sendInfo == 3) { | 272 | } else if (sendInfo == 3) { |
| 302 | Toast.makeText(this, "还没有邀请对方呦~", Toast.LENGTH_SHORT).show(); | 273 | Toast.makeText(this, "还没有邀请对方呦~", Toast.LENGTH_SHORT).show(); |
| 303 | } else if (sendInfo == 5) { | 274 | } else if (sendInfo == 5) { |
| @@ -315,7 +286,6 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -315,7 +286,6 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 315 | fromPicture(); | 286 | fromPicture(); |
| 316 | } else if (type.equals(VOICE_MESSAGE)) { | 287 | } else if (type.equals(VOICE_MESSAGE)) { |
| 317 | mPop.showAtLocation(privateLayout, Gravity.CENTER, 0, 0); | 288 | mPop.showAtLocation(privateLayout, Gravity.CENTER, 0, 0); |
| 318 | - | ||
| 319 | sendVoice.setText("松开发送"); | 289 | sendVoice.setText("松开发送"); |
| 320 | mAudioRecordUtil.startRecord(); | 290 | mAudioRecordUtil.startRecord(); |
| 321 | } | 291 | } |
| @@ -351,18 +321,13 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -351,18 +321,13 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 351 | if (resultCode == Activity.RESULT_OK) { | 321 | if (resultCode == Activity.RESULT_OK) { |
| 352 | switch (requestCode) { | 322 | switch (requestCode) { |
| 353 | case IMG_FROM_PICTURE: | 323 | case IMG_FROM_PICTURE: |
| 354 | -// String localImagePath = "/sdcard/test.png"; | ||
| 355 | -// Uri selectedImage = Uri.parse("file://" + localImagePath); | ||
| 356 | Uri selectedImage = data.getData(); | 324 | Uri selectedImage = data.getData(); |
| 357 | String[] filePathColumn = {MediaStore.Images.Media.DATA}; | 325 | String[] filePathColumn = {MediaStore.Images.Media.DATA}; |
| 358 | - | ||
| 359 | Cursor cursor = getContentResolver().query(selectedImage, | 326 | Cursor cursor = getContentResolver().query(selectedImage, |
| 360 | filePathColumn, null, null, null); | 327 | filePathColumn, null, null, null); |
| 361 | cursor.moveToFirst(); | 328 | cursor.moveToFirst(); |
| 362 | - | ||
| 363 | int columnIndex = cursor.getColumnIndex(filePathColumn[0]); | 329 | int columnIndex = cursor.getColumnIndex(filePathColumn[0]); |
| 364 | final String picturePath = cursor.getString(columnIndex); | 330 | final String picturePath = cursor.getString(columnIndex); |
| 365 | - | ||
| 366 | Uri uri = Uri.parse("file://" + picturePath); | 331 | Uri uri = Uri.parse("file://" + picturePath); |
| 367 | ChatUtil.sendImaMessage(IChat.PRIVATE, oppositeID, uri, uri, sendMessageListener); | 332 | ChatUtil.sendImaMessage(IChat.PRIVATE, oppositeID, uri, uri, sendMessageListener); |
| 368 | break; | 333 | break; |
| @@ -372,7 +337,6 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -372,7 +337,6 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 372 | String imgPath = FileUtil.createFile(bitmap, System.currentTimeMillis() + ""); | 337 | String imgPath = FileUtil.createFile(bitmap, System.currentTimeMillis() + ""); |
| 373 | ChatUtil.sendVideoMessage(IChat.PRIVATE, oppositeID, videoPath, imgPath, MediaUtil.getInstance().getDuration(videoPath), sendMessageListener); | 338 | ChatUtil.sendVideoMessage(IChat.PRIVATE, oppositeID, videoPath, imgPath, MediaUtil.getInstance().getDuration(videoPath), sendMessageListener); |
| 374 | break; | 339 | break; |
| 375 | - | ||
| 376 | default: | 340 | default: |
| 377 | break; | 341 | break; |
| 378 | } | 342 | } |
| @@ -381,8 +345,6 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -381,8 +345,6 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 381 | 345 | ||
| 382 | //连接监听 | 346 | //连接监听 |
| 383 | private IChat.OnConnectListener connectListener = new IChat.OnConnectListener() { | 347 | private IChat.OnConnectListener connectListener = new IChat.OnConnectListener() { |
| 384 | - | ||
| 385 | - | ||
| 386 | @Override | 348 | @Override |
| 387 | public void onTokenIncorrect(String s) { | 349 | public void onTokenIncorrect(String s) { |
| 388 | Log.e(TAG, "ConnectListener TokenIncorrect"); | 350 | Log.e(TAG, "ConnectListener TokenIncorrect"); |
| @@ -393,21 +355,16 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -393,21 +355,16 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 393 | public void onSuccess(String s) { | 355 | public void onSuccess(String s) { |
| 394 | Log.e(TAG, "ConnectListener 连接监听" + s); | 356 | Log.e(TAG, "ConnectListener 连接监听" + s); |
| 395 | Toast.makeText(Private3Activity.this, s, Toast.LENGTH_SHORT).show(); | 357 | Toast.makeText(Private3Activity.this, s, Toast.LENGTH_SHORT).show(); |
| 396 | - | ||
| 397 | } | 358 | } |
| 398 | 359 | ||
| 399 | @Override | 360 | @Override |
| 400 | public void onError(int i, String s) { | 361 | public void onError(int i, String s) { |
| 401 | Log.e(TAG, "ConnectListener errorCode : " + i + " : errorMessage : " + s); | 362 | Log.e(TAG, "ConnectListener errorCode : " + i + " : errorMessage : " + s); |
| 402 | Toast.makeText(Private3Activity.this, s, Toast.LENGTH_SHORT).show(); | 363 | Toast.makeText(Private3Activity.this, s, Toast.LENGTH_SHORT).show(); |
| 403 | - | ||
| 404 | } | 364 | } |
| 405 | }; | 365 | }; |
| 406 | 366 | ||
| 407 | - | ||
| 408 | - /** | ||
| 409 | - * 发送消息监听 | ||
| 410 | - */ | 367 | + //发送消息监听 |
| 411 | private IChat.OnSendMessageListener sendMessageListener = new IChat.OnSendMessageListener() { | 368 | private IChat.OnSendMessageListener sendMessageListener = new IChat.OnSendMessageListener() { |
| 412 | @Override | 369 | @Override |
| 413 | public void onAttached(CNBaseMessage o) { | 370 | public void onAttached(CNBaseMessage o) { |
| @@ -558,18 +515,17 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -558,18 +515,17 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 558 | */ | 515 | */ |
| 559 | private void requestPermission() { | 516 | private void requestPermission() { |
| 560 | //判断是否开启摄像头权限 | 517 | //判断是否开启摄像头权限 |
| 561 | - if ((ContextCompat.checkSelfPermission(context, | 518 | + if ((ContextCompat.checkSelfPermission(this, |
| 562 | Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) && | 519 | Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) && |
| 563 | - (ContextCompat.checkSelfPermission(context, | 520 | + (ContextCompat.checkSelfPermission(this, |
| 564 | Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) | 521 | Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) |
| 565 | - && (ContextCompat.checkSelfPermission(context, | 522 | + && (ContextCompat.checkSelfPermission(this, |
| 566 | Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)) { | 523 | Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)) { |
| 567 | StartListener(); | 524 | StartListener(); |
| 568 | - | ||
| 569 | //判断是否开启语音权限 | 525 | //判断是否开启语音权限 |
| 570 | } else { | 526 | } else { |
| 571 | //请求获取摄像头权限 | 527 | //请求获取摄像头权限 |
| 572 | - ActivityCompat.requestPermissions((Activity) context, | 528 | + ActivityCompat.requestPermissions(this, |
| 573 | new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA}, VOICE_REQUEST_CODE); | 529 | new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA}, VOICE_REQUEST_CODE); |
| 574 | } | 530 | } |
| 575 | } | 531 | } |
| @@ -581,7 +537,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -581,7 +537,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 581 | if ((grantResults[0] == PackageManager.PERMISSION_GRANTED) && (grantResults[1] == PackageManager.PERMISSION_GRANTED)) { | 537 | if ((grantResults[0] == PackageManager.PERMISSION_GRANTED) && (grantResults[1] == PackageManager.PERMISSION_GRANTED)) { |
| 582 | StartListener(); | 538 | StartListener(); |
| 583 | } else { | 539 | } else { |
| 584 | - Toast.makeText(context, "已拒绝权限!", Toast.LENGTH_SHORT).show(); | 540 | + Toast.makeText(this, "已拒绝权限!", Toast.LENGTH_SHORT).show(); |
| 585 | } | 541 | } |
| 586 | } | 542 | } |
| 587 | } | 543 | } |
| @@ -750,13 +706,13 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -750,13 +706,13 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 750 | if (FileUtil.isCacheFileExist(voiceUuid)) { | 706 | if (FileUtil.isCacheFileExist(voiceUuid)) { |
| 751 | File file = new File(voicePath); | 707 | File file = new File(voicePath); |
| 752 | if (file.length() < voiceMessage.getCnVoiceMessage().getDataSize()) { | 708 | if (file.length() < voiceMessage.getCnVoiceMessage().getDataSize()) { |
| 753 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 709 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 754 | return; | 710 | return; |
| 755 | } | 711 | } |
| 756 | startVoice(voicePath, animationDrawable); | 712 | startVoice(voicePath, animationDrawable); |
| 757 | } else { | 713 | } else { |
| 758 | if (voiceMessage.isDownloading()) { | 714 | if (voiceMessage.isDownloading()) { |
| 759 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 715 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 760 | } else { | 716 | } else { |
| 761 | voiceMessage.setDownloading(true); | 717 | voiceMessage.setDownloading(true); |
| 762 | voiceMessage.getCnVoiceMessage().getVoice(voicePath, new IChat.OnDownloadListener() { | 718 | voiceMessage.getCnVoiceMessage().getVoice(voicePath, new IChat.OnDownloadListener() { |
| @@ -788,7 +744,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -788,7 +744,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 788 | if (FileUtil.isCacheFileExist(videoUuid)) { | 744 | if (FileUtil.isCacheFileExist(videoUuid)) { |
| 789 | File file = new File(videoPath); | 745 | File file = new File(videoPath); |
| 790 | if (file.length() < videoMessage.getCnVideoMessage().getVideo().getSize()) { | 746 | if (file.length() < videoMessage.getCnVideoMessage().getVideo().getSize()) { |
| 791 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 747 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 792 | return; | 748 | return; |
| 793 | } | 749 | } |
| 794 | Intent intent = new Intent(Private3Activity.this, VideoActivity.class); | 750 | Intent intent = new Intent(Private3Activity.this, VideoActivity.class); |
| @@ -796,7 +752,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -796,7 +752,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 796 | startActivity(intent); | 752 | startActivity(intent); |
| 797 | } else { | 753 | } else { |
| 798 | if (videoMessage.isDownloading()) { | 754 | if (videoMessage.isDownloading()) { |
| 799 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 755 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 800 | } else { | 756 | } else { |
| 801 | videoMessage.setDownloading(true); | 757 | videoMessage.setDownloading(true); |
| 802 | videoMessage.getCnVideoMessage().getVideo().getVideo(videoPath, new IChat.OnDownloadListener() { | 758 | videoMessage.getCnVideoMessage().getVideo().getVideo(videoPath, new IChat.OnDownloadListener() { |
| @@ -831,7 +787,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -831,7 +787,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 831 | if (FileUtil.isCacheFileExist(videoUuid)) { | 787 | if (FileUtil.isCacheFileExist(videoUuid)) { |
| 832 | File file = new File(videoPath); | 788 | File file = new File(videoPath); |
| 833 | if (file.length() < ugcVideoMessage.getCnUgcMessage().getVideo().getSize()) { | 789 | if (file.length() < ugcVideoMessage.getCnUgcMessage().getVideo().getSize()) { |
| 834 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 790 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 835 | return; | 791 | return; |
| 836 | } | 792 | } |
| 837 | Intent intent = new Intent(Private3Activity.this, VideoActivity.class); | 793 | Intent intent = new Intent(Private3Activity.this, VideoActivity.class); |
| @@ -839,7 +795,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -839,7 +795,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 839 | startActivity(intent); | 795 | startActivity(intent); |
| 840 | } else { | 796 | } else { |
| 841 | if (ugcVideoMessage.isDownloading()) { | 797 | if (ugcVideoMessage.isDownloading()) { |
| 842 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 798 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 843 | } else { | 799 | } else { |
| 844 | ugcVideoMessage.setDownloading(true); | 800 | ugcVideoMessage.setDownloading(true); |
| 845 | ugcVideoMessage.getCnUgcMessage().getVideo().getVideo(videoPath, new IChat.OnDownloadListener() { | 801 | ugcVideoMessage.getCnUgcMessage().getVideo().getVideo(videoPath, new IChat.OnDownloadListener() { |
| @@ -873,7 +829,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -873,7 +829,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 873 | if (FileUtil.isCacheFileExist(remoteUuid)) { | 829 | if (FileUtil.isCacheFileExist(remoteUuid)) { |
| 874 | File file = new File(imagePath); | 830 | File file = new File(imagePath); |
| 875 | if (file.length() < imagMessage.getCnImgMessage().getRemoteSize()) { | 831 | if (file.length() < imagMessage.getCnImgMessage().getRemoteSize()) { |
| 876 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 832 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 877 | return; | 833 | return; |
| 878 | } | 834 | } |
| 879 | Intent intent = new Intent(Private3Activity.this, ImageViewActivity.class); | 835 | Intent intent = new Intent(Private3Activity.this, ImageViewActivity.class); |
| @@ -881,7 +837,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -881,7 +837,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 881 | startActivity(intent); | 837 | startActivity(intent); |
| 882 | } else { | 838 | } else { |
| 883 | if (imagMessage.isDownloading()) { | 839 | if (imagMessage.isDownloading()) { |
| 884 | - Toast.makeText(context, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); | 840 | + Toast.makeText(this, "请稍等,正在下载...", Toast.LENGTH_SHORT).show(); |
| 885 | } else { | 841 | } else { |
| 886 | imagMessage.setDownloading(true); | 842 | imagMessage.setDownloading(true); |
| 887 | imagMessage.getCnImgMessage().getRemoteImage(imagePath, new IChat.OnDownloadListener() { | 843 | imagMessage.getCnImgMessage().getRemoteImage(imagePath, new IChat.OnDownloadListener() { |
| @@ -896,7 +852,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | @@ -896,7 +852,7 @@ public class Private3Activity extends AppCompatActivity implements View.OnClickL | ||
| 896 | @Override | 852 | @Override |
| 897 | public void onError(int i, String s) { | 853 | public void onError(int i, String s) { |
| 898 | imagMessage.setDownloading(false); | 854 | imagMessage.setDownloading(false); |
| 899 | - Toast.makeText(context, "下载失败", Toast.LENGTH_SHORT).show(); | 855 | + Toast.makeText(Private3Activity.this, "下载失败", Toast.LENGTH_SHORT).show(); |
| 900 | } | 856 | } |
| 901 | }); | 857 | }); |
| 902 | } | 858 | } |