Created
July 28, 2015 13:01
-
-
Save zserge/4d3ba482645151e79a5b to your computer and use it in GitHub Desktop.
Simple camera example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.anvil.empty; | |
import android.app.Activity; | |
import android.hardware.Camera; | |
import android.os.Bundle; | |
import android.view.SurfaceHolder; | |
import android.view.SurfaceView; | |
import android.view.View; | |
import android.widget.FrameLayout; | |
import java.io.IOException; | |
import static trikita.anvil.v15.Attrs.*; | |
import trikita.anvil.RenderableView; | |
public class MainActivity extends Activity { | |
private Camera mCamera = Camera.open(); | |
private SurfaceHolder.Callback mHolderCallback = new SurfaceHolder.Callback() { | |
public void surfaceCreated(SurfaceHolder holder) {} | |
public void surfaceDestroyed(SurfaceHolder holder) {} | |
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { | |
try { | |
System.out.println("Surface changed"); | |
mCamera.setPreviewDisplay(holder); | |
mCamera.startPreview(); | |
} catch (IOException e){ | |
e.printStackTrace(); | |
} | |
} | |
}; | |
private ConfigListener mConfigListener = new ConfigListener() { | |
public void onConfig(View v) { | |
System.out.println("onConfig(): v=" + v); | |
SurfaceView sv = (SurfaceView) v; | |
SurfaceHolder holder = sv.getHolder(); | |
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); | |
holder.addCallback(mHolderCallback); | |
} | |
}; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(new RenderableView(this) { | |
public ViewNode view() { | |
System.out.println("view()"); | |
return | |
v(FrameLayout.class, | |
v(SurfaceView.class, | |
config(mConfigListener))); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment