OSDN Git Service

フラッシュモードとセルフタイマーの設定を変更できるようにする。
[gokigen/Gr2Control.git] / app / src / main / java / net / osdn / gokigen / gr2control / camera / fuji_x / wrapper / FujiXStatusHolder.java
1 package net.osdn.gokigen.gr2control.camera.fuji_x.wrapper;
2
3 import android.util.Log;
4 import android.util.SparseIntArray;
5
6 import androidx.annotation.NonNull;
7 import androidx.annotation.Nullable;
8 import androidx.collection.SparseArrayCompat;
9 import androidx.fragment.app.FragmentActivity;
10
11 import net.osdn.gokigen.gr2control.R;
12 import net.osdn.gokigen.gr2control.camera.ICameraStatus;
13 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.FujiXReplyMessageReceiver;
14 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.IFujiXCommandPublisher;
15 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.messages.SetPropertyValue;
16 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXBatteryMode;
17 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXCameraProperties;
18 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXFSSControl;
19 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXFilmSimulation;
20 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXFlashMode;
21 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXFocusingMode;
22 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXImageAspectMode;
23 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXImageFormatMode;
24 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXShootingMode;
25 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXTimerMode;
26 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXWhiteBalanceMode;
27 import net.osdn.gokigen.gr2control.liveview.ICameraStatusUpdateNotify;
28
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Locale;
32
33 class FujiXStatusHolder
34 {
35     private final String TAG = toString();
36     private final FragmentActivity activity;
37     private final IFujiXCommandPublisher publisher;
38     private static final boolean logcat = true;
39     private SparseIntArray statusHolder;
40     private SparseArrayCompat<String> statusNameArray;
41
42     FujiXStatusHolder(@NonNull FragmentActivity activity, @NonNull IFujiXCommandPublisher publisher)
43     {
44         statusHolder = new SparseIntArray();
45         statusHolder.clear();
46
47         this.activity = activity;
48         this.publisher = publisher;
49         statusNameArray = new SparseArrayCompat<>();
50         prepareStatusNameArray();
51     }
52
53     private void prepareStatusNameArray()
54     {
55         statusNameArray.clear();
56         statusNameArray.append(IFujiXCameraProperties.BATTERY_LEVEL, IFujiXCameraProperties.BATTERY_LEVEL_STR);
57         statusNameArray.append(IFujiXCameraProperties.WHITE_BALANCE, IFujiXCameraProperties.WHITE_BALANCE_STR);
58         statusNameArray.append(IFujiXCameraProperties.APERTURE, IFujiXCameraProperties.APERTURE_STR);
59         statusNameArray.append(IFujiXCameraProperties.FOCUS_MODE, IFujiXCameraProperties.FOCUS_MODE_STR);
60         statusNameArray.append(IFujiXCameraProperties.SHOOTING_MODE, IFujiXCameraProperties.SHOOTING_MODE_STR);
61         statusNameArray.append(IFujiXCameraProperties.FLASH, IFujiXCameraProperties.FLASH_STR);
62         statusNameArray.append(IFujiXCameraProperties.EXPOSURE_COMPENSATION, IFujiXCameraProperties.EXPOSURE_COMPENSATION_STR);
63         statusNameArray.append(IFujiXCameraProperties.SELF_TIMER, IFujiXCameraProperties.SELF_TIMER_STR);
64         statusNameArray.append(IFujiXCameraProperties.FILM_SIMULATION, IFujiXCameraProperties.FILM_SIMULATION_STR);
65         statusNameArray.append(IFujiXCameraProperties.IMAGE_FORMAT, IFujiXCameraProperties.IMAGE_FORMAT_STR);
66         statusNameArray.append(IFujiXCameraProperties.RECMODE_ENABLE, IFujiXCameraProperties.RECMODE_ENABLE_STR);
67         statusNameArray.append(IFujiXCameraProperties.F_SS_CONTROL, IFujiXCameraProperties.F_SS_CONTROL_STR);
68         statusNameArray.append(IFujiXCameraProperties.ISO, IFujiXCameraProperties.ISO_STR);
69         statusNameArray.append(IFujiXCameraProperties.MOVIE_ISO, IFujiXCameraProperties.MOVIE_ISO_STR);
70         statusNameArray.append(IFujiXCameraProperties.FOCUS_POINT, IFujiXCameraProperties.FOCUS_POINT_STR);
71         statusNameArray.append(IFujiXCameraProperties.DEVICE_ERROR, IFujiXCameraProperties.DEVICE_ERROR_STR);
72         statusNameArray.append(IFujiXCameraProperties.IMAGE_FILE_COUNT, IFujiXCameraProperties.IMAGE_FILE_COUNT_STR);
73         statusNameArray.append(IFujiXCameraProperties.SDCARD_REMAIN_SIZE, IFujiXCameraProperties.SDCARD_REMAIN_SIZE_STR);
74         statusNameArray.append(IFujiXCameraProperties.FOCUS_LOCK, IFujiXCameraProperties.FOCUS_LOCK_STR);
75         statusNameArray.append(IFujiXCameraProperties.MOVIE_REMAINING_TIME, IFujiXCameraProperties.MOVIE_REMAINING_TIME_STR);
76         statusNameArray.append(IFujiXCameraProperties.SHUTTER_SPEED, IFujiXCameraProperties.SHUTTER_SPEED_STR);
77         statusNameArray.append(IFujiXCameraProperties.IMAGE_ASPECT, IFujiXCameraProperties.IMAGE_ASPECT_STR);
78         statusNameArray.append(IFujiXCameraProperties.BATTERY_LEVEL_2, IFujiXCameraProperties.BATTERY_LEVEL_2_STR);
79         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_DF00, IFujiXCameraProperties.UNKNOWN_DF00_STR);
80         statusNameArray.append(IFujiXCameraProperties.PICTURE_JPEG_COUNT, IFujiXCameraProperties.PICTURE_JPEG_COUNT_STR);
81         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_D400, IFujiXCameraProperties.UNKNOWN_D400_STR);
82         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_D401, IFujiXCameraProperties.UNKNOWN_D401_STR);
83         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_D52F, IFujiXCameraProperties.UNKNOWN_D52F_STR);
84         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_D245, IFujiXCameraProperties.UNKNOWN_D245_STR);
85         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_DF41, IFujiXCameraProperties.UNKNOWN_DF41_STR);
86         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_DF26, IFujiXCameraProperties.UNKNOWN_DF26_STR);
87         statusNameArray.append(IFujiXCameraProperties.UNKNOWN_DF27, IFujiXCameraProperties.UNKNOWN_DF27_STR);
88     }
89
90     void updateValue(@Nullable ICameraStatusUpdateNotify notifier, int id, byte data0, byte data1, byte data2, byte data3)
91     {
92         try
93         {
94             int value = ((((int) data3) & 0xff) << 24) + ((((int) data2) & 0xff) << 16) + ((((int) data1) & 0xff) << 8) + (((int) data0) & 0xff);
95             int currentValue = statusHolder.get(id, -1);
96             //logcat(String.format(Locale.US, " STATUS [id: 0x%04x] 0x%08x(%d) -> 0x%08x(%d)", id, currentValue, currentValue, value, value));
97             if ((notifier != null) && (currentValue != value))
98             {
99                 statusHolder.put(id, value);
100                 //logcat(String.format(Locale.US," STATUS UPDATE [id: 0x%04x] 0x%08x(%d) -> 0x%08x(%d)", id, currentValue, currentValue, value, value));
101                 updateDetected(notifier, id, currentValue, value);
102             }
103         }
104         catch (Exception e)
105         {
106             e.printStackTrace();
107         }
108     }
109
110     private void updateDetected(@NonNull ICameraStatusUpdateNotify notifier, int id, int previous, int current)
111     {
112         try
113         {
114             //String idName = statusNameArray.get(id, "Unknown");
115             //logcat(String.format(Locale.US, " << UPDATE STATUS >> id: 0x%04x[%s] 0x%08x(%d) -> 0x%08x(%d)", id, idName, previous, previous, current, current));
116             switch (id)
117             {
118                 case IFujiXCameraProperties.FOCUS_LOCK:
119                     updateFocusedStatus(notifier, previous, current);
120                     break;
121                 case IFujiXCameraProperties.SHOOTING_MODE:
122                     updatedTakeMode(notifier, previous, current);
123                     break;
124                 case IFujiXCameraProperties.BATTERY_LEVEL:
125                 case IFujiXCameraProperties.BATTERY_LEVEL_2:
126                     updateBatteryLevel(notifier, previous, current);
127                     break;
128                 case IFujiXCameraProperties.FOCUS_MODE:
129                     updateFocusMode(notifier, previous, current);
130                     break;
131                 case IFujiXCameraProperties.APERTURE:
132                     updateAperture(notifier, previous, current);
133                     break;
134                 case IFujiXCameraProperties.SHUTTER_SPEED:
135                     updateShutterSpeed(notifier, previous, current);
136                     break;
137                 case IFujiXCameraProperties.WHITE_BALANCE:
138                     updateWhiteBalance(notifier, previous, current);
139                     break;
140                 case IFujiXCameraProperties.EXPOSURE_COMPENSATION:
141                     updateExposureCompensation(notifier, previous, current);
142                     break;
143                 case IFujiXCameraProperties.ISO:
144                     updateIsoSensitivity(notifier, previous, current);
145                     break;
146                 case IFujiXCameraProperties.DEVICE_ERROR:
147                     updateDeviceError(notifier, previous, current);
148                     break;
149                 case IFujiXCameraProperties.SELF_TIMER:
150                     updateSelfTimer(notifier, previous, current);
151                     break;
152                 case IFujiXCameraProperties.SDCARD_REMAIN_SIZE:
153                     updateSdCardRemainSize(notifier, previous, current);
154                     break;
155                 case IFujiXCameraProperties.MOVIE_REMAINING_TIME:
156                     updateMovieRemainTime(notifier, previous, current);
157                     break;
158                 case IFujiXCameraProperties.FOCUS_POINT:
159                     updateFocusPoint(notifier, previous, current);
160                     break;
161                 case IFujiXCameraProperties.F_SS_CONTROL:
162                     updateFSSControl(notifier, previous, current);
163                     break;
164                 case IFujiXCameraProperties.IMAGE_ASPECT:
165                     updateImageAspect(notifier, previous, current);
166                     break;
167                 case IFujiXCameraProperties.FILM_SIMULATION:
168                     updateFilmSimulation(notifier, previous, current);
169                     break;
170                 case IFujiXCameraProperties.FLASH:
171                     updateFlashMode(notifier, previous, current);
172                     break;
173                 case IFujiXCameraProperties.IMAGE_FORMAT:
174                     updateImageFormat(notifier, previous, current);
175                     break;
176                 case IFujiXCameraProperties.UNKNOWN_D245:
177                 case IFujiXCameraProperties.UNKNOWN_DF41:
178                 case IFujiXCameraProperties.UNKNOWN_DF26:
179                 case IFujiXCameraProperties.UNKNOWN_DF27:
180                 default:
181                     updateUnknownValue(id, previous, current);
182                     break;
183             }
184         }
185         catch (Exception e)
186         {
187             e.printStackTrace();
188         }
189     }
190
191     private void updateImageFormat(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
192     {
193         String value;
194         switch (current)
195         {
196             case IFujiXImageFormatMode.IMAGE_FORMAT_RAW:
197                 value = "RAW";
198                 break;
199             case IFujiXImageFormatMode.IMAGE_FORMAT_FINE:
200                 value = "FINE";
201                 break;
202             case IFujiXImageFormatMode.IMAGE_FORMAT_NORMAL:
203                 value = "NORMAL";
204                 break;
205             case IFujiXImageFormatMode.IMAGE_FORMAT_FINE_RAW:
206                 value = "RAW+F";
207                 break;
208             case IFujiXImageFormatMode.IMAGE_FORMAT_NORMAL_RAW:
209                 value = "RAW+N";
210                 break;
211             default:
212                 value = "UNKNOWN : " + current;
213                 break;
214         }
215         logcat(" Image Format : " + value);
216     }
217
218     private void updateFlashMode(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
219     {
220         String value;
221         switch (current)
222         {
223             case IFujiXFlashMode.FLASH_AUTO:
224                 value = "AUTO";
225                 break;
226             case IFujiXFlashMode.FLASH_OFF:
227                 value = "OFF";
228                 break;
229             case IFujiXFlashMode.FLASH_FILL:
230                 value = "FILL";
231                 break;
232             case IFujiXFlashMode.FLASH_REDEYE_AUTO:
233                 value = "REDEYE_AUTO";
234                 break;
235             case IFujiXFlashMode.FLASH_REDEYE_FILL:
236                 value = "REDEYE_FILL";
237                 break;
238             case IFujiXFlashMode.FLASH_EXTERNAL_SYNC:
239                 value = "EXTERNAL_SYNC";
240                 break;
241             case IFujiXFlashMode.FLASH_ON:
242                 value = "ON";
243                 break;
244             case IFujiXFlashMode.FLASH_REDEYE:
245                 value = "REDEYE";
246                 break;
247             case IFujiXFlashMode.FLASH_REDEYE_ON:
248                 value = "REDEYE_ON";
249                 break;
250             case IFujiXFlashMode.FLASH_REDEYE_SYNC:
251                 value = "REDEYE_SYNC";
252                 break;
253             case IFujiXFlashMode.FLASH_REDEYE_REAR:
254                 value = "REDEYE_REAR";
255                 break;
256             case IFujiXFlashMode.FLASH_SLOW_SYNC:
257                 value = "SLOW_SYNC";
258                 break;
259             case IFujiXFlashMode.FLASH_REAR_SYNC:
260                 value = "REAR_SYNC";
261                 break;
262             case IFujiXFlashMode.FLASH_COMMANDER:
263                 value = "COMMANDER";
264                 break;
265             case IFujiXFlashMode.FLASH_DISABLE:
266                 value = "DISABLE";
267                 break;
268             case IFujiXFlashMode.FLASH_ENABLE:
269                 value = "ENABLE";
270                 break;
271             default:
272                 value = " UNKNOWN : " + current;
273                 break;
274         }
275         logcat(" FLASH MODE : " + value);
276     }
277
278     private void updateFilmSimulation(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
279     {
280         String value;
281         switch (current)
282         {
283             case IFujiXFilmSimulation.FILM_SIMULATION_PROVIA:
284                 value = IFujiXFilmSimulation.FILM_SIMULATION_PROVIA_STR;
285                 break;
286             case IFujiXFilmSimulation.FILM_SIMULATION_VELVIA:
287                 value = IFujiXFilmSimulation.FILM_SIMULATION_VELVIA_STR;
288                 break;
289             case IFujiXFilmSimulation.FILM_SIMULATION_ASTIA:
290                 value = IFujiXFilmSimulation.FILM_SIMULATION_ASTIA_STR;
291                 break;
292             case IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME:
293                 value = IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_STR;
294                 break;
295             case IFujiXFilmSimulation.FILM_SIMULATION_SEPIA:
296                 value = IFujiXFilmSimulation.FILM_SIMULATION_SEPIA_STR;
297                 break;
298             case IFujiXFilmSimulation.FILM_SIMULATION_PRO_NEG_HI:
299                 value = IFujiXFilmSimulation.FILM_SIMULATION_PRO_NEG_HI_STR;
300                 break;
301             case IFujiXFilmSimulation.FILM_SIMULATION_PRO_NEG_STD:
302                 value = IFujiXFilmSimulation.FILM_SIMULATION_PRO_NEG_STD_STR;
303                 break;
304             case IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_Y_FILTER:
305                 value = IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_Y_FILTER_STR;
306                 break;
307             case IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_R_FILTER:
308                 value = IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_R_FILTER_STR;
309                 break;
310             case IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_G_FILTER:
311                 value = IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_G_FILTER_STR;
312                 break;
313             case IFujiXFilmSimulation.FILM_SIMULATION_CLASSIC_CHROME:
314                 value = IFujiXFilmSimulation.FILM_SIMULATION_CLASSIC_CHROME_STR;
315                 break;
316             case IFujiXFilmSimulation.FILM_SIMULATION_ACROS:
317                 value = IFujiXFilmSimulation.FILM_SIMULATION_ACROS_STR;
318                 break;
319             case IFujiXFilmSimulation.FILM_SIMULATION_ACROS_Y:
320                 value = IFujiXFilmSimulation.FILM_SIMULATION_ACROS_Y_STR;
321                 break;
322             case IFujiXFilmSimulation.FILM_SIMULATION_ACROS_R:
323                 value = IFujiXFilmSimulation.FILM_SIMULATION_ACROS_R_STR;
324                 break;
325             case IFujiXFilmSimulation.FILM_SIMULATION_ACROS_G:
326                 value = IFujiXFilmSimulation.FILM_SIMULATION_ACROS_G_STR;
327                 break;
328             case IFujiXFilmSimulation.FILM_SIMULATION_ETERNA:
329                 value = IFujiXFilmSimulation.FILM_SIMULATION_ETERNA_STR;
330                 break;
331             case IFujiXFilmSimulation.FILM_SIMULATION_CLASSIC_NEGATIVE:
332                 value = IFujiXFilmSimulation.FILM_SIMULATION_CLASSIC_NEGATIVE_STR;
333                 break;
334             case IFujiXFilmSimulation.FILM_SIMULATION_ETERNA_BLEACH_BYPASS:
335                 value = IFujiXFilmSimulation.FILM_SIMULATION_ETERNA_BLEACH_BYPASS_STR;
336                 break;
337             default:
338                 value = "??? " + current;
339                 break;
340         }
341         logcat(" FILM SIMULATION : " + value);
342     }
343
344     private void updateImageAspect(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
345     {
346         String value;
347         switch (current)
348         {
349             case IFujiXImageAspectMode.IMAGE_ASPECT_S_3x2:
350               value = "S:3x2";
351               break;
352             case IFujiXImageAspectMode.IMAGE_ASPECT_S_16x9:
353               value = "S:16x9";
354               break;
355             case IFujiXImageAspectMode.IMAGE_ASPECT_S_1x1:
356               value = "S:1x1";
357               break;
358             case IFujiXImageAspectMode.IMAGE_ASPECT_M_3x2:
359                 value = "M:3x2";
360                 break;
361             case IFujiXImageAspectMode.IMAGE_ASPECT_M_16x9:
362                 value = "M:16x9";
363                 break;
364             case IFujiXImageAspectMode.IMAGE_ASPECT_M_1x1:
365                 value = "M:1x1";
366                 break;
367             case IFujiXImageAspectMode.IMAGE_ASPECT_L_3x2:
368                 value = "L:3x2";
369                 break;
370             case IFujiXImageAspectMode.IMAGE_ASPECT_L_16x9:
371                 value = "L:16x9";
372                 break;
373             case IFujiXImageAspectMode.IMAGE_ASPECT_L_1x1:
374                 value = "L:1x1";
375                 break;
376             default:
377                 value = "? " + current;
378                 break;
379         }
380         logcat(" Image Aspect : " + value);
381     }
382
383
384     private void updateFSSControl(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
385     {
386         String value;
387         switch (current)
388         {
389             case IFujiXFSSControl.F_SS_CTRL_BOTH:
390                 value = "BOTH";
391                 break;
392             case IFujiXFSSControl.F_SS_CTRL_F:
393                 value = "F";
394                 break;
395             case IFujiXFSSControl.F_SS_CTRL_SS:
396                 value = "SS";
397                 break;
398             case IFujiXFSSControl.F_SS_CTRL_NONE:
399                 value = "NONE";
400                 break;
401             default:
402                 value = "? " + current;
403                 break;
404         }
405         logcat(" F_SS : " + value);
406     }
407
408     private void updateUnknownValue(int id, int previous, int current)
409     {
410         logcat(String.format(Locale.US,"<< UPDATE UNKNOWN STATUS >> id: 0x%04x 0x%08x(%d) -> 0x%08x(%d)", id, previous, previous, current, current));
411     }
412
413     private void updateFocusPoint(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
414     {
415         logcat(String.format(Locale.ENGLISH, " Focus Point : %x ", current));
416     }
417
418     private void updateMovieRemainTime(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
419     {
420         logcat(" MOVIE REMAIN : " + current);
421     }
422
423     private void updateSdCardRemainSize(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
424     {
425         logcat(" SDCARD REMAIN : " + current);
426     }
427
428     private void updateSelfTimer(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
429     {
430         int value = -1;
431         try
432         {
433             switch (current)
434             {
435                 case IFujiXTimerMode.TIMER_OFF:
436                     value = 0;
437                     break;
438
439                 case IFujiXTimerMode.TIMER_1SEC:
440                     value = 1;
441                     break;
442
443                 case IFujiXTimerMode.TIMER_2SEC:
444                     value = 2;
445                     break;
446
447                 case IFujiXTimerMode.TIMER_5SEC:
448                     value = 5;
449                     break;
450
451                 case IFujiXTimerMode.TIMER_10SEC:
452                     value = 10;
453                     break;
454
455                 default:
456                     break;
457             }
458         }
459         catch (Exception e)
460         {
461             e.printStackTrace();
462         }
463         if (value <= 0)
464         {
465             logcat(" SELF TIMER IS OFF (" + value + ")");
466         }
467         else
468         {
469             logcat(" SELF TIMER IS " + value + " sec.");
470         }
471     }
472
473     private void updateDeviceError(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
474     {
475         if (current != 0)
476         {
477             notifier.updateWarning("ERROR " + current);
478         }
479     }
480
481     private void updateIsoSensitivity(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
482     {
483         String iso = "";
484         try
485         {
486             int isoValue = (0x0000ffff & current);
487             if ((0xffff0000 & current) != 0)
488             {
489                 iso = "AUTO_" + isoValue;
490             }
491             else if (isoValue > 12800)
492             {
493                 iso = "H" + isoValue;
494
495             }
496             else if (isoValue < 200)
497             {
498                 iso = "L" + isoValue;
499             }
500             else
501             {
502                 iso = "" + isoValue;
503             }
504         }
505         catch (Exception e)
506         {
507             e.printStackTrace();
508         }
509         logcat(" ISO SENSITIVITY : " + iso);
510         notifier.updateIsoSensitivity(iso);
511     }
512
513     private void updateExposureCompensation(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
514     {
515         String exposureCompensation = "";
516         try
517         {
518             float value = ((float) current / 1000.0f);
519             exposureCompensation = String.format(Locale.ENGLISH, "%+1.1f", value);
520         }
521         catch (Exception e)
522         {
523             e.printStackTrace();
524         }
525         notifier.updatedExposureCompensation(exposureCompensation);
526     }
527
528     private void updateWhiteBalance(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
529     {
530         String value = "";
531         try
532         {
533             switch (current)
534             {
535                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_AUTO:
536                     value = "Auto";
537                     break;
538                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_FINE:
539                     value = "Fine";
540                     break;
541                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_INCANDESCENT:
542                     value = "Incandescent";
543                     break;
544                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_FLUORESCENT_1:
545                     value = "Fluorescent 1";
546                     break;
547                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_FLUORESCENT_2:
548                     value = "Fluorescent 2";
549                     break;
550                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_FLUORESCENT_3:
551                     value = "Fluorescent 3";
552                     break;
553                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_SHADE:
554                     value = "Shade";
555                     break;
556                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_UNDERWATER:
557                     value = "Underwater";
558                     break;
559                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_TEMPERATURE:
560                     value = "Kelvin";
561                     break;
562                 case IFujiXWhiteBalanceMode.WHITE_BALANCE_CUSTOM:
563                     value = "Custom";
564                     break;
565                 default:
566                     value = "Unknown";
567                     break;
568             }
569         }
570         catch (Exception e)
571         {
572             e.printStackTrace();
573         }
574         notifier.updatedWBMode(value);
575     }
576
577     private void updateShutterSpeed(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
578     {
579         String shutterSpeed = "--";
580         try
581         {
582             if ((0x80000000 & current) != 0)
583             {
584                 int value = 0x0fffffff & current;
585                 shutterSpeed = ("1/" + (value / 1000));
586             }
587             else
588             {
589                 shutterSpeed = (current + "");
590             }
591         }
592         catch (Exception e)
593         {
594             e.printStackTrace();
595         }
596         notifier.updatedShutterSpeed(shutterSpeed);
597     }
598
599     private void updateAperture(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
600     {
601         String aperature = "---";
602         try
603         {
604             float value = ((float) current / 100.0f);
605             aperature = String.format(Locale.ENGLISH, "%1.1f", value);
606         }
607         catch (Exception e)
608         {
609             e.printStackTrace();
610         }
611         notifier.updatedAperture(aperature);
612     }
613
614     private void updateFocusMode(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
615     {
616         String mode = "";
617
618         // Focus Mode
619         if (current == IFujiXFocusingMode.FOCUS_MANUAL)
620         {
621             mode = "MF";
622         }
623         else if (current == IFujiXFocusingMode.FOCUS_CONTINUOUS_AUTO)
624         {
625             mode = "AF-C";
626         }
627         else if (current == IFujiXFocusingMode.FOCUS_SINGLE_AUTO)
628         {
629             mode = "AF-S";
630         }
631         else
632         {
633             mode = mode + current;
634         }
635         logcat(" Focus Mode : " + mode);
636     }
637
638     private void updateFocusedStatus(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
639     {
640         if (current == 1)
641         {
642             // focus Lock
643             notifier.updateFocusedStatus(true, true);
644         }
645         else
646         {
647             // focus unlock
648             notifier.updateFocusedStatus(false, false);
649         }
650     }
651
652     private void updatedTakeMode(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
653     {
654         String mode = "";
655         switch (current)
656         {
657             case IFujiXShootingMode.SHOOTING_MANUAL:
658                 mode = "M";
659                 break;
660             case IFujiXShootingMode.SHOOTING_PROGRAM:
661                 mode = "P";
662                 break;
663             case IFujiXShootingMode.SHOOTING_APERTURE:
664                 mode = "A";
665                 break;
666             case IFujiXShootingMode.SHOOTING_SHUTTER:
667                 mode = "S";
668                 break;
669             case IFujiXShootingMode.SHOOTING_CUSTOM:
670                 mode = "C";
671                 break;
672             case IFujiXShootingMode.SHOOTING_AUTO:
673                 mode = "a";
674                 break;
675             default:
676                 mode = mode + current;
677                 break;
678         }
679         notifier.updatedTakeMode(mode);
680     }
681
682     private void updateBatteryLevel(@NonNull ICameraStatusUpdateNotify notifier, int previous, int current)
683     {
684         int level;
685         if ((current == IFujiXBatteryMode.BATTERY_CRITICAL) || (current == IFujiXBatteryMode.BATTERY_126S_CRITICAL))
686         {
687             level = 0;
688         }
689         else if (current == IFujiXBatteryMode.BATTERY_126S_ONE_BAR)
690         {
691             level = 20;
692         }
693         else if ((current == IFujiXBatteryMode.BATTERY_ONE_BAR) || (current == IFujiXBatteryMode.BATTERY_126S_TWO_BAR))
694         {
695             level = 40;
696         }
697         else if (current == IFujiXBatteryMode.BATTERY_126S_THREE_BAR)
698         {
699             level = 60;
700         }
701         else if ((current == IFujiXBatteryMode.BATTERY_TWO_BAR) || (current == IFujiXBatteryMode.BATTERY_126S_FOUR_BAR))
702         {
703             level = 80;
704         }
705         else // if ((current == IFujiXBatteryMode.BATTERY_FULL) || (current == IFujiXBatteryMode.BATTERY_126S_FULL))
706         {
707             level = 100;
708         }
709         notifier.updateRemainBattery(level);
710     }
711
712
713     /**
714      *   認識したカメラのステータス名称のリストを応答する
715      *
716      */
717     private List<String> getAvailableStatusNameList()
718     {
719         ArrayList<String> selection = new ArrayList<>();
720         try
721         {
722             for (int index = 0; index < statusHolder.size(); index++)
723             {
724                 int key = statusHolder.keyAt(index);
725                 selection.add(statusNameArray.get(key, String.format(Locale.US, "0x%04x", key)));
726             }
727         }
728         catch (Exception e)
729         {
730             e.printStackTrace();
731         }
732         return (selection);
733
734     }
735
736     List<String> getAvailableItemList(String listKey)
737     {
738         if ((listKey == null)||(listKey.isEmpty()))
739         {
740             // アイテム名の一覧を応答する
741             return (getAvailableStatusNameList());
742         }
743         if (listKey.matches(ICameraStatus.EFFECT))
744         {
745             return (getAvailableEffectItemList());
746         }
747         if (listKey.matches(ICameraStatus.AE))
748         {
749             return (new ArrayList<>());
750         }
751         if (listKey.matches(ICameraStatus.WHITE_BALANCE))
752         {
753             return (getAvailableResourceArrayItemList(R.array.fuji_x_white_balance));
754         }
755         if (listKey.matches(ICameraStatus.ISO_SENSITIVITY))
756         {
757             return (getAvailableResourceArrayItemList(R.array.fuji_x_iso_sensitivity));
758         }
759         if (listKey.matches(ICameraStatus.FLASH_XV))
760         {
761             return (getAvailableResourceArrayItemList(R.array.fuji_x_flash_control));
762         }
763         if (listKey.matches(ICameraStatus.SELF_TIMER))
764         {
765             return (getAvailableResourceArrayItemList(R.array.fuji_x_timer_control));
766         }
767
768         /////  選択可能なステータスの一覧を取得する : でも以下はアイテム名の一覧... /////
769         /*
770         ArrayList<String> selection = new ArrayList<>();
771         try
772         {
773             for (int index = 0; index < statusHolder.size(); index++)
774             {
775                 int key = statusHolder.keyAt(index);
776                 selection.add(statusNameArray.get(key));
777             }
778         }
779         catch (Exception e)
780         {
781             e.printStackTrace();
782         }
783         */
784         return (new ArrayList<>());
785     }
786
787     private List<String> getAvailableEffectItemList()
788     {
789         // EFFECTの選択肢をリストにして返す  : Film Simulation にした。
790         ArrayList<String> selection = new ArrayList<>();
791         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_PROVIA_STR);
792         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_VELVIA_STR);
793         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_ASTIA_STR);
794         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_STR);
795         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_SEPIA_STR);
796         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_PRO_NEG_HI_STR);
797         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_PRO_NEG_STD_STR);
798         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_Y_FILTER_STR);
799         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_R_FILTER_STR);
800         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_MONOCHROME_G_FILTER_STR);
801         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_CLASSIC_CHROME_STR);
802         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_ACROS_STR);
803         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_ACROS_Y_STR);
804         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_ACROS_R_STR);
805         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_ACROS_G_STR);
806         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_ETERNA_STR);
807         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_CLASSIC_NEGATIVE_STR);
808         selection.add(IFujiXFilmSimulation.FILM_SIMULATION_ETERNA_BLEACH_BYPASS_STR);
809         return(selection);
810     }
811
812     private List<String> getAvailableResourceArrayItemList(int id)
813     {
814         // リソースのの選択肢をリストにして返す
815         ArrayList<String> selection = new ArrayList<>();
816
817         String[] items = activity.getResources().getStringArray(id);
818         for (String item : items)
819         {
820             Log.v(TAG, " SELECTION : " + item);
821             selection.add(item);
822         }
823         return (selection);
824     }
825
826     private String getCurrentEffectStatus()
827     {
828         // EFFECTの現在状態を応答する : FILM Simulationにした
829         try
830         {
831             int value = statusHolder.get(IFujiXCameraProperties.FILM_SIMULATION);
832             List<String> itemList = getAvailableEffectItemList();
833             if ((value >= IFujiXFilmSimulation.FILM_SIMULATION_MIN)&&(value < itemList.size()))
834             {
835                 return (itemList.get(value - 1));
836             }
837         }
838         catch (Exception e)
839         {
840             e.printStackTrace();
841         }
842         return ("");
843     }
844
845     private String getCurrentWhiteBalanceStatus()
846     {
847         // White Balanceの現在状態を取得する
848         try
849         {
850             int value = statusHolder.get(IFujiXCameraProperties.WHITE_BALANCE);
851             String[] items = activity.getResources().getStringArray(R.array.fuji_x_white_balance);
852             String[] itemValues = activity.getResources().getStringArray(R.array.fuji_x_white_balance_value);
853             int index = 0;
854             for (String itemValue : itemValues)
855             {
856                 int itemValueInt = Integer.parseInt(itemValue);
857                 if (itemValueInt == value)
858                 {
859                     return (items[index]);
860                 }
861                 index++;
862             }
863         }
864         catch (Exception e)
865         {
866             e.printStackTrace();
867         }
868         return ("");
869     }
870
871     private String getCurrentIsoSensitivityStatus()
872     {
873         String iso = "";
874         try
875         {
876             int current = statusHolder.get(IFujiXCameraProperties.ISO);
877             int isoValue = (0x0000ffff & current);
878             if ((0xffff0000 & current) != 0)
879             {
880                 iso = "AUTO_" + isoValue;
881             }
882             else if (isoValue > 12800)
883             {
884                 iso = "H" + isoValue;
885
886             }
887             else if (isoValue < 200)
888             {
889                 iso = "L" + isoValue;
890             }
891             else
892             {
893                 iso = "" + isoValue;
894             }
895         }
896         catch (Exception e)
897         {
898             e.printStackTrace();
899         }
900         logcat(" ISO SENSITIVITY : " + iso);
901         return (iso);
902     }
903
904     private String getCurrentFlashStatus()
905     {
906         String flash = "";
907         try
908         {
909             int current = statusHolder.get(IFujiXCameraProperties.FLASH);
910             String[] items = activity.getResources().getStringArray(R.array.fuji_x_flash_control);
911             String[] itemValues = activity.getResources().getStringArray(R.array.fuji_x_flash_control_value);
912             int index = 0;
913             for (String itemValue : itemValues)
914             {
915                 int itemValueInt = Integer.parseInt(itemValue, 16);
916                 if (itemValueInt == current)
917                 {
918                     return (items[index]);
919                 }
920                 index++;
921             }
922         }
923         catch (Exception e)
924         {
925             e.printStackTrace();
926         }
927         return (flash);
928     }
929
930     private String getCurrentSelfTimerStatus()
931     {
932         String selfTimer = "";
933         try
934         {
935             int current = statusHolder.get(IFujiXCameraProperties.SELF_TIMER);
936             String[] items = activity.getResources().getStringArray(R.array.fuji_x_timer_control);
937             String[] itemValues = activity.getResources().getStringArray(R.array.fuji_x_timer_control_value);
938             int index = 0;
939             for (String itemValue : itemValues)
940             {
941                 int itemValueInt = Integer.parseInt(itemValue, 16);
942                 if (itemValueInt == current)
943                 {
944                     return (items[index]);
945                 }
946                 index++;
947             }
948         }
949         catch (Exception e)
950         {
951             e.printStackTrace();
952         }
953         return (selfTimer);
954     }
955
956     private void setEffectItem(String value)
957     {
958         try
959         {
960             int index = 1;
961             List<String> itemList = getAvailableEffectItemList();
962             for (String item : itemList)
963             {
964                 if (item.matches(value))
965                 {
966                     //  見つかった! この値に設定する
967                     publisher.enqueueCommand(new SetPropertyValue(new FujiXReplyMessageReceiver(" Set Film Simulation", true), IFujiXCameraProperties.FILM_SIMULATION, 4, index));
968                     return;
969                 }
970                 index++;
971             }
972         }
973         catch (Exception e)
974         {
975             e.printStackTrace();
976         }
977     }
978
979     private void setCurrentWhiteBalanceStatus(String value)
980     {
981         // White Balanceを設定する
982         try
983         {
984             String[] items = activity.getResources().getStringArray(R.array.fuji_x_white_balance);
985             String[] itemValues = activity.getResources().getStringArray(R.array.fuji_x_white_balance_value);
986             int index = 0;
987             for (String item : items)
988             {
989                 if (item.matches(value))
990                 {
991                     // 見つかった! この値を設定する
992                     String itemValue = itemValues[index];
993                     int itemValueInt = Integer.parseInt(itemValue);
994                     publisher.enqueueCommand(new SetPropertyValue(new FujiXReplyMessageReceiver(" Set White Balance", true), IFujiXCameraProperties.WHITE_BALANCE, 4, itemValueInt));
995                     return;
996                 }
997                 index++;
998             }
999         }
1000         catch (Exception e)
1001         {
1002             e.printStackTrace();
1003         }
1004     }
1005
1006     private void setCurrentIsoSensitivityStatus(String value)
1007     {
1008         // ISO感度を設定する
1009         try
1010         {
1011             String[] items = activity.getResources().getStringArray(R.array.fuji_x_iso_sensitivity);
1012             String[] itemValues = activity.getResources().getStringArray(R.array.fuji_x_iso_sensitivity_value);
1013             int index = 0;
1014             for (String item : items)
1015             {
1016                 //Log.v(TAG, " ===== ISO : " + value + " " + item + " ===== ");
1017                 if (item.matches(value))
1018                 {
1019                     // 見つかった! この値を設定する
1020                     String itemValue = itemValues[index];
1021                     int itemValueInt = (int) Long.parseLong(itemValue,16);
1022                     logcat(" SET ISO SENSITIVITY : " + value + " " + itemValueInt);
1023                     publisher.enqueueCommand(new SetPropertyValue(new FujiXReplyMessageReceiver(" Set ISO", true), IFujiXCameraProperties.ISO, 4, itemValueInt));
1024                     return;
1025                 }
1026                 index++;
1027             }
1028         }
1029         catch (Exception e)
1030         {
1031             e.printStackTrace();
1032         }
1033     }
1034
1035     private void setCurrentFlashStatus(String value)
1036     {
1037         // ISO感度を設定する
1038         try
1039         {
1040             String[] items = activity.getResources().getStringArray(R.array.fuji_x_flash_control);
1041             String[] itemValues = activity.getResources().getStringArray(R.array.fuji_x_flash_control_value);
1042             int index = 0;
1043             for (String item : items)
1044             {
1045                 Log.v(TAG, " ===== FLASH : " + value + " " + item + " ===== ");
1046                 if (item.matches(value))
1047                 {
1048                     // 見つかった! この値を設定する
1049                     String itemValue = itemValues[index];
1050                     int itemValueInt = (int) Long.parseLong(itemValue,16);
1051                     logcat(" SET FLASH : " + value + " " + itemValueInt);
1052                     publisher.enqueueCommand(new SetPropertyValue(new FujiXReplyMessageReceiver(" Set FLASH", true), IFujiXCameraProperties.FLASH, 4, itemValueInt));
1053                     return;
1054                 }
1055                 index++;
1056             }
1057         }
1058         catch (Exception e)
1059         {
1060             e.printStackTrace();
1061         }
1062     }
1063
1064     private void setSelfTimerStatus(String value)
1065     {
1066         // セルフタイマーを設定する
1067         try
1068         {
1069             String[] items = activity.getResources().getStringArray(R.array.fuji_x_timer_control);
1070             String[] itemValues = activity.getResources().getStringArray(R.array.fuji_x_timer_control_value);
1071             int index = 0;
1072             for (String item : items)
1073             {
1074                 Log.v(TAG, " ===== SELF-TIMER : " + value + " " + item + " ===== ");
1075                 if (item.matches(value))
1076                 {
1077                     // 見つかった! この値を設定する
1078                     String itemValue = itemValues[index];
1079                     int itemValueInt = (int) Long.parseLong(itemValue,16);
1080                     logcat(" SET SELF-TIMER : " + value + " " + itemValueInt);
1081                     publisher.enqueueCommand(new SetPropertyValue(new FujiXReplyMessageReceiver(" Set SELF-TIMER", true), IFujiXCameraProperties.SELF_TIMER, 4, itemValueInt));
1082                     return;
1083                 }
1084                 index++;
1085             }
1086         }
1087         catch (Exception e)
1088         {
1089             e.printStackTrace();
1090         }
1091     }
1092
1093     String getItemStatus(String key)
1094     {
1095         if (key.matches(ICameraStatus.EFFECT))
1096         {
1097             return (getCurrentEffectStatus());
1098         }
1099         if (key.matches(ICameraStatus.WHITE_BALANCE))
1100         {
1101             return (getCurrentWhiteBalanceStatus());
1102         }
1103         if (key.matches(ICameraStatus.ISO_SENSITIVITY))
1104         {
1105             return (getCurrentIsoSensitivityStatus());
1106         }
1107         if (key.matches(ICameraStatus.FLASH_XV))
1108         {
1109             return (getCurrentFlashStatus());
1110         }
1111         if (key.matches(ICameraStatus.SELF_TIMER))
1112         {
1113             return (getCurrentSelfTimerStatus());
1114         }
1115         if (key.matches(ICameraStatus.TAKE_MODE))
1116         {
1117             return ("");
1118         }
1119         try
1120         {
1121             int strIndex = key.indexOf("x");
1122             Log.v(TAG, "getItemStatus() : " + key + " [" + strIndex + "]");
1123             if (strIndex >= 1)
1124             {
1125                 key = key.substring(strIndex + 1);
1126                 try
1127                 {
1128                     int id = Integer.parseInt(key, 16);
1129                     int value = statusHolder.get(id);
1130                     logcat("getItemStatus() value : " + value + " key : " + key + " [" + id + "]");
1131                     // dumpStatus();
1132                     return (value + "");
1133                 }
1134                 catch (Exception e)
1135                 {
1136                     e.printStackTrace();
1137                 }
1138             }
1139
1140             for (int index = 0; index < statusNameArray.size(); index++)
1141             {
1142                 int id = statusNameArray.keyAt(index);
1143                 String strKey = statusNameArray.valueAt(index);
1144                 if (key.contentEquals(strKey))
1145                 {
1146                     int value = statusHolder.get(id);
1147                     return (value + "");
1148                 }
1149             }
1150         }
1151         catch (Exception e)
1152         {
1153             e.printStackTrace();
1154         }
1155         return ("? [" + key + "]");
1156     }
1157
1158     void setItemStatus(@NonNull String key, @NonNull String value)
1159     {
1160         try
1161         {
1162             logcat(" setStatus(" + key + ", " + value + ")");
1163             if (key.matches(ICameraStatus.EFFECT))
1164             {
1165                 setEffectItem(value);
1166             }
1167             else if (key.matches(ICameraStatus.WHITE_BALANCE))
1168             {
1169                 setCurrentWhiteBalanceStatus(value);
1170             }
1171             else if (key.matches(ICameraStatus.ISO_SENSITIVITY))
1172             {
1173                 setCurrentIsoSensitivityStatus(value);
1174             }
1175             else if (key.matches(ICameraStatus.FLASH_XV))
1176             {
1177                 setCurrentFlashStatus(value);
1178             }
1179             else if (key.matches(ICameraStatus.SELF_TIMER))
1180             {
1181                 setSelfTimerStatus(value);
1182             }
1183             // その他の設定...
1184         }
1185         catch (Exception e)
1186         {
1187             e.printStackTrace();
1188         }
1189     }
1190
1191     private void dumpStatus()
1192     {
1193         try
1194         {
1195             Log.v(TAG, " - - - status - - - ");
1196             for (int index = 0; index < statusHolder.size(); index++)
1197             {
1198                 int key = statusHolder.keyAt(index);
1199                 int value = statusHolder.get(key);
1200                 Log.v(TAG, String.format("id : 0x%x value : %d (0x%x) ", key, value, value));
1201             }
1202             Log.v(TAG, " - - - status - - - ");
1203         }
1204         catch (Exception e)
1205         {
1206             e.printStackTrace();
1207         }
1208     }
1209
1210     private void logcat(String message)
1211     {
1212         if (logcat)
1213         {
1214             Log.v(TAG, message);
1215         }
1216     }
1217 }