OSDN Git Service

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