mirror of
https://github.com/purplecabbage/phonegap-plugins.git
synced 2026-01-13 16:38:08 -05:00
74 lines
2.1 KiB
Java
74 lines
2.1 KiB
Java
/*
|
|
Copyright 2012 Bruno Carreira - Lucas Farias - Rafael Luna - Vinícius Fonseca.
|
|
|
|
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.
|
|
*/
|
|
|
|
package com.foregroundcameraplugin;
|
|
|
|
import java.io.IOException;
|
|
|
|
import android.content.Context;
|
|
import android.hardware.Camera;
|
|
import android.util.Log;
|
|
import android.view.SurfaceHolder;
|
|
import android.view.SurfaceView;
|
|
|
|
public class ForegroundCameraPreview extends SurfaceView implements SurfaceHolder.Callback {
|
|
private SurfaceHolder mHolder;
|
|
private Camera mCamera;
|
|
private static final String TAG = "CameraPreview";
|
|
|
|
public ForegroundCameraPreview(Context context, Camera camera) {
|
|
super(context);
|
|
mCamera = camera;
|
|
|
|
mHolder = getHolder();
|
|
mHolder.addCallback(this);
|
|
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
|
}
|
|
|
|
public void surfaceCreated(SurfaceHolder holder) {
|
|
try {
|
|
mCamera.setPreviewDisplay(holder);
|
|
mCamera.startPreview();
|
|
} catch (IOException e) {
|
|
Log.d(TAG, "Error setting camera preview: " + e.getMessage());
|
|
}
|
|
}
|
|
|
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
|
}
|
|
|
|
|
|
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
|
|
|
if (mHolder.getSurface() == null){
|
|
return;
|
|
}
|
|
|
|
try {
|
|
mCamera.stopPreview();
|
|
} catch (Exception e){
|
|
}
|
|
|
|
try {
|
|
mCamera.setPreviewDisplay(mHolder);
|
|
mCamera.startPreview();
|
|
|
|
} catch (Exception e){
|
|
Log.d(TAG, "Error starting camera preview: " + e.getMessage());
|
|
}
|
|
}
|
|
}
|