OnResume/OnPause handlers added to start/stop camera.
OpenCV initialization moved to onResume event to support package installation waiting.
This commit is contained in:
parent
cc3430dbcc
commit
09901fae2b
@ -26,8 +26,8 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener,
|
||||
private int mGameWidth;
|
||||
private int mGameHeight;
|
||||
|
||||
|
||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
||||
|
||||
@Override
|
||||
public void onManagerConnected(int status) {
|
||||
switch (status) {
|
||||
@ -35,8 +35,6 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener,
|
||||
{
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
|
||||
mPuzzle15 = new Puzzle15Processor();
|
||||
mPuzzle15.prepareNewGame();
|
||||
/* Now enable camera view to start receiving frames */
|
||||
mOpenCvCameraView.setOnTouchListener(Puzzle15Activity.this);
|
||||
mOpenCvCameraView.enableView();
|
||||
@ -49,9 +47,6 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -61,6 +56,21 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener,
|
||||
|
||||
mOpenCvCameraView = (OpenCvNativeCameraView) findViewById(R.id.puzzle_activity_surface_view);
|
||||
mOpenCvCameraView.setCvCameraViewListener(this);
|
||||
mPuzzle15 = new Puzzle15Processor();
|
||||
mPuzzle15.prepareNewGame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
mOpenCvCameraView.disableView();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mLoaderCallback);
|
||||
}
|
||||
|
||||
@ -88,7 +98,6 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener,
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCameraViewStarted(int width, int height) {
|
||||
mGameWidth = width;
|
||||
@ -120,8 +129,6 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener,
|
||||
mPuzzle15.deliverTouchEvent(xpos, ypos);
|
||||
}
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ public class Puzzle15Processor {
|
||||
private int[] mTextWidths;
|
||||
private int[] mTextHeights;
|
||||
|
||||
private Mat mRgba;
|
||||
private Mat mRgba15;
|
||||
|
||||
private Mat[] mCells;
|
||||
@ -38,14 +37,9 @@ public class Puzzle15Processor {
|
||||
|
||||
mIndexes = new int [GRID_AREA];
|
||||
|
||||
for (int i = 0; i < GRID_AREA; i++) {
|
||||
Size s = Core.getTextSize(Integer.toString(i + 1), 3/* CV_FONT_HERSHEY_COMPLEX */, 1, 2, null);
|
||||
mTextHeights[i] = (int) s.height;
|
||||
mTextWidths[i] = (int) s.width;
|
||||
|
||||
for (int i = 0; i < GRID_AREA; i++)
|
||||
mIndexes[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* this method is intended to make processor prepared for a new game */
|
||||
public synchronized void prepareNewGame() {
|
||||
@ -67,14 +61,16 @@ public class Puzzle15Processor {
|
||||
for (int i = 0; i < GRID_SIZE; i++) {
|
||||
for (int j = 0; j < GRID_SIZE; j++) {
|
||||
int k = i * GRID_SIZE + j;
|
||||
// mCells[k] = mRgba.submat(i * height / GRID_SIZE, (i + 1) * height / GRID_SIZE, j * width / GRID_SIZE, (j + 1) * width / GRID_SIZE);
|
||||
mCells15[k] = mRgba15.submat(i * height / GRID_SIZE, (i + 1) * height / GRID_SIZE, j * width / GRID_SIZE, (j + 1) * width / GRID_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < GRID_AREA; i++) {
|
||||
Size s = Core.getTextSize(Integer.toString(i + 1), 3/* CV_FONT_HERSHEY_COMPLEX */, 1, 2, null);
|
||||
mTextHeights[i] = (int) s.height;
|
||||
mTextWidths[i] = (int) s.width;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* this method to be called from the outside. it processes the frame and shuffles
|
||||
* the tiles as specified by mIndexes array
|
||||
@ -83,12 +79,9 @@ public class Puzzle15Processor {
|
||||
int rows = inputPicture.rows();
|
||||
int cols = inputPicture.cols();
|
||||
|
||||
int type = inputPicture.type();
|
||||
|
||||
rows = rows - rows%4;
|
||||
cols = cols - cols%4;
|
||||
|
||||
|
||||
for (int i = 0; i < GRID_SIZE; i++) {
|
||||
for (int j = 0; j < GRID_SIZE; j++) {
|
||||
int k = i * GRID_SIZE + j;
|
||||
@ -118,7 +111,6 @@ public class Puzzle15Processor {
|
||||
return mRgba15;
|
||||
}
|
||||
|
||||
|
||||
public void toggleTileNumbers() {
|
||||
mShowTileNumbers = !mShowTileNumbers;
|
||||
}
|
||||
@ -172,7 +164,6 @@ public class Puzzle15Processor {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void shuffle(int[] array) {
|
||||
for (int i = array.length; i > 1; i--) {
|
||||
int temp = array[i - 1];
|
||||
@ -199,5 +190,4 @@ public class Puzzle15Processor {
|
||||
}
|
||||
return sum % 2 == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user