3dphotoshoot

annotate src/android/MainActivity.java @ 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
rev   line source
nuclear@0 1 package com.mutantstargoat.photoshoot3d;
nuclear@0 2
nuclear@0 3 import android.app.NativeActivity;
nuclear@0 4 import android.util.Log;
nuclear@3 5 /*
nuclear@3 6 import android.os.Bundle;
nuclear@3 7 import android.content.Context;
nuclear@3 8 import android.hardware.Camera;
nuclear@3 9 import android.hardware.Camera.CameraInfo;
nuclear@3 10 import android.hardware.camera2.*;
nuclear@3 11 */
nuclear@0 12
nuclear@0 13 public class MainActivity extends NativeActivity {
nuclear@3 14 private static String tag = "photoshoot3d";
nuclear@3 15
nuclear@2 16 public static int foo(String s, int n)
nuclear@0 17 {
nuclear@3 18 Log.i(tag, s + ": " + n);
nuclear@2 19 return 42;
nuclear@0 20 }
nuclear@3 21
nuclear@3 22 /*
nuclear@3 23 // old camera api (fallback)
nuclear@3 24 private Camera cam;
nuclear@3 25
nuclear@3 26 // camera2 api (sdk version >= 21)
nuclear@3 27 private CameraManager cman;
nuclear@3 28 private CameraDevice cam2;
nuclear@3 29 private CameraCaptureSession cam_session;
nuclear@3 30
nuclear@3 31 @Override
nuclear@3 32 protected void onCreate(Bundle state)
nuclear@3 33 {
nuclear@3 34 super.onCreate(state);
nuclear@3 35
nuclear@3 36 if(android.os.Build.VERSION.SDK_INT >= 21) {
nuclear@3 37 Log.i(tag, "Using the new camera API");
nuclear@3 38
nuclear@3 39 cman = (CameraManager)getSystemService(Context.CAMERA_SERVICE);
nuclear@3 40
nuclear@3 41 try {
nuclear@3 42 String [] clist = cman.getCameraIdList();
nuclear@3 43 Log.i(tag, "Found " + clist.length + " cameras");
nuclear@3 44
nuclear@3 45 for(int i=0; i<clist.length; i++) {
nuclear@3 46 Log.i(tag, "camera[" + i + "]: " + clist[i]);
nuclear@3 47 }
nuclear@3 48 }
nuclear@3 49 catch(CameraAccessException e) {
nuclear@3 50 Log.e(tag, "camera access exception");
nuclear@3 51 }
nuclear@3 52
nuclear@3 53 } else {
nuclear@3 54 // fallback to the old Camera API
nuclear@3 55 Log.i(tag, "Using the old camera API");
nuclear@3 56
nuclear@3 57 int num_cams = Camera.getNumberOfCameras();
nuclear@3 58 Log.i(tag, "Found " + num_cams + " cameras");
nuclear@3 59
nuclear@3 60 for(int i=0; i<num_cams; i++) {
nuclear@3 61 CameraInfo info = new CameraInfo();
nuclear@3 62 Camera.getCameraInfo(i, info);
nuclear@3 63
nuclear@3 64 String facing_str = info.facing == CameraInfo.CAMERA_FACING_FRONT ? "front" : "back";
nuclear@3 65
nuclear@3 66 Log.i(tag, "camera[" + i + "]: " + facing_str);
nuclear@3 67 }
nuclear@3 68 }
nuclear@3 69
nuclear@3 70 start_video();
nuclear@3 71 }
nuclear@3 72
nuclear@3 73 public void start_video()
nuclear@3 74 {
nuclear@3 75 cam = Camera.open();
nuclear@3 76
nuclear@3 77 CamPreview preview = new CamPreview(this, cam);
nuclear@3 78
nuclear@3 79 }
nuclear@3 80 */
nuclear@0 81 }
nuclear@3 82
nuclear@3 83 /*
nuclear@3 84 class CamPreview extends ViewGroup implements SurfaceHolder.Callback {
nuclear@3 85 SurfaceView surf_view;
nuclear@3 86 SurfaceHolder surf_holder;
nuclear@3 87
nuclear@3 88 CamPreview(Context ctx)
nuclear@3 89 {
nuclear@3 90 super(ctx);
nuclear@3 91
nuclear@3 92 surf_view = new SurfaceView(ctx);
nuclear@3 93 addView(surf_view);
nuclear@3 94
nuclear@3 95 surf_holder = surf_view.getHolder();
nuclear@3 96 surf_holder.addCallback(this);
nuclear@3 97 surf_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
nuclear@3 98 }
nuclear@3 99 }
nuclear@3 100 */