3dphotoshoot
annotate src/android/MainActivity.java @ 6:e31e23ead56f
GAMO TO XRISTO KAI TIN PANAGIA TOU ANDROID
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 21 May 2015 19:03:00 +0300 |
parents | 38377f54527a |
children | 7f6e6eb3d20e |
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@4 | 5 import static android.opengl.GLES20.*; |
nuclear@4 | 6 import android.hardware.Camera; |
nuclear@4 | 7 import android.hardware.Camera.CameraInfo; |
nuclear@4 | 8 import android.graphics.SurfaceTexture; |
nuclear@3 | 9 /* |
nuclear@3 | 10 import android.os.Bundle; |
nuclear@3 | 11 import android.content.Context; |
nuclear@3 | 12 import android.hardware.camera2.*; |
nuclear@3 | 13 */ |
nuclear@0 | 14 |
nuclear@0 | 15 public class MainActivity extends NativeActivity { |
nuclear@6 | 16 public static String tag = "photoshoot3d"; |
nuclear@3 | 17 |
nuclear@4 | 18 public static void foo() |
nuclear@0 | 19 { |
nuclear@4 | 20 glClearColor(0.2f, 1.0f, 0.3f, 1.0f); |
nuclear@0 | 21 } |
nuclear@3 | 22 |
nuclear@3 | 23 // old camera api (fallback) |
nuclear@4 | 24 private static Camera cam; |
nuclear@3 | 25 |
nuclear@4 | 26 public static int start_video(int texid) |
nuclear@4 | 27 { |
nuclear@4 | 28 int num_cams = Camera.getNumberOfCameras(); |
nuclear@4 | 29 Log.i(tag, "Found " + num_cams + " cameras"); |
nuclear@3 | 30 |
nuclear@4 | 31 for(int i=0; i<num_cams; i++) { |
nuclear@4 | 32 CameraInfo info = new CameraInfo(); |
nuclear@4 | 33 Camera.getCameraInfo(i, info); |
nuclear@3 | 34 |
nuclear@4 | 35 String facing_str = info.facing == CameraInfo.CAMERA_FACING_FRONT ? "front" : "back"; |
nuclear@3 | 36 |
nuclear@4 | 37 Log.i(tag, "camera[" + i + "]: " + facing_str); |
nuclear@3 | 38 } |
nuclear@3 | 39 |
nuclear@4 | 40 SurfaceTexture surftex = new SurfaceTexture(texid); |
nuclear@4 | 41 surftex.setOnFrameAvailableListener(new FrameHandler()); |
nuclear@4 | 42 |
nuclear@4 | 43 cam = Camera.open(); |
nuclear@4 | 44 try { |
nuclear@4 | 45 cam.setPreviewTexture(surftex); |
nuclear@4 | 46 } |
nuclear@4 | 47 catch(java.io.IOException e) { |
nuclear@4 | 48 Log.e(tag, "failed to set preview texture"); |
nuclear@4 | 49 cam = null; |
nuclear@4 | 50 return -1; |
nuclear@4 | 51 } |
nuclear@4 | 52 cam.startPreview(); |
nuclear@4 | 53 |
nuclear@4 | 54 return 0; |
nuclear@3 | 55 } |
nuclear@3 | 56 |
nuclear@4 | 57 public static void stop_video() |
nuclear@3 | 58 { |
nuclear@4 | 59 cam.stopPreview(); |
nuclear@4 | 60 cam = null; |
nuclear@3 | 61 } |
nuclear@0 | 62 } |
nuclear@3 | 63 |
nuclear@4 | 64 class FrameHandler implements SurfaceTexture.OnFrameAvailableListener { |
nuclear@6 | 65 @Override |
nuclear@6 | 66 public synchronized void onFrameAvailable(SurfaceTexture stex) |
nuclear@3 | 67 { |
nuclear@6 | 68 Log.i(MainActivity.tag, "new video frame"); |
nuclear@4 | 69 stex.updateTexImage(); |
nuclear@3 | 70 } |
nuclear@3 | 71 } |