@Override
 public void surfaceCreated(SurfaceHolder holder) {
   synchronized (thread) {
     thread.setRunning(true);
     if (!thread.isAlive()) {
       thread.start();
     }
     thread.notify();
   }
 }
 @Override
 public void surfaceDestroyed(SurfaceHolder holder) {
   synchronized (thread) {
     thread.setRunning(false);
     try {
       thread.wait();
     } catch (InterruptedException e) {
     }
   }
 }
 public void doTouch(MotionEvent event) {
   if (event.getAction() == MotionEvent.ACTION_DOWN) {
     thread.doTouch(event.getX() / getWidth());
   }
 }