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.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(getActivity(), interfaceProvider, vibrator);
230             }
231             setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_sv_minus);
232             setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_sv_plus);
233             setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_tv_minus);
234             setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_tv_plus);
235             setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_xv_minus);
236             setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_xv_plus);
237             setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_flash);
238             setFujiXKeyPanelClickListener(view, R.id.button_fuji_x_timer);
239
240             connectStatus = view.findViewById(R.id.connect_disconnect_button);
241             if (connectStatus != null)
242             {
243                 connectStatus.setOnClickListener(onClickTouchListener);
244             }
245
246             View keyPanel = view.findViewById(R.id.showKeyPanelImageView);
247             ICameraButtonControl buttonControl = interfaceProvider.getButtonControl();
248             if (keyPanel != null)
249             {
250                 keyPanel.setVisibility((buttonControl == null) ? View.INVISIBLE : View.VISIBLE);
251                 keyPanel.invalidate();
252             }
253         }
254         catch (Exception e)
255         {
256             e.printStackTrace();
257         }
258
259         return (view);
260     }
261
262     private void setOnClickListener(View view, int id)
263     {
264         try
265         {
266             View button = view.findViewById(id);
267             if (button != null)
268             {
269                 button.setOnClickListener(onClickTouchListener);
270             }
271         }
272         catch (Exception e)
273         {
274             e.printStackTrace();
275         }
276     }
277
278     private void setPanelClickListener(View view, int id)
279     {
280         try
281         {
282             View button = view.findViewById(id);
283             if (button != null)
284             {
285                 button.setOnClickListener(onPanelClickListener);
286             }
287         }
288         catch (Exception e)
289         {
290             e.printStackTrace();
291         }
292     }
293
294     private void setKeyPanelClickListener(View view, int id)
295     {
296         try
297         {
298             View button = view.findViewById(id);
299             if (button != null)
300             {
301                 button.setOnClickListener(onKeyPanelClickListener);
302                 button.setOnLongClickListener(onKeyPanelClickListener);
303             }
304         }
305         catch (Exception e)
306         {
307             e.printStackTrace();
308         }
309     }
310
311     private void setFujiXKeyPanelClickListener(View view, int id)
312     {
313         try
314         {
315             View button = view.findViewById(id);
316             if (button != null)
317             {
318                 button.setOnClickListener(fujiXOnKeyPanelClickListener);
319                 button.setOnLongClickListener(fujiXOnKeyPanelClickListener);
320             }
321         }
322         catch (Exception e)
323         {
324             e.printStackTrace();
325         }
326     }
327
328     /**
329      *
330      */
331     private void prepare(IChangeScene sceneSelector, IInterfaceProvider interfaceProvider)
332     {
333         Log.v(TAG, "prepare()");
334
335         this.changeScene = sceneSelector;
336         this.interfaceProvider = interfaceProvider;
337         this.interfaceInjector = interfaceProvider.getDisplayInjector();
338         this.liveViewControl = interfaceProvider.getLiveViewControl();
339         this.zoomLensControl = interfaceProvider.getZoomLensControl();
340         this.cameraInformation = interfaceProvider.getCameraInformation();
341         this.statusWatcher = interfaceProvider.getCameraStatusWatcher();
342     }
343
344     /**
345      *  カメラとの接続状態の更新
346      *
347      */
348     @Override
349     public void updateConnectionStatus(final ICameraConnection.CameraConnectionStatus connectionStatus)
350     {
351         try
352         {
353             currentConnectionStatus = connectionStatus;
354             runOnUiThread(new Runnable()
355             {
356                 @Override
357                 public void run()
358                 {
359                     int id = R.drawable.ic_cloud_off_black_24dp;
360                     if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTING)
361                     {
362                         id = R.drawable.ic_cloud_queue_black_24dp;
363                     }
364                     else if  (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
365                     {
366                         id = R.drawable.ic_cloud_done_black_24dp;
367                     }
368                     if (connectStatus != null)
369                     {
370                         connectStatus.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
371                         connectStatus.invalidate();
372                     }
373                     if (imageView != null)
374                     {
375                         imageView.invalidate();
376                     }
377                 }
378             });
379
380         }
381         catch (Exception e)
382         {
383             e.printStackTrace();
384         }
385     }
386
387     /**
388      *  グリッドの表示・非表示の更新
389      *
390      */
391     @Override
392     public void updateGridIcon()
393     {
394         try
395         {
396             FragmentActivity activity = getActivity();
397             if (activity != null)
398             {
399                 if (showGrid == null) {
400                     showGrid = activity.findViewById(R.id.show_hide_grid_button);
401                 }
402                 activity.runOnUiThread(new Runnable() {
403                     @Override
404                     public void run()
405                     {
406                         int id = (imageView.isShowGrid()) ? R.drawable.ic_grid_off_black_24dp : R.drawable.ic_grid_on_black_24dp;
407                         if (showGrid != null)
408                         {
409                             showGrid.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
410                             showGrid.invalidate();
411                         }
412                         imageView.invalidate();
413                     }
414                 });
415             }
416         }
417         catch (Exception e)
418         {
419             e.printStackTrace();
420         }
421     }
422
423     /**
424      *
425      *
426      */
427     @Override
428     public void changedFocusingMode()
429     {
430         try
431         {
432             if ((cameraInformation == null)||(manualFocus == null))
433             {
434                 return;
435             }
436             runOnUiThread(new Runnable()
437             {
438                 @Override
439                 public void run()
440                 {
441                     if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
442                     {
443                         manualFocus.setSelected(cameraInformation.isManualFocus());
444                         manualFocus.invalidate();
445                     }
446                 }
447             });
448         }
449         catch (Exception e)
450         {
451             e.printStackTrace();
452         }
453     }
454
455     @Override
456     public void updateLiveViewScale(boolean isChangeScale)
457     {
458         try
459         {
460             Log.v(TAG, "updateLiveViewScale() : " + isChangeScale);
461
462             // ライブビューの倍率設定
463             liveViewControl.updateMagnifyingLiveViewScale(isChangeScale);
464
465             // ボタンの文字を更新する
466             float scale = liveViewControl.getMagnifyingLiveViewScale();
467             final String datavalue = "LV: " + scale;
468
469             // デジタルズームの倍率を表示する
470             float digitalZoom = liveViewControl.getDigitalZoomScale();
471             final String digitalValue = (digitalZoom > 1.0f) ? "D x" + digitalZoom : "";
472
473             // 更新自体は、UIスレッドで行う
474             runOnUiThread(new Runnable()
475             {
476                 @Override
477                 public void run()
478                 {
479                     changeLiveViewScale.setText(datavalue);
480                     changeLiveViewScale.postInvalidate();
481
482                     focalLengthArea.setText(digitalValue);
483                     focalLengthArea.postInvalidate();
484                 }
485             });
486         }
487         catch (Exception e)
488         {
489             e.printStackTrace();
490         }
491     }
492
493     /**
494      *
495      *
496      *
497      */
498     @Override
499     public void onStart()
500     {
501         super.onStart();
502         Log.v(TAG, "onStart()");
503     }
504
505     /**
506      *
507      *
508      */
509     @Override
510     public void onResume()
511     {
512         super.onResume();
513         Log.v(TAG, "onResume() Start");
514
515         AppCompatActivity activity = (AppCompatActivity)getActivity();
516         if (activity != null)
517         {
518             ActionBar bar = activity.getSupportActionBar();
519             if (bar != null)
520             {
521                 bar.hide();   // ActionBarの表示を消す
522             }
523         }
524
525         // 撮影モードかどうかを確認して、撮影モードではなかったら撮影モードに切り替える
526         ICameraRunMode changeRunModeExecutor = interfaceProvider.getCameraRunMode();
527         if ((changeRunModeExecutor != null)&&(!changeRunModeExecutor.isRecordingMode()))
528         {
529             // Runモードを切り替える。(でも切り替えると、設定がクリアされてしまう...。)
530             changeRunModeExecutor.changeRunMode(true, this);
531             Log.v(TAG, "onResume() End");
532             return;
533         }
534         prepareToStart();
535         Log.v(TAG, "onResume() End");
536     }
537
538     private void prepareToStart()
539     {
540         try
541         {
542             Context context = getContext();
543             if (context != null)
544             {
545                 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
546
547                 // グリッド・フォーカスアシストの情報を戻す
548                 boolean showGrid = preferences.getBoolean(IPreferencePropertyAccessor.SHOW_GRID_STATUS, false);
549                 if ((imageView != null) && (imageView.isShowGrid() != showGrid)) {
550                     imageView.toggleShowGridFrame();
551                     imageView.postInvalidate();
552                 }
553             }
554             if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
555             {
556                 startLiveView();
557             }
558         }
559         catch (Exception e)
560         {
561             e.printStackTrace();
562         }
563     }
564
565     @Override
566     public void onCompleted(boolean isRecording)
567     {
568         prepareToStart();
569     }
570
571     @Override
572     public void onErrorOccurred(boolean isRecording)
573     {
574         prepareToStart();
575     }
576
577     /**
578      *
579      *
580      */
581     @Override
582     public void onPause()
583     {
584         super.onPause();
585         Log.v(TAG, "onPause() Start");
586
587         // ライブビューとステータス監視の停止
588         try
589         {
590             liveViewControl.stopLiveView();
591             stopWatchStatus();
592         }
593         catch (Exception e)
594         {
595             e.printStackTrace();
596         }
597
598         Log.v(TAG, "onPause() End");
599     }
600
601     /**
602      *   表示エリアに文字を表示する
603      *
604      */
605     @Override
606     public void updateStatusView(String message)
607     {
608         messageValue = message;
609         runOnUiThread(new Runnable()
610         {
611             /**
612              * カメラの状態(ステータステキスト)を更新する
613              * (ステータステキストは、プライベート変数で保持して、書き換える)
614              */
615             @Override
616             public void run()
617             {
618                 if (statusArea != null)
619                 {
620                     statusArea.setText(messageValue);
621                     statusArea.invalidate();
622                 }
623             }
624         });
625     }
626
627     /**
628      *   ライブビューの開始
629      *
630      */
631     @Override
632     public void startLiveView()
633     {
634         Log.v(TAG, " LiveViewFragment::startLiveView() ");
635         ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
636         if (liveViewControl == null)
637         {
638             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
639             {
640                 Log.v(TAG, "startLiveView() : liveViewControl is null.");
641                 return;
642             }
643             else
644             {
645                 // ダミー
646                 prepare(changeScene, interfaceProvider);
647             }
648         }
649         try
650         {
651             // ライブビューの開始
652             Context context = getContext();
653             boolean isCameraScreen = true;
654             if (context != null)
655             {
656                 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
657                 liveViewControl.changeLiveViewSize(preferences.getString(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY, IPreferencePropertyAccessor.LIVE_VIEW_QUALITY_DEFAULT_VALUE));
658                 isCameraScreen = preferences.getBoolean(IPreferencePropertyAccessor.GR2_DISPLAY_CAMERA_VIEW, true);
659             }
660             ILiveViewListener lvListener = interfaceProvider.getLiveViewListener();
661             if (lvListener != null)
662             {
663                 lvListener.setCameraLiveImageView(imageView);
664             }
665             liveViewControl.startLiveView(isCameraScreen);   // false : ライブビューのみ、 true : カメラ画面をミラー
666
667             // ここでグリッドアイコンを更新する
668             updateGridIcon();
669
670             // ここでズームレンズ制御ができるか確認する
671             if ((zoomLensControl != null)&&(zoomLensControl.canZoom()))
672             {
673                 //Log.v(TAG, "CAN ZOOM LENS");
674                 updateZoomlensControl(true);
675             }
676             else
677             {
678                 //Log.v(TAG, "NO ZOOM LENS");
679                 updateZoomlensControl(false);
680             }
681
682
683             // ステータス監視も実施する
684             startWatchStatus();
685         }
686         catch (Exception e)
687         {
688             e.printStackTrace();
689         }
690     }
691
692     @Override
693     public void showFavoriteSettingDialog()
694     {
695         try
696         {
697             Log.v(TAG, "showFavoriteSettingDialog()");
698             LoadSaveMyCameraPropertyDialog dialog = LoadSaveMyCameraPropertyDialog.newInstance(new LoadSaveCameraProperties(getActivity(), interfaceProvider.getOlympusInterfaceProvider()));
699             dialog.show(getChildFragmentManager(), "favorite_dialog");
700         }
701         catch (Exception e)
702         {
703             e.printStackTrace();
704         }
705     }
706
707     /**
708      *
709      *
710      *
711      */
712     private void updateZoomlensControl(final boolean isVisible)
713     {
714         runOnUiThread(new Runnable() {
715             @Override
716             public void run() {
717                 // isVisibleがtrueなら、ズームレンズボタンを有効にする
718                 FragmentActivity activity = getActivity();
719                 if (activity != null)
720                 {
721                     try
722                     {
723                         View view1 = activity.findViewById(R.id.zoom_out_button);
724                         if (view1 != null)
725                         {
726                             view1.setVisibility((isVisible) ? View.VISIBLE : View.INVISIBLE);
727                             view1.invalidate();
728                         }
729
730                         View view2 = activity.findViewById(R.id.zoom_in_button);
731                         if (view2 != null)
732                         {
733                             view2.setVisibility((isVisible) ? View.VISIBLE : View.INVISIBLE);
734                             view2.invalidate();
735                         }
736                     }
737                     catch (Exception e)
738                     {
739                         e.printStackTrace();
740                     }
741                 }
742             }
743         });
744     }
745
746     /**
747      *
748      *
749      */
750     private void startWatchStatus()
751     {
752         if (statusWatcher != null)
753         {
754             statusWatcher.startStatusWatch(this);
755         }
756     }
757
758     /**
759      *
760      *
761      */
762     private void stopWatchStatus()
763     {
764         if (statusWatcher != null)
765         {
766             statusWatcher.stopStatusWatch();
767         }
768     }
769
770     /**
771      *
772      *
773      */
774     private void runOnUiThread(Runnable action)
775     {
776         FragmentActivity activity = getActivity();
777         if (activity == null)
778         {
779             return;
780         }
781         activity.runOnUiThread(action);
782     }
783
784     @Override
785     public void updatedTakeMode(final String mode)
786     {
787         try
788         {
789             final FragmentActivity activity = getActivity();
790             if (activity == null)
791             {
792                 return;
793             }
794             activity.runOnUiThread(new Runnable()
795             {
796                 @Override
797                 public void run()
798                 {
799                     TextView view = activity.findViewById(R.id.takemodeTextView);
800                     if (view != null)
801                     {
802                         view.setText(mode);
803                         view.invalidate();
804                     }
805                 }
806             });
807         }
808         catch (Exception e)
809         {
810             e.printStackTrace();
811         }
812     }
813
814     @Override
815     public void updatedShutterSpeed(final String tv)
816     {
817         try
818         {
819             final String shutterSpeed = tv.replace(".", "/");
820             final FragmentActivity activity = getActivity();
821             if (activity == null)
822             {
823                 return;
824             }
825             activity.runOnUiThread(new Runnable()
826             {
827                 @Override
828                 public void run()
829                 {
830                     TextView view = activity.findViewById(R.id.shutterSpeedTextView);
831                     if (view != null) {
832                         view.setText(shutterSpeed);
833                         view.invalidate();
834                     }
835                 }
836             });
837         }
838         catch (Exception e)
839         {
840             e.printStackTrace();
841         }
842
843     }
844
845     @Override
846     public void updatedAperture(final String av)
847     {
848         try
849         {
850             final String apertureValue = (av.length() > 1) ? ("F" + av) : "";
851             final FragmentActivity activity = getActivity();
852             if (activity == null)
853             {
854                 return;
855             }
856             activity.runOnUiThread(new Runnable()
857             {
858                 @Override
859                 public void run()
860                 {
861                     TextView view = activity.findViewById(R.id.apertureValueTextView);
862                     if (view != null)
863                     {
864                         view.setText(apertureValue);
865                         view.invalidate();
866                     }
867                 }
868             });
869         }
870         catch (Exception e)
871         {
872             e.printStackTrace();
873         }
874     }
875
876     @Override
877     public void updatedExposureCompensation(final String xv)
878     {
879         try
880         {
881             final FragmentActivity activity = getActivity();
882             if (activity == null)
883             {
884                 return;
885             }
886             activity.runOnUiThread(new Runnable()
887             {
888                 @Override
889                 public void run()
890                 {
891                     TextView view = activity.findViewById(R.id.exposureCompensationTextView);
892                     if (view != null)
893                     {
894                         view.setText(xv);
895                         view.invalidate();
896                     }
897                 }
898             });
899         }
900         catch (Exception e)
901         {
902             e.printStackTrace();
903         }
904     }
905
906     @Override
907     public void updatedMeteringMode(final String meteringMode)
908     {
909         try
910         {
911             Log.v(TAG, "updatedMeteringMode() : " + meteringMode);
912             final FragmentActivity activity = getActivity();
913             if ((activity == null)||(meteringMode == null))
914             {
915                 return;
916             }
917
918             int iconId = R.drawable.ic_crop_free_black_24dp;
919             switch (meteringMode)
920             {
921                 case ICameraStatus.AE_STATUS_MULTI:
922                 case ICameraStatus.AE_STATUS_ESP:
923                     iconId = R.drawable.ic_crop_free_black_24dp;
924                     break;
925                 case ICameraStatus.AE_STATUS_CENTER:
926                 case ICameraStatus.AE_STATUS_CENTER2:
927                     iconId = R.drawable.ic_center_focus_weak_black_24dp;
928                     break;
929                 case ICameraStatus.AE_STATUS_SPOT:
930                 case ICameraStatus.AE_STATUS_PINPOINT:
931                     iconId = R.drawable.ic_filter_center_focus_black_24dp;
932                     break;
933             }
934             final int id = iconId;
935             activity.runOnUiThread(new Runnable()
936             {
937                 @Override
938                 public void run()
939                 {
940                     ImageView view = activity.findViewById(R.id.aeModeImageView);
941                     if (view != null)
942                     {
943                         view.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
944                         view.invalidate();
945                     }
946                 }
947             });
948         }
949         catch (Exception e)
950         {
951             e.printStackTrace();
952         }
953     }
954
955     @Override
956     public void updatedWBMode(final String wbMode)
957     {
958         // とりあえず何もしない... 選択肢は以下 (Ricohの場合...)
959         // auto, multiAuto, daylight, shade, cloud, tungsten, warmWhiteFluorescent, daylightFluorescent, dayWhiteFluorescent, coolWhiteFluorescent, incandescent,manual1, cte, custom
960     }
961
962     /**
963      *   残りバッテリー状態をアイコンで示す
964      *
965      */
966     @Override
967     public void updateRemainBattery(final int percentage)
968     {
969         try
970         {
971             final FragmentActivity activity = getActivity();
972             if (activity == null)
973             {
974                 return;
975             }
976             int iconId;
977             if (percentage < 20)
978             {
979                 iconId = R.drawable.ic_battery_alert_black_24dp;
980             }
981             else if (percentage < 60)
982             {
983                 iconId = R.drawable.ic_battery_20_black_24dp;
984             }
985             else if (percentage < 80)
986             {
987                 iconId = R.drawable.ic_battery_60_black_24dp;
988             }
989             else
990             {
991                 iconId = R.drawable.ic_battery_full_black_24dp;
992             }
993             final int id = iconId;
994             activity.runOnUiThread(new Runnable()
995             {
996                 @Override
997                 public void run()
998                 {
999                     ImageView view = activity.findViewById(R.id.currentBatteryImageView);
1000                     if (view != null)
1001                     {
1002                         Drawable target = ResourcesCompat.getDrawable(getResources(), id, null);
1003                         if (target != null)
1004                         {
1005                             if (percentage <= 20)
1006                             {
1007                                 DrawableCompat.setTint(target, Color.RED);
1008                             } else if (percentage <= 40)
1009                             {
1010                                 DrawableCompat.setTint(target, Color.YELLOW);
1011                             }
1012                             view.setImageDrawable(target);
1013                             view.invalidate();
1014                         }
1015                     }
1016                 }
1017             });
1018         }
1019         catch (Exception e)
1020         {
1021             e.printStackTrace();
1022         }
1023     }
1024
1025     @Override
1026     public void updateFocusedStatus(final boolean focused, final boolean focusLocked)
1027     {
1028         final FragmentActivity activity = getActivity();
1029         try
1030         {
1031             if (activity != null)
1032             {
1033                 activity.runOnUiThread(new Runnable() {
1034                     @Override
1035                     public void run() {
1036                         try
1037                         {
1038                             ImageView view = activity.findViewById(R.id.focusUnlockImageView);
1039                             if (focused) {
1040                                 Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_center_focus_strong_black_24dp, null);
1041                                 if (icon != null) {
1042                                     DrawableCompat.setTint(icon, Color.GREEN);
1043                                     view.setImageDrawable(icon);
1044                                 }
1045                             } else {
1046                                 Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_focus_free_black_24dp, null);
1047                                 if (icon != null) {
1048                                     int color = Color.BLACK;
1049                                     if (focusLocked) {
1050                                         color = Color.RED;
1051                                     }
1052                                     DrawableCompat.setTint(icon, color);
1053                                     view.setImageDrawable(icon);
1054                                 }
1055                             }
1056                             view.invalidate();
1057                         }
1058                         catch (Exception e)
1059                         {
1060                             e.printStackTrace();
1061                         }
1062                     }
1063                 });
1064             }
1065         }
1066         catch (Exception e)
1067         {
1068             e.printStackTrace();
1069         }
1070     }
1071
1072     @Override
1073     public void updateIsoSensitivity(String sv)
1074     {
1075         Log.v(TAG, "updateIsoSensitivity : " + sv);
1076     }
1077
1078     @Override
1079     public void updateWarning(String warning)
1080     {
1081         Log.v(TAG, "updateWarning : " + warning);
1082     }
1083
1084     @Override
1085     public void updateStorageStatus(String status)
1086     {
1087         Log.v(TAG, "updateStorageStatus : " + status);
1088     }
1089
1090     @Override
1091     public void updateToggleButton(boolean isOn)
1092     {
1093         try
1094         {
1095             FragmentActivity activity = getActivity();
1096             if (activity != null)
1097             {
1098                 ImageView imageView = activity.findViewById(R.id.button_toggle_aeaf);
1099                 if (isOn)
1100                 {
1101                     imageView.setImageDrawable(ContextCompat.getDrawable(activity,R.drawable.ic_radio_button_checked_black_24dp));
1102                 }
1103                 else
1104                 {
1105                     imageView.setImageDrawable(ContextCompat.getDrawable(activity,R.drawable.ic_radio_button_unchecked_black_24dp));
1106                 }
1107                 imageView.invalidate();
1108             }
1109         }
1110         catch (Exception e)
1111         {
1112             e.printStackTrace();
1113         }
1114     }
1115
1116     @Override
1117     public void updateLcdOnOff(boolean isOn)
1118     {
1119         Log.v(TAG, "updateLcdOnOff() " + isOn);
1120     }
1121
1122     @Override
1123     public void updateAFLlever(boolean isCaf)
1124     {
1125         try
1126         {
1127             FragmentActivity activity = getActivity();
1128             if (activity != null)
1129             {
1130                 TextView textView = activity.findViewById(R.id.lever_ael_caf);
1131                 if (isCaf)
1132                 {
1133                     textView.setText(getString(R.string.label_c_af));
1134                 }
1135                 else
1136                 {
1137                     textView.setText(getString(R.string.label_aelock));
1138                 }
1139                 textView.invalidate();
1140             }
1141         }
1142         catch (Exception e)
1143         {
1144             e.printStackTrace();
1145         }
1146     }
1147
1148     public boolean handleKeyDown(int keyCode, KeyEvent event)
1149     {
1150         return (onClickTouchListener.onKey(null, keyCode, event));
1151     }
1152 }