Пример #1
0
  @Override
  public int getItemViewType(int position) {
    try {
      /** 默认是失败类型 */
      RenderType type = RenderType.MESSAGE_TYPE_INVALID;

      Object obj = msgObjectList.get(position);
      if (obj instanceof Integer) {
        type = RenderType.MESSAGE_TYPE_TIME_TITLE;
      } else if (obj instanceof MessageEntity) {
        MessageEntity info = (MessageEntity) obj;
        boolean isMine = info.getFromId() == loginUser.getPeerId();
        switch (info.getDisplayType()) {
          case DBConstant.SHOW_AUDIO_TYPE:
            type =
                isMine ? RenderType.MESSAGE_TYPE_MINE_AUDIO : RenderType.MESSAGE_TYPE_OTHER_AUDIO;
            break;
          case DBConstant.SHOW_IMAGE_TYPE:
            ImageMessage imageMessage = (ImageMessage) info;
            if (CommonUtil.gifCheck(imageMessage.getUrl())) {
              type =
                  isMine
                      ? RenderType.MESSAGE_TYPE_MINE_GIF_IMAGE
                      : RenderType.MESSAGE_TYPE_OTHER_GIF_IMAGE;
            } else {
              type =
                  isMine ? RenderType.MESSAGE_TYPE_MINE_IMAGE : RenderType.MESSAGE_TYPE_OTHER_IMAGE;
            }

            break;
          case DBConstant.SHOW_ORIGIN_TEXT_TYPE:
            if (info.isGIfEmo()) {
              type = isMine ? RenderType.MESSAGE_TYPE_MINE_GIF : RenderType.MESSAGE_TYPE_OTHER_GIF;
            } else {
              type =
                  isMine ? RenderType.MESSAGE_TYPE_MINE_TETX : RenderType.MESSAGE_TYPE_OTHER_TEXT;
            }

            break;
          case DBConstant.SHOW_MIX_TEXT:
            //
            logger.e("混合的消息类型%s", obj);
          default:
            break;
        }
      }
      return type.ordinal();
    } catch (Exception e) {
      logger.e(e.getMessage());
      return RenderType.MESSAGE_TYPE_INVALID.ordinal();
    }
  }
Пример #2
0
  // 主要是录制语音的
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    int id = v.getId();
    scrollToBottomListItem();
    if (id == R.id.record_voice_btn) {
      if (event.getAction() == MotionEvent.ACTION_DOWN) {

        if (AudioPlayerHandler.getInstance().isPlaying())
          AudioPlayerHandler.getInstance().stopPlayer();
        y1 = event.getY();
        recordAudioBtn.setBackgroundResource(R.drawable.tt_pannel_btn_voiceforward_pressed);
        recordAudioBtn.setText(
            MessageActivity.this.getResources().getString(R.string.release_to_send_voice));

        soundVolumeImg.setImageResource(R.drawable.tt_sound_volume_01);
        soundVolumeImg.setVisibility(View.VISIBLE);
        soundVolumeLayout.setBackgroundResource(R.drawable.tt_sound_volume_default_bk);
        soundVolumeDialog.show();
        audioSavePath = CommonUtil.getAudioSavePath(IMLoginManager.instance().getLoginId());

        // 这个callback很蛋疼,发送消息从MotionEvent.ACTION_UP 判断
        audioRecorderInstance = new AudioRecordHandler(audioSavePath);

        audioRecorderThread = new Thread(audioRecorderInstance);
        audioRecorderInstance.setRecording(true);
        logger.d("message_activity#audio#audio record thread starts");
        audioRecorderThread.start();
      } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        y2 = event.getY();
        if (y1 - y2 > 180) {
          soundVolumeImg.setVisibility(View.GONE);
          soundVolumeLayout.setBackgroundResource(R.drawable.tt_sound_volume_cancel_bk);
        } else {
          soundVolumeImg.setVisibility(View.VISIBLE);
          soundVolumeLayout.setBackgroundResource(R.drawable.tt_sound_volume_default_bk);
        }
      } else if (event.getAction() == MotionEvent.ACTION_UP) {
        y2 = event.getY();
        if (audioRecorderInstance.isRecording()) {
          audioRecorderInstance.setRecording(false);
        }
        if (soundVolumeDialog.isShowing()) {
          soundVolumeDialog.dismiss();
        }
        recordAudioBtn.setBackgroundResource(R.drawable.tt_pannel_btn_voiceforward_normal);
        recordAudioBtn.setText(
            MessageActivity.this.getResources().getString(R.string.tip_for_voice_forward));
        if (y1 - y2 <= 180) {
          if (audioRecorderInstance.getRecordTime() >= 0.5) {
            if (audioRecorderInstance.getRecordTime() < SysConstant.MAX_SOUND_RECORD_TIME) {
              Message msg = uiHandler.obtainMessage();
              msg.what = HandlerConstant.HANDLER_RECORD_FINISHED;
              msg.obj = audioRecorderInstance.getRecordTime();
              uiHandler.sendMessage(msg);
            }
          } else {
            soundVolumeImg.setVisibility(View.GONE);
            soundVolumeLayout.setBackgroundResource(R.drawable.tt_sound_volume_short_tip_bk);
            soundVolumeDialog.show();
            Timer timer = new Timer();
            timer.schedule(
                new TimerTask() {
                  public void run() {
                    if (soundVolumeDialog.isShowing()) soundVolumeDialog.dismiss();
                    this.cancel();
                  }
                },
                700);
          }
        }
      }
    }
    return false;
  }