Android Open Source - iSlide Take Picture Activity






From Project

Back to project page iSlide.

License

The source code is released under:

MIT License

If you think the Android project iSlide 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 edu.csun.group2.islide;
/*from   w w  w . j  a  v a2  s .  c o m*/
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.PictureCallback;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;

public class TakePictureActivity extends Activity {
  private final static String DEBUG_TAG = "MakePhotoActivity";
  // private Camera camera;
  private int cameraId = 0;

  private Camera mCamera;
  private CameraPreview mPreview;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_take_picture);

    // Create an instance of Camera
    mCamera = getCameraInstance();

    // Create our Preview view and set it as the content of our activity.
    mPreview = new CameraPreview(this, mCamera);
    FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);

    preview.addView(mPreview);
  }

  public void onClick(View view) {

    if (mCamera != null) {
      // camera = Camera.open(cameraId);
      mCamera.takePicture(null, null, new PhotoHandler(
          TakePictureActivity.this));
      // new PhotoHandler(getApplicationContext()));
    }

  }

  public static Camera getCameraInstance() {
    Camera c = null;
    try {
      c = Camera.open(); // attempt to get a Camera instance
    } catch (Exception e) {
      // Camera is not available (in use or does not exist)

    }
    return c; // returns null if camera is unavailable
  }

  private int findBackFacingCamera() {
    int cameraId = -1;
    // Search for the front facing camera
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
      CameraInfo info = new CameraInfo();
      Camera.getCameraInfo(i, info);
      if (info.facing == CameraInfo.CAMERA_FACING_BACK) {
        Log.d(DEBUG_TAG, "Camera found");
        cameraId = i;
        break;
      }
    }
    return cameraId;
  }

  @Override
  protected void onPause() {
    if (mCamera != null) {
      mCamera.release();
      mCamera = null;
    }
    super.onPause();
  }

  private boolean checkCameraHardware(Context context) {
    if (context.getPackageManager().hasSystemFeature(
        PackageManager.FEATURE_CAMERA)) {
      // this device has a camera
      return true;
    } else {
      // no camera on this device
      return false;
    }
  }
}




Java Source Code List

edu.csun.group2.islide.CameraPreview.java
edu.csun.group2.islide.HighScore.java
edu.csun.group2.islide.MainActivity.java
edu.csun.group2.islide.MainMenuActivity.java
edu.csun.group2.islide.PhotoHandler.java
edu.csun.group2.islide.PlayMenu.java
edu.csun.group2.islide.SelectImageActivity.java
edu.csun.group2.islide.SettingsMenu.java
edu.csun.group2.islide.TakePictureActivity.java
edu.csun.group2.islide.UtilityInfo.java
edu.csun.group2.islide.Utility.java
edu.csun.group2.islide.engine.BoardTest.java
edu.csun.group2.islide.engine.Board.java
edu.csun.group2.islide.engine.GameBoardTest.java
edu.csun.group2.islide.engine.GameBoard.java
edu.csun.group2.islide.engine.GameManager.java
edu.csun.group2.islide.engine.InputHandler.java
edu.csun.group2.islide.engine.MoveComparator.java
edu.csun.group2.islide.engine.MoveTest.java
edu.csun.group2.islide.engine.Move.java
edu.csun.group2.islide.engine.Pair.java
edu.csun.group2.islide.engine.entity.SlideTile.java
edu.csun.group2.islide.engine.entity.TileManager.java
edu.csun.group2.islide.global.GameInfo.java
edu.csun.group2.islide.interfaces.IRenderable.java
edu.csun.group2.islide.iSlide.java