|
87
|
+ startCapture();
|
|
|
88
|
+ LogHelper.d("czy", "CameraService 收到开始拍摄任务");
|
|
|
89
|
+ }
|
|
|
90
|
+
|
|
82
|
91
|
}
|
|
83
|
|
- }else if(cmd == CMD_STOP_CAPTURE_PHOTO){
|
|
84
|
|
- LogHelper.d("czy","CameraService 收到结束拍摄任务");
|
|
|
92
|
+ } else if (cmd == CMD_STOP_CAPTURE_PHOTO) {
|
|
|
93
|
+ LogHelper.d("czy", "CameraService 收到结束拍摄任务");
|
|
85
|
94
|
stopCapture();
|
|
86
|
95
|
}
|
|
87
|
96
|
}
|
|
|
|
@@ -94,13 +103,14 @@ public class CameraService extends Service implements Handler.Callback, Camera.C
|
|
94
|
103
|
super.onDestroy();
|
|
95
|
104
|
}
|
|
96
|
105
|
|
|
97
|
|
- private void startCamera(Intent intent){
|
|
98
|
|
- LogHelper.d("czy","CameraService 尝试与相机建立连接");
|
|
|
106
|
+ private void startCamera(Intent intent) {
|
|
|
107
|
+ LogHelper.d("czy", "CameraService 尝试与相机建立连接");
|
|
99
|
108
|
ptp.setCameraListener(this);
|
|
100
|
109
|
ptp.initialize(this, intent);
|
|
101
|
110
|
}
|
|
102
|
|
- private void stopCamera(){
|
|
103
|
|
- LogHelper.d("czy","CameraService stopCameraService ");
|
|
|
111
|
+
|
|
|
112
|
+ private void stopCamera() {
|
|
|
113
|
+ LogHelper.d("czy", "CameraService stopCameraService ");
|
|
104
|
114
|
mainHandler.removeCallbacksAndMessages(null);
|
|
105
|
115
|
ptp.setCameraListener(null);
|
|
106
|
116
|
ptp.shutdown();
|
|
|
|
@@ -115,7 +125,7 @@ public class CameraService extends Service implements Handler.Callback, Camera.C
|
|
115
|
125
|
mainHandler.sendEmptyMessage(MSG_CHECK_STORAGE);
|
|
116
|
126
|
}
|
|
117
|
127
|
|
|
118
|
|
- public void stopCapture(){
|
|
|
128
|
+ public void stopCapture() {
|
|
119
|
129
|
mainHandler.removeCallbacksAndMessages(null);
|
|
120
|
130
|
origin = new int[0];
|
|
121
|
131
|
}
|
|
|
|
@@ -126,13 +136,13 @@ public class CameraService extends Service implements Handler.Callback, Camera.C
|
|
126
|
136
|
if (camera != null) {
|
|
127
|
137
|
mainHandler.removeMessages(MSG_CHECK_STORAGE);
|
|
128
|
138
|
camera.retrieveImageHandles(CameraService.this, 0xFFFFFFFF, PtpConstants.ObjectFormat.EXIF_JPEG);
|
|
129
|
|
- mainHandler.sendEmptyMessageDelayed(MSG_CHECK_STORAGE, Preferences.getInstance().getCameraQueryInterval());
|
|
|
139
|
+ mainHandler.sendEmptyMessageDelayed(MSG_CHECK_STORAGE, Preferences.getInstance().getCameraQueryInterval());
|
|
130
|
140
|
}
|
|
131
|
141
|
}
|
|
132
|
142
|
return false;
|
|
133
|
143
|
}
|
|
134
|
144
|
|
|
135
|
|
- private void sendCameraIntent(Bundle bundle){
|
|
|
145
|
+ private void sendCameraIntent(Bundle bundle) {
|
|
136
|
146
|
Intent intent = new Intent(ACTION_CAMERA_SERVICE_STATUS_CHANGE);
|
|
137
|
147
|
intent.putExtras(bundle);
|
|
138
|
148
|
sendBroadcast(intent);
|
|
|
|
@@ -142,9 +152,9 @@ public class CameraService extends Service implements Handler.Callback, Camera.C
|
|
142
|
152
|
@Override
|
|
143
|
153
|
public void onCameraStarted(Camera camera) {
|
|
144
|
154
|
this.camera = camera;
|
|
145
|
|
- LogHelper.d("czy","CameraService 相机初始化成功");
|
|
|
155
|
+ LogHelper.d("czy", "CameraService 相机初始化成功");
|
|
146
|
156
|
Bundle bundle = new Bundle();
|
|
147
|
|
- bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_INIT_SUCCESS);
|
|
|
157
|
+ bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_INIT_SUCCESS);
|
|
148
|
158
|
sendCameraIntent(bundle);
|
|
149
|
159
|
}
|
|
150
|
160
|
|
|
|
|
@@ -152,7 +162,7 @@ public class CameraService extends Service implements Handler.Callback, Camera.C
|
|
152
|
162
|
public void onCameraStopped(Camera camera) {
|
|
153
|
163
|
this.camera = null;
|
|
154
|
164
|
Bundle bundle = new Bundle();
|
|
155
|
|
- bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_CONN_ERROR);
|
|
|
165
|
+ bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR);
|
|
156
|
166
|
sendCameraIntent(bundle);
|
|
157
|
167
|
}
|
|
158
|
168
|
|
|
|
|
@@ -160,7 +170,7 @@ public class CameraService extends Service implements Handler.Callback, Camera.C
|
|
160
|
170
|
public void onNoCameraFound() {
|
|
161
|
171
|
this.camera = null;
|
|
162
|
172
|
Bundle bundle = new Bundle();
|
|
163
|
|
- bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_CONN_ERROR);
|
|
|
173
|
+ bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR);
|
|
164
|
174
|
sendCameraIntent(bundle);
|
|
165
|
175
|
}
|
|
166
|
176
|
|
|
|
|
@@ -168,7 +178,7 @@ public class CameraService extends Service implements Handler.Callback, Camera.C
|
|
168
|
178
|
public void onError(String message) {
|
|
169
|
179
|
camera = null;
|
|
170
|
180
|
Bundle bundle = new Bundle();
|
|
171
|
|
- bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_CONN_ERROR);
|
|
|
181
|
+ bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR);
|
|
172
|
182
|
sendCameraIntent(bundle);
|
|
173
|
183
|
}
|
|
174
|
184
|
|
|
|
|
@@ -205,8 +215,8 @@ public class CameraService extends Service implements Handler.Callback, Camera.C
|
|
205
|
215
|
@Override
|
|
206
|
216
|
public void onCapturedPictureReceived(int objectHandle, String filename, Bitmap thumbnail, Bitmap bitmap) {
|
|
207
|
217
|
|
|
208
|
|
- LogHelper.d("czy","CameraService fetchPhotoTask new photo found");
|
|
209
|
|
- saveBmpAndNotify(objectHandle,filename,bitmap);
|
|
|
218
|
+ LogHelper.d("czy", "CameraService fetchPhotoTask new photo found");
|
|
|
219
|
+ saveBmpAndNotify(objectHandle, filename, bitmap);
|
|
210
|
220
|
}
|
|
211
|
221
|
|
|
212
|
222
|
@Override
|
|
|
|
@@ -241,7 +251,7 @@ public class CameraService extends Service implements Handler.Callback, Camera.C
|
|
241
|
251
|
|
|
242
|
252
|
@Override
|
|
243
|
253
|
public void onObjectAdded(int handle) {
|
|
244
|
|
- LogHelper.d("czy","CameraService onObjectAdded: "+ handle);
|
|
|
254
|
+ LogHelper.d("czy", "CameraService onObjectAdded: " + handle);
|
|
245
|
255
|
}
|
|
246
|
256
|
|
|
247
|
257
|
@Override
|
|
|
|
@@ -261,12 +271,12 @@ public class CameraService extends Service implements Handler.Callback, Camera.C
|
|
261
|
271
|
|
|
262
|
272
|
@Override
|
|
263
|
273
|
public void onImageHandlesRetrieved(int[] handles) {
|
|
264
|
|
- LogHelper.d("czy","CameraService onImageHandlesRetrieved: "+ handles.length);
|
|
|
274
|
+ LogHelper.d("czy", "CameraService onImageHandlesRetrieved: " + handles.length);
|
|
265
|
275
|
|
|
266
|
|
- if(origin.length ==0){
|
|
|
276
|
+ if (origin.length == 0) {
|
|
267
|
277
|
origin = handles;
|
|
268
|
|
- }else{
|
|
269
|
|
- if(origin.length == handles.length){
|
|
|
278
|
+ } else {
|
|
|
279
|
+ if (origin.length == handles.length) {
|
|
270
|
280
|
return;
|
|
271
|
281
|
}
|
|
272
|
282
|
ArrayList<Integer> diff = new ArrayList<>();
|
|
|
|
@@ -282,9 +292,9 @@ public class CameraService extends Service implements Handler.Callback, Camera.C
|
|
282
|
292
|
diff.add(handles[i]);
|
|
283
|
293
|
}
|
|
284
|
294
|
}
|
|
285
|
|
- if(camera != null && diff.size() >0){
|
|
286
|
|
- for(int k = 0; k< diff.size();k++){
|
|
287
|
|
- LogHelper.d("czy","CameraService fetchPhotoTask new photo found: "+ diff.get(k));
|
|
|
295
|
+ if (camera != null && diff.size() > 0) {
|
|
|
296
|
+ for (int k = 0; k < diff.size(); k++) {
|
|
|
297
|
+ LogHelper.d("czy", "CameraService fetchPhotoTask new photo found: " + diff.get(k));
|
|
288
|
298
|
// camera.retrievePicture(diff.get(k));
|
|
289
|
299
|
}
|
|
290
|
300
|
}
|
|
|
|
@@ -297,12 +307,59 @@ public class CameraService extends Service implements Handler.Callback, Camera.C
|
|
297
|
307
|
|
|
298
|
308
|
}
|
|
299
|
309
|
|
|
300
|
|
- private void saveBmpAndNotify(int objectHandle, String filename, Bitmap bmp){
|
|
|
310
|
+ private void saveBmpAndNotify(int objectHandle, String filename, Bitmap bmp) {
|
|
|
311
|
+
|
|
|
312
|
+ new SaveBitmapTask(objectHandle, filename, bmp).execute();
|
|
|
313
|
+ }
|
|
|
314
|
+
|
|
|
315
|
+ class SaveBitmapTask extends AsyncTask<Void, Integer, Integer> {
|
|
|
316
|
+ private String filename;
|
|
|
317
|
+ private Bitmap bitmap;
|
|
|
318
|
+ private int handle;
|
|
|
319
|
+
|
|
|
320
|
+ SaveBitmapTask(int objectHandle, String filename, Bitmap bmp) {
|
|
|
321
|
+ this.filename = filename;
|
|
|
322
|
+ this.bitmap = bmp;
|
|
|
323
|
+ this.handle = objectHandle;
|
|
|
324
|
+ }
|
|
301
|
325
|
|
|
302
|
|
-// Bundle bundle = new Bundle();
|
|
303
|
|
-// bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_NEW_PHOTO_FOUND);
|
|
304
|
|
-// bundle.putString(EXTRA_DATA_PART,filename);
|
|
305
|
|
-// sendCameraIntent(bundle);
|
|
|
326
|
+ private boolean isCancelled = false;
|
|
|
327
|
+
|
|
|
328
|
+ public void cancel() {
|
|
|
329
|
+ isCancelled = true;
|
|
|
330
|
+ }
|
|
|
331
|
+
|
|
|
332
|
+ @Override
|
|
|
333
|
+ protected Integer doInBackground(Void... params) {
|
|
|
334
|
+ try {
|
|
|
335
|
+ File dir = new File(sessionDir);
|
|
|
336
|
+ if(!dir.exists()){
|
|
|
337
|
+ dir.mkdir();
|
|
|
338
|
+ }
|
|
|
339
|
+ File file = new File(dir,handle +".jpg");
|
|
|
340
|
+ FileOutputStream fos = new FileOutputStream(file);
|
|
|
341
|
+ bitmap.compress(Bitmap.CompressFormat.JPEG,100,fos);
|
|
|
342
|
+ fos.flush();
|
|
|
343
|
+ fos.close();
|
|
|
344
|
+ return 0;
|
|
|
345
|
+ } catch (Throwable t) {
|
|
|
346
|
+ t.printStackTrace();
|
|
|
347
|
+ return -1;
|
|
|
348
|
+ }
|
|
|
349
|
+ }
|
|
|
350
|
+
|
|
|
351
|
+ @Override
|
|
|
352
|
+ protected void onPostExecute(Integer result) {
|
|
|
353
|
+ if (isCancelled) {
|
|
|
354
|
+ return;
|
|
|
355
|
+ }
|
|
|
356
|
+ if (result >= 0) {
|
|
|
357
|
+ Bundle bundle = new Bundle();
|
|
|
358
|
+ bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_NEW_PHOTO_FOUND);
|
|
|
359
|
+ bundle.putString(EXTRA_DATA_PART, filename);
|
|
|
360
|
+ sendCameraIntent(bundle);
|
|
|
361
|
+ }
|
|
|
362
|
+ }
|
|
306
|
363
|
}
|
|
307
|
364
|
|
|
308
|
365
|
}
|
|
|
|
@@ -20,7 +20,6 @@ import ai.pai.lensman.dslr.CameraService;
|
|
20
|
20
|
import ai.pai.lensman.service.Constants;
|
|
21
|
21
|
|
|
22
|
22
|
import static ai.pai.lensman.dslr.CameraService.ACTION_CAMERA_SERVICE_STATUS_CHANGE;
|
|
23
|
|
-import static ai.pai.lensman.dslr.CameraService.CMD_EXIT_CAMERA_CONNECTION;
|
|
24
|
23
|
import static ai.pai.lensman.dslr.CameraService.CMD_INIT_CAMERA_CONNECTION;
|
|
25
|
24
|
import static ai.pai.lensman.dslr.CameraService.CMD_START_CAPTURE_PHOTO;
|
|
26
|
25
|
import static ai.pai.lensman.dslr.CameraService.CMD_STOP_CAPTURE_PHOTO;
|