From 82c61eba4917a5aa00d99e91795d6370e2e031ea Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Wed, 10 Apr 2013 13:38:59 +0400 Subject: [PATCH] Feature #2893 Create Java sample without layout.xml implemented. --- .../15-puzzle/res/layout/activity_puzzle15.xml | 11 ----------- .../15-puzzle/res/menu/activity_puzzle15.xml | 6 ------ .../samples/puzzle15/Puzzle15Activity.java | 18 ++++++++++++------ 3 files changed, 12 insertions(+), 23 deletions(-) delete mode 100644 samples/android/15-puzzle/res/layout/activity_puzzle15.xml delete mode 100644 samples/android/15-puzzle/res/menu/activity_puzzle15.xml diff --git a/samples/android/15-puzzle/res/layout/activity_puzzle15.xml b/samples/android/15-puzzle/res/layout/activity_puzzle15.xml deleted file mode 100644 index 3257ed801..000000000 --- a/samples/android/15-puzzle/res/layout/activity_puzzle15.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - diff --git a/samples/android/15-puzzle/res/menu/activity_puzzle15.xml b/samples/android/15-puzzle/res/menu/activity_puzzle15.xml deleted file mode 100644 index 7810d8196..000000000 --- a/samples/android/15-puzzle/res/menu/activity_puzzle15.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - diff --git a/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/Puzzle15Activity.java b/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/Puzzle15Activity.java index 466400d87..ebd34fc7e 100644 --- a/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/Puzzle15Activity.java +++ b/samples/android/15-puzzle/src/org/opencv/samples/puzzle15/Puzzle15Activity.java @@ -6,6 +6,7 @@ import org.opencv.android.OpenCVLoader; import org.opencv.core.Mat; import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener; +import org.opencv.android.JavaCameraView; import android.os.Bundle; import android.app.Activity; @@ -22,6 +23,9 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener, private CameraBridgeViewBase mOpenCvCameraView; private Puzzle15Processor mPuzzle15; + private MenuItem mItemHideNumbers; + private MenuItem mItemStartNewGame; + private int mGameWidth; private int mGameHeight; @@ -52,9 +56,9 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener, super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - setContentView(R.layout.activity_puzzle15); - - mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.puzzle_activity_surface_view); + Log.d(TAG, "Creating and seting view"); + mOpenCvCameraView = (CameraBridgeViewBase) new JavaCameraView(this, -1); + setContentView(mOpenCvCameraView); mOpenCvCameraView.setCvCameraViewListener(this); mPuzzle15 = new Puzzle15Processor(); mPuzzle15.prepareNewGame(); @@ -83,17 +87,19 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener, @Override public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.activity_puzzle15, menu); + Log.i(TAG, "called onCreateOptionsMenu"); + mItemHideNumbers = menu.add("Show/hide tile numbers"); + mItemStartNewGame = menu.add("Start new game"); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { Log.i(TAG, "Menu Item selected " + item); - if (item.getItemId() == R.id.menu_start_new_game) { + if (item == mItemStartNewGame) { /* We need to start new game */ mPuzzle15.prepareNewGame(); - } else if (item.getItemId() == R.id.menu_toggle_tile_numbers) { + } else if (item == mItemHideNumbers) { /* We need to enable or disable drawing of the tile numbers */ mPuzzle15.toggleTileNumbers(); }