@Override
    public void onVisibilityChanged(boolean visible) {
      if (visible) {
        painting.resumePainting();
      } else {

        painting.pausePainting();
      }
    }
 @Override
 public void onSurfaceDestroyed(SurfaceHolder holder) {
   super.onSurfaceDestroyed(holder);
   boolean retry = true;
   painting.stopPainting();
   while (retry) {
     try {
       painting.join();
       retry = false;
     } catch (InterruptedException e) {
     }
   }
 }
 @Override
 public void onTouchEvent(MotionEvent event) {
   super.onTouchEvent(event);
   painting.doTouchEvent(event);
 }
 @Override
 public void onSurfaceCreated(SurfaceHolder holder) {
   super.onSurfaceCreated(holder);
   painting.start();
 }
 @Override
 public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
   super.onSurfaceChanged(holder, format, width, height);
   painting.setSurfaceSize(width, height);
 }
    @Override
    public void onDestroy() {
      super.onDestroy();

      painting.stopPainting();
    }
 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
   painting.setRadius(Integer.parseInt(prefs.getString(PREFERENCE_RADIUS, "10")));
 }