Пример #1
0
 @Override
 public boolean onTouch(View v, MotionEvent event) {
   switch (event.getAction()) {
     case MotionEvent.ACTION_DOWN:
       if (!NetStateUtils.checkSdCard()) {
         ShowToast("发送语音需要sdcard支持!");
         return false;
       }
       try {
         v.setPressed(true);
         layout_record.setVisibility(View.VISIBLE);
         tv_voice_tips.setText(getString(R.string.chat_voice_cancel_tips));
         // 开始录音
         recordManager.startRecording(targetId);
       } catch (Exception e) {
       }
       return true;
     case MotionEvent.ACTION_MOVE:
       {
         if (event.getY() < 0) {
           tv_voice_tips.setText(getString(R.string.chat_voice_cancel_tips));
           tv_voice_tips.setTextColor(Color.RED);
         } else {
           tv_voice_tips.setText(getString(R.string.chat_voice_up_tips));
           tv_voice_tips.setTextColor(Color.WHITE);
         }
         return true;
       }
     case MotionEvent.ACTION_UP:
       v.setPressed(false);
       layout_record.setVisibility(View.INVISIBLE);
       try {
         if (event.getY() < 0) { // 放弃录音
           recordManager.cancelRecording();
           BmobLog.i("voice", "放弃发送语音");
         } else {
           int recordTime = recordManager.stopRecording();
           if (recordTime > 1) {
             // 发送语音文件
             BmobLog.i("voice", "发送语音");
             sendVoiceMessage(recordManager.getRecordFilePath(targetId), recordTime);
           } else { // 录音时间过短,则提示录音过短的提示
             layout_record.setVisibility(View.GONE);
             showShortToast().show();
           }
         }
       } catch (Exception e) {
       }
       return true;
     default:
       return false;
   }
 }
Пример #2
0
  @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;
    }
  }