OSDN Git Service

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