Back to project page BluetoothGlass.
The source code is released under:
GNU General Public License
If you think the Android project BluetoothGlass listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.vicmns.bluetoothglass.client.views; import android.content.Context; import android.hardware.Camera; import android.hardware.Camera.Parameters; import android.view.SurfaceHolder; import android.view.SurfaceView; //from ww w . j a v a 2s . c o m public class CameraView extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder surfaceHolder = null; private Camera camera = null; @SuppressWarnings("deprecation") public CameraView(Context context) { super(context); surfaceHolder = this.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } /* * (non-Javadoc) * @see android.view.SurfaceHolder.Callback#surfaceCreated(android.view.SurfaceHolder) */ @Override public void surfaceCreated(SurfaceHolder holder) { camera = Camera.open(); // Set the Hotfix for Google Glass this.setCameraParameters(camera); // Show the Camera display try { camera.setPreviewDisplay(holder); } catch (Exception e) { this.releaseCamera(); } } /* * (non-Javadoc) * @see android.view.SurfaceHolder.Callback#surfaceChanged(android.view.SurfaceHolder, int, int, int) */ @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // Start the preview for surfaceChanged if (camera != null) { camera.startPreview(); } } /* * (non-Javadoc) * @see android.view.SurfaceHolder.Callback#surfaceDestroyed(android.view.SurfaceHolder) */ @Override public void surfaceDestroyed(SurfaceHolder holder) { // Do not hold the camera during surfaceDestroyed - view should be gone this.releaseCamera(); } /** * Important HotFix for Google Glass (post-XE11) update * @param camera Object */ public void setCameraParameters(Camera camera) { if (camera != null) { Parameters parameters = camera.getParameters(); parameters.setPreviewFpsRange(30000, 30000); camera.setParameters(parameters); } } /** * Release the camera from use */ public void releaseCamera() { if (camera != null) { camera.release(); camera = null; } } }