OSDN Git Service

OPCで現在のカメラ設定値を表示できるようにする。ライブビューをVGA基準にする。
[gokigen/Gr2Control.git] / app / src / main / java / net / osdn / gokigen / gr2control / liveview / LiveViewFragment.java
1 package net.osdn.gokigen.gr2control.liveview;
2
3 import android.app.Activity;
4 import android.content.Context;
5 import android.content.SharedPreferences;
6 import android.os.Bundle;
7 import android.os.Vibrator;
8 import android.support.annotation.NonNull;
9 import android.support.v4.app.Fragment;
10 import android.support.v4.content.res.ResourcesCompat;
11 import android.support.v7.app.ActionBar;
12 import android.support.v7.app.AppCompatActivity;
13 import android.support.v7.preference.PreferenceManager;
14 import android.util.Log;
15 import android.view.LayoutInflater;
16 import android.view.View;
17 import android.view.ViewGroup;
18 import android.widget.Button;
19 import android.widget.ImageButton;
20 import android.widget.ImageView;
21 import android.widget.TextView;
22
23 import net.osdn.gokigen.gr2control.R;
24 import net.osdn.gokigen.gr2control.camera.ICameraConnection;
25 import net.osdn.gokigen.gr2control.camera.ICameraInformation;
26 import net.osdn.gokigen.gr2control.camera.ICameraRunMode;
27 import net.osdn.gokigen.gr2control.camera.ICameraStatusWatcher;
28 import net.osdn.gokigen.gr2control.camera.IDisplayInjector;
29 import net.osdn.gokigen.gr2control.camera.IFocusingModeNotify;
30 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
31 import net.osdn.gokigen.gr2control.camera.ILiveViewControl;
32 import net.osdn.gokigen.gr2control.liveview.liveviewlistener.ILiveViewListener;
33 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
34 import net.osdn.gokigen.gr2control.scene.IChangeScene;
35
36 import static android.content.Context.VIBRATOR_SERVICE;
37
38 /**
39  *  撮影用ライブビュー画面
40  *
41  */
42 public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFocusingModeNotify, IFavoriteSettingDialogKicker, ICameraStatusUpdateNotify
43 {
44     private final String TAG = this.toString();
45
46     private ILiveViewControl liveViewControl = null;
47     //private IZoomLensControl zoomLensControl = null;
48     private IInterfaceProvider interfaceProvider = null;
49     private IDisplayInjector interfaceInjector = null;
50     //private OlympusCameraLiveViewListenerImpl liveViewListener = null;
51     private IChangeScene changeScene = null;
52     private ICameraInformation cameraInformation = null;
53     private ICameraStatusWatcher statusWatcher = null;
54     private LiveViewClickTouchListener onClickTouchListener = null;
55     private LiveViewControlPanelClickListener onPanelClickListener = null;
56     private LiveViewKeyPanelClickListener onKeyPanelClickListener = null;
57
58     private TextView statusArea = null;
59     private TextView focalLengthArea = null;
60     private CameraLiveImageView imageView = null;
61
62     private ImageView manualFocus = null;
63     private ImageButton showGrid = null;
64     private ImageView connectStatus = null;
65     private Button changeLiveViewScale = null;
66
67     private boolean imageViewCreated = false;
68     private View myView = null;
69     private String messageValue = "";
70
71     private ICameraConnection.CameraConnectionStatus currentConnectionStatus =  ICameraConnection.CameraConnectionStatus.UNKNOWN;
72
73     public static LiveViewFragment newInstance(IChangeScene sceneSelector, @NonNull IInterfaceProvider provider)
74     {
75         LiveViewFragment instance = new LiveViewFragment();
76         instance.prepare(sceneSelector, provider);
77
78         // パラメータはBundleにまとめておく
79         Bundle arguments = new Bundle();
80         //arguments.putString("title", title);
81         //arguments.putString("message", message);
82         instance.setArguments(arguments);
83
84         return (instance);
85     }
86
87     /**
88      *
89      *
90      */
91     @Override
92     public void onCreate(Bundle savedInstanceState)
93     {
94         super.onCreate(savedInstanceState);
95         Log.v(TAG, "onCreate()");
96 /*
97         if (liveViewListener == null)
98         {
99             liveViewListener = new OlympusCameraLiveViewListenerImpl();
100         }
101 */
102     }
103
104     /**
105      *
106      *
107      */
108     @Override
109     public void onAttach(Context context)
110     {
111         super.onAttach(context);
112         Log.v(TAG, "onAttach()");
113     }
114
115     /**
116      *
117      *
118      */
119     @Override
120     public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
121     {
122         super.onCreateView(inflater, container, savedInstanceState);
123
124         Log.v(TAG, "onCreateView()");
125         if ((imageViewCreated)&&(myView != null))
126         {
127             // Viewを再利用。。。
128             Log.v(TAG, "onCreateView() : called again, so do nothing... : " + myView);
129             return (myView);
130         }
131
132         View view = inflater.inflate(R.layout.fragment_live_view, container, false);
133         myView = view;
134         imageViewCreated = true;
135         try
136         {
137
138             imageView = view.findViewById(R.id.cameraLiveImageView);
139             if (interfaceInjector != null)
140             {
141                 interfaceInjector.injectDisplay(imageView, imageView, this);
142             }
143             else
144             {
145                 Log.v(TAG, "interfaceInjector is NULL...");
146             }
147             Activity activity = this.getActivity();
148             Vibrator vibrator = (activity != null) ? (Vibrator) activity.getSystemService(VIBRATOR_SERVICE) : null;
149             if ((onClickTouchListener == null)&&(activity != null))
150             {
151                 onClickTouchListener = new LiveViewClickTouchListener(activity, imageView, this, changeScene, interfaceProvider, this);
152             }
153             imageView.setOnClickListener(onClickTouchListener);
154             imageView.setOnTouchListener(onClickTouchListener);
155
156             setOnClickListener(view, R.id.hideControlPanelTextView);
157             setOnClickListener(view, R.id.showControlPanelTextView);
158             setOnClickListener(view, R.id.showKeyPanelImageView);
159             setOnClickListener(view, R.id.hideKeyPanelTextView);
160             setOnClickListener(view, R.id.shutter_button);
161             setOnClickListener(view, R.id.focusUnlockImageView);
162             setOnClickListener(view, R.id.show_images_button);
163             setOnClickListener(view, R.id.camera_power_off_button);
164             setOnClickListener(view, R.id.show_preference_button);
165
166             if (onPanelClickListener == null)
167             {
168                 onPanelClickListener = new LiveViewControlPanelClickListener(activity, interfaceProvider);
169             }
170             setPanelClickListener(view, R.id.takemodeTextView);
171             setPanelClickListener(view, R.id.shutterSpeedTextView);
172             setPanelClickListener(view, R.id.apertureValueTextView);
173             setPanelClickListener(view, R.id.exposureCompensationTextView);
174             setPanelClickListener(view, R.id.aeModeTextView);
175             setPanelClickListener(view, R.id.whiteBalanceImageView);
176             setPanelClickListener(view, R.id.setEffectImageView);
177
178             if (onKeyPanelClickListener == null)
179             {
180                 onKeyPanelClickListener = new LiveViewKeyPanelClickListener(interfaceProvider, vibrator);
181             }
182             setKeyPanelClickListener(view, R.id.button_front_left);
183             setKeyPanelClickListener(view, R.id.button_front_right);
184             setKeyPanelClickListener(view, R.id.button_adjust_left);
185             setKeyPanelClickListener(view, R.id.button_adjust_enter);
186             setKeyPanelClickListener(view, R.id.button_adjust_right);
187             setKeyPanelClickListener(view, R.id.button_toggle_aeaf);
188             setKeyPanelClickListener(view, R.id.lever_ael_caf);
189             setKeyPanelClickListener(view, R.id.button_up);
190             setKeyPanelClickListener(view, R.id.button_left);
191             setKeyPanelClickListener(view, R.id.button_center_enter);
192             setKeyPanelClickListener(view, R.id.button_right);
193             setKeyPanelClickListener(view, R.id.button_down);
194             setKeyPanelClickListener(view, R.id.button_function_1);
195             setKeyPanelClickListener(view, R.id.button_function_2);
196             setKeyPanelClickListener(view, R.id.button_function_3);
197             setKeyPanelClickListener(view, R.id.button_plus);
198             setKeyPanelClickListener(view, R.id.button_minus);
199             setKeyPanelClickListener(view, R.id.button_playback);
200
201             /*
202             view.findViewById(R.id.show_preference_button).setOnClickListener(onClickTouchListener);
203             view.findViewById(R.id.camera_property_settings_button).setOnClickListener(onClickTouchListener);
204             view.findViewById(R.id.shutter_button).setOnClickListener(onClickTouchListener);
205             view.findViewById(R.id.btn_zoomin).setOnClickListener(onClickTouchListener);
206             view.findViewById(R.id.btn_zoomout).setOnClickListener(onClickTouchListener);
207
208             manualFocus = view.findViewById(R.id.focusing_button);
209             changeLiveViewScale = view.findViewById(R.id.live_view_scale_button);
210
211             ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
212
213             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
214             {
215                 view.findViewById(R.id.show_favorite_settings_button).setOnClickListener(onClickTouchListener);
216             }
217             else
218             {
219                 // お気に入りボタン(とMFボタン)は、SONYモード, RICOH GR2モードのときには表示しない
220                 final View favoriteButton = view.findViewById(R.id.show_favorite_settings_button);
221                 final View propertyButton = view.findViewById(R.id.camera_property_settings_button);
222                 if ((favoriteButton != null)&&(manualFocus != null))
223                 {
224                     runOnUiThread(new Runnable()
225                     {
226                         @Override
227                         public void run()
228                         {
229                             favoriteButton.setVisibility(View.INVISIBLE);
230                             if (manualFocus != null)
231                             {
232                                 manualFocus.setVisibility(View.INVISIBLE);
233                             }
234                             propertyButton.setVisibility(View.INVISIBLE);
235                         }
236                     });
237                 }
238                 if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
239                 {
240                     if (changeLiveViewScale != null)
241                     {
242                         changeLiveViewScale.setVisibility(View.INVISIBLE);
243                     }
244                 }
245                 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
246                 {
247                     if (changeLiveViewScale != null)
248                     {
249                         changeLiveViewScale.setVisibility(View.VISIBLE);
250                     }
251                 }
252             }
253
254             if (manualFocus != null)
255             {
256                 manualFocus.setOnClickListener(onClickTouchListener);
257             }
258             changedFocusingMode();
259
260             if (changeLiveViewScale != null)
261             {
262                 changeLiveViewScale.setOnClickListener(onClickTouchListener);
263             }
264
265             showGrid = view.findViewById(R.id.show_hide_grid_button);
266             showGrid.setOnClickListener(onClickTouchListener);
267             updateGridIcon();
268
269             updateConnectionStatus(ICameraConnection.CameraConnectionStatus.UNKNOWN);
270
271             statusArea = view.findViewById(R.id.informationMessageTextView);
272             focalLengthArea = view.findViewById(R.id.focal_length_with_digital_zoom_view);
273 */
274             connectStatus = view.findViewById(R.id.connect_disconnect_button);
275             if (connectStatus != null)
276             {
277                 connectStatus.setOnClickListener(onClickTouchListener);
278             }
279         }
280         catch (Exception e)
281         {
282             e.printStackTrace();
283         }
284
285         return (view);
286     }
287
288     private void setOnClickListener(View view, int id)
289     {
290         try
291         {
292             View button = view.findViewById(id);
293             if (button != null)
294             {
295                 button.setOnClickListener(onClickTouchListener);
296             }
297         }
298         catch (Exception e)
299         {
300             e.printStackTrace();
301         }
302     }
303
304     private void setPanelClickListener(View view, int id)
305     {
306         try
307         {
308             View button = view.findViewById(id);
309             if (button != null)
310             {
311                 button.setOnClickListener(onPanelClickListener);
312             }
313         }
314         catch (Exception e)
315         {
316             e.printStackTrace();
317         }
318     }
319
320     private void setKeyPanelClickListener(View view, int id)
321     {
322         try
323         {
324             View button = view.findViewById(id);
325             if (button != null)
326             {
327                 button.setOnClickListener(onKeyPanelClickListener);
328             }
329         }
330         catch (Exception e)
331         {
332             e.printStackTrace();
333         }
334     }
335
336     /**
337      *
338      */
339     private void prepare(IChangeScene sceneSelector, IInterfaceProvider interfaceProvider)
340     {
341         Log.v(TAG, "prepare()");
342
343         this.changeScene = sceneSelector;
344         this.interfaceProvider = interfaceProvider;
345         this.interfaceInjector = interfaceProvider.getDisplayInjector();
346         this.liveViewControl = interfaceProvider.getLiveViewControl();
347         //this.zoomLensControl = interfaceProvider.getZoomLensControl();
348         this.cameraInformation = interfaceProvider.getCameraInformation();
349         this.statusWatcher = interfaceProvider.getCameraStatusWatcher();
350     }
351
352     /**
353      *  カメラとの接続状態の更新
354      *
355      */
356     @Override
357     public void updateConnectionStatus(final ICameraConnection.CameraConnectionStatus connectionStatus)
358     {
359         try
360         {
361             currentConnectionStatus = connectionStatus;
362             runOnUiThread(new Runnable()
363             {
364                 @Override
365                 public void run()
366                 {
367                     int id = R.drawable.ic_cloud_off_black_24dp;
368                     if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTING)
369                     {
370                         id = R.drawable.ic_cloud_queue_black_24dp;
371                     }
372                     else if  (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
373                     {
374                         id = R.drawable.ic_cloud_done_black_24dp;
375                     }
376                     if (connectStatus != null)
377                     {
378                         connectStatus.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
379                         connectStatus.invalidate();
380                     }
381                     if (imageView != null)
382                     {
383                         imageView.invalidate();
384                     }
385                 }
386             });
387
388         }
389         catch (Exception e)
390         {
391             e.printStackTrace();
392         }
393     }
394
395     /**
396      *  グリッドの表示・非表示の更新
397      *
398      */
399     @Override
400     public void updateGridIcon()
401     {
402         try
403         {
404             int id = (imageView.isShowGrid()) ? R.drawable.ic_grid_off_black_24dp : R.drawable.ic_grid_on_black_24dp;
405             showGrid.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
406             showGrid.invalidate();
407             imageView.invalidate();
408         }
409         catch (Exception e)
410         {
411             e.printStackTrace();
412         }
413     }
414
415     /**
416      *   AF/MFの表示を更新する
417      *
418      */
419     @Override
420     public void changedFocusingMode()
421     {
422         try
423         {
424             if ((cameraInformation == null)||(manualFocus == null))
425             {
426                 return;
427             }
428             runOnUiThread(new Runnable()
429             {
430                 @Override
431                 public void run()
432                 {
433                     if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
434                     {
435                         manualFocus.setSelected(cameraInformation.isManualFocus());
436                         manualFocus.invalidate();
437                     }
438                 }
439             });
440         }
441         catch (Exception e)
442         {
443             e.printStackTrace();
444         }
445     }
446
447     @Override
448     public void updateLiveViewScale(boolean isChangeScale)
449     {
450         try
451         {
452             Log.v(TAG, "updateLiveViewScale() : " + isChangeScale);
453
454             // ライブビューの倍率設定
455             liveViewControl.updateMagnifyingLiveViewScale(isChangeScale);
456
457             // ボタンの文字を更新する
458             float scale = liveViewControl.getMagnifyingLiveViewScale();
459             final String datavalue = "LV: " + scale;
460
461             // デジタルズームの倍率を表示する
462             float digitalZoom = liveViewControl.getDigitalZoomScale();
463             final String digitalValue = (digitalZoom > 1.0f) ? "D x" + digitalZoom : "";
464
465             // 更新自体は、UIスレッドで行う
466             runOnUiThread(new Runnable()
467             {
468                 @Override
469                 public void run()
470                 {
471                     changeLiveViewScale.setText(datavalue);
472                     changeLiveViewScale.postInvalidate();
473
474                     focalLengthArea.setText(digitalValue);
475                     focalLengthArea.postInvalidate();
476                 }
477             });
478         }
479         catch (Exception e)
480         {
481             e.printStackTrace();
482         }
483     }
484
485     /**
486      *
487      *
488      *
489      */
490     @Override
491     public void onStart()
492     {
493         super.onStart();
494         Log.v(TAG, "onStart()");
495     }
496
497     /**
498      *
499      *
500      */
501     @Override
502     public void onResume()
503     {
504         super.onResume();
505         Log.v(TAG, "onResume() Start");
506
507         AppCompatActivity activity = (AppCompatActivity)getActivity();
508         if (activity != null)
509         {
510             ActionBar bar = activity.getSupportActionBar();
511             if (bar != null)
512             {
513                 bar.hide();   // ActionBarの表示を消す
514             }
515         }
516
517         // 撮影モードかどうかを確認して、撮影モードではなかったら撮影モードに切り替える
518         ICameraRunMode changeRunModeExecutor = interfaceProvider.getCameraRunMode();
519         if ((changeRunModeExecutor != null)&&(!changeRunModeExecutor.isRecordingMode()))
520         {
521             // Runモードを切り替える。(でも切り替えると、設定がクリアされてしまう...。)
522             changeRunModeExecutor.changeRunMode(true);
523         }
524
525 /*
526         // ステータスの変更を通知してもらう
527         camera.setCameraStatusListener(statusListener);
528
529         // 画面下部の表示エリアの用途を切り替える
530         setupLowerDisplayArea();
531 */
532         // propertyを取得
533         try
534         {
535             Context context = getContext();
536             if (context != null)
537             {
538                 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
539
540                 // グリッド・フォーカスアシストの情報を戻す
541                 boolean showGrid = preferences.getBoolean(IPreferencePropertyAccessor.SHOW_GRID_STATUS, false);
542                 if ((imageView != null) && (imageView.isShowGrid() != showGrid)) {
543                     imageView.toggleShowGridFrame();
544                     imageView.postInvalidate();
545                 }
546             }
547             if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
548             {
549                 startLiveView();
550             }
551         }
552         catch (Exception e)
553         {
554             e.printStackTrace();
555         }
556         Log.v(TAG, "onResume() End");
557     }
558
559     /**
560      *
561      *
562      */
563     @Override
564     public void onPause()
565     {
566         super.onPause();
567         Log.v(TAG, "onPause() Start");
568
569         // ライブビューとステータス監視の停止
570         try
571         {
572             liveViewControl.stopLiveView();
573             stopWatchStatus();
574         }
575         catch (Exception e)
576         {
577             e.printStackTrace();
578         }
579
580         Log.v(TAG, "onPause() End");
581     }
582
583     /**
584      *   表示エリアに文字を表示する
585      *
586      */
587     @Override
588     public void updateStatusView(String message)
589     {
590         messageValue = message;
591         runOnUiThread(new Runnable()
592         {
593             /**
594              * カメラの状態(ステータステキスト)を更新する
595              * (ステータステキストは、プライベート変数で保持して、書き換える)
596              */
597             @Override
598             public void run()
599             {
600                 if (statusArea != null)
601                 {
602                     statusArea.setText(messageValue);
603                     statusArea.invalidate();
604                 }
605             }
606         });
607     }
608
609     /**
610      *   ライブビューの開始
611      *
612      */
613     @Override
614     public void startLiveView()
615     {
616         ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
617         if (liveViewControl == null)
618         {
619             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
620             {
621                 Log.v(TAG, "startLiveView() : liveViewControl is null.");
622                 return;
623             }
624             else
625             {
626                 // ダミー
627                 prepare(changeScene, interfaceProvider);
628             }
629         }
630         try
631         {
632             // ライブビューの開始
633             Context context = getContext();
634             boolean isCameraScreen = true;
635             if (context != null)
636             {
637                 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
638                 liveViewControl.changeLiveViewSize(preferences.getString(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY, IPreferencePropertyAccessor.LIVE_VIEW_QUALITY_DEFAULT_VALUE));
639                 isCameraScreen = preferences.getBoolean(IPreferencePropertyAccessor.GR2_DISPLAY_CAMERA_VIEW, true);
640             }
641             ILiveViewListener lvListener = interfaceProvider.getLiveViewListener();
642             if (lvListener != null)
643             {
644                 lvListener.setCameraLiveImageView(imageView);
645             }
646             liveViewControl.startLiveView(isCameraScreen);   // false : ライブビューのみ、 true : カメラ画面をミラー
647
648             // ステータス監視も実施する
649             startWatchStatus();
650         }
651         catch (Exception e)
652         {
653             e.printStackTrace();
654         }
655     }
656
657     @Override
658     public void showFavoriteSettingDialog()
659     {
660         try
661         {
662             Log.v(TAG, "showFavoriteSettingDialog()");
663 /*
664             LoadSaveMyCameraPropertyDialog dialog = new LoadSaveMyCameraPropertyDialog();
665             dialog.setTargetFragment(this, COMMAND_MY_PROPERTY);
666             dialog.setPropertyOperationsHolder(new LoadSaveCameraProperties(getActivity(), interfaceProvider.getOlympusInterface()));
667             FragmentManager manager = getFragmentManager();
668             if (manager != null)
669             {
670                 dialog.show(manager, "my_dialog");
671             }
672 */
673         }
674         catch (Exception e)
675         {
676             e.printStackTrace();
677         }
678     }
679
680     /**
681      *
682      *
683      */
684     private void startWatchStatus()
685     {
686         if (statusWatcher != null)
687         {
688             statusWatcher.startStatusWatch(this);
689         }
690     }
691
692     /**
693      *
694      *
695      */
696     private void stopWatchStatus()
697     {
698         if (statusWatcher != null)
699         {
700             statusWatcher.stoptStatusWatch();
701         }
702     }
703
704     /**
705      *
706      *
707      */
708     private void runOnUiThread(Runnable action)
709     {
710         Activity activity = getActivity();
711         if (activity == null)
712         {
713             return;
714         }
715         activity.runOnUiThread(action);
716     }
717
718     @Override
719     public void updatedTakeMode(final String mode)
720     {
721         try
722         {
723             final Activity activity = getActivity();
724             if (activity == null)
725             {
726                 return;
727             }
728             activity.runOnUiThread(new Runnable()
729             {
730                 @Override
731                 public void run()
732                 {
733                     TextView view = activity.findViewById(R.id.takemodeTextView);
734                     if (view != null)
735                     {
736                         view.setText(mode);
737                         view.invalidate();
738                     }
739                 }
740             });
741         }
742         catch (Exception e)
743         {
744             e.printStackTrace();
745         }
746     }
747
748     @Override
749     public void updatedShutterSpeed(final String tv)
750     {
751         try
752         {
753             final String shutterSpeed = tv.replace(".", "/");
754             final Activity activity = getActivity();
755             if (activity == null)
756             {
757                 return;
758             }
759             activity.runOnUiThread(new Runnable()
760             {
761                 @Override
762                 public void run()
763                 {
764                     TextView view = activity.findViewById(R.id.shutterSpeedTextView);
765                     if (view != null) {
766                         view.setText(shutterSpeed);
767                         view.invalidate();
768                     }
769                 }
770             });
771         }
772         catch (Exception e)
773         {
774             e.printStackTrace();
775         }
776
777     }
778
779     @Override
780     public void updatedAperture(final String av)
781     {
782         try
783         {
784             final String apertureValue = (av.length() > 1) ? ("F" + av) : "";
785             final Activity activity = getActivity();
786             if (activity == null)
787             {
788                 return;
789             }
790             activity.runOnUiThread(new Runnable()
791             {
792                 @Override
793                 public void run()
794                 {
795                     TextView view = activity.findViewById(R.id.apertureValueTextView);
796                     if (view != null)
797                     {
798                         view.setText(apertureValue);
799                         view.invalidate();
800                     }
801                 }
802             });
803         }
804         catch (Exception e)
805         {
806             e.printStackTrace();
807         }
808     }
809
810     @Override
811     public void updatedExposureCompensation(final String xv)
812     {
813         try
814         {
815             final Activity activity = getActivity();
816             if (activity == null)
817             {
818                 return;
819             }
820             activity.runOnUiThread(new Runnable()
821             {
822                 @Override
823                 public void run()
824                 {
825                     TextView view = activity.findViewById(R.id.exposureCompensationTextView);
826                     if (view != null)
827                     {
828                         view.setText(xv);
829                         view.invalidate();
830                     }
831                 }
832             });
833         }
834         catch (Exception e)
835         {
836             e.printStackTrace();
837         }
838     }
839
840     @Override
841     public void updatedMeteringMode(final String meteringMode)
842     {
843         try
844         {
845             final Activity activity = getActivity();
846             if (activity == null)
847             {
848                 return;
849             }
850             activity.runOnUiThread(new Runnable()
851             {
852                 @Override
853                 public void run()
854                 {
855                     TextView view = activity.findViewById(R.id.aeModeTextView);
856                     if (view != null)
857                     {
858                         view.setText(meteringMode);
859                         view.invalidate();
860                     }
861                 }
862             });
863         }
864         catch (Exception e)
865         {
866             e.printStackTrace();
867         }
868     }
869
870     @Override
871     public void updatedWBMode(final String wbMode)
872     {
873         // とりあえず何もしない... 選択肢は以下
874         // auto, multiAuto, daylight, shade, cloud, tungsten, warmWhiteFluorescent, daylightFluorescent, dayWhiteFluorescent, coolWhiteFluorescent, incandescent,manual1, cte, custom
875     }
876
877     /**
878      *   残りバッテリー状態をアイコンで示す
879      *
880      */
881     @Override
882     public void updateRemainBattery(int percentage)
883     {
884         try
885         {
886             final Activity activity = getActivity();
887             if (activity == null)
888             {
889                 return;
890             }
891             int iconId;
892             if (percentage < 20)
893             {
894                 iconId = R.drawable.ic_battery_alert_black_24dp;
895             }
896             else if (percentage < 60)
897             {
898                 iconId = R.drawable.ic_battery_20_black_24dp;
899             }
900             else if (percentage < 80)
901             {
902                 iconId = R.drawable.ic_battery_60_black_24dp;
903             }
904             else
905             {
906                 iconId = R.drawable.ic_battery_full_black_24dp;
907             }
908             final int id = iconId;
909             activity.runOnUiThread(new Runnable()
910             {
911                 @Override
912                 public void run()
913                 {
914                     ImageView view = activity.findViewById(R.id.currentBatteryImageView);
915                     if (view != null)
916                     {
917                         view.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
918                         view.invalidate();
919                     }
920                 }
921             });
922         }
923         catch (Exception e)
924         {
925             e.printStackTrace();
926         }
927     }
928
929     @Override
930     public void updateIsoSensitivity(String sv)
931     {
932         Log.v(TAG, "updateIsoSensitivity : " + sv);
933     }
934
935     @Override
936     public void updateWarning(String warning)
937     {
938         Log.v(TAG, "updateWarning : " + warning);
939     }
940
941     @Override
942     public void updateStorageStatus(String status)
943     {
944         Log.v(TAG, "updateStorageStatus : " + status);
945     }
946 }