fix for #1724: making Java samples compatible with Android 3.1+ targets

This commit is contained in:
Andrey Pavlenko 2012-03-28 15:32:01 +00:00
parent cff117c08b
commit 74749fccbf
4 changed files with 48 additions and 36 deletions

View File

@ -39,6 +39,13 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
return mFrameHeight;
}
public void setPreview() throws IOException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
mCamera.setPreviewTexture( new SurfaceTexture(10) );
else
mCamera.setPreviewDisplay(null);
}
public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) {
Log.i(TAG, "surfaceCreated");
if (mCamera != null) {
@ -61,15 +68,11 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
params.setPreviewSize(getFrameWidth(), getFrameHeight());
mCamera.setParameters(params);
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);
}
}
try {
setPreview();
} catch (IOException e) {
Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e);
}
mCamera.startPreview();
}
}

View File

@ -39,6 +39,13 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
return mFrameHeight;
}
public void setPreview() throws IOException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
mCamera.setPreviewTexture( new SurfaceTexture(10) );
else
mCamera.setPreviewDisplay(null);
}
public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) {
Log.i(TAG, "surfaceCreated");
if (mCamera != null) {
@ -61,15 +68,11 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
params.setPreviewSize(getFrameWidth(), getFrameHeight());
mCamera.setParameters(params);
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);
}
}
try {
setPreview();
} catch (IOException e) {
Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e);
}
mCamera.startPreview();
}
}

View File

@ -39,6 +39,13 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
return mFrameHeight;
}
public void setPreview() throws IOException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
mCamera.setPreviewTexture( new SurfaceTexture(10) );
else
mCamera.setPreviewDisplay(null);
}
public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) {
Log.i(TAG, "surfaceCreated");
if (mCamera != null) {
@ -61,15 +68,11 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
params.setPreviewSize(getFrameWidth(), getFrameHeight());
mCamera.setParameters(params);
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);
}
}
try {
setPreview();
} catch (IOException e) {
Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e);
}
mCamera.startPreview();
}
}

View File

@ -39,6 +39,13 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
return mFrameHeight;
}
public void setPreview() throws IOException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
mCamera.setPreviewTexture( new SurfaceTexture(10) );
else
mCamera.setPreviewDisplay(null);
}
public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) {
Log.i(TAG, "surfaceCreated");
if (mCamera != null) {
@ -61,15 +68,11 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde
params.setPreviewSize(getFrameWidth(), getFrameHeight());
mCamera.setParameters(params);
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);
}
}
try {
setPreview();
} catch (IOException e) {
Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e);
}
mCamera.startPreview();
}
}