OSDN Git Service

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