OSDN Git Service

0467914964d985a443afefb5c25d3621a7a04cbc
[gokigen/PKRemote.git] / app / src / main / java / net / osdn / gokigen / pkremote / camera / CameraInterfaceProvider.java
1 package net.osdn.gokigen.pkremote.camera;
2
3 import android.content.SharedPreferences;
4
5 import net.osdn.gokigen.pkremote.IInformationReceiver;
6 import net.osdn.gokigen.pkremote.camera.interfaces.control.ICameraButtonControl;
7 import net.osdn.gokigen.pkremote.camera.interfaces.control.ICameraConnection;
8 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.ILiveViewListener;
9 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContentsRecognizer;
10 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraHardwareStatus;
11 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraInformation;
12 import net.osdn.gokigen.pkremote.camera.interfaces.control.ICameraRunMode;
13 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatus;
14 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatusReceiver;
15 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatusWatcher;
16 import net.osdn.gokigen.pkremote.camera.interfaces.control.ICaptureControl;
17 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.IDisplayInjector;
18 import net.osdn.gokigen.pkremote.camera.interfaces.control.IFocusingControl;
19 import net.osdn.gokigen.pkremote.camera.interfaces.IInterfaceProvider;
20 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.ILiveViewControl;
21 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IPlaybackControl;
22 import net.osdn.gokigen.pkremote.camera.interfaces.control.IZoomLensControl;
23 import net.osdn.gokigen.pkremote.camera.playback.CameraContentsRecognizer;
24 import net.osdn.gokigen.pkremote.camera.utils.CameraStatusListener;
25 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.FujiXInterfaceProvider;
26 import net.osdn.gokigen.pkremote.camera.vendor.olympus.IOlympusInterfaceProvider;
27 import net.osdn.gokigen.pkremote.camera.vendor.olympus.wrapper.OlympusInterfaceProvider;
28 import net.osdn.gokigen.pkremote.camera.vendor.panasonic.wrapper.PanasonicCameraWrapper;
29 import net.osdn.gokigen.pkremote.camera.vendor.ricoh.wrapper.RicohGr2InterfaceProvider;
30 import net.osdn.gokigen.pkremote.camera.vendor.sony.ISonyInterfaceProvider;
31 import net.osdn.gokigen.pkremote.camera.vendor.sony.wrapper.SonyCameraWrapper;
32 import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor;
33 import net.osdn.gokigen.pkremote.preference.panasonic.PanasonicPreferenceFragment;
34
35 import androidx.annotation.NonNull;
36 import androidx.appcompat.app.AppCompatActivity;
37 import androidx.preference.PreferenceManager;
38
39 /**
40  *
41  *
42  */
43 public class CameraInterfaceProvider implements IInterfaceProvider
44 {
45     private final SonyCameraWrapper sony;
46     private final OlympusInterfaceProvider olympus;
47     private final RicohGr2InterfaceProvider ricohGr2;
48     private final FujiXInterfaceProvider fujiX;
49     private final PanasonicCameraWrapper panasonic;
50     private final IInformationReceiver informationReceiver;
51     private final CameraContentsRecognizer cameraContentsRecognizer;
52     private final AppCompatActivity context;
53     //private final CameraStatusListener statusListener;
54     private ICameraConnection.CameraConnectionMethod connectionMethod = ICameraConnection.CameraConnectionMethod.UNKNOWN;
55
56     public static IInterfaceProvider newInstance(@NonNull AppCompatActivity context, @NonNull ICameraStatusReceiver provider, @NonNull IInformationReceiver informationReceiver)
57     {
58         return (new CameraInterfaceProvider(context, provider, informationReceiver));
59     }
60
61     /**
62      *
63      *
64      */
65     private CameraInterfaceProvider(@NonNull AppCompatActivity context, @NonNull ICameraStatusReceiver provider, @NonNull IInformationReceiver informationReceiver)
66     {
67         this.context = context;
68         CameraStatusListener statusListener = new CameraStatusListener();
69         olympus = new OlympusInterfaceProvider(context, provider);
70         ricohGr2 = new RicohGr2InterfaceProvider(context, provider);
71         fujiX = new FujiXInterfaceProvider(context, provider, statusListener, informationReceiver);
72         sony = new SonyCameraWrapper(context, provider, statusListener, informationReceiver);
73         panasonic = new PanasonicCameraWrapper(context, provider, statusListener);
74         this.informationReceiver = informationReceiver;
75         this.cameraContentsRecognizer = new CameraContentsRecognizer(context, this);
76     }
77
78     @Override
79     public IOlympusInterfaceProvider getOlympusInterfaceProvider()
80     {
81         return (olympus);
82     }
83
84     @Override
85     public ISonyInterfaceProvider getSonyInterface()
86     {
87         return (sony);
88     }
89
90     /**
91      *
92      *
93      */
94     @Override
95     public ICameraConnection getCameraConnection()
96     {
97         try
98         {
99             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
100             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
101             {
102                 return (olympus.getOlyCameraConnection());
103             }
104             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
105             {
106                 return (fujiX.getFujiXCameraConnection());
107             }
108             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
109             {
110                 return (panasonic.getPanasonicCameraConnection());
111             }
112             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
113             {
114                 return (sony.getSonyCameraConnection());
115             }
116             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
117             {
118                 return (ricohGr2.getRicohGr2CameraConnection());
119             }
120         }
121         catch (Exception e)
122         {
123             e.printStackTrace();
124         }
125         return (null);
126     }
127
128     @Override
129     public ICameraButtonControl getButtonControl()
130     {
131         try
132         {
133             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
134             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
135             {
136                 return (olympus.getButtonControl());
137             }
138             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
139             {
140                 return (fujiX.getButtonControl());
141             }
142             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
143             {
144                 return (panasonic.getButtonControl());
145             }
146             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
147             {
148                 return (sony.getButtonControl());
149             }
150             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
151             {
152                 return (ricohGr2.getButtonControl());
153             }
154         }
155         catch (Exception e)
156         {
157             e.printStackTrace();
158         }
159         return (null);
160     }
161
162     @Override
163     public IDisplayInjector getDisplayInjector()
164     {
165         try
166         {
167             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
168             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
169             {
170                 return (olympus.getDisplayInjector());
171             }
172             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
173             {
174                 return (fujiX.getDisplayInjector());
175             }
176             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
177             {
178                 return (panasonic.getDisplayInjector());
179             }
180             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
181             {
182                 return (sony.getDisplayInjector());
183             }
184             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
185             {
186                 return (ricohGr2.getDisplayInjector());
187             }
188         }
189         catch (Exception e)
190         {
191             e.printStackTrace();
192         }
193         return (null);
194     }
195
196     @Override
197     public ILiveViewControl getLiveViewControl()
198     {
199         try
200         {
201             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
202             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
203             {
204                 return (olympus.getLiveViewControl());
205             }
206             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
207             {
208                 return (fujiX.getLiveViewControl());
209             }
210             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
211             {
212                 return (panasonic.getPanasonicLiveViewControl());
213             }
214             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
215             {
216                 return (sony.getLiveViewControl());
217             }
218             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
219             {
220                 return (ricohGr2.getLiveViewControl());
221             }
222         }
223         catch (Exception e)
224         {
225             e.printStackTrace();
226         }
227         return (null);
228     }
229
230     @Override
231     public ILiveViewListener getLiveViewListener()
232     {
233         try
234         {
235             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
236             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
237             {
238                 return (olympus.getLiveViewListener());
239             }
240             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
241             {
242                 return (fujiX.getLiveViewListener());
243             }
244             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
245             {
246                 return (panasonic.getLiveViewListener());
247             }
248             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
249             {
250                 return (sony.getLiveViewListener());
251             }
252             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
253             {
254                 return (ricohGr2.getLiveViewListener());
255             }
256         }
257         catch (Exception e)
258         {
259             e.printStackTrace();
260         }
261         return (null);
262     }
263
264     @Override
265     public IFocusingControl getFocusingControl()
266     {
267         try
268         {
269             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
270             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
271             {
272                 return (olympus.getFocusingControl());
273             }
274             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
275             {
276                 return (fujiX.getFocusingControl());
277             }
278             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
279             {
280                 return (panasonic.getFocusingControl());
281             }
282             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
283             {
284                 return (sony.getFocusingControl());
285             }
286             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
287             {
288                 return (ricohGr2.getFocusingControl());
289             }
290         }
291         catch (Exception e)
292         {
293             e.printStackTrace();
294         }
295         return (null);
296     }
297
298     @Override
299     public ICameraInformation getCameraInformation()
300     {
301         try
302         {
303             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
304             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
305             {
306                 return (olympus.getCameraInformation());
307             }
308             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
309             {
310                 return (fujiX.getCameraInformation());
311             }
312             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
313             {
314                 return (panasonic.getCameraInformation());
315             }
316             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
317             {
318                 return (sony.getCameraInformation());
319             }
320             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
321             {
322                 return (ricohGr2.getCameraInformation());
323             }
324         }
325         catch (Exception e)
326         {
327             e.printStackTrace();
328         }
329         return (null);
330     }
331
332     @Override
333     public IZoomLensControl getZoomLensControl()
334     {
335         try
336         {
337             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
338             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
339             {
340                 return (olympus.getZoomLensControl());
341             }
342             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
343             {
344                 return (fujiX.getZoomLensControl());
345             }
346             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
347             {
348                 return (panasonic.getZoomLensControl());
349             }
350             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
351             {
352                 return (sony.getZoomLensControl());
353             }
354             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
355             {
356                 return (ricohGr2.getZoomLensControl());
357             }
358         }
359         catch (Exception e)
360         {
361             e.printStackTrace();
362         }
363         return (null);
364     }
365
366     @Override
367     public ICaptureControl getCaptureControl()
368     {
369         try
370         {
371             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
372             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
373             {
374                 return (olympus.getCaptureControl());
375             }
376             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
377             {
378                 return (fujiX.getCaptureControl());
379             }
380             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
381             {
382                 return (panasonic.getCaptureControl());
383             }
384             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
385             {
386                 return (sony.getCaptureControl());
387             }
388             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
389             {
390                 return (ricohGr2.getCaptureControl());
391             }
392         }
393         catch (Exception e)
394         {
395             e.printStackTrace();
396         }
397         return (null);
398     }
399
400     @Override
401     public ICameraStatus getCameraStatusListHolder()
402     {
403         try
404         {
405             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
406             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
407             {
408                 return (olympus.getCameraStatusListHolder());
409             }
410             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
411             {
412                 return (fujiX.getCameraStatusListHolder());
413             }
414             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
415             {
416                 return (panasonic.getCameraStatusListHolder());
417             }
418             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
419             {
420                 return (sony.getCameraStatusListHolder());
421             }
422             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
423             {
424                 return (ricohGr2.getCameraStatusListHolder());
425             }
426         }
427         catch (Exception e)
428         {
429             e.printStackTrace();
430         }
431         return (null);
432     }
433
434     @Override
435     public ICameraStatusWatcher getCameraStatusWatcher()
436     {
437         try
438         {
439             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
440             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
441             {
442                 return (olympus.getCameraStatusWatcher());
443             }
444             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
445             {
446                 return (fujiX.getCameraStatusWatcher());
447             }
448             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
449             {
450                 return (panasonic.getCameraStatusWatcher());
451             }
452             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
453             {
454                 return (sony.getCameraStatusWatcher());
455             }
456             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
457             {
458                 return (ricohGr2.getCameraStatusWatcher());
459             }
460         }
461         catch (Exception e)
462         {
463             e.printStackTrace();
464         }
465         return (null);
466     }
467
468     @Override
469     public IPlaybackControl getPlaybackControl()
470     {
471         try
472         {
473             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
474             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
475             {
476                 return (olympus.getPlaybackControl());
477             }
478             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
479             {
480                 return (fujiX.getPlaybackControl());
481             }
482             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
483             {
484                 return (panasonic.getPlaybackControl());
485             }
486             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
487             {
488                 return (sony.getPlaybackControl());
489             }
490             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
491             {
492                 return (ricohGr2.getPlaybackControl());
493             }
494         }
495         catch (Exception e)
496         {
497             e.printStackTrace();
498         }
499         return (null);
500     }
501
502     @Override
503     public ICameraHardwareStatus getHardwareStatus()
504     {
505         try
506         {
507             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
508             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
509             {
510                 return (olympus.getHardwareStatus());
511             }
512             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
513             {
514                 return (fujiX.getHardwareStatus());
515             }
516             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
517             {
518                 return (panasonic.getHardwareStatus());
519             }
520             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
521             {
522                 return (sony.getHardwareStatus());
523             }
524             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
525             {
526                 return (ricohGr2.getHardwareStatus());
527             }
528         }
529         catch (Exception e)
530         {
531             e.printStackTrace();
532         }
533         return (null);
534     }
535
536     @Override
537     public ICameraRunMode getCameraRunMode()
538     {
539         try
540         {
541             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
542             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
543             {
544                 return (olympus.getCameraRunMode());
545             }
546             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
547             {
548                 return (fujiX.getCameraRunMode());
549             }
550             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
551             {
552                 return (panasonic.getCameraRunMode());
553             }
554             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
555             {
556                 return (sony.getCameraRunMode());
557             }
558             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
559             {
560                 return (ricohGr2.getCameraRunMode());
561             }
562         }
563         catch (Exception e)
564         {
565             e.printStackTrace();
566         }
567         return (null);
568     }
569
570     /**
571      *   OPC/GR2/SONY カメラを使用するかどうか
572      *
573      * @return OPC / SONY / RICOH  (ICameraConnection.CameraConnectionMethod)
574      */
575     public ICameraConnection.CameraConnectionMethod getCammeraConnectionMethod()
576     {
577         return (getCammeraConnectionMethodImpl());
578     }
579
580     /**
581      *
582      *
583      */
584     @Override
585     public void resetCameraConnectionMethod()
586     {
587         connectionMethod = ICameraConnection.CameraConnectionMethod.UNKNOWN;
588     }
589
590     /**
591      *
592      *
593      */
594     @Override
595     public IInformationReceiver getInformationReceiver()
596     {
597         return (informationReceiver);
598     }
599
600     @Override
601     public ICameraContentsRecognizer getCameraContentsRecognizer()
602     {
603         return (cameraContentsRecognizer);
604     }
605
606     /**
607      *
608      *
609      */
610     private ICameraConnection.CameraConnectionMethod getCammeraConnectionMethodImpl()
611     {
612         if (connectionMethod != ICameraConnection.CameraConnectionMethod.UNKNOWN)
613         {
614             return (connectionMethod);
615         }
616         ICameraConnection.CameraConnectionMethod ret;
617         try
618         {
619             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
620             String connectionMethod = preferences.getString(IPreferencePropertyAccessor.CONNECTION_METHOD, "RICOH");
621             if (connectionMethod.contains("RICOH"))
622             {
623                 ret = ICameraConnection.CameraConnectionMethod.RICOH;
624             }
625             else if (connectionMethod.contains("FUJI_X"))
626             {
627                 ret = ICameraConnection.CameraConnectionMethod.FUJI_X;
628             }
629             else if (connectionMethod.contains("PANASONIC"))
630             {
631                 ret = ICameraConnection.CameraConnectionMethod.PANASONIC;
632             }
633             else if (connectionMethod.contains("SONY"))
634             {
635                 ret = ICameraConnection.CameraConnectionMethod.SONY;
636             }
637             else // if (connectionMethod.contains("OPC"))
638             {
639                 ret = ICameraConnection.CameraConnectionMethod.OPC;
640             }
641 /*
642             else if (connectionMethod.contains("SONY"))
643             {
644                 ret = ICameraConnection.CameraConnectionMethod.SONY;
645             }
646 */
647         }
648         catch (Exception e)
649         {
650             e.printStackTrace();
651             ret = ICameraConnection.CameraConnectionMethod.UNKNOWN;
652         }
653         connectionMethod = ret;
654         return (connectionMethod);
655     }
656 }