package com.example.tensioncamapp.views; /** * @author Lisa Ryth�n Larsson, Fredrik Johansson * @copyright Lisa Ryth�n Larsson, Fredrik Johansson, Max Dubois, Martin Falk Danauskis * * Copyright 2013 Fredrik Johansson, Lisa Ryth�n Larsson, Martin Falk Danauskis, Max Dubois * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ import java.io.IOException; import android.content.Context; import android.hardware.Camera; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; /** A basic Camera preview class */ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private static final String TAG = "PreviewAactivity"; private SurfaceHolder mHolder; private Camera mCamera; public CameraPreview(Context context, Camera camera) { super(context); this.mCamera = camera; // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. this.mHolder = getHolder(); this.mHolder.addCallback(this); } /**Displays the picture on the camera */ public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { this.mCamera.setPreviewDisplay(holder); this.mCamera.startPreview(); } catch (IOException e) { Log.d(TAG, "Error setting camera preview: " + e.getMessage()); } } public void surfaceDestroyed(SurfaceHolder holder) { //not uses } public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { //not used } }