OSDN Git Service

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