PageRenderTime 73ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 1ms

/yueai/src/main/java/com/yueai/activity/ChatActivity.java

https://bitbucket.org/juzhiwiscom/datelove
Java | 1981 lines | 815 code | 105 blank | 1061 comment | 112 complexity | 1f9cd2475def9abff8c6790db19dedd0 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. package com.yueai.activity;
  2. import android.Manifest;
  3. import android.app.Activity;
  4. import android.app.Dialog;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.pm.PackageManager;
  8. import android.graphics.Color;
  9. import android.graphics.drawable.AnimationDrawable;
  10. import android.graphics.drawable.ColorDrawable;
  11. import android.graphics.drawable.Drawable;
  12. import android.net.Uri;
  13. import android.os.Handler;
  14. import android.os.Vibrator;
  15. import android.support.annotation.NonNull;
  16. import android.support.v4.app.ActivityCompat;
  17. import android.support.v4.content.ContextCompat;
  18. import android.support.v4.widget.SwipeRefreshLayout;
  19. import android.support.v7.widget.LinearLayoutManager;
  20. import android.support.v7.widget.RecyclerView;
  21. import android.text.TextUtils;
  22. import android.view.Display;
  23. import android.view.Gravity;
  24. import android.view.LayoutInflater;
  25. import android.view.MotionEvent;
  26. import android.view.View;
  27. import android.view.Window;
  28. import android.view.WindowManager;
  29. import android.widget.AdapterView;
  30. import android.widget.Button;
  31. import android.widget.ImageView;
  32. import android.widget.PopupWindow;
  33. import android.widget.RelativeLayout;
  34. import android.widget.TextView;
  35. import com.alibaba.fastjson.JSON;
  36. import com.library.dialog.OnDoubleDialogClickListener;
  37. import com.library.utils.DialogUtil;
  38. import com.library.utils.LogUtil;
  39. import com.library.utils.SharedPreferenceUtil;
  40. import com.library.utils.ToastUtil;
  41. import com.library.utils.Util;
  42. import com.library.utils.VersionInfoUtil;
  43. import com.library.widgets.AutoSwipeRefreshLayout;
  44. import com.library.widgets.ClearableEditText;
  45. import com.yueai.R;
  46. import com.yueai.adapter.ChatAdapter;
  47. import com.yueai.base.BaseTitleActivity;
  48. import com.yueai.bean.BaseModel;
  49. import com.yueai.bean.Image;
  50. import com.yueai.bean.Message;
  51. import com.yueai.bean.MessageList;
  52. import com.yueai.bean.WriteMsg;
  53. import com.yueai.constant.IConfigConstant;
  54. import com.yueai.constant.IUrlConstant;
  55. import com.yueai.event.MessageChangedEvent;
  56. import com.yueai.event.RefreshChatEvent;
  57. import com.yueai.fragment.MessageFragment;
  58. import com.yueai.haoping.ActionSheetDialog;
  59. import com.yueai.haoping.OnOperItemClickL;
  60. import com.yueai.online.MessageDao;
  61. import com.yueai.utils.FileUtil;
  62. import com.yueai.utils.GreenDaoUtil;
  63. import com.yueai.utils.RecordUtil;
  64. import com.yueai.utils.Utils;
  65. import com.yueai.xml.PlatformInfoXml;
  66. import com.yueai.xml.UserInfoXml;
  67. import com.zhy.http.okhttp.OkHttpUtils;
  68. import com.zhy.http.okhttp.callback.Callback;
  69. import org.greenrobot.eventbus.EventBus;
  70. import org.greenrobot.eventbus.Subscribe;
  71. import org.greenrobot.greendao.query.QueryBuilder;
  72. import java.io.File;
  73. import java.lang.ref.WeakReference;
  74. import java.util.ArrayList;
  75. import java.util.HashMap;
  76. import java.util.List;
  77. import java.util.Map;
  78. import butterknife.BindView;
  79. import butterknife.OnClick;
  80. import okhttp3.Call;
  81. import okhttp3.Response;
  82. /**
  83. * 聊天页面
  84. * Created by zhangdroid on 2016/11/2.
  85. */
  86. public class ChatActivity extends BaseTitleActivity {
  87. @BindView(R.id.chat_swiperefresh)
  88. AutoSwipeRefreshLayout mAutoSwipeRefresh;
  89. @BindView(R.id.chat_RecyclerView)
  90. RecyclerView mRecyclerView;
  91. @BindView(R.id.chat_bottom_bar)
  92. RelativeLayout mRlChatBottom;
  93. @BindView(R.id.chat_operate_container)
  94. RelativeLayout mRlChatContainer;
  95. @BindView(R.id.chat_et_input)
  96. ClearableEditText mEtInput;
  97. @BindView(R.id.chat_send_msg)
  98. Button mBtnSend;// 发送文字消息
  99. @BindView(R.id.chat_send_photo)
  100. ImageView mIvSendPhoto;// 发送图片
  101. @BindView(R.id.chat_intercept)
  102. TextView mTvIntercept;
  103. // 语音
  104. @BindView(R.id.chat_msg_switch)
  105. ImageView mIvChatSwitch;
  106. @BindView(R.id.record)
  107. Button mBtnRecord;
  108. /**
  109. * 用户id
  110. */
  111. private String mUserId;
  112. /**
  113. * 用户昵称
  114. */
  115. private String mNickname;
  116. /**
  117. * 用户头像url
  118. */
  119. private String mAvatarUrl;
  120. private ChatAdapter mChatAdapter;
  121. private LinearLayoutManager mLinearLayoutManager;
  122. // 录音框
  123. private PopupWindow mRecordPopupWindow;
  124. private static final int PERMISSION_CODE_RECORD_AUDIO = 0;
  125. private static final int PERMISSION_CODE_WRITE_EXTERNAL_STORAGE = 1;
  126. private static final int MSG_TYPE_TIMER = 1;
  127. // 录音文件路径
  128. private String mOutputPath;
  129. // 录音文件名
  130. private String mRecordFileName;
  131. // 是否正在录音
  132. private boolean mIsRecording;
  133. // 录音是否被取消
  134. private boolean mIsRecordCanceled;
  135. // 录音时长(毫秒)
  136. private long mRecordDuration;
  137. // 录音计时刷新间隔(毫秒)
  138. private final long mRefreshInterval = 250;
  139. // 计算录音时长的Handler
  140. private Handler mTimerHandler = new Handler() {
  141. @Override
  142. public void handleMessage(android.os.Message msg) {
  143. super.handleMessage(msg);
  144. switch (msg.what) {
  145. case MSG_TYPE_TIMER:
  146. if (mIsRecording) {
  147. // 计时
  148. mRecordDuration += mRefreshInterval;
  149. // 录音超过1分钟自动发送
  150. if (mRecordDuration > 60 * 1000) {
  151. stopRecordAndSend();
  152. } else {
  153. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_TIMER, mRefreshInterval);
  154. }
  155. }
  156. break;
  157. }
  158. }
  159. };
  160. private Message msg;
  161. // 录音状态常量
  162. private enum STATE {
  163. /**
  164. * 默认值
  165. */
  166. IDLE,
  167. /**
  168. * 录音中
  169. */
  170. RECORDING,
  171. /**
  172. * 取消
  173. */
  174. CANCELED,
  175. /**
  176. * 录音时间太短
  177. */
  178. TOO_SHORT
  179. }
  180. private boolean mIsShowSendVipByPraise = false;
  181. private boolean mIsShowWriteMsgIntercept = false;
  182. private static final String INTENT_KEY_UID = "key_userId";
  183. private static final String INTENT_KEY_NICKNAME = "key_nickname";
  184. private static final String INTENT_KEY_AVATAR_URL = "key_avatar_url";
  185. private Dialog dialog;
  186. /**
  187. * 跳转聊天页
  188. *
  189. * @param from
  190. * @param userId 用户id
  191. * @param nickname 用户昵称
  192. * @param avatarUrl 用户头像url
  193. */
  194. public static void toChatActivity(Activity from, String userId, String nickname, String avatarUrl) {
  195. Map<String, String> map = new HashMap<String, String>();
  196. map.put(INTENT_KEY_UID, userId);
  197. map.put(INTENT_KEY_NICKNAME, nickname);
  198. map.put(INTENT_KEY_AVATAR_URL, avatarUrl);
  199. Util.gotoActivity(from, ChatActivity.class, false, map);
  200. }
  201. /**
  202. * 跳转聊天页
  203. *
  204. * @param context
  205. * @param userId 用户id
  206. * @param nickname 用户昵称
  207. * @param avatarUrl 用户头像url
  208. */
  209. public static void toChatActivity(Context context, String userId, String nickname, String avatarUrl) {
  210. Intent intent = new Intent(context, ChatActivity.class);
  211. intent.putExtra(INTENT_KEY_UID, userId);
  212. intent.putExtra(INTENT_KEY_NICKNAME, nickname);
  213. intent.putExtra(INTENT_KEY_AVATAR_URL, avatarUrl);
  214. context.startActivity(intent);
  215. }
  216. @Override
  217. protected int getLayoutResId() {
  218. return R.layout.activity_chat;
  219. }
  220. @Override
  221. protected String getCenterTitle() {
  222. return null;
  223. }
  224. @Override
  225. protected void initViewsAndVariables() {
  226. //// /**加载读信拦截对话框**/
  227. // boolean showDalog = SharedPreferenceUtil.getBooleanValue(Utils.getContext(), "INTERCEPT_DIALOG", "DIALOG", true);
  228. // if(showDalog){
  229. // mTvIntercept.setVisibility(View.VISIBLE);
  230. // mRlChatContainer.setVisibility(View.GONE);
  231. // }
  232. Intent intent = getIntent();
  233. if (intent != null) {
  234. mUserId = intent.getStringExtra(INTENT_KEY_UID);
  235. mNickname = intent.getStringExtra(INTENT_KEY_NICKNAME);
  236. mAvatarUrl = intent.getStringExtra(INTENT_KEY_AVATAR_URL);
  237. }
  238. if (!TextUtils.isEmpty(mNickname)) {
  239. setTitle(mNickname);
  240. }
  241. // 设置下拉刷新动画样式
  242. mAutoSwipeRefresh.setColorSchemeResources(R.color.main_color);
  243. mAutoSwipeRefresh.setProgressBackgroundColorSchemeColor(Color.WHITE);
  244. mLinearLayoutManager = new LinearLayoutManager(this);
  245. mLinearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
  246. mRecyclerView.setLayoutManager(mLinearLayoutManager);
  247. mChatAdapter = new ChatAdapter(this, -1);
  248. mRecyclerView.setAdapter(mChatAdapter);
  249. loadMsgList();
  250. }
  251. /**加载读信拦截的对话框**/
  252. private void showDialog() {
  253. dialog= new Dialog(this);
  254. LayoutInflater li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
  255. View v=li.inflate(R.layout.dialog_layout, null);
  256. dialog.setContentView(v);
  257. ImageView ivBack = (ImageView)v.findViewById(R.id.iv_back);
  258. Button btnUpgrade = (Button)v.findViewById(R.id.btn_upgrade);
  259. ivBack.setOnClickListener(new View.OnClickListener() {
  260. @Override
  261. public void onClick(View view) {
  262. finish();
  263. // dialog.dismiss();
  264. }
  265. });
  266. btnUpgrade.setOnClickListener(new View.OnClickListener() {
  267. @Override
  268. public void onClick(View view) {
  269. //添加好评送会员
  270. if (mIsShowSendVipByPraise) {
  271. ActionSheetDialogNoTitle();
  272. } else {
  273. BuyServiceActivity.toBuyServiceActivity(ChatActivity.this, BuyServiceActivity.INTENT_FROM_INTERCEPT,
  274. IConfigConstant.PAY_TAG_FROM_CHAT, IConfigConstant.PAY_WAY_ALL);
  275. }
  276. }
  277. });
  278. // dialog.setTitle("Custom Dialog");
  279. Window dialogWindow = dialog.getWindow();
  280. WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
  281. dialogWindow.setGravity(Gravity.LEFT | Gravity.BOTTOM);
  282. /*
  283. * 将对话框的大小按屏幕大小的百分比设置
  284. */
  285. WindowManager m = getWindowManager();
  286. Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
  287. p.height = (int) (d.getHeight() * 0.6); // 高度设置为屏幕的0.6
  288. p.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.65
  289. p.x = (int) (d.getWidth() * 0.135); // 新位置X坐标
  290. p.y = (int) (d.getHeight() * 0.24); // 新位置Y坐标
  291. // p.y = (int) (d.getHeight() * 0.1); // 新位置Y坐标
  292. // p.alpha = 1.0f; // 透明度
  293. // p.dimAmount = 0.7f;//黑暗度
  294. dialogWindow.setAttributes(p);
  295. // getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
  296. // WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
  297. // getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
  298. dialog.setCancelable(false);
  299. dialog.show();
  300. }
  301. /**根据是否是会员来判断拦截对话框的显示与否**/
  302. private void isShowDialog() {
  303. OkHttpUtils.post()
  304. .url(IUrlConstant.URL_GET_CHAT_MSG)
  305. .addHeader("token", PlatformInfoXml.getToken())
  306. .addParams("platformInfo", PlatformInfoXml.getPlatformJsonString())
  307. .addParams("uid", mUserId)
  308. .addParams("isUpdateUnPay", "0")
  309. .build()
  310. .execute(new Callback<MessageList>() {
  311. @Override
  312. public MessageList parseNetworkResponse(Response response, int id) throws Exception {
  313. String resultJson = response.body().string();
  314. if (!TextUtils.isEmpty(resultJson)) {
  315. return JSON.parseObject(resultJson, MessageList.class);
  316. }
  317. return null;
  318. }
  319. @Override
  320. public void onError(Call call, Exception e, int id) {
  321. stopRefresh(3);
  322. }
  323. @Override
  324. public void onResponse(MessageList response, int id) {
  325. if (response != null) {
  326. // 设置支付拦截
  327. String intercept = response.getShowWriteMsgIntercept();
  328. if (!TextUtils.isEmpty(intercept) && "1".equals(intercept)) {
  329. // dialog.show();
  330. // showDialog=true;
  331. showDialog();
  332. SharedPreferenceUtil.setBooleanValue(Utils.getContext(), "INTERCEPT_DIALOG", "DIALOG", true);
  333. } else {
  334. // 不展示拦截入口
  335. // dialog.dismiss();
  336. // showDialog=false;
  337. }
  338. }
  339. // stopRefresh(1);
  340. }
  341. });
  342. }
  343. @Override
  344. protected void addListeners() {
  345. // mIvLeft = (ImageView) findViewById(R.id.activity_base_iv_left);
  346. mIvLeft.setOnClickListener(new View.OnClickListener() {
  347. @Override
  348. public void onClick(View v) {
  349. // 刷新聊天列表
  350. EventBus.getDefault().post(new MessageChangedEvent());
  351. finish();
  352. }
  353. });
  354. mAutoSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
  355. @Override
  356. public void onRefresh() {
  357. loadMsgList();
  358. }
  359. });
  360. // 处理滑动冲突
  361. mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
  362. @Override
  363. public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
  364. super.onScrollStateChanged(recyclerView, newState);
  365. }
  366. @Override
  367. public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
  368. super.onScrolled(recyclerView, dx, dy);
  369. // 判断是否滑动到顶部
  370. int scrolledPosition = (mRecyclerView == null || mRecyclerView.getChildCount() == 0) ? 0 : mRecyclerView.getChildAt(0).getTop();
  371. mAutoSwipeRefresh.setEnabled(scrolledPosition >= 0);
  372. }
  373. });
  374. // 发送文字消息
  375. mEtInput.setTextWatcherCallback(new ClearableEditText.TextWatcherCallback() {
  376. @Override
  377. public void handleTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
  378. if (mEtInput.length() > 0) {
  379. mBtnSend.setVisibility(View.VISIBLE);
  380. mIvSendPhoto.setVisibility(View.GONE);
  381. } else {
  382. mBtnSend.setVisibility(View.GONE);
  383. mIvSendPhoto.setVisibility(View.VISIBLE);
  384. }
  385. }
  386. });
  387. // 切换文字/语音
  388. mIvChatSwitch.setOnClickListener(new View.OnClickListener() {
  389. @Override
  390. public void onClick(View v) {
  391. mIvChatSwitch.setSelected(!mIvChatSwitch.isSelected());
  392. if (mIvChatSwitch.isSelected()) { // 显示发送语音
  393. mBtnRecord.setText(getString(R.string.press_to_speak));
  394. mBtnRecord.setVisibility(View.VISIBLE);
  395. mEtInput.setVisibility(View.GONE);
  396. mBtnSend.setVisibility(View.GONE);
  397. mIvSendPhoto.setVisibility(View.GONE);
  398. if (mIsShowWriteMsgIntercept) {// 支付拦截时不可用
  399. mBtnRecord.setClickable(false);
  400. mBtnRecord.setEnabled(false);
  401. mBtnRecord.setTextColor(getResources().getColor(R.color.textcolor_light_gray));
  402. } else {
  403. mBtnRecord.setClickable(true);
  404. mBtnRecord.setEnabled(true);
  405. mBtnRecord.setTextColor(getResources().getColor(R.color.main_color));
  406. }
  407. } else { // 显示输入框
  408. mBtnRecord.setVisibility(View.GONE);
  409. mEtInput.setVisibility(View.VISIBLE);
  410. if (mEtInput.getText().length() > 0) {
  411. // 已经输入文字
  412. mBtnSend.setVisibility(View.VISIBLE);
  413. mIvSendPhoto.setVisibility(View.GONE);
  414. } else {
  415. mBtnSend.setVisibility(View.GONE);
  416. mIvSendPhoto.setVisibility(View.VISIBLE);
  417. }
  418. }
  419. }
  420. });
  421. // 发送语音消息
  422. mBtnRecord.setOnTouchListener(new View.OnTouchListener() {
  423. @Override
  424. public boolean onTouch(View v, MotionEvent event) {
  425. // 检查权限
  426. if (!checkPermissions()) {// 请求权限时不录音
  427. switch (event.getAction()) {
  428. case MotionEvent.ACTION_DOWN:// 按下时开始录音
  429. mBtnRecord.setText(getString(R.string.loose_to_end));
  430. showRecordPopupWindow(STATE.RECORDING);
  431. startRecord();
  432. mIsRecordCanceled = false;
  433. LogUtil.e(LogUtil.TAG_ZL, "ACTION_DOWN start()");
  434. break;
  435. case MotionEvent.ACTION_MOVE:
  436. if (event.getY() < -100) { // 上滑取消发送
  437. mIsRecordCanceled = true;
  438. showRecordPopupWindow(STATE.CANCELED);
  439. } else {
  440. mIsRecordCanceled = false;
  441. showRecordPopupWindow(STATE.RECORDING);
  442. }
  443. LogUtil.e(LogUtil.TAG_ZL, "ACTION_MOVE " + event.getY() + " mIsRecordCanceled = " + mIsRecordCanceled);
  444. break;
  445. case MotionEvent.ACTION_UP:// 松开时停止录音并发送
  446. mBtnRecord.setText(getString(R.string.press_to_speak));
  447. if (mIsRecordCanceled) {
  448. cancelRecord();
  449. LogUtil.e(LogUtil.TAG_ZL, "ACTION_UP canceld()");
  450. } else {
  451. stopRecordAndSend();
  452. LogUtil.e(LogUtil.TAG_ZL, "ACTION_UP stop()");
  453. }
  454. break;
  455. }
  456. }
  457. return true;
  458. }
  459. });
  460. // 发送图片
  461. mIvSendPhoto.setOnClickListener(new View.OnClickListener() {
  462. @Override
  463. public void onClick(View v) {
  464. GetPhotoActivity.toGetPhotoActivity(ChatActivity.this, IConfigConstant.LOCAL_PIC_PATH, new GetPhotoActivity.OnGetPhotoListener() {
  465. @Override
  466. public void getSelectedPhoto(File file) {
  467. if (file != null) {
  468. // 发送图片前显示要发送的图片进度
  469. Message message = new Message();
  470. if (mChatAdapter != null) {
  471. mChatAdapter.isShowImgLoading(true);
  472. mChatAdapter.isShowImgRetry(false);
  473. message.setUid(UserInfoXml.getUID());
  474. message.setMsgType("10");
  475. message.setCreateDateMills(System.currentTimeMillis());
  476. Image image = new Image();
  477. image.setIsMain(2);
  478. image.setThumbnailUrl(file.getAbsolutePath());
  479. image.setThumbnailUrlM(file.getAbsolutePath());
  480. image.setImageUrl(file.getAbsolutePath());
  481. message.setChatImage(image);
  482. mChatAdapter.insertItem(mChatAdapter.getItemCount(), message);
  483. // 滚动到底部
  484. mLinearLayoutManager.scrollToPosition(mChatAdapter.getItemCount() - 1);
  485. }
  486. sendPhotoMsg(file, message);
  487. }
  488. }
  489. });
  490. }
  491. });
  492. }
  493. private boolean checkPermissions() {
  494. boolean needRequestPermission = false;
  495. if (ContextCompat.checkSelfPermission(ChatActivity.this.getApplicationContext(),
  496. Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_DENIED) {
  497. needRequestPermission = true;
  498. // 请求android.permission.RECORD_AUDIO权限
  499. ActivityCompat.requestPermissions(ChatActivity.this, new String[]{Manifest.permission.RECORD_AUDIO}, PERMISSION_CODE_RECORD_AUDIO);
  500. }
  501. if (ContextCompat.checkSelfPermission(ChatActivity.this.getApplicationContext(),
  502. Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
  503. needRequestPermission = true;
  504. // 请求android.permission.WRITE_EXTERNAL_STORAGE权限
  505. ActivityCompat.requestPermissions(ChatActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_CODE_WRITE_EXTERNAL_STORAGE);
  506. }
  507. return needRequestPermission;
  508. }
  509. @Override
  510. public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  511. super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  512. }
  513. /**
  514. * 开始录音
  515. */
  516. private void startRecord() {
  517. // 录音开始前震动一下
  518. Vibrator vibrator = (Vibrator) ChatActivity.this.getSystemService(Context.VIBRATOR_SERVICE);
  519. vibrator.vibrate(88);
  520. // 根据系统时间生成文件名
  521. mRecordFileName = FileUtil.createFileNameByTime() + ".mp3";
  522. // 录音文件保存路径: 根目录/DateLove/record/用户id/xxx.mp3
  523. mOutputPath = FileUtil.RECORD_DIRECTORY_PATH + File.separator + UserInfoXml.getUID() + File.separator + mRecordFileName;
  524. LogUtil.e(LogUtil.TAG_ZL, "录音存放路径:" + mOutputPath);
  525. // 开始录音
  526. RecordUtil.getInstance().startRecord(mOutputPath);
  527. mIsRecording = true;
  528. mRecordDuration = 0;
  529. // 计时,间隔250毫秒刷新
  530. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_TIMER, mRefreshInterval);
  531. }
  532. /**
  533. * 停止录音并发送
  534. */
  535. private void stopRecordAndSend() {
  536. if (mIsRecording) {
  537. mIsRecording = false;
  538. LogUtil.e(LogUtil.TAG_ZL, "录音时长(毫秒):" + mRecordDuration);
  539. if (mRecordDuration < 1 * 1000) {// 录音时长小于1秒的不发送
  540. showRecordPopupWindow(STATE.TOO_SHORT);
  541. new Handler().postDelayed(new Runnable() {
  542. @Override
  543. public void run() {
  544. // 延时500毫秒调用MediaRecorder#stop(),防止出现start()之后立马调用stop()的异常
  545. RecordUtil.getInstance().stopRecord();
  546. // 删除小于1秒的文件
  547. FileUtil.deleteFile(mOutputPath);
  548. }
  549. }, 500);
  550. } else {// 发送语音
  551. RecordUtil.getInstance().stopRecord();
  552. sendVoiceMsg();
  553. }
  554. // 隐藏录音框
  555. new Handler().postDelayed(new Runnable() {
  556. @Override
  557. public void run() {
  558. if (mRecordPopupWindow != null && mRecordPopupWindow.isShowing()) {
  559. mRecordPopupWindow.dismiss();
  560. }
  561. }
  562. }, 500);
  563. }
  564. }
  565. /**
  566. * 录音取消,删除已经录制的文件
  567. */
  568. private void cancelRecord() {
  569. if (mIsRecordCanceled) {
  570. RecordUtil.getInstance().stopRecord();
  571. mIsRecordCanceled = false;
  572. FileUtil.deleteFile(mOutputPath);
  573. // 隐藏录音框
  574. new Handler().postDelayed(new Runnable() {
  575. @Override
  576. public void run() {
  577. if (mRecordPopupWindow != null && mRecordPopupWindow.isShowing()) {
  578. mRecordPopupWindow.dismiss();
  579. }
  580. }
  581. }, 500);
  582. }
  583. }
  584. /**
  585. * 弹出录音框
  586. */
  587. private void showRecordPopupWindow(STATE state) {
  588. if (mRecordPopupWindow == null) {
  589. View contentView = LayoutInflater.from(ChatActivity.this).inflate(R.layout.popup_chat_record, null);
  590. mRecordPopupWindow = new PopupWindow(contentView, WindowManager.LayoutParams.WRAP_CONTENT,
  591. WindowManager.LayoutParams.WRAP_CONTENT, true);
  592. mRecordPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
  593. }
  594. View view = mRecordPopupWindow.getContentView();
  595. if (view != null) {
  596. RelativeLayout rlRecording = (RelativeLayout) view.findViewById(R.id.popup_recording_container);
  597. ImageView ivRecording = (ImageView) view.findViewById(R.id.popup_record_anim);
  598. // 设置动画
  599. List<Drawable> drawableList = new ArrayList<Drawable>();
  600. drawableList.add(getResources().getDrawable(R.drawable.voice1));
  601. drawableList.add(getResources().getDrawable(R.drawable.voice2));
  602. drawableList.add(getResources().getDrawable(R.drawable.voice3));
  603. drawableList.add(getResources().getDrawable(R.drawable.voice4));
  604. drawableList.add(getResources().getDrawable(R.drawable.voice5));
  605. drawableList.add(getResources().getDrawable(R.drawable.voice6));
  606. AnimationDrawable animationDrawable = Utils.getFrameAnim(drawableList, true, 150);
  607. ivRecording.setImageDrawable(animationDrawable);
  608. ImageView ivCancel = (ImageView) view.findViewById(R.id.popup_cancel_record);
  609. ImageView ivTooShort = (ImageView) view.findViewById(R.id.popup_record_too_short);
  610. TextView tvState = (TextView) view.findViewById(R.id.popup_record_state);
  611. switch (state) {
  612. case RECORDING: // 正在录音
  613. rlRecording.setVisibility(View.VISIBLE);
  614. // 播放动画
  615. animationDrawable.start();
  616. ivCancel.setVisibility(View.GONE);
  617. ivTooShort.setVisibility(View.GONE);
  618. tvState.setText(getString(R.string.slideup_to_cancel));
  619. break;
  620. case CANCELED: // 取消录音
  621. rlRecording.setVisibility(View.GONE);
  622. // 停止动画
  623. if (animationDrawable.isRunning()) {
  624. animationDrawable.stop();
  625. }
  626. ivCancel.setVisibility(View.VISIBLE);
  627. ivTooShort.setVisibility(View.GONE);
  628. tvState.setText(getString(R.string.loose_to_cancel));
  629. break;
  630. case TOO_SHORT:// 录音时间太短
  631. rlRecording.setVisibility(View.GONE);
  632. // 停止动画
  633. if (animationDrawable.isRunning()) {
  634. animationDrawable.stop();
  635. }
  636. ivCancel.setVisibility(View.GONE);
  637. ivTooShort.setVisibility(View.VISIBLE);
  638. tvState.setText(getString(R.string.record_too_short));
  639. break;
  640. }
  641. }
  642. mRecordPopupWindow.showAtLocation(mRecyclerView, Gravity.CENTER, 0, 0);
  643. }
  644. @OnClick({R.id.chat_send_msg, R.id.chat_intercept})
  645. public void onClick(View view) {
  646. switch (view.getId()) {
  647. case R.id.chat_send_msg:// 发送文字消息
  648. mBtnSend.setEnabled(true);
  649. sendTextMessage();
  650. break;
  651. case R.id.chat_intercept:// 支付拦截
  652. //添加好评送会员
  653. if (mIsShowSendVipByPraise) {
  654. ActionSheetDialogNoTitle();
  655. } else {
  656. BuyServiceActivity.toBuyServiceActivity(ChatActivity.this, BuyServiceActivity.INTENT_FROM_INTERCEPT,
  657. IConfigConstant.PAY_TAG_FROM_CHAT, IConfigConstant.PAY_WAY_ALL);
  658. }
  659. break;
  660. }
  661. }
  662. private void ActionSheetDialogNoTitle() {
  663. final String[] stringItems = {getString(R.string.free_use), getString(R.string.buy_vip_service)};
  664. final ActionSheetDialog dialog = new ActionSheetDialog(ChatActivity.this, stringItems, mTvIntercept);
  665. dialog.isTitleShow(false).show();
  666. dialog.setOnOperItemClickL(new OnOperItemClickL() {
  667. @Override
  668. public void onOperItemClick(AdapterView<?> parent, View view, int position, long id) {
  669. if (position == 0) {
  670. DialogUtil.showDoubleBtnDialog(getSupportFragmentManager(), getString(R.string.hour12_vip), getString(R.string.send_vip), getString(R.string.go_good), getString(R.string.cancel), false, new OnDoubleDialogClickListener() {
  671. @Override
  672. public void onPositiveClick(View view) {
  673. Intent intent = new Intent();
  674. intent.setAction(Intent.ACTION_VIEW);
  675. intent.setData(Uri.parse("market://details?id=" + VersionInfoUtil.getPackageName(ChatActivity.this)));
  676. intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  677. if (VersionInfoUtil.checkAPKExist(ChatActivity.this, "com.android.vending")) {
  678. // 直接跳转Google商店
  679. intent.setPackage("com.android.vending");
  680. }
  681. startActivity(intent);
  682. }
  683. @Override
  684. public void onNegativeClick(View view) {
  685. }
  686. });
  687. } else if (position == 1) {
  688. BuyServiceActivity.toBuyServiceActivity(ChatActivity.this, BuyServiceActivity.INTENT_FROM_INTERCEPT,
  689. IConfigConstant.PAY_TAG_FROM_CHAT, IConfigConstant.PAY_WAY_ALL);
  690. }
  691. dialog.dismiss();
  692. }
  693. });
  694. }
  695. private void loadMsgList() {
  696. OkHttpUtils.post()
  697. .url(IUrlConstant.URL_GET_CHAT_MSG)
  698. .addHeader("token", PlatformInfoXml.getToken())
  699. .addParams("platformInfo", PlatformInfoXml.getPlatformJsonString())
  700. .addParams("uid", mUserId)
  701. .build()
  702. .execute(new Callback<MessageList>() {
  703. @Override
  704. public MessageList parseNetworkResponse(Response response, int id) throws Exception {
  705. String resultJson = response.body().string();
  706. if (!TextUtils.isEmpty(resultJson)) {
  707. return JSON.parseObject(resultJson, MessageList.class);
  708. }
  709. return null;
  710. }
  711. @Override
  712. public void onError(Call call, Exception e, int id) {
  713. stopRefresh(3);
  714. }
  715. @Override
  716. public void onResponse(MessageList response, int id) {
  717. if (response != null) {
  718. // 设置支付拦截
  719. String intercept = response.getShowWriteMsgIntercept();
  720. if (!TextUtils.isEmpty(intercept) && "1".equals(intercept)) {
  721. // 展示拦截入口
  722. mIsShowWriteMsgIntercept = true;
  723. mTvIntercept.setVisibility(View.VISIBLE);
  724. mRlChatContainer.setVisibility(View.GONE);
  725. // SharedPreferenceUtil.setBooleanValue(Utils.getContext(), "INTERCEPT_DIALOG", "DIALOG", true);
  726. } else {// 不展示拦截入口
  727. mIsShowWriteMsgIntercept = false;
  728. mTvIntercept.setVisibility(View.GONE);
  729. mRlChatContainer.setVisibility(View.VISIBLE);
  730. // SharedPreferenceUtil.setBooleanValue(Utils.getContext(), "INTERCEPT_DIALOG", "DIALOG", false);
  731. }
  732. mRlChatBottom.setVisibility(View.VISIBLE);
  733. String isSucceed = response.getIsSucceed();
  734. if (!TextUtils.isEmpty(isSucceed) && "1".equals(isSucceed)) {
  735. if (mChatAdapter != null) {
  736. mChatAdapter.setAvatarUrl(mAvatarUrl);
  737. mChatAdapter.setServerSystemTime(response.getSystemTime());
  738. mChatAdapter.isIntercept(mIsShowWriteMsgIntercept);
  739. mChatAdapter.isShowVoiceLoading(false);
  740. mChatAdapter.isShowVoiceRetry(false);
  741. mChatAdapter.isShowImgLoading(false);
  742. mChatAdapter.isShowImgRetry(false);
  743. List<Message> messageList = response.getListMsg();
  744. if (!Util.isListEmpty(messageList)) {
  745. List<Image> imageList = new ArrayList<Image>();
  746. for (Message message : messageList) {
  747. if (message != null) {
  748. Image image = message.getChatImage();
  749. if (image != null) {
  750. imageList.add(image);
  751. }
  752. }
  753. }
  754. mChatAdapter.setAllImageList(imageList);
  755. mChatAdapter.replaceAll(messageList);
  756. // 滚动到底部
  757. mLinearLayoutManager.scrollToPosition(mLinearLayoutManager.getItemCount() - 1);
  758. }
  759. }
  760. }
  761. // 设置五星好评
  762. if (response.getIsShowSendVipByPraise() != null && response.getIsShowSendVipByPraise().equals("1")) {
  763. mIsShowSendVipByPraise = true;
  764. } else {
  765. mIsShowSendVipByPraise = false;
  766. }
  767. }
  768. stopRefresh(1);
  769. }
  770. });
  771. }
  772. private void stopRefresh(int secs) {
  773. new Handler().postDelayed(new Runnable() {
  774. @Override
  775. public void run() {
  776. if (mAutoSwipeRefresh != null) {
  777. mAutoSwipeRefresh.setRefreshing(false);
  778. }
  779. }
  780. }, secs * 1000);
  781. }
  782. /**
  783. * 发送文字消息
  784. */
  785. private void sendTextMessage() {
  786. OkHttpUtils.post()
  787. .url(IUrlConstant.URL_SEND_TEXT_MSG)
  788. .addHeader("token", PlatformInfoXml.getToken())
  789. .addParams("platformInfo", PlatformInfoXml.getPlatformJsonString())
  790. .addParams("uid", mUserId)
  791. .addParams("writeMsgType", "1")
  792. .addParams("content", mEtInput.getText().toString().trim())
  793. .build()
  794. .execute(new Callback<WriteMsg>() {
  795. @Override
  796. public WriteMsg parseNetworkResponse(Response response, int id) throws Exception {
  797. String resultJson = response.body().string();
  798. if (!TextUtils.isEmpty(resultJson)) {
  799. return JSON.parseObject(resultJson, WriteMsg.class);
  800. }
  801. mBtnSend.setEnabled(true);
  802. return null;
  803. }
  804. @Override
  805. public void onError(Call call, Exception e, int id) {
  806. ToastUtil.showShortToast(ChatActivity.this, getString(R.string.send_fail));
  807. mBtnSend.setEnabled(true);
  808. }
  809. @Override
  810. public void onResponse(WriteMsg response, int id) {
  811. if (response != null) {
  812. String isSucceed = response.getIsSucceed();
  813. if (!TextUtils.isEmpty(isSucceed) && "1".equals(isSucceed)) {
  814. // 重置状态
  815. mEtInput.setText("");
  816. loadMsgList();
  817. // 发送事件,更新聊天列表
  818. EventBus.getDefault().post(new MessageChangedEvent());
  819. } else {
  820. ToastUtil.showShortToast(ChatActivity.this, getString(R.string.send_fail));
  821. }
  822. } else {
  823. ToastUtil.showShortToast(ChatActivity.this, getString(R.string.send_fail));
  824. }
  825. }
  826. });
  827. }
  828. /**
  829. * 发送语音消息
  830. */
  831. private void sendVoiceMsg() {
  832. // 发送语音前显示要发送的图片进度
  833. final Message message = new Message();
  834. if (mChatAdapter != null) {
  835. mChatAdapter.isShowVoiceLoading(true);
  836. mChatAdapter.isShowVoiceRetry(false);
  837. message.setUid(UserInfoXml.getUID());
  838. message.setMsgType("7");
  839. message.setCreateDateMills(System.currentTimeMillis());
  840. message.setRecevStatus("1");
  841. message.setAudioTime(String.valueOf(Math.round(mRecordDuration / 1000)));
  842. message.setAudioUrl(mOutputPath);
  843. mChatAdapter.insertItem(mChatAdapter.getItemCount(), message);
  844. // 滚动到底部
  845. mLinearLayoutManager.scrollToPosition(mChatAdapter.getItemCount() - 1);
  846. }
  847. OkHttpUtils.post()
  848. .url(IUrlConstant.URL_SEND_VOICE_MSG)
  849. .addHeader("token", PlatformInfoXml.getToken())
  850. .addHeader("platformInfo", PlatformInfoXml.getPlatformJsonString())
  851. .addHeader("uid", mUserId)
  852. .addHeader("writeMsgType", "1")
  853. .addHeader("audioSecond", String.valueOf(Math.round(mRecordDuration / 1000)))
  854. .addFile("file", mRecordFileName, new File(mOutputPath))
  855. .build()
  856. .execute(new Callback<BaseModel>() {
  857. @Override
  858. public BaseModel parseNetworkResponse(Response response, int id) throws Exception {
  859. String resultJson = response.body().string();
  860. if (!TextUtils.isEmpty(resultJson)) {
  861. return JSON.parseObject(resultJson, BaseModel.class);
  862. }
  863. return null;
  864. }
  865. @Override
  866. public void onError(Call call, Exception e, int id) {
  867. sendVoiceFailed(message);
  868. }
  869. @Override
  870. public void onResponse(BaseModel response, int id) {
  871. if (response != null) {
  872. String isSucceed = response.getIsSucceed();
  873. if (!TextUtils.isEmpty(isSucceed) && "1".equals(isSucceed)) {
  874. loadMsgList();
  875. // 发送事件,更新聊天列表
  876. EventBus.getDefault().post(new MessageChangedEvent());
  877. } else {
  878. sendVoiceFailed(message);
  879. }
  880. } else {
  881. sendVoiceFailed(message);
  882. }
  883. }
  884. });
  885. }
  886. /**
  887. * 发送语音失败,刷新状态
  888. */
  889. private void sendVoiceFailed(Message message) {
  890. mChatAdapter.isShowVoiceLoading(false);
  891. mChatAdapter.isShowVoiceRetry(true);
  892. mChatAdapter.updateItem(mChatAdapter.getItemCount() - 1, message);
  893. ToastUtil.showShortToast(ChatActivity.this, getString(R.string.send_fail));
  894. }
  895. /**
  896. * 发送图片消息
  897. */
  898. private void sendPhotoMsg(File file, final Message message) {
  899. OkHttpUtils.post()
  900. .url(IUrlConstant.URL_SEND_PHOTO_MSG)
  901. .addHeader("token", PlatformInfoXml.getToken())
  902. .addHeader("platformInfo", PlatformInfoXml.getPlatformJsonString())
  903. .addHeader("recevUserId", mUserId)
  904. .addFile("request", file.getName(), file)
  905. .build()
  906. .execute(new Callback<BaseModel>() {
  907. @Override
  908. public BaseModel parseNetworkResponse(Response response, int id) throws Exception {
  909. String resultJson = response.body().string();
  910. if (!TextUtils.isEmpty(resultJson)) {
  911. return JSON.parseObject(resultJson, BaseModel.class);
  912. }
  913. return null;
  914. }
  915. @Override
  916. public void onError(Call call, Exception e, int id) {
  917. sendPhotoFailed(message);
  918. }
  919. @Override
  920. public void onResponse(BaseModel response, int id) {
  921. if (response != null) {
  922. String isSucceed = response.getIsSucceed();
  923. if (!TextUtils.isEmpty(isSucceed) && "1".equals(isSucceed)) {
  924. loadMsgList();
  925. // 发送事件,更新聊天列表
  926. EventBus.getDefault().post(new MessageChangedEvent());
  927. } else {
  928. sendPhotoFailed(message);
  929. }
  930. } else {
  931. sendPhotoFailed(message);
  932. }
  933. }
  934. });
  935. }
  936. /**
  937. * 发送图片失败,刷新状态
  938. */
  939. private void sendPhotoFailed(Message message) {
  940. mChatAdapter.isShowImgLoading(false);
  941. mChatAdapter.isShowImgRetry(true);
  942. mChatAdapter.updateItem(mChatAdapter.getItemCount() - 1, message);
  943. ToastUtil.showShortToast(ChatActivity.this, getString(R.string.send_fail));
  944. }
  945. @Override
  946. protected void doRegister() {
  947. super.doRegister();
  948. EventBus.getDefault().register(this);
  949. }
  950. @Override
  951. protected void unregister() {
  952. super.unregister();
  953. EventBus.getDefault().unregister(this);
  954. // 释放录音和播放器资源
  955. RecordUtil.getInstance().releaseRecord();
  956. if (RecordUtil.getInstance().isPlaying()) {// 如果正在播放语音,需要停止
  957. RecordUtil.getInstance().stop();
  958. }
  959. RecordUtil.getInstance().release();
  960. }
  961. @Subscribe
  962. public void onEvent(RefreshChatEvent event) {
  963. loadMsgList();
  964. }
  965. }
  966. ///**
  967. // * 聊天页面
  968. // * Created by zhangdroid on 2016/11/2.
  969. // */
  970. //public class ChatActivity extends BaseTitleActivity {
  971. // @BindView(R.id.chat_swiperefresh)
  972. // AutoSwipeRefreshLayout mAutoSwipeRefresh;
  973. // @BindView(R.id.chat_RecyclerView)
  974. // RecyclerView mRecyclerView;
  975. // @BindView(R.id.chat_bottom_bar)
  976. // RelativeLayout mRlChatBottom;
  977. // @BindView(R.id.chat_operate_container)
  978. // RelativeLayout mRlChatContainer;
  979. // @BindView(R.id.chat_et_input)
  980. // ClearableEditText mEtInput;
  981. // @BindView(R.id.chat_send_msg)
  982. // Button mBtnSend;// 发送文字消息
  983. // @BindView(R.id.chat_send_photo)
  984. // ImageView mIvSendPhoto;// 发送图片
  985. // @BindView(R.id.chat_intercept)
  986. // TextView mTvIntercept;
  987. // // 语音
  988. // @BindView(R.id.chat_msg_switch)
  989. // ImageView mIvChatSwitch;
  990. // @BindView(R.id.record)
  991. // Button mBtnRecord;
  992. //
  993. // /**
  994. // * 用户id
  995. // */
  996. // private String mUserId;
  997. // /**
  998. // * 用户昵称
  999. // */
  1000. // private String mNickname;
  1001. // /**
  1002. // * 用户头像url
  1003. // */
  1004. // private String mAvatarUrl;
  1005. //
  1006. // private ChatAdapter mChatAdapter;
  1007. // private LinearLayoutManager mLinearLayoutManager;
  1008. // // 录音框
  1009. // private PopupWindow mRecordPopupWindow;
  1010. // private static final int PERMISSION_CODE_RECORD_AUDIO = 0;
  1011. // private static final int PERMISSION_CODE_WRITE_EXTERNAL_STORAGE = 1;
  1012. // private static final int MSG_TYPE_TIMER = 1;
  1013. //
  1014. // // 录音文件路径
  1015. // private String mOutputPath;
  1016. // // 录音文件名
  1017. // private String mRecordFileName;
  1018. // // 是否正在录音
  1019. // private boolean mIsRecording;
  1020. // // 录音是否被取消
  1021. // private boolean mIsRecordCanceled;
  1022. // // 录音时长(毫秒)
  1023. // private long mRecordDuration;
  1024. // // 录音计时刷新间隔(毫秒)
  1025. // private final long mRefreshInterval = 250;
  1026. // // 计算录音时长的Handler
  1027. // private Handler mTimerHandler = new Handler() {
  1028. //
  1029. // @Override
  1030. // public void handleMessage(android.os.Message msg) {
  1031. // super.handleMessage(msg);
  1032. // switch (msg.what) {
  1033. // case MSG_TYPE_TIMER:
  1034. // if (mIsRecording) {
  1035. // // 计时
  1036. // mRecordDuration += mRefreshInterval;
  1037. // // 录音超过1分钟自动发送
  1038. // if (mRecordDuration > 60 * 1000) {
  1039. // stopRecordAndSend();
  1040. // } else {
  1041. // mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_TIMER, mRefreshInterval);
  1042. // }
  1043. // }
  1044. // break;
  1045. // }
  1046. // }
  1047. // };
  1048. //
  1049. // // 录音状态常量
  1050. // private enum STATE {
  1051. // /**
  1052. // * 默认值
  1053. // */
  1054. // IDLE,
  1055. // /**
  1056. // * 录音中
  1057. // */
  1058. // RECORDING,
  1059. // /**
  1060. // * 取消
  1061. // */
  1062. // CANCELED,
  1063. // /**
  1064. // * 录音时间太短
  1065. // */
  1066. // TOO_SHORT
  1067. // }
  1068. //
  1069. // private boolean mIsShowSendVipByPraise = false;
  1070. // private boolean mIsShowWriteMsgIntercept = false;
  1071. //
  1072. // private static final String INTENT_KEY_UID = "key_userId";
  1073. // private static final String INTENT_KEY_NICKNAME = "key_nickname";
  1074. // private static final String INTENT_KEY_AVATAR_URL = "key_avatar_url";
  1075. // private static final String INTENT_KEY_NEED_REFRESH = "key_need_refresh";
  1076. //
  1077. // /**
  1078. // * 跳转聊天页
  1079. // *
  1080. // * @param from
  1081. // * @param userId 用户id
  1082. // * @param nickname 用户昵称
  1083. // * @param avatarUrl 用户头像url
  1084. // */
  1085. // public static void toChatActivity(Activity from, String userId, String nickname, String avatarUrl) {
  1086. // Map<String, String> map = new HashMap<String, String>();
  1087. // map.put(INTENT_KEY_UID, userId);
  1088. // map.put(INTENT_KEY_NICKNAME, nickname);
  1089. // map.put(INTENT_KEY_AVATAR_URL, avatarUrl);
  1090. // Util.gotoActivity(from, ChatActivity.class, false, map);
  1091. // }
  1092. //
  1093. // /**
  1094. // * 跳转聊天页
  1095. // *
  1096. // * @param context
  1097. // * @param userId 用户id
  1098. // * @param nickname 用户昵称
  1099. // * @param avatarUrl 用户头像url
  1100. // */
  1101. // public static void toChatActivity(Context context, String userId, String nickname, String avatarUrl) {
  1102. // Intent intent = new Intent(context, ChatActivity.class);
  1103. // intent.putExtra(INTENT_KEY_UID, userId);
  1104. // intent.putExtra(INTENT_KEY_NICKNAME, nickname);
  1105. // intent.putExtra(INTENT_KEY_AVATAR_URL, avatarUrl);
  1106. // context.startActivity(intent);
  1107. // }
  1108. //
  1109. // // 数据库相关
  1110. // private MessageDao mMessageDao;
  1111. // private MyHandler mMyHandler;
  1112. //
  1113. // private static final int MSG_TYPE_DB = 0;
  1114. // private static final int MSG_TYPE_NET = 1;
  1115. //
  1116. // private static class MyHandler extends Handler {
  1117. // private WeakReference<ChatActivity> mChatActivity;
  1118. //
  1119. // public MyHandler(ChatActivity chatActivity) {
  1120. // this.mChatActivity = new WeakReference<ChatActivity>(chatActivity);
  1121. // }
  1122. //
  1123. // @Override
  1124. // public void handleMessage(android.os.Message msg) {
  1125. // …

Large files files are truncated, but you can click here to view the full file