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