@Override
 public void onAttachedToWindow() {
   super.onAttachedToWindow();
   if (mGesture != null) {
     final GestureOverlayView overlay = (GestureOverlayView) findViewById(R.id.gestures_overlay);
     overlay.post(
         new Runnable() {
           @Override
           public void run() {
             overlay.setGesture(mGesture);
             mDoneButton.setEnabled(true);
           }
         });
   }
 }
  @Override
  protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);

    mGesture = savedInstanceState.getParcelable("gesture");
    if (mGesture != null) {
      final GestureOverlayView overlay = (GestureOverlayView) findViewById(R.id.gestures_overlay);
      overlay.post(
          new Runnable() {
            public void run() {
              overlay.setGesture(mGesture);
            }
          });

      mDoneButton.setEnabled(true);
    }
  }