Java samples updated to be compatible with both old (2.2+) and new (3.0+) Android...
authorAndrey Pavlenko <no@email>
Fri, 24 Feb 2012 08:43:11 +0000 (08:43 +0000)
committerAndrey Pavlenko <no@email>
Fri, 24 Feb 2012 08:43:11 +0000 (08:43 +0000)
modules/java/android_test/.classpath
modules/java/android_test/.project
samples/android/tutorial-0-androidcamera/AndroidManifest.xml
samples/android/tutorial-0-androidcamera/project.properties
samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/SampleViewBase.java
samples/android/tutorial-1-addopencv/project.properties
samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/SampleViewBase.java
samples/android/tutorial-3-native/project.properties
samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/SampleViewBase.java
samples/android/tutorial-4-mixed/project.properties
samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/SampleViewBase.java

index 90f44c9..b1dcdef 100644 (file)
@@ -4,7 +4,6 @@
        <classpathentry kind="src" path="gen"/>\r
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>\r
        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>\r
-       <classpathentry kind="src" path="OpenCV_src"/>\r
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>\r
        <classpathentry kind="output" path="bin/classes"/>\r
 </classpath>\r
index e47735c..67148f8 100644 (file)
@@ -1,40 +1,33 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-       <name>OpenCV_JavaAPI_Tests</name>
-       <comment></comment>
-       <projects>
-       </projects>
-       <buildSpec>
-               <buildCommand>
-                       <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-               <buildCommand>
-                       <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-               <buildCommand>
-                       <name>org.eclipse.jdt.core.javabuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-               <buildCommand>
-                       <name>com.android.ide.eclipse.adt.ApkBuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-       </buildSpec>
-       <natures>
-               <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
-               <nature>org.eclipse.jdt.core.javanature</nature>
-       </natures>
-       <linkedResources>
-               <link>
-                       <name>OpenCV_src</name>
-                       <type>2</type>
-                       <locationURI>_android_OpenCV_8d28b05d/src</locationURI>
-               </link>
-       </linkedResources>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+       <name>OpenCV_JavaAPI_Tests</name>\r
+       <comment></comment>\r
+       <projects>\r
+       </projects>\r
+       <buildSpec>\r
+               <buildCommand>\r
+                       <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.jdt.core.javabuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>com.android.ide.eclipse.adt.ApkBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+       </buildSpec>\r
+       <natures>\r
+               <nature>com.android.ide.eclipse.adt.AndroidNature</nature>\r
+               <nature>org.eclipse.jdt.core.javanature</nature>\r
+       </natures>\r
+</projectDescription>\r
index ddfcd5a..51aa236 100644 (file)
                       android:largeScreens="true" 
                       android:anyDensity="true" />
 
+    <uses-sdk android:minSdkVersion="8"/>
+    
+    <uses-permission android:name="android.permission.CAMERA"/>
+    <uses-feature android:name="android.hardware.camera" />
+    <uses-feature android:name="android.hardware.camera.autofocus" />
+    
     <application android:label="@string/app_name" android:icon="@drawable/icon">
         <activity android:name="Sample0Base"
                   android:label="@string/app_name"
         </activity>
     </application>
     
-    <uses-sdk android:minSdkVersion="8" />
-
-    <uses-permission android:name="android.permission.CAMERA"/>
-    <uses-feature android:name="android.hardware.camera" />
-    <uses-feature android:name="android.hardware.camera.autofocus" />
 
 </manifest> 
index 05800ba..aab549a 100644 (file)
@@ -6,8 +6,10 @@ import java.util.List;
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
+import android.graphics.SurfaceTexture;
 import android.hardware.Camera;
 import android.hardware.Camera.PreviewCallback;
+import android.os.Build;
 import android.util.Log;
 import android.view.SurfaceHolder;
 import android.view.SurfaceView;
@@ -59,11 +61,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
 
             params.setPreviewSize(getFrameWidth(), getFrameHeight());
             mCamera.setParameters(params);
-            try {
-                               mCamera.setPreviewDisplay(null);
-                       } catch (IOException e) {
-                               Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e);
-                       }
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+               mCamera.setPreviewTexture( new SurfaceTexture(10) );
+            } else {
+                   try {
+                                       mCamera.setPreviewDisplay(null);
+                               } catch (IOException e) {
+                                       Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e);
+                               }
+            }
             mCamera.startPreview();
         }
     }
index fb3ea1f..25192ad 100644 (file)
@@ -1,3 +1,3 @@
 android.library.reference.1=../../../android/build
 # Project target.
-target=android-8
+target=android-11
index 45f39d0..8e53383 100644 (file)
@@ -6,8 +6,10 @@ import java.util.List;
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
+import android.graphics.SurfaceTexture;
 import android.hardware.Camera;
 import android.hardware.Camera.PreviewCallback;
+import android.os.Build;
 import android.util.Log;
 import android.view.SurfaceHolder;
 import android.view.SurfaceView;
@@ -59,11 +61,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
 
             params.setPreviewSize(getFrameWidth(), getFrameHeight());
             mCamera.setParameters(params);
-            try {
-                               mCamera.setPreviewDisplay(null);
-                       } catch (IOException e) {
-                               Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e);
-                       }
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+               mCamera.setPreviewTexture( new SurfaceTexture(10) );
+            } else {
+                   try {
+                                       mCamera.setPreviewDisplay(null);
+                               } catch (IOException e) {
+                                       Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e);
+                               }
+            }
             mCamera.startPreview();
         }
     }
index 83af4ca..81e192a 100644 (file)
@@ -6,8 +6,10 @@ import java.util.List;
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
+import android.graphics.SurfaceTexture;
 import android.hardware.Camera;
 import android.hardware.Camera.PreviewCallback;
+import android.os.Build;
 import android.util.Log;
 import android.view.SurfaceHolder;
 import android.view.SurfaceView;
@@ -59,11 +61,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
 
             params.setPreviewSize(getFrameWidth(), getFrameHeight());
             mCamera.setParameters(params);
-            try {
-                               mCamera.setPreviewDisplay(null);
-                       } catch (IOException e) {
-                               Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e);
-                       }
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+               mCamera.setPreviewTexture( new SurfaceTexture(10) );
+            } else {
+                   try {
+                                       mCamera.setPreviewDisplay(null);
+                               } catch (IOException e) {
+                                       Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e);
+                               }
+            }
             mCamera.startPreview();
         }
     }
index fb3ea1f..25192ad 100644 (file)
@@ -1,3 +1,3 @@
 android.library.reference.1=../../../android/build
 # Project target.
-target=android-8
+target=android-11
index a0d474c..634ef25 100644 (file)
@@ -6,8 +6,10 @@ import java.util.List;
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
+import android.graphics.SurfaceTexture;
 import android.hardware.Camera;
 import android.hardware.Camera.PreviewCallback;
+import android.os.Build;
 import android.util.Log;
 import android.view.SurfaceHolder;
 import android.view.SurfaceView;
@@ -59,11 +61,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
 
             params.setPreviewSize(getFrameWidth(), getFrameHeight());
             mCamera.setParameters(params);
-            try {
-                               mCamera.setPreviewDisplay(null);
-                       } catch (IOException e) {
-                               Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e);
-                       }
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+               mCamera.setPreviewTexture( new SurfaceTexture(10) );
+            } else {
+                   try {
+                                       mCamera.setPreviewDisplay(null);
+                               } catch (IOException e) {
+                                       Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e);
+                               }
+            }
             mCamera.startPreview();
         }
     }