Android 仿微信语音聊天,正式加入字节跳动

该博客详细介绍了如何在Android中实现类似微信的语音聊天功能,包括自定义Dialog、VoiceListAdapter、MyAudioManager和MediaManager的实现。通过这些组件,可以完成录音、显示音量、控制录音状态等功能。
摘要由CSDN通过智能技术生成

/**

  • 恢复标志位

*/

private void resetState() {

isRecording = false;

isReady = false;

changeState(STATE_NORMAL);

mTime = 0;

}

private boolean wantCancel(int x, int y) {

if (x < 0 || x > getWidth()) {

return true;

}

// 零点在左下角?

if (y < -DISTANCE_CANCEL_Y || y > getHeight() + DISTANCE_CANCEL_Y) {

return true;

}

return false;

}

private void changeState(int state) {

if (currentState != state) {

currentState = state;

switch (state) {

case STATE_NORMAL:

setBackgroundResource(R.drawable.btn_recorder_normal);

setText(R.string.btn_recorder_normal);

break;

case STATE_RECORDING:

setBackgroundResource(R.drawable.btn_recorder_normal);

setText(R.string.btn_recorder_recording);

if (isRecording) {

dialogManager.stateRecording();

}

break;

case STATE_WANT_CANCEL:

setBackgroundResource(R.drawable.btn_recorder_normal);

setText(R.string.btn_recorder_want_cancel);

dialogManager.stateWantCancel();

break;

default:

break;

}

}

}

}

自定义Dialog

package com.zms.wechatrecorder.view;

import com.zms.wechatrecorder.R;

import android.app.Dialog;

import android.content.Context;

import android.view.LayoutInflater;

import android.view.View;

import android.widget.ImageView;

import android.widget.TextView;

public class AudioRecordDialog {

private Dialog dialog;

private ImageView imageRecord, imageVolume;

private TextView textHint;

private Context context;

public AudioRecordDialog(Context context) {

this.context = context;

}

public void showDialog() {

dialog = new Dialog(context, R.style.Theme_RecorderDialog);

LayoutInflater inflater = LayoutInflater.from(context);

View view = inflater.inflate(R.layout.dialog, null);

dialog.setContentView(view);

imageRecord = (ImageView) dialog.findViewById(R.id.imageRecord);

imageVolume = (ImageView) dialog.findViewByI

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值