我的代码有问题。我想在 Action_UP 3 秒后清除画布(通过重置功能)(这里我使用了计时器)。在此期间,如果事件 Action_Down OR Action_Move 我必须取消 Timer-Task。
(Action_down & Action_move 应该取消 Action_up 中的计时器)我必须做什么??请帮我。
谢谢
public boolean onTouch(View view, MotionEvent event) {
// Check event type
switch (event.getAction()) {
// Finger down
case MotionEvent.ACTION_DOWN:
paint.setColor(Color.BLACK);
paint.setStrokeWidth(7f);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setAntiAlias(true);
// Get current position
pX = event.getX();
pY = event.getY();
// Set beginning of path to (posX,posY)
path.moveTo(pX, pY);
if (start)
{
mytimer.cancel();
start = false;
}
break;
// Finger moves
case MotionEvent.ACTION_MOVE:
mX = event.getX();
mY = event.getY();
// Set position of end of path
path.lineTo(mX, mY);
// Draw path
bitmapCanvas.drawPath(path, paint);
// Invalidate canvas (redraw the view)
if (start)
{
mytimer.cancel();
start = false;
}
invalidate();
break;
// Finger up
case MotionEvent.ACTION_UP:
//bitmap = getResizedBitmap(bitmap, 16, 16);
//here We have to start our neocogniton :)
mX = event.getX();
mY = event.getY();
if (mY == pY && mX == pX){
bitmapCanvas.drawPoint(pX, pY, paint);
invalidate();
}
path.reset();
mytimer.schedule(new TimerTask() {
@Override
public void run() {reset();}}, 3000);
break;
}
return true;
}
重置()
public void reset(){
bitmapCanvas.drawColor(Color.WHITE);
start = true;
}