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