Commit 5bea651e authored by Andrey Pavlenko's avatar Andrey Pavlenko

Java samples updated to be compatible with both old (2.2+) and new (3.0+) Android versions

parent b6c2c61c
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="src" path="OpenCV_src"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>OpenCV_JavaAPI_Tests</name> <name>OpenCV_JavaAPI_Tests</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name> <name>org.eclipse.jdt.core.javabuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name> <name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature> <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
</natures> </natures>
<linkedResources> </projectDescription>
<link>
<name>OpenCV_src</name>
<type>2</type>
<locationURI>_android_OpenCV_8d28b05d/src</locationURI>
</link>
</linkedResources>
</projectDescription>
...@@ -10,6 +10,12 @@ ...@@ -10,6 +10,12 @@
android:largeScreens="true" android:largeScreens="true"
android:anyDensity="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"> <application android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:name="Sample0Base" <activity android:name="Sample0Base"
android:label="@string/app_name" android:label="@string/app_name"
...@@ -22,10 +28,5 @@ ...@@ -22,10 +28,5 @@
</activity> </activity>
</application> </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> </manifest>
# Project target. # Project target.
target=android-8 target=android-11
...@@ -6,8 +6,10 @@ import java.util.List; ...@@ -6,8 +6,10 @@ import java.util.List;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.SurfaceTexture;
import android.hardware.Camera; import android.hardware.Camera;
import android.hardware.Camera.PreviewCallback; import android.hardware.Camera.PreviewCallback;
import android.os.Build;
import android.util.Log; import android.util.Log;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
...@@ -59,11 +61,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde ...@@ -59,11 +61,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
params.setPreviewSize(getFrameWidth(), getFrameHeight()); params.setPreviewSize(getFrameWidth(), getFrameHeight());
mCamera.setParameters(params); mCamera.setParameters(params);
try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mCamera.setPreviewDisplay(null); mCamera.setPreviewTexture( new SurfaceTexture(10) );
} catch (IOException e) { } else {
Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e); try {
} mCamera.setPreviewDisplay(null);
} catch (IOException e) {
Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e);
}
}
mCamera.startPreview(); mCamera.startPreview();
} }
} }
......
android.library.reference.1=../../../android/build android.library.reference.1=../../../android/build
# Project target. # Project target.
target=android-8 target=android-11
...@@ -6,8 +6,10 @@ import java.util.List; ...@@ -6,8 +6,10 @@ import java.util.List;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.SurfaceTexture;
import android.hardware.Camera; import android.hardware.Camera;
import android.hardware.Camera.PreviewCallback; import android.hardware.Camera.PreviewCallback;
import android.os.Build;
import android.util.Log; import android.util.Log;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
...@@ -59,11 +61,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde ...@@ -59,11 +61,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
params.setPreviewSize(getFrameWidth(), getFrameHeight()); params.setPreviewSize(getFrameWidth(), getFrameHeight());
mCamera.setParameters(params); mCamera.setParameters(params);
try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mCamera.setPreviewDisplay(null); mCamera.setPreviewTexture( new SurfaceTexture(10) );
} catch (IOException e) { } else {
Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e); try {
} mCamera.setPreviewDisplay(null);
} catch (IOException e) {
Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e);
}
}
mCamera.startPreview(); mCamera.startPreview();
} }
} }
......
# Project target. # Project target.
target=android-8 target=android-11
...@@ -6,8 +6,10 @@ import java.util.List; ...@@ -6,8 +6,10 @@ import java.util.List;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.SurfaceTexture;
import android.hardware.Camera; import android.hardware.Camera;
import android.hardware.Camera.PreviewCallback; import android.hardware.Camera.PreviewCallback;
import android.os.Build;
import android.util.Log; import android.util.Log;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
...@@ -59,11 +61,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde ...@@ -59,11 +61,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
params.setPreviewSize(getFrameWidth(), getFrameHeight()); params.setPreviewSize(getFrameWidth(), getFrameHeight());
mCamera.setParameters(params); mCamera.setParameters(params);
try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mCamera.setPreviewDisplay(null); mCamera.setPreviewTexture( new SurfaceTexture(10) );
} catch (IOException e) { } else {
Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e); try {
} mCamera.setPreviewDisplay(null);
} catch (IOException e) {
Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e);
}
}
mCamera.startPreview(); mCamera.startPreview();
} }
} }
......
android.library.reference.1=../../../android/build android.library.reference.1=../../../android/build
# Project target. # Project target.
target=android-8 target=android-11
...@@ -6,8 +6,10 @@ import java.util.List; ...@@ -6,8 +6,10 @@ import java.util.List;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.SurfaceTexture;
import android.hardware.Camera; import android.hardware.Camera;
import android.hardware.Camera.PreviewCallback; import android.hardware.Camera.PreviewCallback;
import android.os.Build;
import android.util.Log; import android.util.Log;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
...@@ -59,11 +61,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde ...@@ -59,11 +61,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
params.setPreviewSize(getFrameWidth(), getFrameHeight()); params.setPreviewSize(getFrameWidth(), getFrameHeight());
mCamera.setParameters(params); mCamera.setParameters(params);
try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mCamera.setPreviewDisplay(null); mCamera.setPreviewTexture( new SurfaceTexture(10) );
} catch (IOException e) { } else {
Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e); try {
} mCamera.setPreviewDisplay(null);
} catch (IOException e) {
Log.e(TAG, "mCamera.setPreviewDisplay fails: " + e);
}
}
mCamera.startPreview(); mCamera.startPreview();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment