/** * 根据是否点击笑脸来显示文本输入框的状态 @Title: showEditState * * @param @param isEmo: 用于区分文字和表情 * @return void * @throws */ private void showEditState(boolean isEmo) { edit_user_comment.setVisibility(View.VISIBLE); btn_chat_keyboard.setVisibility(View.GONE); btn_chat_voice.setVisibility(View.VISIBLE); btn_speak.setVisibility(View.GONE); edit_user_comment.requestFocus(); if (isEmo) { layout_more.setVisibility(View.VISIBLE); layout_more.setVisibility(View.VISIBLE); layout_emo.setVisibility(View.VISIBLE); layout_add.setVisibility(View.GONE); hideSoftInputView(); } else { layout_more.setVisibility(View.GONE); showSoftInputView(); } }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.edit_user_comment: // 点击文本输入框 mListView.setSelection(mListView.getCount() - 1); if (layout_more.getVisibility() == View.VISIBLE) { layout_add.setVisibility(View.GONE); layout_emo.setVisibility(View.GONE); layout_more.setVisibility(View.GONE); } break; case R.id.btn_chat_emo: // 点击笑脸图标 if (layout_more.getVisibility() == View.GONE) { showEditState(true); } else { if (layout_add.getVisibility() == View.VISIBLE) { layout_add.setVisibility(View.GONE); layout_emo.setVisibility(View.VISIBLE); } else { layout_more.setVisibility(View.GONE); } } break; case R.id.btn_chat_add: // 添加按钮-显示图片、拍照、位置 if (layout_more.getVisibility() == View.GONE) { layout_more.setVisibility(View.VISIBLE); layout_add.setVisibility(View.VISIBLE); layout_emo.setVisibility(View.GONE); hideSoftInputView(); } else { if (layout_emo.getVisibility() == View.VISIBLE) { layout_emo.setVisibility(View.GONE); layout_add.setVisibility(View.VISIBLE); } else { layout_more.setVisibility(View.GONE); } } break; case R.id.btn_chat_voice: // 语音按钮 edit_user_comment.setVisibility(View.GONE); layout_more.setVisibility(View.GONE); btn_chat_voice.setVisibility(View.GONE); btn_chat_keyboard.setVisibility(View.VISIBLE); btn_speak.setVisibility(View.VISIBLE); hideSoftInputView(); break; case R.id.btn_chat_keyboard: // 键盘按钮,点击就弹出键盘并隐藏掉声音按钮 showEditState(false); break; case R.id.btn_chat_send: // 发送文本 final String msg = edit_user_comment.getText().toString(); if (msg.equals("")) { ShowToast("请输入发送消息!"); return; } boolean isNetConnected = NetStateUtils.isNetworkAvailable(this); if (!isNetConnected) { ShowToast(R.string.network_error); // return; } // 组装BmobMessage对象 BmobMsg message = BmobMsg.createTextSendMsg(this, targetId, msg); message.setExtra("Bmob"); // 默认发送完成,将数据保存到本地消息表和最近会话表中 manager.sendTextMessage(targetUser, message); // 刷新界面 refreshMessage(message); break; case R.id.tv_camera: // 拍照 selectImageFromCamera(); break; case R.id.tv_picture: // 图片 selectImageFromLocal(); break; case R.id.tv_location: // 位置 selectLocationFromMap(); break; default: break; } }