Clean up RetroActivityFuture a little. Remove a pointless if statement check (the only Android versions this launches on are the ones that satisfy this condition).

Also misc other cleanup.
This commit is contained in:
Lioncash 2013-12-09 02:29:56 -05:00
parent f57210cb41
commit 6bdaadb82e
1 changed files with 29 additions and 36 deletions

View File

@ -9,18 +9,20 @@ import android.annotation.SuppressLint;
import android.app.NativeActivity; import android.app.NativeActivity;
import android.content.Intent; import android.content.Intent;
import android.graphics.SurfaceTexture; import android.graphics.SurfaceTexture;
import android.graphics.SurfaceTexture.OnFrameAvailableListener;
import android.hardware.Camera; import android.hardware.Camera;
import android.os.Build; import android.os.Build;
import android.util.Log; import android.util.Log;
//For Android 3.0 and up //For Android 3.0 and up
@SuppressLint("NewApi")
public final class RetroActivityFuture extends NativeActivity public final class RetroActivityFuture extends NativeActivity
{ {
private Camera mCamera; private Camera mCamera;
private long lastTimestamp = 0; private long lastTimestamp = 0;
private SurfaceTexture texture; private SurfaceTexture texture;
private Boolean updateSurface = true; private boolean updateSurface = true;
private Intent pendingIntent = null; private Intent pendingIntent = null;
public void onCameraStart() public void onCameraStart()
@ -38,12 +40,11 @@ public final class RetroActivityFuture extends NativeActivity
mCamera = Camera.open(); mCamera = Camera.open();
} }
@SuppressLint("NewApi")
public boolean onCameraPoll() public boolean onCameraPoll()
{ {
if (texture == null) if (texture == null)
{ {
Log.i("RetroActivity", "no texture"); Log.i("RetroActivity", "No texture");
return true; return true;
} }
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@ -72,36 +73,28 @@ public final class RetroActivityFuture extends NativeActivity
mCamera.release(); mCamera.release();
} }
@SuppressLint("NewApi")
public void onCameraTextureInit(int gl_texid) public void onCameraTextureInit(int gl_texid)
{ {
texture = new SurfaceTexture(gl_texid); texture = new SurfaceTexture(gl_texid);
texture.setOnFrameAvailableListener(onCameraFrameAvailableListener); texture.setOnFrameAvailableListener(onCameraFrameAvailableListener);
} }
@SuppressLint("NewApi") private final OnFrameAvailableListener onCameraFrameAvailableListener = new OnFrameAvailableListener()
private SurfaceTexture.OnFrameAvailableListener onCameraFrameAvailableListener = {
new SurfaceTexture.OnFrameAvailableListener() {
@Override @Override
public void onFrameAvailable(SurfaceTexture surfaceTexture) { public void onFrameAvailable(SurfaceTexture surfaceTexture)
{
updateSurface = true; updateSurface = true;
} }
}; };
@SuppressLint("NewApi")
public void onCameraSetTexture(int gl_texid) throws IOException public void onCameraSetTexture(int gl_texid) throws IOException
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
{ {
if (texture == null) if (texture == null)
onCameraTextureInit(gl_texid); onCameraTextureInit(gl_texid);
mCamera.setPreviewTexture(texture); mCamera.setPreviewTexture(texture);
} }
else
{
mCamera.setPreviewDisplay(null);
}
}
@Override @Override
public void onDestroy() public void onDestroy()