@Override
 public void surfaceDestroyed(SurfaceHolder arg0) {
   boolean retry = true;
   mThread.setRunning(false);
   while (retry) {
     try {
       mThread.join();
       retry = false;
     } catch (InterruptedException e) {
       // do nothing but keep retry
     }
   }
 }
  @Override
  public boolean onTouchEvent(MotionEvent me) {
    synchronized (mThread.getSurfaceHolder()) {
      if (!mIsScratchable) {
        return true;
      }

      switch (me.getAction()) {
        case MotionEvent.ACTION_DOWN:
          path = new Path();
          path.moveTo(me.getX(), me.getY());
          startX = me.getX();
          startY = me.getY();
          mPathList.add(path);
          break;
        case MotionEvent.ACTION_MOVE:
          if (mScratchStart) {
            path.lineTo(me.getX(), me.getY());
          } else {
            if (isScratch(startX, me.getX(), startY, me.getY())) {
              mScratchStart = true;
              path.lineTo(me.getX(), me.getY());
            }
          }
          break;
        case MotionEvent.ACTION_UP:
          mScratchStart = false;
          break;
      }
      return true;
    }
  }
 @Override
 public void resetView() {
   synchronized (mThread.getSurfaceHolder()) {
     mPathList.clear();
   }
 }
 @Override
 public void surfaceCreated(SurfaceHolder arg0) {
   mThread = new WScratchViewThread(getHolder(), this);
   mThread.setRunning(true);
   mThread.start();
 }