Android Open Source - visualekg Camera Activity






From Project

Back to project page visualekg.

License

The source code is released under:

GNU General Public License

If you think the Android project visualekg 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 o6systems.kalpdroid;
/*w  w  w.  jav  a  2 s .c o  m*/
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.multv.R;

import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

public class CameraActivity extends BaseActivity {

  final static int LAYOUT_ID =  R.layout.activity_camera;
  public static final int MEDIA_TYPE_IMAGE = 1;
  public static final int MEDIA_TYPE_VIDEO = 2;
  
       
  Camera mCamera;
  CameraPreview mPreview;
  LinearLayout preview;
  Button btnPhoto;
  MediaRecorder mMediaRecorder;
  File currentOutVideoFile;
  private boolean isRecording = false;
  PrintWriter outLogFileWriter;
  boolean mLoggedIn;

  


  public void insertLog(String str){
    Toast.makeText(getApplicationContext(), str, Toast.LENGTH_LONG).show();
  }
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    layoutID = LAYOUT_ID;
    insertLog("Out0.9:\r\n");
    super.onCreate(savedInstanceState);  
    //initializeDropbox();
    insertLog("Out1.3:\r\n");
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.camera, menu);
    return true;
  }
  
  
  /** Check if this device has a camera */
  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;
      }
  }
  
  /** A safe way to get an instance of the Camera object. */
  public static Camera getCameraInstance(){
      Camera c = null;
      try {
          c = Camera.open(CameraInfo.CAMERA_FACING_FRONT);
      }
      catch (Exception e){
          // Camera is not available (in use or does not exist)
      }
      return c; // returns null if camera is unavailable
  }
  

  @Override
  public void initViews() {
        // Create an instance of Camera
        mCamera = getCameraInstance();
        mCamera.setDisplayOrientation(90);
       
        // Create our Preview view and set it as the content of our activity.
        mPreview = new CameraPreview(this, mCamera);
        
        try {
      mCamera.setPreviewDisplay(mPreview.getHolder());
    } catch (IOException e) {
      System.out.println("set Preview Display: Exception");
      e.printStackTrace();
    }
       
        mCamera.startPreview();
        preview = (LinearLayout) findViewById(R.id.cameraLayout);
        preview.addView(mPreview);
        
        
        btnPhoto = (Button)findViewById(R.id.btnPhoto);
    
  }
  
  public void setCaptureButtonText(String text){
    btnPhoto.setText(text);
  }
  
  

  @Override
  public void setListeners() {
    
    
  }

  @Override
  public void constructViewviaXML() {
    // TODO Auto-generated method stub
    
  }
  
  @Override
  protected void onDestroy(){
    super.onDestroy();
    releaseMediaRecorder();
     releaseCamera(); 
  } 
  
   @Override
      protected void onPause() {
          super.onPause();
          releaseMediaRecorder();       // if you are using MediaRecorder, release it first
          releaseCamera();              // release the camera immediately on pause event
      }

      private void releaseMediaRecorder(){
          if (mMediaRecorder != null) {
              mMediaRecorder.reset();   // clear recorder configuration
              mMediaRecorder.release(); // release the recorder object
              mMediaRecorder = null;
              mCamera.lock();           // lock camera for later use
          }
      }

      private void releaseCamera(){
          if (mCamera != null){
              mCamera.release();        // release the camera for other applications
              mCamera = null;
          }
      }

      

     
      
      @Override
      protected void onResume() {
          super.onResume();
          insertLog("On resume!\r\n");
          // The next part must be inserted in the onResume() method of the
          // activity from which session.startAuthentication() was called, so
          // that Dropbox authentication completes properly.
         
      }
      
}




Java Source Code List

o6systems.kalpdroid.BaseActivity.java
o6systems.kalpdroid.CameraActivity.java
o6systems.kalpdroid.CameraPreview.java
xmlMessages.ErrorDefinitions.java
xmlMessages.MessageFunction.java
xmlMessages.XMLMessage.java