PageRenderTime 15ms CodeModel.GetById 2ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/magnify/src/com/google/marvin/magnify/CaptureActivity.java

http://eyes-free.googlecode.com/
Java | 97 lines | 77 code | 20 blank | 0 comment | 4 complexity | c3ed291efe9a0290dbd1698a32749eac MD5 | raw file
 1package com.google.marvin.magnify;
 2
 3import android.app.Activity;
 4import android.content.Intent;
 5import android.graphics.Bitmap;
 6import android.graphics.BitmapFactory;
 7import android.hardware.Camera;
 8import android.os.Bundle;
 9import android.util.Log;
10import android.view.SurfaceHolder;
11import android.view.SurfaceView;
12import android.view.View;
13
14import java.io.IOException;
15
16public class CaptureActivity extends Activity implements SurfaceHolder.Callback,
17    Camera.PictureCallback, Camera.AutoFocusCallback, View.OnClickListener {
18  private static final String TAG = "CaptureActivity";
19
20  private SurfaceHolder mHolder;
21  private SurfaceView mPreview;
22  private Camera mCamera;
23  
24  protected static Bitmap mBitmap;
25  
26  int[] mImage;
27  int mWidth;
28  int mHeight;
29
30  @Override
31  public void onCreate(Bundle savedInstanceState) {
32    super.onCreate(savedInstanceState);
33    
34    Log.i(TAG, "Started " + TAG);
35
36    setContentView(R.layout.main);
37
38    mPreview = (SurfaceView) findViewById(R.id.preview);
39    mPreview.setOnClickListener(this);
40
41    mHolder = mPreview.getHolder();
42    mHolder.addCallback(this);
43    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
44  }
45
46  @Override
47  public void surfaceCreated(SurfaceHolder holder) {
48    try {
49      mCamera = Camera.open();
50      mCamera.setPreviewDisplay(holder);
51    } catch (IOException e) {
52      Log.e(TAG, e.toString());
53    }
54  }
55
56  @Override
57  public void surfaceDestroyed(SurfaceHolder holder) {
58    mCamera.stopPreview();
59    mCamera.release();
60    mCamera = null;
61  }
62
63  @Override
64  public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
65    mHolder.setFixedSize(w, h);
66    
67    Camera.Parameters parameters = mCamera.getParameters();
68    parameters.setPreviewSize(w, h);
69    parameters.setPictureSize(2048, 1536);
70    mCamera.setParameters(parameters);
71    mCamera.startPreview();
72  }
73
74  @Override
75  public void onClick(View v) {
76    if (v == mPreview) {
77      mCamera.autoFocus(this);
78    }
79  }
80
81  @Override
82  public void onPictureTaken(byte[] data, Camera camera) {
83    if (mBitmap != null) {
84      mBitmap.recycle();
85    }
86    
87    mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
88    
89    Intent intent = new Intent(this, ZoomActivity.class);
90    startActivity(intent);
91  }
92
93  @Override
94  public void onAutoFocus(boolean success, Camera camera) {
95    mCamera.takePicture(null, null, this);
96  }
97}