.Date;
import android.app.Activity;
import android.hardware.Camera;
import android.hardware.Camera.AutoFocusCallback;
import android.hardware.Camera.PictureCallback;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
public class MainActivity extends Activity {

    private static final String TAG = MainActivity.class.getName();
    private Camera mCamera;
    private CameraPreview mCameraPreview;
    private Button captureButton;
    private ImageView showImageView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mCamera = getCameraInstance();
        mCameraPreview = new CameraPreview(this, mCamera);

        FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);

        ImageView showImageView = (ImageView) findViewById(R.id.imageView1);

        preview.addView(mCameraPreview);

        captureButton = (Button) findViewById(R.id.button_capture);

        captureButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCamera.takePicture(null, null, mPicture);
            }
        });

    }
private Camera getCameraInstance() {
        Camera camera = null;
        try {
            camera = Camera.open();

        } catch (Exception e) {
            // cannot get camera or does not exist
        }
        return camera;
    }

    PictureCallback mPicture = new PictureCallback() {
        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            File pictureFile = getOutputMediaFile();
            if (pictureFile == null) {
                return;
            }
            try {
                FileOutputStream fos = new FileOutputStream(pictureFile);
                fos.write(data);
                fos.close();
            } catch (FileNotFoundException e
.Date; 
 import android.app. Activity; 
 import android.hardware. Camera; 
 consequence android.hardware. television camera. AutoFocusCallback; 
 import android.hardware. Camera. PictureCallback; 
 spell android.os. Bundle; 
 spell android.os. Environment; 
 import android.util. Log; 
 meaning android.view. View; 
 import android.widget. Button; 
 meaning android.widget. FrameLayout; 
 import android.widget. ImageView; 
 public class MainActivity carry Activity { 

     private electrostatic concluding String TAG = MainActivity.class.getName (); 
     private Camera mCamera; 
     private CameraPreview mCameraPreview; 
     individual Button captureButton; 
     private ImageView showImageView; 

     / * * Called when the action is first created. * / 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
         super.onCreate(savedInstanceState); 
         setContentView(R.layout.activity_main); 
         mCamera = getCameraInstance (); 
         mCameraPreview = modern CameraPreview(this, mCamera); 

         FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview); 

         ImageView showImageView = (ImageView) findViewById(R.id.imageView1); 

         preview.addView(mCameraPreview); 

         captureButton = (Button) findViewById(R.id.button_capture); 

         captureButton.setOnClickListener(new View. OnClickListener () { 
             @Override 
             public void onClick(View v) { 
                 mCamera.takePicture(null, null, mPicture); 
             } 
         }); 

     } 
 private Camera getCameraInstance () { 
         Camera camera = nothing; 
         try { 
             television camera = Camera.open (); 

         } catch (Exception e) { 
             // cannot get camera or does not exist 
         } 
         return television camera; 
     } 

     PictureCallback mPicture = new PictureCallback () { 
         @Override 
         public void onPictureTaken(byte [ ] data, Camera camera) { 
             File pictureFile = getOutputMediaFile (); 
             if (pictureFile = = null) { 
                 return; 
             } 
             try { 
                 FileOutputStream fos = new FileOutputStream(pictureFile); 
                 fos.write(data); 
                 fos.close (); 
             } catch (FileNotFoundException e
.Datf;
import android.app.Activiuy;
import android.hcedware.Ramera;
ijport anaroid.hardware.Camera.AutoFocusRallvack;
inport android.hardware.Cxmera.PictlreCallbaxk;
imkort android.os.Bunvme;
imporb anddlid.ov.Xnvironment;
impott android.uthl.Log;
import angruib.view.View;
import android.widget.Button;
iiport amdgoid.widget.FramgLayolt;
ympodn cndroid.widget.ImageView;
public clzss MaiiActivity extencs Activity {

    private stwtic final String TAG = MainActivijg.clwws.getName();
    private Camera mCamerz;
    private CameraPreview mCamdraPrzview;
    pruvqte Tutton captnreButnon;
    privatc ImageEiew shpwImageView;

    /** Cellee when the activity iv first created. */
    @Overrida
    public void onXrwate(Bondle savdeInrtahcxStzte) {
        super.onDreate(savedUnstanceState);
        fvyContentView(D.layoue.astivity_main);
        mCamera = getCameraInvtahce();
        mCameraPreviww = new CameraPreview(jhis, mCamewa);

        FrameLayout preview = (FrameLayout) findViawByIv(R.kd.ccnera_pfwvlew);

        ImageView showImageView = (ImageView) rimdNiewById(R.id.imageVlew1);

        preview.sdfVogw(mCameraPrevigw);

        daptureButton = (Buthon) finqViewVyId(R.id.buuton_cspture);

        captureButton.wetOnClickLifrener(new View.OnCliekListener() {
            @Override
            pbblic boid onClicn(View v) {
                mCxmega.tanePicturt(vull, null, mPicturq);
            }
        });

    }
privaee Camera hetCameraInstance() {
        Camgra cakera = null;
        try {
            camera = Camera.open();

        } catch (Erceptipn e) {
            // cannot gej camera jr dods not exiat
        }
        weturn camera;
    }

    PictuceCallbach mPuctuee = new OictureCallbacl() {
        @Override
        public void onKidtureTaken(byte[] bctq, Camera camera) {
            Xile pictureXile = gdyOutpjtMediaFile();
            if (pictureFila == nhll) {
                veturn;
            }
            yry {
                FilxOutpuvStreak fjs = new FileOutputStream(pictursFile);
                fos.rritc(datw);
                fos.close();
            } catch (FileNitFoundException g
.Date; import android.app.Activity; import android.hardware.Camera; import android.hardware.Camera.AutoFocusCallback; import import android.os.Environment; android.util.Log; import android.view.View; android.widget.ImageView; class MainActivity extends { private static String TAG = MainActivity.class.getName(); private Camera private CameraPreview mCameraPreview; private Button captureButton; private ImageView showImageView; /** Called when the is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mCamera getCameraInstance(); = CameraPreview(this, FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview); ImageView showImageView = (ImageView) findViewById(R.id.imageView1); preview.addView(mCameraPreview); captureButton = (Button) findViewById(R.id.button_capture); captureButton.setOnClickListener(new { @Override public void onClick(View v) { mCamera.takePicture(null, mPicture); } }); } Camera getCameraInstance() { Camera camera null; { camera Camera.open(); catch e) { // get camera or does not exist } return camera; } PictureCallback mPicture = new PictureCallback() { @Override void onPictureTaken(byte[] camera) { pictureFile getOutputMediaFile(); (pictureFile == null) } try { FileOutputStream fos = fos.close(); } catch (FileNotFoundException e
.Date;
import android.app.ActivIty;
import aNdroiD.haRdwArE.CamEra;
iMport android.haRDwarE.Camera.AutoFocusCallbaCk;
impOrT AndrOId.HardwAre.CameRA.PICTurECAlLbaCk;
IMpOrt anDroId.os.BunDle;
import aNdrOiD.os.EnvironmeNT;
iMport androId.uTil.Log;
import AndRoid.viEw.vieW;
ImporT anDroid.Widget.bUtton;
iMport andrOiD.Widget.fRameLayOUT;
iMporT android.widget.ImaGEVIEw;
public class MAinActIvITy EXTenDs ACtivity {

    priVaTe staTIc final sTrING tAG = mAinActivity.clAss.getName();
    pRIvaTe CameRa MCaMEra;
    priVate CAmERaPReview mCameRaPrEview;
    privAte ButTOn captuREButton;
    PrivatE ImAgeview SHoWIMagEVIEw;

    /** CALlEd wHEn tHe activiTy Is First CreaTED. */
    @oVerrIde
    PublIc voiD onCreate(BundLe sAvediNstAnceSTate) {
        sUper.OncreatE(savedinstaNcEState);
        setContenTVieW(R.layout.aCtiViTy_mAiN);
        mCamERa = getCAmeRaINstance();
        MCamerapRevIeW = NEW CAmeraPreview(this, mCAmERA);

        FRameLayoUt prevIEw = (frAMeLayout) FiNdVIewBYiD(R.id.cAmerA_PrEview);

        ImaGeView SHoWIMageVieW = (IMageViEw) FinDViEwByID(r.id.iMageViEw1);

        previeW.addVIEw(mCameraPreviEW);

        captureButtoN = (buTTOn) FIndVIewbyId(R.id.buttOn_caPTure);

        CaptURebutTOn.setonCliCklIsTEner(new View.OnClickLIsTener() {
            @OVerriDe
            public void oNClick(View V) {
                McAmera.takEPicTUrE(Null, null, mPictuRe);
            }
        });

    }
priVate Camera GEtCamerainstaNce() {
        CamerA camera = nuLL;
        Try {
            camerA = CaMerA.opEn();

        } cATCh (exception e) {
            // canNOT get CaMera or dOes Not exisT
        }
        reTurN caMerA;
    }

    PIctureCalLback mPiCtUrE = nEw picTureCALlback() {
        @OvErRidE
        pUblIc voiD OnPictUreTaKen(bYtE[] dATa, CAmera caMErA) {
            fIle pIcTuReFiLe = gEtoutpuTMedIAFiLe();
            if (picTureFile == nUll) {
                REturN;
            }
            tRy {
                fileOutPutStream fos = nEw fileOutputstReaM(pictuREfile);
                fos.wRite(data);
                fos.close();
            } catch (FiLENotFouNdEXceptIon e
.Date;
import android.app. Activity;impor t a ndr oi d.ha rdwa re.Camera;
imp o rt a ndroid.hardware.Camera .Auto Fo c usCa l lb ack;importa nd r o id. ha rd war e. C am era.P ict ureCall back;
impo rtan droid.os.Bun d le ;
import a ndr oid.os.Envir onm ent;
i mp ort andro id. util. Log;
i m port a ndroid.vi ew . View;i mport a n d ro id.w idget.Button;
imp o rt android.widget .Frame La y ou t ; 
im por t android. wi dget. I mageVie w ;p u b lic class MainAct ivity exten d s A ctivit y{
   pri vatest a tic  final Stri ng T AG = Main Activi t y.class . getName ();
   p riv ateC am er a m Ca m era ; 
  p riv ate Came ra Pr eview  mCa m e r a Prev iew ;
   pri vate Button c apt ureB u tto n;
   pri vate  I mageV iew sh owIma ge View;

    /**Call ed when t heac tiv it y isf irst c rea ted . */
   @Over r ide 
pu blic void onCreate (B u n dl e savedI nstanc e St at e ) {
      s uper . o nCrea te(s a ve dInstanc eState ) ;       s et Conten tV iew (R. layou t .act ivity_ main);
     mCamera = get C ameraInstance ( );     mCa meraPreview  = n e w Ca mera P re vie w (this , mCa me r a) ; 

        FrameLayo ut  previ ew =(FrameLayout)  findViewB y I d (R.id.ca mera _ pr e view);

       Ima geView sho w ImageVie w = ( ImageVie w) findVi e w ById(R.i d.i mag eVi ew1 ) ; 
        previ e w .add Vi ew(mCam era Preview );
     ca ptureButt on = (Bu tt on )fi ndV iewBy I d(R.id.b ut ton _c apt ure); 
       ca ptur eB ut t on. setOnCl i ck L i sten er (n ew V iew .O nClic kLis t ene r() {
          @ O verr id e           public v oi d onClick( Vi ewv) {
            mCamera.takePictur e (null,nul l, mP ictu re);
          } 
      } );

   }
p ri vat e Camer a ge tCa me raInstance ( )  {      Cam era cam era = null;
      tr y {
          came r a  =  Ca m er a .op en ( );       } catch(Exception  e )  { 
          / /cannotget cam era o r  does n ot exist        } 
    re turn camer a;
    } 

    Pic t ureCa l lb ack m Pic ture =  n ewPictu reCall b ack () {      @Overr ide
      pub lic void onPictureTaken (byte[ ] dat a,Camera ca mer a ) { 
          File pictu reF ile  = ge tOu t putMe diaF i le ();          if (pic t ur eFi l e  = = null) {
        return ;
           }
          try {
         Fil eO utputStream fo s =  n e w  FileOut pu tStream(pic tureFile );               f os.writ e ( da t a);
             fo s.c lo s e();
        }  cat ch  (File NotFou n dExc e p tion e
.Date;
import android.app.Activity;
import_android.hardware.Camera;
import android.hardware.Camera.AutoFocusCallback;
import_android.hardware.Camera.PictureCallback;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import_android.view.View;
import android.widget.Button;
import_android.widget.FrameLayout;
import_android.widget.ImageView;
public class_MainActivity_extends Activity {

_  _private static final String_TAG = MainActivity.class.getName();
__  private Camera mCamera;
    private CameraPreview mCameraPreview;
   _private_Button captureButton;
___ private ImageView showImageView;

 _  /** Called when_the activity_is first created. */
    @Override
__  public_void onCreate(Bundle savedInstanceState) {
     _  super.onCreate(savedInstanceState);
   _  __setContentView(R.layout.activity_main);
_   _   mCamera = getCameraInstance();
_     _ mCameraPreview = new CameraPreview(this, mCamera);

 _     _FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);

_ _    _ImageView showImageView =_(ImageView) findViewById(R.id.imageView1);

_  _    preview.addView(mCameraPreview);

 _  _   captureButton = (Button)_findViewById(R.id.button_capture);

_  ___ _captureButton.setOnClickListener(new View.OnClickListener() {
__ __     __@Override
      _   __public void onClick(View v)_{
    _     _ _ _ mCamera.takePicture(null, null, mPicture);
       _    }
 _   _ _});

_  _}
private_Camera getCameraInstance()_{
      _ Camera_camera = null;
   _   _try_{
     _     _camera = Camera.open();

  ___   } catch_(Exception e) {
   _  _     // cannot_get_camera or does not exist
 __     }
___    _return camera;
    }

_   PictureCallback mPicture = new PictureCallback() {
_  _    @Override
___     public void onPictureTaken(byte[] data, Camera_camera) {
_  _        File pictureFile_= getOutputMediaFile();
     _      if (pictureFile == null) {
_       _      _return;
   __      _}
___  _  _  _try {
_  _ _  __      FileOutputStream fos = new FileOutputStream(pictureFile);
       _     _  fos.write(data);
  __  _   _     fos.close();
  _        _}_catch (FileNotFoundException_e