Skip to content

Instantly share code, notes, and snippets.

View DavidTPate's full-sized avatar

David Pate DavidTPate

  • Denver
View GitHub Profile
@Override
protected void onResume() {
super.onResume();
initialize();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// If your preview can change or rotate, take care of those events here.
// Make sure to stop the preview before resizing or reformatting it.
if (mHolder.getSurface() == null) {
// preview surface does not exist
Log.d(TAG, "Preview Surface does not exist");
return;
}
@SuppressWarnings("deprecation")
public class SimpleCameraPreview extends SurfaceView implements SurfaceHolder.Callback {
private static final String TAG = "Simple Camera Preview";
private final SurfaceHolder mHolder;
private final Camera mCamera;
@SuppressWarnings("deprecation")
public SimpleCameraPreview(Context context, Camera camera) {
super(context);
mCamera = camera;
<resources>
<style name="Theme.SimpleCamera" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen" />
</resources>
<resources>
<dimen name="control_panel_min_length">105dp</dimen>
</resources>
<style name="SimpleCamera" parent="android:Theme.Holo.NoActionBar.Fullscreen">
<item name="android:windowBackground">@android:color/black</item>
<item name="android:colorBackground">@android:color/black</item>
<item name="android:colorBackgroundCacheHint">@android:color/black</item>
</style>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/SimpleCamera"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
tools:context=".SimpleCamera" >
<FrameLayout
android:id="@+id/camera_preview"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.craftingmobile.tutorials.simplecamera"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="true"/>