Android Open Source - BluetoothGlass Camera View






From Project

Back to project page BluetoothGlass.

License

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.

Java Source Code

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;
    }
  }
}




Java Source Code List

com.vicmns.bluetoothglass.client.MainApplication.java
com.vicmns.bluetoothglass.client.activities.BluetoothClient.java
com.vicmns.bluetoothglass.client.activities.MainActivity.java
com.vicmns.bluetoothglass.client.adapters.BluetoothDevicesAdapter.java
com.vicmns.bluetoothglass.client.bluetooth.SendFileToDeviceTask.java
com.vicmns.bluetoothglass.client.callbacks.CardScrollCallBacks.java
com.vicmns.bluetoothglass.client.data.BluetoothParametersHolder.java
com.vicmns.bluetoothglass.client.models.BluetoothDeviceModel.java
com.vicmns.bluetoothglass.client.services.GoogleVoiceTriggerService.java
com.vicmns.bluetoothglass.client.services.SendPictureToDevice.java
com.vicmns.bluetoothglass.client.tools.FileExtensionFilter.java
com.vicmns.bluetoothglass.client.views.CameraView.java
com.vicmns.bluetoothglass.client.views.OverlayView.java
com.vicmns.bluetoothglass.server.MainActivity.java
com.vicmns.bluetoothglass.server.MainApplication.java
com.vicmns.bluetoothglass.server.data.BluetoothParametersHolder.java
com.vicmns.bluetoothglass.server.handlers.BluetoothConnectionHandler.java
com.vicmns.bluetoothglass.server.handlers.BluetoothReadFromSocketHandler.java
com.vicmns.bluetoothglass.server.receivers.DeviceBootReceiver.java
com.vicmns.bluetoothglass.server.service.BluetoothService.java