OSDN Git Service

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