OSDN Git Service

FUJIのフィルムシミュレーションの変更をできるようにした。
[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.content.Context;
4 import android.content.SharedPreferences;
5 import android.graphics.Color;
6 import android.graphics.drawable.Drawable;
7 import android.os.Bundle;
8 import android.os.Vibrator;
9
10 import androidx.annotation.NonNull;
11 import androidx.appcompat.app.ActionBar;
12 import androidx.appcompat.app.AppCompatActivity;
13 import androidx.core.content.ContextCompat;
14 import androidx.core.content.res.ResourcesCompat;
15 import androidx.core.graphics.drawable.DrawableCompat;
16 import androidx.fragment.app.Fragment;
17 import androidx.fragment.app.FragmentActivity;
18 import androidx.preference.PreferenceManager;
19
20 import android.util.Log;
21 import android.view.KeyEvent;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.widget.Button;
26 import android.widget.ImageView;
27 import android.widget.TextView;
28
29 import net.osdn.gokigen.gr2control.R;
30 import net.osdn.gokigen.gr2control.camera.ICameraButtonControl;
31 import net.osdn.gokigen.gr2control.camera.ICameraConnection;
32 import net.osdn.gokigen.gr2control.camera.ICameraInformation;
33 import net.osdn.gokigen.gr2control.camera.ICameraRunMode;
34 import net.osdn.gokigen.gr2control.camera.ICameraRunModeCallback;
35 import net.osdn.gokigen.gr2control.camera.ICameraStatus;
36 import net.osdn.gokigen.gr2control.camera.ICameraStatusWatcher;
37 import net.osdn.gokigen.gr2control.camera.IDisplayInjector;
38 import net.osdn.gokigen.gr2control.camera.IFocusingModeNotify;
39 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
40 import net.osdn.gokigen.gr2control.camera.ILiveViewControl;
41 import net.osdn.gokigen.gr2control.camera.IZoomLensControl;
42 import net.osdn.gokigen.gr2control.camera.olympus.myolycameraprops.LoadSaveCameraProperties;
43 import net.osdn.gokigen.gr2control.camera.olympus.myolycameraprops.LoadSaveMyCameraPropertyDialog;
44 import net.osdn.gokigen.gr2control.liveview.liveviewlistener.ILiveViewListener;
45 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
46 import net.osdn.gokigen.gr2control.scene.IChangeScene;
47
48 import static android.content.Context.VIBRATOR_SERVICE;
49
50 /**
51  *  撮影用ライブビュー画面
52  *
53  */
54 public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFocusingModeNotify, IFavoriteSettingDialogKicker, ICameraStatusUpdateNotify, LiveViewKeyPanelClickListener.KeyPanelFeedback, ICameraRunModeCallback
55 {
56     private final String TAG = this.toString();
57
58     private ILiveViewControl liveViewControl = null;
59     private IZoomLensControl zoomLensControl = null;
60     private IInterfaceProvider interfaceProvider = null;
61     private IDisplayInjector interfaceInjector = null;
62     //private OlympusCameraLiveViewListenerImpl liveViewListener = null;
63     private IChangeScene changeScene = null;
64     private ICameraInformation cameraInformation = null;
65     private ICameraStatusWatcher statusWatcher = null;
66     private LiveViewClickTouchListener onClickTouchListener = null;
67     private LiveViewControlPanelClickListener onPanelClickListener = null;
68     private LiveViewKeyPanelClickListener onKeyPanelClickListener = null;
69     private LiveViewFujiXKeyPanelClickListener fujiXOnKeyPanelClickListener = null;
70
71     private TextView statusArea = null;
72     private TextView focalLengthArea = null;
73     private CameraLiveImageView imageView = null;
74
75     private ImageView manualFocus = null;
76     private ImageView showGrid = null;
77     private ImageView connectStatus = null;
78     private Button changeLiveViewScale = null;
79
80     private boolean imageViewCreated = false;
81     private View myView = null;
82     private String messageValue = "";
83
84     private ICameraConnection.CameraConnectionStatus currentConnectionStatus =  ICameraConnection.CameraConnectionStatus.UNKNOWN;
85
86     public static LiveViewFragment newInstance(IChangeScene sceneSelector, @NonNull IInterfaceProvider provider)
87     {
88         LiveViewFragment instance = new LiveViewFragment();
89         instance.prepare(sceneSelector, provider);
90
91         // パラメータはBundleにまとめておく
92         Bundle arguments = new Bundle();
93         //arguments.putString("title", title);
94         //arguments.putString("message", message);
95         instance.setArguments(arguments);
96
97         return (instance);
98     }
99
100     /**
101      *
102      *
103      */
104     @Override
105     public void onCreate(Bundle savedInstanceState)
106     {
107         super.onCreate(savedInstanceState);
108         Log.v(TAG, "onCreate()");
109 /*
110         if (liveViewListener == null)
111         {
112             liveViewListener = new OlympusCameraLiveViewListenerImpl();
113         }
114 */
115     }
116
117     /**
118      *
119      *
120      */
121     @Override
122     public void onAttach(@NonNull Context context)
123     {
124         super.onAttach(context);
125         Log.v(TAG, "onAttach()");
126     }
127
128     /**
129      *
130      *
131      */
132     @Override
133     public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
134     {
135         super.onCreateView(inflater, container, savedInstanceState);
136
137         Log.v(TAG, "onCreateView()");
138         if ((imageViewCreated)&&(myView != null))
139         {
140             // Viewを再利用。。。
141             Log.v(TAG, "onCreateView() : called again, so do nothing... : " + myView);
142             return (myView);
143         }
144
145         View view = inflater.inflate(R.layout.fragment_live_view, container, false);
146         myView = view;
147         imageViewCreated = true;
148         try
149         {
150
151             imageView = view.findViewById(R.id.cameraLiveImageView);
152             if (interfaceInjector != null)
153             {
154                 interfaceInjector.injectDisplay(imageView, imageView, this);
155             }
156             else
157             {
158                 Log.v(TAG, "interfaceInjector is NULL...");
159             }
160             FragmentActivity activity = this.getActivity();
161             Vibrator vibrator = (activity != null) ? (Vibrator) activity.getSystemService(VIBRATOR_SERVICE) : null;
162             if ((onClickTouchListener == null)&&(activity != null))
163             {
164                 onClickTouchListener = new LiveViewClickTouchListener(activity, imageView, this, changeScene, interfaceProvider, this);
165             }
166             imageView.setOnClickListener(onClickTouchListener);
167             imageView.setOnTouchListener(onClickTouchListener);
168
169             // キーイベントを拾うことにする
170             view.setOnKeyListener(onClickTouchListener);
171             view.setFocusableInTouchMode(true);
172
173             setOnClickListener(view, R.id.hideControlPanelTextView);
174             setOnClickListener(view, R.id.showControlPanelTextView);
175             setOnClickListener(view, R.id.showKeyPanelImageView);
176             setOnClickListener(view, R.id.hideKeyPanelTextView);
177             setOnClickListener(view, R.id.shutter_button);
178             setOnClickListener(view, R.id.focusUnlockImageView);
179             setOnClickListener(view, R.id.show_images_button);
180             setOnClickListener(view, R.id.camera_power_off_button);
181             setOnClickListener(view, R.id.show_preference_button);
182             setOnClickListener(view, R.id.show_hide_grid_button);
183             setOnClickListener(view, R.id.zoom_in_button);
184             setOnClickListener(view, R.id.zoom_out_button);
185             setOnClickListener(view, R.id.specialButtonImageView);
186             setOnClickListener(view, R.id.fuji_x_hideKeyPanelTextView);
187
188             if (onPanelClickListener == null)
189             {
190                 onPanelClickListener = new LiveViewControlPanelClickListener(activity, interfaceProvider);
191             }
192             setPanelClickListener(view, R.id.takemodeTextView);
193             setPanelClickListener(view, R.id.shutterSpeedTextView);
194             setPanelClickListener(view, R.id.apertureValueTextView);
195             setPanelClickListener(view, R.id.exposureCompensationTextView);
196             setPanelClickListener(view, R.id.aeModeImageView);
197             setPanelClickListener(view, R.id.whiteBalanceTextView);
198             setPanelClickListener(view, R.id.isoSensitivityTextView);
199             setPanelClickListener(view, R.id.setEffectImageView);
200
201             if (onKeyPanelClickListener == null)
202             {
203                 onKeyPanelClickListener = new LiveViewKeyPanelClickListener(interfaceProvider, this, vibrator);
204             }
205             setKeyPanelClickListener(view, R.id.button_front_left);
206             setKeyPanelClickListener(view, R.id.button_front_right);
207             setKeyPanelClickListener(view, R.id.button_adjust_left);
208             setKeyPanelClickListener(view, R.id.button_adjust_enter);
209             setKeyPanelClickListener(view, R.id.button_adjust_right);
210             setKeyPanelClickListener(view, R.id.button_toggle_aeaf);
211             setKeyPanelClickListener(view, R.id.lever_ael_caf);
212             setKeyPanelClickListener(view, R.id.button_up);
213             setKeyPanelClickListener(view, R.id.button_left);
214             setKeyPanelClickListener(view, R.id.button_center_enter);
215             setKeyPanelClickListener(view, R.id.button_right);
216             setKeyPanelClickListener(view, R.id.button_down);
217             setKeyPanelClickListener(view, R.id.button_function_1);
218             setKeyPanelClickListener(view, R.id.button_function_2);
219             setKeyPanelClickListener(view, R.id.button_function_3);
220             setKeyPanelClickListener(view, R.id.button_plus);
221             setKeyPanelClickListener(view, R.id.button_minus);
222             setKeyPanelClickListener(view, R.id.button_playback);
223             setKeyPanelClickListener(view, R.id.button_acclock);
224             setKeyPanelClickListener(view, R.id.button_lcd_onoff);
225             setKeyPanelClickListener(view, R.id.button_highlight);
226
227             if (fujiXOnKeyPanelClickListener == null)
228             {
229                 fujiXOnKeyPanelClickListener = new LiveViewFujiXKeyPanelClickListener(interfaceProvider, vibrator);
230             }
231             //setFujiXKeyPanelClickListener(view, xxx);
232
233
234             connectStatus = view.findViewById(R.id.connect_disconnect_button);
235             if (connectStatus != null)
236             {
237                 connectStatus.setOnClickListener(onClickTouchListener);
238             }
239
240             View keyPanel = view.findViewById(R.id.showKeyPanelImageView);
241             ICameraButtonControl buttonControl = interfaceProvider.getButtonControl();
242             if (keyPanel != null)
243             {
244                 keyPanel.setVisibility((buttonControl == null) ? View.INVISIBLE : View.VISIBLE);
245                 keyPanel.invalidate();
246             }
247         }
248         catch (Exception e)
249         {
250             e.printStackTrace();
251         }
252
253         return (view);
254     }
255
256     private void setOnClickListener(View view, int id)
257     {
258         try
259         {
260             View button = view.findViewById(id);
261             if (button != null)
262             {
263                 button.setOnClickListener(onClickTouchListener);
264             }
265         }
266         catch (Exception e)
267         {
268             e.printStackTrace();
269         }
270     }
271
272     private void setPanelClickListener(View view, int id)
273     {
274         try
275         {
276             View button = view.findViewById(id);
277             if (button != null)
278             {
279                 button.setOnClickListener(onPanelClickListener);
280             }
281         }
282         catch (Exception e)
283         {
284             e.printStackTrace();
285         }
286     }
287
288     private void setKeyPanelClickListener(View view, int id)
289     {
290         try
291         {
292             View button = view.findViewById(id);
293             if (button != null)
294             {
295                 button.setOnClickListener(onKeyPanelClickListener);
296                 button.setOnLongClickListener(onKeyPanelClickListener);
297             }
298         }
299         catch (Exception e)
300         {
301             e.printStackTrace();
302         }
303     }
304
305     private void setFujiXKeyPanelClickListener(View view, int id)
306     {
307         try
308         {
309             View button = view.findViewById(id);
310             if (button != null)
311             {
312                 button.setOnClickListener(fujiXOnKeyPanelClickListener);
313                 button.setOnLongClickListener(fujiXOnKeyPanelClickListener);
314             }
315         }
316         catch (Exception e)
317         {
318             e.printStackTrace();
319         }
320     }
321
322     /**
323      *
324      */
325     private void prepare(IChangeScene sceneSelector, IInterfaceProvider interfaceProvider)
326     {
327         Log.v(TAG, "prepare()");
328
329         this.changeScene = sceneSelector;
330         this.interfaceProvider = interfaceProvider;
331         this.interfaceInjector = interfaceProvider.getDisplayInjector();
332         this.liveViewControl = interfaceProvider.getLiveViewControl();
333         this.zoomLensControl = interfaceProvider.getZoomLensControl();
334         this.cameraInformation = interfaceProvider.getCameraInformation();
335         this.statusWatcher = interfaceProvider.getCameraStatusWatcher();
336     }
337
338     /**
339      *  カメラとの接続状態の更新
340      *
341      */
342     @Override
343     public void updateConnectionStatus(final ICameraConnection.CameraConnectionStatus connectionStatus)
344     {
345         try
346         {
347             currentConnectionStatus = connectionStatus;
348             runOnUiThread(new Runnable()
349             {
350                 @Override
351                 public void run()
352                 {
353                     int id = R.drawable.ic_cloud_off_black_24dp;
354                     if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTING)
355                     {
356                         id = R.drawable.ic_cloud_queue_black_24dp;
357                     }
358                     else if  (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
359                     {
360                         id = R.drawable.ic_cloud_done_black_24dp;
361                     }
362                     if (connectStatus != null)
363                     {
364                         connectStatus.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
365                         connectStatus.invalidate();
366                     }
367                     if (imageView != null)
368                     {
369                         imageView.invalidate();
370                     }
371                 }
372             });
373
374         }
375         catch (Exception e)
376         {
377             e.printStackTrace();
378         }
379     }
380
381     /**
382      *  グリッドの表示・非表示の更新
383      *
384      */
385     @Override
386     public void updateGridIcon()
387     {
388         try
389         {
390             FragmentActivity activity = getActivity();
391             if (activity != null)
392             {
393                 if (showGrid == null) {
394                     showGrid = activity.findViewById(R.id.show_hide_grid_button);
395                 }
396                 activity.runOnUiThread(new Runnable() {
397                     @Override
398                     public void run()
399                     {
400                         int id = (imageView.isShowGrid()) ? R.drawable.ic_grid_off_black_24dp : R.drawable.ic_grid_on_black_24dp;
401                         if (showGrid != null)
402                         {
403                             showGrid.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
404                             showGrid.invalidate();
405                         }
406                         imageView.invalidate();
407                     }
408                 });
409             }
410         }
411         catch (Exception e)
412         {
413             e.printStackTrace();
414         }
415     }
416
417     /**
418      *
419      *
420      */
421     @Override
422     public void changedFocusingMode()
423     {
424         try
425         {
426             if ((cameraInformation == null)||(manualFocus == null))
427             {
428                 return;
429             }
430             runOnUiThread(new Runnable()
431             {
432                 @Override
433                 public void run()
434                 {
435                     if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
436                     {
437                         manualFocus.setSelected(cameraInformation.isManualFocus());
438                         manualFocus.invalidate();
439                     }
440                 }
441             });
442         }
443         catch (Exception e)
444         {
445             e.printStackTrace();
446         }
447     }
448
449     @Override
450     public void updateLiveViewScale(boolean isChangeScale)
451     {
452         try
453         {
454             Log.v(TAG, "updateLiveViewScale() : " + isChangeScale);
455
456             // ライブビューの倍率設定
457             liveViewControl.updateMagnifyingLiveViewScale(isChangeScale);
458
459             // ボタンの文字を更新する
460             float scale = liveViewControl.getMagnifyingLiveViewScale();
461             final String datavalue = "LV: " + scale;
462
463             // デジタルズームの倍率を表示する
464             float digitalZoom = liveViewControl.getDigitalZoomScale();
465             final String digitalValue = (digitalZoom > 1.0f) ? "D x" + digitalZoom : "";
466
467             // 更新自体は、UIスレッドで行う
468             runOnUiThread(new Runnable()
469             {
470                 @Override
471                 public void run()
472                 {
473                     changeLiveViewScale.setText(datavalue);
474                     changeLiveViewScale.postInvalidate();
475
476                     focalLengthArea.setText(digitalValue);
477                     focalLengthArea.postInvalidate();
478                 }
479             });
480         }
481         catch (Exception e)
482         {
483             e.printStackTrace();
484         }
485     }
486
487     /**
488      *
489      *
490      *
491      */
492     @Override
493     public void onStart()
494     {
495         super.onStart();
496         Log.v(TAG, "onStart()");
497     }
498
499     /**
500      *
501      *
502      */
503     @Override
504     public void onResume()
505     {
506         super.onResume();
507         Log.v(TAG, "onResume() Start");
508
509         AppCompatActivity activity = (AppCompatActivity)getActivity();
510         if (activity != null)
511         {
512             ActionBar bar = activity.getSupportActionBar();
513             if (bar != null)
514             {
515                 bar.hide();   // ActionBarの表示を消す
516             }
517         }
518
519         // 撮影モードかどうかを確認して、撮影モードではなかったら撮影モードに切り替える
520         ICameraRunMode changeRunModeExecutor = interfaceProvider.getCameraRunMode();
521         if ((changeRunModeExecutor != null)&&(!changeRunModeExecutor.isRecordingMode()))
522         {
523             // Runモードを切り替える。(でも切り替えると、設定がクリアされてしまう...。)
524             changeRunModeExecutor.changeRunMode(true, this);
525             Log.v(TAG, "onResume() End");
526             return;
527         }
528         prepareToStart();
529         Log.v(TAG, "onResume() End");
530     }
531
532     private void prepareToStart()
533     {
534         try
535         {
536             Context context = getContext();
537             if (context != null)
538             {
539                 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
540
541                 // グリッド・フォーカスアシストの情報を戻す
542                 boolean showGrid = preferences.getBoolean(IPreferencePropertyAccessor.SHOW_GRID_STATUS, false);
543                 if ((imageView != null) && (imageView.isShowGrid() != showGrid)) {
544                     imageView.toggleShowGridFrame();
545                     imageView.postInvalidate();
546                 }
547             }
548             if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
549             {
550                 startLiveView();
551             }
552         }
553         catch (Exception e)
554         {
555             e.printStackTrace();
556         }
557     }
558
559     @Override
560     public void onCompleted(boolean isRecording)
561     {
562         prepareToStart();
563     }
564
565     @Override
566     public void onErrorOccurred(boolean isRecording)
567     {
568         prepareToStart();
569     }
570
571     /**
572      *
573      *
574      */
575     @Override
576     public void onPause()
577     {
578         super.onPause();
579         Log.v(TAG, "onPause() Start");
580
581         // ライブビューとステータス監視の停止
582         try
583         {
584             liveViewControl.stopLiveView();
585             stopWatchStatus();
586         }
587         catch (Exception e)
588         {
589             e.printStackTrace();
590         }
591
592         Log.v(TAG, "onPause() End");
593     }
594
595     /**
596      *   表示エリアに文字を表示する
597      *
598      */
599     @Override
600     public void updateStatusView(String message)
601     {
602         messageValue = message;
603         runOnUiThread(new Runnable()
604         {
605             /**
606              * カメラの状態(ステータステキスト)を更新する
607              * (ステータステキストは、プライベート変数で保持して、書き換える)
608              */
609             @Override
610             public void run()
611             {
612                 if (statusArea != null)
613                 {
614                     statusArea.setText(messageValue);
615                     statusArea.invalidate();
616                 }
617             }
618         });
619     }
620
621     /**
622      *   ライブビューの開始
623      *
624      */
625     @Override
626     public void startLiveView()
627     {
628         Log.v(TAG, " LiveViewFragment::startLiveView() ");
629         ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
630         if (liveViewControl == null)
631         {
632             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
633             {
634                 Log.v(TAG, "startLiveView() : liveViewControl is null.");
635                 return;
636             }
637             else
638             {
639                 // ダミー
640                 prepare(changeScene, interfaceProvider);
641             }
642         }
643         try
644         {
645             // ライブビューの開始
646             Context context = getContext();
647             boolean isCameraScreen = true;
648             if (context != null)
649             {
650                 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
651                 liveViewControl.changeLiveViewSize(preferences.getString(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY, IPreferencePropertyAccessor.LIVE_VIEW_QUALITY_DEFAULT_VALUE));
652                 isCameraScreen = preferences.getBoolean(IPreferencePropertyAccessor.GR2_DISPLAY_CAMERA_VIEW, true);
653             }
654             ILiveViewListener lvListener = interfaceProvider.getLiveViewListener();
655             if (lvListener != null)
656             {
657                 lvListener.setCameraLiveImageView(imageView);
658             }
659             liveViewControl.startLiveView(isCameraScreen);   // false : ライブビューのみ、 true : カメラ画面をミラー
660
661             // ここでグリッドアイコンを更新する
662             updateGridIcon();
663
664             // ここでズームレンズ制御ができるか確認する
665             if ((zoomLensControl != null)&&(zoomLensControl.canZoom()))
666             {
667                 //Log.v(TAG, "CAN ZOOM LENS");
668                 updateZoomlensControl(true);
669             }
670             else
671             {
672                 //Log.v(TAG, "NO ZOOM LENS");
673                 updateZoomlensControl(false);
674             }
675
676
677             // ステータス監視も実施する
678             startWatchStatus();
679         }
680         catch (Exception e)
681         {
682             e.printStackTrace();
683         }
684     }
685
686     @Override
687     public void showFavoriteSettingDialog()
688     {
689         try
690         {
691             Log.v(TAG, "showFavoriteSettingDialog()");
692             LoadSaveMyCameraPropertyDialog dialog = LoadSaveMyCameraPropertyDialog.newInstance(new LoadSaveCameraProperties(getActivity(), interfaceProvider.getOlympusInterfaceProvider()));
693             dialog.show(getChildFragmentManager(), "favorite_dialog");
694         }
695         catch (Exception e)
696         {
697             e.printStackTrace();
698         }
699     }
700
701     /**
702      *
703      *
704      *
705      */
706     private void updateZoomlensControl(final boolean isVisible)
707     {
708         runOnUiThread(new Runnable() {
709             @Override
710             public void run() {
711                 // isVisibleがtrueなら、ズームレンズボタンを有効にする
712                 FragmentActivity activity = getActivity();
713                 if (activity != null)
714                 {
715                     try
716                     {
717                         View view1 = activity.findViewById(R.id.zoom_out_button);
718                         if (view1 != null)
719                         {
720                             view1.setVisibility((isVisible) ? View.VISIBLE : View.INVISIBLE);
721                             view1.invalidate();
722                         }
723
724                         View view2 = activity.findViewById(R.id.zoom_in_button);
725                         if (view2 != null)
726                         {
727                             view2.setVisibility((isVisible) ? View.VISIBLE : View.INVISIBLE);
728                             view2.invalidate();
729                         }
730                     }
731                     catch (Exception e)
732                     {
733                         e.printStackTrace();
734                     }
735                 }
736             }
737         });
738     }
739
740     /**
741      *
742      *
743      */
744     private void startWatchStatus()
745     {
746         if (statusWatcher != null)
747         {
748             statusWatcher.startStatusWatch(this);
749         }
750     }
751
752     /**
753      *
754      *
755      */
756     private void stopWatchStatus()
757     {
758         if (statusWatcher != null)
759         {
760             statusWatcher.stopStatusWatch();
761         }
762     }
763
764     /**
765      *
766      *
767      */
768     private void runOnUiThread(Runnable action)
769     {
770         FragmentActivity activity = getActivity();
771         if (activity == null)
772         {
773             return;
774         }
775         activity.runOnUiThread(action);
776     }
777
778     @Override
779     public void updatedTakeMode(final String mode)
780     {
781         try
782         {
783             final FragmentActivity activity = getActivity();
784             if (activity == null)
785             {
786                 return;
787             }
788             activity.runOnUiThread(new Runnable()
789             {
790                 @Override
791                 public void run()
792                 {
793                     TextView view = activity.findViewById(R.id.takemodeTextView);
794                     if (view != null)
795                     {
796                         view.setText(mode);
797                         view.invalidate();
798                     }
799                 }
800             });
801         }
802         catch (Exception e)
803         {
804             e.printStackTrace();
805         }
806     }
807
808     @Override
809     public void updatedShutterSpeed(final String tv)
810     {
811         try
812         {
813             final String shutterSpeed = tv.replace(".", "/");
814             final FragmentActivity activity = getActivity();
815             if (activity == null)
816             {
817                 return;
818             }
819             activity.runOnUiThread(new Runnable()
820             {
821                 @Override
822                 public void run()
823                 {
824                     TextView view = activity.findViewById(R.id.shutterSpeedTextView);
825                     if (view != null) {
826                         view.setText(shutterSpeed);
827                         view.invalidate();
828                     }
829                 }
830             });
831         }
832         catch (Exception e)
833         {
834             e.printStackTrace();
835         }
836
837     }
838
839     @Override
840     public void updatedAperture(final String av)
841     {
842         try
843         {
844             final String apertureValue = (av.length() > 1) ? ("F" + av) : "";
845             final FragmentActivity activity = getActivity();
846             if (activity == null)
847             {
848                 return;
849             }
850             activity.runOnUiThread(new Runnable()
851             {
852                 @Override
853                 public void run()
854                 {
855                     TextView view = activity.findViewById(R.id.apertureValueTextView);
856                     if (view != null)
857                     {
858                         view.setText(apertureValue);
859                         view.invalidate();
860                     }
861                 }
862             });
863         }
864         catch (Exception e)
865         {
866             e.printStackTrace();
867         }
868     }
869
870     @Override
871     public void updatedExposureCompensation(final String xv)
872     {
873         try
874         {
875             final FragmentActivity activity = getActivity();
876             if (activity == null)
877             {
878                 return;
879             }
880             activity.runOnUiThread(new Runnable()
881             {
882                 @Override
883                 public void run()
884                 {
885                     TextView view = activity.findViewById(R.id.exposureCompensationTextView);
886                     if (view != null)
887                     {
888                         view.setText(xv);
889                         view.invalidate();
890                     }
891                 }
892             });
893         }
894         catch (Exception e)
895         {
896             e.printStackTrace();
897         }
898     }
899
900     @Override
901     public void updatedMeteringMode(final String meteringMode)
902     {
903         try
904         {
905             Log.v(TAG, "updatedMeteringMode() : " + meteringMode);
906             final FragmentActivity activity = getActivity();
907             if ((activity == null)||(meteringMode == null))
908             {
909                 return;
910             }
911
912             int iconId = R.drawable.ic_crop_free_black_24dp;
913             switch (meteringMode)
914             {
915                 case ICameraStatus.AE_STATUS_MULTI:
916                 case ICameraStatus.AE_STATUS_ESP:
917                     iconId = R.drawable.ic_crop_free_black_24dp;
918                     break;
919                 case ICameraStatus.AE_STATUS_CENTER:
920                 case ICameraStatus.AE_STATUS_CENTER2:
921                     iconId = R.drawable.ic_center_focus_weak_black_24dp;
922                     break;
923                 case ICameraStatus.AE_STATUS_SPOT:
924                 case ICameraStatus.AE_STATUS_PINPOINT:
925                     iconId = R.drawable.ic_filter_center_focus_black_24dp;
926                     break;
927             }
928             final int id = iconId;
929             activity.runOnUiThread(new Runnable()
930             {
931                 @Override
932                 public void run()
933                 {
934                     ImageView view = activity.findViewById(R.id.aeModeImageView);
935                     if (view != null)
936                     {
937                         view.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
938                         view.invalidate();
939                     }
940                 }
941             });
942         }
943         catch (Exception e)
944         {
945             e.printStackTrace();
946         }
947     }
948
949     @Override
950     public void updatedWBMode(final String wbMode)
951     {
952         // とりあえず何もしない... 選択肢は以下 (Ricohの場合...)
953         // auto, multiAuto, daylight, shade, cloud, tungsten, warmWhiteFluorescent, daylightFluorescent, dayWhiteFluorescent, coolWhiteFluorescent, incandescent,manual1, cte, custom
954     }
955
956     /**
957      *   残りバッテリー状態をアイコンで示す
958      *
959      */
960     @Override
961     public void updateRemainBattery(final int percentage)
962     {
963         try
964         {
965             final FragmentActivity activity = getActivity();
966             if (activity == null)
967             {
968                 return;
969             }
970             int iconId;
971             if (percentage < 20)
972             {
973                 iconId = R.drawable.ic_battery_alert_black_24dp;
974             }
975             else if (percentage < 60)
976             {
977                 iconId = R.drawable.ic_battery_20_black_24dp;
978             }
979             else if (percentage < 80)
980             {
981                 iconId = R.drawable.ic_battery_60_black_24dp;
982             }
983             else
984             {
985                 iconId = R.drawable.ic_battery_full_black_24dp;
986             }
987             final int id = iconId;
988             activity.runOnUiThread(new Runnable()
989             {
990                 @Override
991                 public void run()
992                 {
993                     ImageView view = activity.findViewById(R.id.currentBatteryImageView);
994                     if (view != null)
995                     {
996                         Drawable target = ResourcesCompat.getDrawable(getResources(), id, null);
997                         if (target != null)
998                         {
999                             if (percentage <= 20)
1000                             {
1001                                 DrawableCompat.setTint(target, Color.RED);
1002                             } else if (percentage <= 40)
1003                             {
1004                                 DrawableCompat.setTint(target, Color.YELLOW);
1005                             }
1006                             view.setImageDrawable(target);
1007                             view.invalidate();
1008                         }
1009                     }
1010                 }
1011             });
1012         }
1013         catch (Exception e)
1014         {
1015             e.printStackTrace();
1016         }
1017     }
1018
1019     @Override
1020     public void updateFocusedStatus(final boolean focused, final boolean focusLocked)
1021     {
1022         final FragmentActivity activity = getActivity();
1023         try
1024         {
1025             if (activity != null)
1026             {
1027                 activity.runOnUiThread(new Runnable() {
1028                     @Override
1029                     public void run() {
1030                         try
1031                         {
1032                             ImageView view = activity.findViewById(R.id.focusUnlockImageView);
1033                             if (focused) {
1034                                 Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_center_focus_strong_black_24dp, null);
1035                                 if (icon != null) {
1036                                     DrawableCompat.setTint(icon, Color.GREEN);
1037                                     view.setImageDrawable(icon);
1038                                 }
1039                             } else {
1040                                 Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_focus_free_black_24dp, null);
1041                                 if (icon != null) {
1042                                     int color = Color.BLACK;
1043                                     if (focusLocked) {
1044                                         color = Color.RED;
1045                                     }
1046                                     DrawableCompat.setTint(icon, color);
1047                                     view.setImageDrawable(icon);
1048                                 }
1049                             }
1050                             view.invalidate();
1051                         }
1052                         catch (Exception e)
1053                         {
1054                             e.printStackTrace();
1055                         }
1056                     }
1057                 });
1058             }
1059         }
1060         catch (Exception e)
1061         {
1062             e.printStackTrace();
1063         }
1064     }
1065
1066     @Override
1067     public void updateIsoSensitivity(String sv)
1068     {
1069         Log.v(TAG, "updateIsoSensitivity : " + sv);
1070     }
1071
1072     @Override
1073     public void updateWarning(String warning)
1074     {
1075         Log.v(TAG, "updateWarning : " + warning);
1076     }
1077
1078     @Override
1079     public void updateStorageStatus(String status)
1080     {
1081         Log.v(TAG, "updateStorageStatus : " + status);
1082     }
1083
1084     @Override
1085     public void updateToggleButton(boolean isOn)
1086     {
1087         try
1088         {
1089             FragmentActivity activity = getActivity();
1090             if (activity != null)
1091             {
1092                 ImageView imageView = activity.findViewById(R.id.button_toggle_aeaf);
1093                 if (isOn)
1094                 {
1095                     imageView.setImageDrawable(ContextCompat.getDrawable(activity,R.drawable.ic_radio_button_checked_black_24dp));
1096                 }
1097                 else
1098                 {
1099                     imageView.setImageDrawable(ContextCompat.getDrawable(activity,R.drawable.ic_radio_button_unchecked_black_24dp));
1100                 }
1101                 imageView.invalidate();
1102             }
1103         }
1104         catch (Exception e)
1105         {
1106             e.printStackTrace();
1107         }
1108     }
1109
1110     @Override
1111     public void updateLcdOnOff(boolean isOn)
1112     {
1113         Log.v(TAG, "updateLcdOnOff() " + isOn);
1114     }
1115
1116     @Override
1117     public void updateAFLlever(boolean isCaf)
1118     {
1119         try
1120         {
1121             FragmentActivity activity = getActivity();
1122             if (activity != null)
1123             {
1124                 TextView textView = activity.findViewById(R.id.lever_ael_caf);
1125                 if (isCaf)
1126                 {
1127                     textView.setText(getString(R.string.label_c_af));
1128                 }
1129                 else
1130                 {
1131                     textView.setText(getString(R.string.label_aelock));
1132                 }
1133                 textView.invalidate();
1134             }
1135         }
1136         catch (Exception e)
1137         {
1138             e.printStackTrace();
1139         }
1140     }
1141
1142     public boolean handleKeyDown(int keyCode, KeyEvent event)
1143     {
1144         return (onClickTouchListener.onKey(null, keyCode, event));
1145     }
1146 }