点击Button后迅速抬起,Button上的文本不会还原
点击Button后迅速抬起,Button上的文本不会还原,会保持为“松开结束”。这是为什么呢?
相关代码片段:
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
int x = (int) event.getX();
int y = (int) event.getY();
switch (action) {
case MotionEvent.ACTION_DOWN:
setBackgroundResource(R.drawable.recorder_button_recording);
setText(R.string.button_recording);
dialogManager.initDialog();
break;
case MotionEvent.ACTION_MOVE:
if (currentState == STATE_RECORDING) {
if (wantToCancel(x, y)) {
changeToState(STATE_CANCEL);
}
} else if (currentState == STATE_CANCEL) {
if (!wantToCancel(x, y)) {
changeToState(STATE_RECORDING);
}
}
break;
case MotionEvent.ACTION_UP:
if(!isLongClicked){
reset();
return super.onTouchEvent(event);
}
if(timeLength < 500){
handler.sendEmptyMessage(MSG_DIALOG_TOOSHORT);
audioManager.cancel();
handler.sendEmptyMessageDelayed(MSG_DIALOG_DIMISS, 1500);
}
if (currentState == STATE_RECORDING) {
handler.sendEmptyMessage(MSG_DIALOG_DIMISS);
if(listener != null){
listener.onFinished(audioManager.getFilePath(), timeLength);
}
audioManager.release();
} else if (currentState == STATE_CANCEL) {
handler.sendEmptyMessage(MSG_DIALOG_DIMISS);
audioManager.cancel();
}
reset();
break;
}
return super.onTouchEvent(event);
}
private void reset() {
changeToState(STATE_NORMAL);
timeLength = 0;
isLongClicked = false;
}
private void changeToState(int state) {
if (currentState != state) {
switch (state) {
case STATE_NORMAL:
currentState = STATE_NORMAL;
setBackgroundResource(R.drawable.recorder_button_normal);
setText(R.string.button_normal);
break;
case STATE_RECORDING:
currentState = STATE_RECORDING;
setBackgroundResource(R.drawable.recorder_button_recording);
setText(R.string.button_recording);
dialogManager.showDialog(STATE_RECORDING);
break;
case STATE_CANCEL:
currentState = STATE_CANCEL;
setBackgroundResource(R.drawable.recorder_button_recording);
setText(R.string.button_cancel);
dialogManager.showDialog(STATE_CANCEL);
break;
}
}
}