diff --git a/modules/java/generator/src/java/android+CameraBridgeViewBase.java b/modules/java/generator/src/java/android+CameraBridgeViewBase.java index 444e4fa7af..1231eeb359 100644 --- a/modules/java/generator/src/java/android+CameraBridgeViewBase.java +++ b/modules/java/generator/src/java/android+CameraBridgeViewBase.java @@ -85,6 +85,7 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac private Object mSyncObject = new Object(); public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) { + Log.d(TAG, "call surfaceChanged event"); synchronized(mSyncObject) { if (!mSurfaceExist) { mSurfaceExist = true; @@ -163,7 +164,7 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac private void checkCurrentState() { int targetState; - if (mEnabled && mSurfaceExist) { + if (mEnabled && mSurfaceExist && getVisibility() == VISIBLE) { targetState = STARTED; } else { targetState = STOPPED; 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 cf2e53c3cb..c6cb1a1b2f 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 @@ -4,8 +4,8 @@ import org.opencv.android.BaseLoaderCallback; import org.opencv.android.LoaderCallbackInterface; 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; @@ -18,13 +18,13 @@ import android.view.View; public class Puzzle15Activity extends Activity implements CvCameraViewListener, View.OnTouchListener { - private static final String TAG = "Sample::Puzzle15::Activity"; + private static final String TAG = "Sample::Puzzle15::Activity"; - private JavaCameraView mOpenCvCameraView; - private Puzzle15Processor mPuzzle15; + private CameraBridgeViewBase mOpenCvCameraView; + private Puzzle15Processor mPuzzle15; - private int mGameWidth; - private int mGameHeight; + private int mGameWidth; + private int mGameHeight; private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @@ -54,7 +54,7 @@ public class Puzzle15Activity extends Activity implements CvCameraViewListener, setContentView(R.layout.activity_puzzle15); - mOpenCvCameraView = (JavaCameraView) findViewById(R.id.puzzle_activity_surface_view); + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.puzzle_activity_surface_view); mOpenCvCameraView.setCvCameraViewListener(this); mPuzzle15 = new Puzzle15Processor(); mPuzzle15.prepareNewGame(); diff --git a/samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetectionActivity.java b/samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetectionActivity.java index 1555aca6c5..be736b9380 100644 --- a/samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetectionActivity.java +++ b/samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetectionActivity.java @@ -12,8 +12,8 @@ import org.opencv.core.MatOfPoint; import org.opencv.core.Rect; import org.opencv.core.Scalar; import org.opencv.core.Size; +import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener; -import org.opencv.android.JavaCameraView; import org.opencv.imgproc.Imgproc; import android.app.Activity; @@ -26,9 +26,9 @@ import android.view.WindowManager; import android.view.View.OnTouchListener; public class ColorBlobDetectionActivity extends Activity implements OnTouchListener, CvCameraViewListener { - private static final String TAG = "OCVSample::Activity"; + private static final String TAG = "OCVSample::Activity"; - private boolean mIsColorSelected = false; + private boolean mIsColorSelected = false; private Mat mRgba; private Scalar mBlobColorRgba; private Scalar mBlobColorHsv; @@ -37,7 +37,7 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe private Size SPECTRUM_SIZE; private Scalar CONTOUR_COLOR; - private JavaCameraView mOpenCvCameraView; + private CameraBridgeViewBase mOpenCvCameraView; private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override @@ -71,7 +71,7 @@ public class ColorBlobDetectionActivity extends Activity implements OnTouchListe setContentView(R.layout.color_blob_detection_surface_view); - mOpenCvCameraView = (JavaCameraView)findViewById(R.id.color_blob_detection_activity_surface_view); + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.color_blob_detection_activity_surface_view); mOpenCvCameraView.setCvCameraViewListener(this); } diff --git a/samples/android/face-detection/src/org/opencv/samples/fd/FdActivity.java b/samples/android/face-detection/src/org/opencv/samples/fd/FdActivity.java index e68989c686..0bb4978a09 100644 --- a/samples/android/face-detection/src/org/opencv/samples/fd/FdActivity.java +++ b/samples/android/face-detection/src/org/opencv/samples/fd/FdActivity.java @@ -14,7 +14,7 @@ import org.opencv.core.MatOfRect; import org.opencv.core.Rect; import org.opencv.core.Scalar; import org.opencv.core.Size; -import org.opencv.android.JavaCameraView; +import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener; import org.opencv.imgproc.Imgproc; import org.opencv.objdetect.CascadeClassifier; @@ -53,7 +53,7 @@ public class FdActivity extends Activity implements CvCameraViewListener { private float mRelativeFaceSize = 0; private int mAbsoluteFaceSize = 0; - private JavaCameraView mOpenCvCameraView; + private CameraBridgeViewBase mOpenCvCameraView; private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override @@ -125,7 +125,7 @@ public class FdActivity extends Activity implements CvCameraViewListener { setContentView(R.layout.face_detect_surface_view); - mOpenCvCameraView = (JavaCameraView)findViewById(R.id.fd_activity_surface_view); + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.fd_activity_surface_view); mOpenCvCameraView.setCvCameraViewListener(this); } diff --git a/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java b/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java index b26145c15a..569de5dc70 100644 --- a/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java +++ b/samples/android/image-manipulations/src/org/opencv/samples/imagemanipulations/ImageManipulationsActivity.java @@ -13,7 +13,7 @@ import org.opencv.core.MatOfInt; import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.core.Size; -import org.opencv.android.JavaCameraView; +import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener; import org.opencv.imgproc.Imgproc; @@ -45,7 +45,7 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView private MenuItem mItemPreviewZoom; private MenuItem mItemPreviewPixelize; private MenuItem mItemPreviewPosterize; - private JavaCameraView mOpenCvCameraView; + private CameraBridgeViewBase mOpenCvCameraView; private Size mSize0; private Size mSizeRgba; @@ -106,7 +106,7 @@ public class ImageManipulationsActivity extends Activity implements CvCameraView setContentView(R.layout.image_manipulations_surface_view); - mOpenCvCameraView = (JavaCameraView)findViewById(R.id.image_manipulations_activity_surface_view); + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.image_manipulations_activity_surface_view); mOpenCvCameraView.setCvCameraViewListener(this); } diff --git a/samples/android/tutorial-1-addopencv/res/layout/tutorial1_surface_view.xml b/samples/android/tutorial-1-addopencv/res/layout/tutorial1_surface_view.xml index 52a73323ff..844fcab00f 100644 --- a/samples/android/tutorial-1-addopencv/res/layout/tutorial1_surface_view.xml +++ b/samples/android/tutorial-1-addopencv/res/layout/tutorial1_surface_view.xml @@ -6,6 +6,13 @@ + android:visibility="gone" + android:id="@+id/tutorial1_activity_java_surface_view" /> + + diff --git a/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1Java.java b/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1Java.java index 0af6f5f79c..beb368f963 100644 --- a/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1Java.java +++ b/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1Java.java @@ -4,19 +4,25 @@ import org.opencv.android.BaseLoaderCallback; import org.opencv.android.LoaderCallbackInterface; 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.app.Activity; import android.os.Bundle; import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.SurfaceView; import android.view.Window; import android.view.WindowManager; +import android.widget.Toast; public class Sample1Java extends Activity implements CvCameraViewListener { private static final String TAG = "OCVSample::Activity"; - private JavaCameraView mOpenCvCameraView; + private CameraBridgeViewBase mOpenCvCameraView; + private boolean mIsJavaCamera = true; + private MenuItem mItemSwitchCamera = null; private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override @@ -49,7 +55,13 @@ public class Sample1Java extends Activity implements CvCameraViewListener { setContentView(R.layout.tutorial1_surface_view); - mOpenCvCameraView = (JavaCameraView)findViewById(R.id.tutorial1_activity_surface_view); + if (mIsJavaCamera) + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_java_surface_view); + else + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_native_surface_view); + + mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE); + mOpenCvCameraView.setCvCameraViewListener(this); } @@ -72,6 +84,40 @@ public class Sample1Java extends Activity implements CvCameraViewListener { mOpenCvCameraView.disableView(); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + Log.i(TAG, "called onCreateOptionsMenu"); + mItemSwitchCamera = menu.add("Switch camera"); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + String toastMesage = new String(); + Log.i(TAG, "called onOptionsItemSelected; selected item: " + item); + + if (item == mItemSwitchCamera) { + mOpenCvCameraView.setVisibility(SurfaceView.GONE); + mIsJavaCamera = !mIsJavaCamera; + + if (mIsJavaCamera) { + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_java_surface_view); + toastMesage = "Java Camera"; + } else { + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_native_surface_view); + toastMesage = "Native Camera"; + } + + mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE); + mOpenCvCameraView.setCvCameraViewListener(this); + mOpenCvCameraView.enableView(); + Toast toast = Toast.makeText(this, toastMesage, Toast.LENGTH_LONG); + toast.show(); + } + + return true; + } + public void onCameraViewStarted(int width, int height) { } diff --git a/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2NativeCamera.java b/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2NativeCamera.java index ae6f43358d..8fbdeef8e3 100644 --- a/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2NativeCamera.java +++ b/samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2NativeCamera.java @@ -8,7 +8,7 @@ import org.opencv.core.CvType; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.Scalar; -import org.opencv.android.NativeCameraView; +import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener; import org.opencv.highgui.Highgui; import org.opencv.imgproc.Imgproc; @@ -22,20 +22,20 @@ import android.view.Window; import android.view.WindowManager; public class Sample2NativeCamera extends Activity implements CvCameraViewListener { - private static final String TAG = "OCVSample::Activity"; + private static final String TAG = "OCVSample::Activity"; - public static final int VIEW_MODE_RGBA = 0; - public static final int VIEW_MODE_GRAY = 1; - public static final int VIEW_MODE_CANNY = 2; + public static final int VIEW_MODE_RGBA = 0; + public static final int VIEW_MODE_GRAY = 1; + public static final int VIEW_MODE_CANNY = 2; private static int viewMode = VIEW_MODE_RGBA; - private MenuItem mItemPreviewRGBA; - private MenuItem mItemPreviewGray; - private MenuItem mItemPreviewCanny; - private Mat mRgba; - private Mat mIntermediateMat; + private MenuItem mItemPreviewRGBA; + private MenuItem mItemPreviewGray; + private MenuItem mItemPreviewCanny; + private Mat mRgba; + private Mat mIntermediateMat; - private NativeCameraView mOpenCvCameraView; + private CameraBridgeViewBase mOpenCvCameraView; private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override @@ -68,7 +68,7 @@ public class Sample2NativeCamera extends Activity implements CvCameraViewListene setContentView(R.layout.tutorial2_surface_view); - mOpenCvCameraView = (NativeCameraView)findViewById(R.id.tutorial2_activity_surface_view); + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial2_activity_surface_view); mOpenCvCameraView.setCvCameraViewListener(this); } diff --git a/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/Sample3Native.java b/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/Sample3Native.java index 498f0d3774..c216bea9a1 100644 --- a/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/Sample3Native.java +++ b/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/Sample3Native.java @@ -5,7 +5,7 @@ import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.CvType; import org.opencv.core.Mat; -import org.opencv.android.JavaCameraView; +import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener; import org.opencv.imgproc.Imgproc; @@ -20,7 +20,7 @@ public class Sample3Native extends Activity implements CvCameraViewListener { private Mat mRgba; private Mat mGrayMat; - private JavaCameraView mOpenCvCameraView; + private CameraBridgeViewBase mOpenCvCameraView; private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override @@ -57,7 +57,7 @@ public class Sample3Native extends Activity implements CvCameraViewListener { setContentView(R.layout.tutorial3_surface_view); - mOpenCvCameraView = (JavaCameraView)findViewById(R.id.tutorial4_activity_surface_view); + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial4_activity_surface_view); mOpenCvCameraView.setCvCameraViewListener(this); } diff --git a/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4Mixed.java b/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4Mixed.java index fa61dc9601..c9e745b65c 100644 --- a/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4Mixed.java +++ b/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4Mixed.java @@ -5,7 +5,7 @@ import org.opencv.android.LoaderCallbackInterface; import org.opencv.android.OpenCVLoader; import org.opencv.core.CvType; import org.opencv.core.Mat; -import org.opencv.android.JavaCameraView; +import org.opencv.android.CameraBridgeViewBase; import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener; import org.opencv.highgui.Highgui; import org.opencv.imgproc.Imgproc; @@ -19,7 +19,7 @@ import android.view.Window; import android.view.WindowManager; public class Sample4Mixed extends Activity implements CvCameraViewListener { - private static final String TAG = "OCVSample::Activity"; + private static final String TAG = "OCVSample::Activity"; private static final int VIEW_MODE_RGBA = 0; private static final int VIEW_MODE_GRAY = 1; @@ -36,7 +36,7 @@ public class Sample4Mixed extends Activity implements CvCameraViewListener { private MenuItem mItemPreviewCanny; private MenuItem mItemPreviewFeatures; - private JavaCameraView mOpenCvCameraView; + private CameraBridgeViewBase mOpenCvCameraView; private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override @@ -73,7 +73,7 @@ public class Sample4Mixed extends Activity implements CvCameraViewListener { setContentView(R.layout.tutorial4_surface_view); - mOpenCvCameraView = (JavaCameraView)findViewById(R.id.tutorial4_activity_surface_view); + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial4_activity_surface_view); mOpenCvCameraView.setCvCameraViewListener(this); }