/**
- 恢复标志位
*/
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