@Override
 public boolean onOptionsItemSelected(MenuItem item) {
   Log.i(TAG, "Menu Item selected " + item);
   if (item == mItemStartNewGame) {
     /* We need to start new game */
     mPuzzle15 = new PuzzleProcessor(Settings.getGridSize(this));
     mPuzzle15.prepareGameSize(mGameWidth, mGameHeight);
     mPuzzle15.prepareNewGame();
   } else if (item == mItemHideNumbers) {
     /* We need to enable or disable drawing of the tile numbers */
     mPuzzle15.toggleTileNumbers();
   } else if (item == mItemSettings) {
     final Intent i = new Intent(this, SettingsActivity.class);
     startActivity(i);
   }
   return true;
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    Log.d(TAG, "************************ Creating and seting view");
    mOpenCvCameraView = (CameraBridgeViewBase) new JavaCameraView(this, -1);
    setContentView(mOpenCvCameraView);
    mOpenCvCameraView.setCvCameraViewListener(this);
    mPuzzle15 = new PuzzleProcessor(Settings.getGridSize(this));
    mPuzzle15.prepareNewGame();
  }
  public boolean onTouch(View view, MotionEvent event) {
    int xpos, ypos;

    xpos = (view.getWidth() - mGameWidth) / 2;
    xpos = (int) event.getX() - xpos;

    ypos = (view.getHeight() - mGameHeight) / 2;
    ypos = (int) event.getY() - ypos;

    if (xpos >= 0 && xpos <= mGameWidth && ypos >= 0 && ypos <= mGameHeight) {
      /* click is inside the picture. Deliver this event to processor */
      mPuzzle15.deliverTouchEvent(xpos, ypos);
    }

    return false;
  }
 public Mat onCameraFrame(Mat inputFrame) {
   return mPuzzle15.puzzleFrame(inputFrame);
 }
 public void onCameraViewStarted(int width, int height) {
   mGameWidth = width;
   mGameHeight = height;
   mPuzzle15.prepareGameSize(mGameWidth, mGameHeight);
 }