OSDN Git Service

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