private static final int TICK_WHAT =2;
private static final int TIME_TO_SEND =10;
private ArrayListlistScores =new ArrayList();
private boolean isPaused;
private long longmillTime;
private ReportMoreTimeAdaptertimeAdapter;
private boolean isStop =true;//暂停
private int recordNum =1;//已记录成绩数
private int num =5;//记录总次数
private int index;
/**
* 递归发送消息
*/
private HandlertimeHandler =new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case TICK_WHAT:
if (!isPaused) {
addTimeUsed();
updateClockUI();
}
if (!isStop) {
timeHandler.sendEmptyMessageDelayed(TICK_WHAT,TIME_TO_SEND);
}
break;
default:
break;
}
}
};
@Override
public void onClick(View v) {
if (v ==textReset) {
String resetS =textReset.getText().toString().trim();
if (StringUtils.equals(resetS,"计次")) {
if (recordNum
recordNum++;
listScores.add(longmillTime);
timeAdapter.setmDatas(listScores);
}else {
recordNum =1;
listScores.add(longmillTime);
timeAdapter.setmDatas(listScores);
textReset.setText("复位");
textStart.setText("开始");
timeHandler.removeMessages(TICK_WHAT);
}
}else if (StringUtils.equals(resetS,"复位")) {
isStop =true;
textReset.setClickable(false);
listScores.clear();
timeAdapter.setmDatas(listScores);
longmillTime =0;
textTimeClock.setText("00:00:00");
}
}else if (v ==textStart) {
if (recordNum
if (isStop) {
textReset.setText("计次");
textStart.setText("停止");
textReset.setClickable(true);
startTime();
isStop =false;
}else {
textReset.setText("复位");
textStart.setText("开始");
isStop =true;
}
}
}
}
private void startTime() {
timeHandler.sendEmptyMessageDelayed(TICK_WHAT,TIME_TO_SEND);
}
/**
* 更新时间的显示
*/
private void updateClockUI() {
String time = getMin() +":" + getSec() +":" + getLongMill();
textTimeClock.setText(time);
}
/**
* 计时步长
*/
public void addTimeUsed() {
longmillTime +=10;
}
/**
* 得到分
*/
public String getMin() {
long min = (longmillTime) /60000;
return min <10 ?"0" + min : min +"";
}
/**
* 得到秒
*/
public String getSec() {
long sec = (longmillTime /1000) %60;
return sec <10 ?"0" + sec : sec +"";
}
/**
* 得到0.01秒
*/
public String getLongMill() {
long longmill = (longmillTime /10) %600 %100;
return longmill <10 ?"0" + longmill : longmill +"";
}
网友评论