1 |
/*
|
2 |
* Copyright (C) 2009 The Android Open Source Project
|
3 |
*
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
* you may not use this file except in compliance with the License.
|
6 |
* You may obtain a copy of the License at
|
7 |
*
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
9 |
*
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
* See the License for the specific language governing permissions and
|
14 |
* limitations under the License.
|
15 |
*/
|
16 |
package com.zoffcc.applications.zanavi;
|
17 |
|
18 |
import android.app.Activity;
|
19 |
import android.widget.TextView;
|
20 |
import android.os.Bundle;
|
21 |
import android.os.Debug;
|
22 |
import android.os.Message;
|
23 |
import android.os.Handler;
|
24 |
import android.content.Context;
|
25 |
import android.util.Log;
|
26 |
import android.hardware.Camera;
|
27 |
import android.hardware.Camera.Parameters;
|
28 |
import android.graphics.Bitmap;
|
29 |
import android.graphics.BitmapFactory;
|
30 |
import android.graphics.PixelFormat;
|
31 |
import android.view.SurfaceHolder;
|
32 |
import android.view.SurfaceView;
|
33 |
import java.io.IOException;
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
public class NavitCamera extends SurfaceView implements SurfaceHolder.Callback {
|
39 |
SurfaceHolder mHolder;
|
40 |
Camera mCamera;
|
41 |
|
42 |
|
43 |
|
44 |
NavitCamera(Context context)
|
45 |
{
|
46 |
super(context);
|
47 |
mHolder = getHolder();
|
48 |
mHolder.addCallback(this);
|
49 |
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
50 |
Log.e("NavitCamera","Creator");
|
51 |
|
52 |
|
53 |
}
|
54 |
|
55 |
|
56 |
public void surfaceCreated(SurfaceHolder holder) {
|
57 |
// The Surface has been created, acquire the camera and tell it where
|
58 |
// to draw.
|
59 |
try {
|
60 |
mCamera = Camera.open();
|
61 |
mCamera.setPreviewDisplay(holder);
|
62 |
} catch (IOException exception) {
|
63 |
mCamera.release();
|
64 |
mCamera = null;
|
65 |
// TODO: add more exception handling logic here
|
66 |
}
|
67 |
Log.e("NavitCamera","surfaceCreated");
|
68 |
}
|
69 |
|
70 |
public void surfaceDestroyed(SurfaceHolder holder) {
|
71 |
// Surface will be destroyed when we return, so stop the preview.
|
72 |
// Because the CameraDevice object is not a shared resource, it's very
|
73 |
// important to release it when the activity is paused.
|
74 |
mCamera.stopPreview();
|
75 |
mCamera = null;
|
76 |
Log.e("NavitCamera","surfaceDestroyed");
|
77 |
}
|
78 |
|
79 |
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
80 |
// Now that the size is known, set up the camera parameters and begin
|
81 |
// the preview.
|
82 |
Log.e("NavitCamera","surfaceChanged "+w+"x"+h);
|
83 |
mCamera.stopPreview();
|
84 |
Camera.Parameters parameters = mCamera.getParameters();
|
85 |
parameters.setPreviewSize(w, h);
|
86 |
mCamera.setParameters(parameters);
|
87 |
mCamera.startPreview();
|
88 |
}
|
89 |
|
90 |
}
|
91 |
|