@@ -20,26 +20,13 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback, C
20
20
private static final String TAG = "AiNNDemo" ;
21
21
22
22
private static final int MINIMUM_PREVIEW_SIZE = 320 ;
23
-
23
+ private static final int PREVIEW_CALLBACK_FREQUENCE = 5 ;
24
24
private Camera mCamera ;
25
25
private Camera .Parameters mParams ;
26
26
private Camera .Size mPreviewSize ;
27
-
28
27
private PreviewCallback mPreviewCallback ;
29
28
private int mOrientationAngle ;
30
-
31
29
private int previewCallbackCount ;
32
- private static final int PREVIEW_CALLBACK_FREQUENCE = 5 ;
33
-
34
- public interface PreviewCallback {
35
- void onGetPreviewOptimalSize (int optimalWidth , int optimalHeight );
36
-
37
- void onPreviewFrame (byte [] data , int imageWidth , int imageHeight , int angle );
38
- }
39
-
40
- public void setPreviewCallback (CameraView .PreviewCallback previewCallback ) {
41
- mPreviewCallback = previewCallback ;
42
- }
43
30
44
31
public CameraView (Context context ) {
45
32
this (context , null );
@@ -52,6 +39,10 @@ public CameraView(Context context, AttributeSet attrs) {
52
39
holder .addCallback (this );
53
40
}
54
41
42
+ public void setPreviewCallback (CameraView .PreviewCallback previewCallback ) {
43
+ mPreviewCallback = previewCallback ;
44
+ }
45
+
55
46
private void openCamera (SurfaceHolder holder ) {
56
47
// release Camera, if not release camera before call camera, it will be locked
57
48
releaseCamera ();
@@ -103,7 +94,6 @@ private synchronized void releaseCamera() {
103
94
}
104
95
}
105
96
106
-
107
97
@ Override
108
98
public void surfaceCreated (SurfaceHolder surfaceHolder ) {
109
99
Log .i ("AiNNDemo" , "surfaceCreated" );
@@ -121,7 +111,6 @@ public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
121
111
Log .i ("AiNNDemo" , "surfaceDestroyed" );
122
112
}
123
113
124
-
125
114
public void setCameraDisplayOrientation (Activity activity ,
126
115
int cameraId , android .hardware .Camera camera ) {
127
116
android .hardware .Camera .CameraInfo info =
@@ -180,7 +169,6 @@ public void onPreviewFrame(byte[] bytes, Camera camera) {
180
169
mPreviewCallback .onPreviewFrame (bytes , mPreviewSize .width , mPreviewSize .height , mOrientationAngle );
181
170
}
182
171
183
-
184
172
/**
185
173
* Given choices supported by a camera, chooses the smallest one whose
186
174
* width and height are at least as large as the minimum of both, or an exact match if possible.
@@ -216,6 +204,13 @@ private Camera.Size getPropPreviewSize(List<Camera.Size> choices, int minWidth,
216
204
}
217
205
}
218
206
207
+
208
+ public interface PreviewCallback {
209
+ void onGetPreviewOptimalSize (int optimalWidth , int optimalHeight );
210
+
211
+ void onPreviewFrame (byte [] data , int imageWidth , int imageHeight , int angle );
212
+ }
213
+
219
214
// Compares two size based on their areas.
220
215
static class CompareSizesByArea implements Comparator <Camera .Size > {
221
216
@ Override
0 commit comments