tr class="same-code nl-2 ol-2"> 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
 }

+ 0 - 1
app/src/main/java/ai/pai/lensman/session/SessionInteractor.java

@@ -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;

Pai2/pai2 - Gogs: Go Git Service

3 Коммиты (d105aa6305a20b4b940762ac2a06ec23e482baba)

Автор SHA1 Сообщение Дата
  Brightcells 9ec76d526a TextField => CharField лет %!s(int64=8): %!d(string=назад)
  Brightcells 2181a06f23 Kodo update лет %!s(int64=8): %!d(string=назад)
  Brightcells aa31a5f59a Add kodo лет %!s(int64=8): %!d(string=назад)