Android Open Source - My-Team--Your-Team Simple Camera






From Project

Back to project page My-Team--Your-Team.

License

The source code is released under:

MIT License

If you think the Android project My-Team--Your-Team 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.selesse.apps.model;
//from  w  w  w  .  j a  va  2  s .  c  o  m
import java.util.ArrayList;
import java.util.List;

import android.annotation.TargetApi;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.Parameters;
import android.os.Build;

import com.selesse.apps.activity.CameraActivity;

public class SimpleCamera {
  public enum FACING {
    CAMERA_FACING_BACK,
    CAMERA_FACING_FRONT
  };

  private int id;
  private SimpleCamera.FACING facing;
  private int orientation;
  private boolean hasFlash;

  public SimpleCamera(int id, SimpleCamera.FACING facing, int orientation) {
    this.setId(id);
    this.setFacing(facing);
    this.setOrientation(orientation);
  }

  public SimpleCamera() {
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public SimpleCamera.FACING getFacing() {
    return facing;
  }

  public void setFacing(SimpleCamera.FACING facing) {
    this.facing = facing;
  }

  public int getOrientation() {
    return orientation;
  }

  public void setOrientation(int orientation) {
    this.orientation = orientation;
  }

  @TargetApi(9)
  public static List<SimpleCamera> getCameraInfoList() {
    List<SimpleCamera> cameraInfoList = new ArrayList<SimpleCamera>();
    if (Build.VERSION.SDK_INT >= 9) {
      Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
      for (int camId = 0; camId < Camera.getNumberOfCameras(); camId++) {
        Camera.getCameraInfo(camId, cameraInfo);
        SimpleCamera simpleCamera = new SimpleCamera();
        simpleCamera.setId(camId);
        SimpleCamera.FACING facingDirection = (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) ? SimpleCamera.FACING.CAMERA_FACING_FRONT
            : SimpleCamera.FACING.CAMERA_FACING_BACK;
        simpleCamera.setFacing(facingDirection);
        simpleCamera.setOrientation(cameraInfo.orientation);
        try {
          Camera camera = Camera.open(camId);
          Parameters p = camera.getParameters();
          camera.release();
        }
        catch (RuntimeException e) {
          CameraActivity.popup("Failed to acquire camera information.");
        }
        cameraInfoList.add(simpleCamera);
      }
    }
    else {
      SimpleCamera simpleCamera = new SimpleCamera();
      Camera camera = Camera.open();
      if (camera != null) {
        Parameters p = camera.getParameters();
        simpleCamera.setId(-1);
        simpleCamera.setFacing(SimpleCamera.FACING.CAMERA_FACING_BACK);
        simpleCamera.setOrientation(90);
        cameraInfoList.add(simpleCamera);
      }
    }

    return cameraInfoList;
  }

  @Override
  public String toString() {
    return "SimpleCamera [id=" + id + ", facing=" + facing + ", orientation=" + orientation
        + ", hasFlash=" + hasFlash + "]";
  }

}




Java Source Code List

com.selesse.apps.EquipePictureCallback.java
com.selesse.apps.Preview.java
com.selesse.apps.activity.CameraActivity.java
com.selesse.apps.model.SimpleCamera.java
com.selesse.apps.model.Team.java