}
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.findViewById(R.id.imageVolume);
textHint = (TextView) dialog.findViewById(R.id.textHint);
dialog.show();
}
public void stateRecording() {
if (dialog != null && dialog.isShowing()) {
imageRecord.setVisibility(View.VISIBLE);
imageVolume.setVisibility(View.VISIBLE);
textHint.setVisibility(View.VISIBLE);
imageRecord.setImageResource(R.drawable.icon_dialog_recording);
textHint.setText(“手指上滑,取消发送”);
}
}
public void stateWantCancel() {
if (dialog != null && dialog.isShowing()) {
imageRecord.setVisibility(View.VISIBLE);
imageRecord.setImageResource(R.drawable.icon_dialog_cancel);
imageVolume.setVisibility(V