3dphotoshoot

changeset 3:9df99687a2ff

the old camera API is horrible
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 15 May 2015 05:15:47 +0300
parents cf5964db7ff3
children 38377f54527a
files android/manifest.xml.in src/android/MainActivity.java
diffstat 2 files changed, 93 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/android/manifest.xml.in	Fri May 15 02:06:26 2015 +0300
     1.2 +++ b/android/manifest.xml.in	Fri May 15 05:15:47 2015 +0300
     1.3 @@ -4,7 +4,10 @@
     1.4  	android:versionCode="1"
     1.5  	android:versionName="1.0">
     1.6  
     1.7 -	<uses-sdk android:minSdkVersion="9"/>
     1.8 +	<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="21"/>
     1.9 +
    1.10 +	<uses-permission android:name="android.permission.CAMERA" />
    1.11 +	<uses-feature android:name="android.hardware.camera" />
    1.12  
    1.13  	<application android:label="$APPNAME" android:debuggable="true">
    1.14  			<!-- android:icon="@drawable/ic_launcher" -->
     2.1 --- a/src/android/MainActivity.java	Fri May 15 02:06:26 2015 +0300
     2.2 +++ b/src/android/MainActivity.java	Fri May 15 05:15:47 2015 +0300
     2.3 @@ -2,11 +2,99 @@
     2.4  
     2.5  import android.app.NativeActivity;
     2.6  import android.util.Log;
     2.7 +/*
     2.8 +import android.os.Bundle;
     2.9 +import android.content.Context;
    2.10 +import android.hardware.Camera;
    2.11 +import android.hardware.Camera.CameraInfo;
    2.12 +import android.hardware.camera2.*;
    2.13 +*/
    2.14  
    2.15  public class MainActivity extends NativeActivity {
    2.16 +	private static String tag = "photoshoot3d";
    2.17 +
    2.18  	public static int foo(String s, int n)
    2.19  	{
    2.20 -		Log.i("photoshoot3d", s + ": " + n);
    2.21 +		Log.i(tag, s + ": " + n);
    2.22  		return 42;
    2.23  	}
    2.24 +
    2.25 +	/*
    2.26 +	// old camera api (fallback)
    2.27 +	private Camera cam;
    2.28 +
    2.29 +	// camera2 api (sdk version >= 21)
    2.30 +	private CameraManager cman;
    2.31 +	private CameraDevice cam2;
    2.32 +	private CameraCaptureSession cam_session;
    2.33 +
    2.34 +	@Override
    2.35 +	protected void onCreate(Bundle state)
    2.36 +	{
    2.37 +		super.onCreate(state);
    2.38 +
    2.39 +		if(android.os.Build.VERSION.SDK_INT >= 21) {
    2.40 +			Log.i(tag, "Using the new camera API");
    2.41 +
    2.42 +			cman = (CameraManager)getSystemService(Context.CAMERA_SERVICE);
    2.43 +
    2.44 +			try {
    2.45 +				String [] clist = cman.getCameraIdList();
    2.46 +				Log.i(tag, "Found " + clist.length + " cameras");
    2.47 +
    2.48 +				for(int i=0; i<clist.length; i++) {
    2.49 +					Log.i(tag, "camera[" + i + "]: " + clist[i]);
    2.50 +				}
    2.51 +			}
    2.52 +			catch(CameraAccessException e) {
    2.53 +				Log.e(tag, "camera access exception");
    2.54 +			}
    2.55 +
    2.56 +		} else {
    2.57 +			// fallback to the old Camera API
    2.58 +			Log.i(tag, "Using the old camera API");
    2.59 +
    2.60 +			int num_cams = Camera.getNumberOfCameras();
    2.61 +			Log.i(tag, "Found " + num_cams + " cameras");
    2.62 +
    2.63 +			for(int i=0; i<num_cams; i++) {
    2.64 +				CameraInfo info = new CameraInfo();
    2.65 +				Camera.getCameraInfo(i, info);
    2.66 +
    2.67 +				String facing_str = info.facing == CameraInfo.CAMERA_FACING_FRONT ? "front" : "back";
    2.68 +
    2.69 +				Log.i(tag, "camera[" + i + "]: " + facing_str);
    2.70 +			}
    2.71 +		}
    2.72 +
    2.73 +		start_video();
    2.74 +	}
    2.75 +
    2.76 +	public void start_video()
    2.77 +	{
    2.78 +		cam = Camera.open();
    2.79 +
    2.80 +		CamPreview preview = new CamPreview(this, cam);
    2.81 +
    2.82 +	}
    2.83 +	*/
    2.84  }
    2.85 +
    2.86 +/*
    2.87 +class CamPreview extends ViewGroup implements SurfaceHolder.Callback {
    2.88 +	SurfaceView surf_view;
    2.89 +	SurfaceHolder surf_holder;
    2.90 +
    2.91 +	CamPreview(Context ctx)
    2.92 +	{
    2.93 +		super(ctx);
    2.94 +
    2.95 +		surf_view = new SurfaceView(ctx);
    2.96 +		addView(surf_view);
    2.97 +
    2.98 +		surf_holder = surf_view.getHolder();
    2.99 +		surf_holder.addCallback(this);
   2.100 +		surf_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
   2.101 +	}
   2.102 +}
   2.103 +*/