OSDN Git Service

Panasonicの一覧表示を入れてみた。
[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);
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.RICOH)
113             {
114                 return (ricohGr2.getRicohGr2CameraConnection());
115             }
116         }
117         catch (Exception e)
118         {
119             e.printStackTrace();
120         }
121         return (null);
122     }
123
124     @Override
125     public ICameraButtonControl getButtonControl()
126     {
127         try
128         {
129             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
130             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
131             {
132                 return (olympus.getButtonControl());
133             }
134             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
135             {
136                 return (fujiX.getButtonControl());
137             }
138             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
139             {
140                 return (panasonic.getButtonControl());
141             }
142             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
143             {
144                 return (ricohGr2.getButtonControl());
145             }
146         }
147         catch (Exception e)
148         {
149             e.printStackTrace();
150         }
151         return (null);
152     }
153
154     @Override
155     public IDisplayInjector getDisplayInjector()
156     {
157         try
158         {
159             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
160             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
161             {
162                 return (olympus.getDisplayInjector());
163             }
164             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
165             {
166                 return (fujiX.getDisplayInjector());
167             }
168             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
169             {
170                 return (panasonic.getDisplayInjector());
171             }
172             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
173             {
174                 return (ricohGr2.getDisplayInjector());
175             }
176         }
177         catch (Exception e)
178         {
179             e.printStackTrace();
180         }
181         return (null);
182     }
183
184     @Override
185     public ILiveViewControl getLiveViewControl()
186     {
187         try
188         {
189             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
190             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
191             {
192                 return (olympus.getLiveViewControl());
193             }
194             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
195             {
196                 return (fujiX.getLiveViewControl());
197             }
198             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
199             {
200                 return (panasonic.getPanasonicLiveViewControl());
201             }
202             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
203             {
204                 return (ricohGr2.getLiveViewControl());
205             }
206         }
207         catch (Exception e)
208         {
209             e.printStackTrace();
210         }
211         return (null);
212     }
213
214     @Override
215     public ILiveViewListener getLiveViewListener()
216     {
217         try
218         {
219             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
220             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
221             {
222                 return (olympus.getLiveViewListener());
223             }
224             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
225             {
226                 return (fujiX.getLiveViewListener());
227             }
228             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
229             {
230                 return (panasonic.getLiveViewListener());
231             }
232             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
233             {
234                 return (ricohGr2.getLiveViewListener());
235             }
236         }
237         catch (Exception e)
238         {
239             e.printStackTrace();
240         }
241         return (null);
242     }
243
244     @Override
245     public IFocusingControl getFocusingControl()
246     {
247         try
248         {
249             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
250             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
251             {
252                 return (olympus.getFocusingControl());
253             }
254             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
255             {
256                 return (fujiX.getFocusingControl());
257             }
258             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
259             {
260                 return (panasonic.getFocusingControl());
261             }
262             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
263             {
264                 return (ricohGr2.getFocusingControl());
265             }
266         }
267         catch (Exception e)
268         {
269             e.printStackTrace();
270         }
271         return (null);
272     }
273
274     @Override
275     public ICameraInformation getCameraInformation()
276     {
277         try
278         {
279             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
280             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
281             {
282                 return (olympus.getCameraInformation());
283             }
284             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
285             {
286                 return (fujiX.getCameraInformation());
287             }
288             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
289             {
290                 return (panasonic.getCameraInformation());
291             }
292             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
293             {
294                 return (ricohGr2.getCameraInformation());
295             }
296         }
297         catch (Exception e)
298         {
299             e.printStackTrace();
300         }
301         return (null);
302     }
303
304     @Override
305     public IZoomLensControl getZoomLensControl()
306     {
307         try
308         {
309             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
310             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
311             {
312                 return (olympus.getZoomLensControl());
313             }
314             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
315             {
316                 return (fujiX.getZoomLensControl());
317             }
318             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
319             {
320                 return (panasonic.getZoomLensControl());
321             }
322             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
323             {
324                 return (ricohGr2.getZoomLensControl());
325             }
326         }
327         catch (Exception e)
328         {
329             e.printStackTrace();
330         }
331         return (null);
332     }
333
334     @Override
335     public ICaptureControl getCaptureControl()
336     {
337         try
338         {
339             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
340             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
341             {
342                 return (olympus.getCaptureControl());
343             }
344             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
345             {
346                 return (fujiX.getCaptureControl());
347             }
348             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
349             {
350                 return (panasonic.getCaptureControl());
351             }
352             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
353             {
354                 return (ricohGr2.getCaptureControl());
355             }
356         }
357         catch (Exception e)
358         {
359             e.printStackTrace();
360         }
361         return (null);
362     }
363
364     @Override
365     public ICameraStatus getCameraStatusListHolder()
366     {
367         try
368         {
369             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
370             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
371             {
372                 return (olympus.getCameraStatusListHolder());
373             }
374             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
375             {
376                 return (fujiX.getCameraStatusListHolder());
377             }
378             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
379             {
380                 return (panasonic.getCameraStatusListHolder());
381             }
382             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
383             {
384                 return (ricohGr2.getCameraStatusListHolder());
385             }
386         }
387         catch (Exception e)
388         {
389             e.printStackTrace();
390         }
391         return (null);
392     }
393
394     @Override
395     public ICameraStatusWatcher getCameraStatusWatcher()
396     {
397         try
398         {
399             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
400             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
401             {
402                 return (olympus.getCameraStatusWatcher());
403             }
404             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
405             {
406                 return (fujiX.getCameraStatusWatcher());
407             }
408             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
409             {
410                 return (panasonic.getCameraStatusWatcher());
411             }
412             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
413             {
414                 return (ricohGr2.getCameraStatusWatcher());
415             }
416         }
417         catch (Exception e)
418         {
419             e.printStackTrace();
420         }
421         return (null);
422     }
423
424     @Override
425     public IPlaybackControl getPlaybackControl()
426     {
427         try
428         {
429             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
430             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
431             {
432                 return (olympus.getPlaybackControl());
433             }
434             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
435             {
436                 return (fujiX.getPlaybackControl());
437             }
438             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
439             {
440                 return (panasonic.getPlaybackControl());
441             }
442             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
443             {
444                 return (ricohGr2.getPlaybackControl());
445             }
446         }
447         catch (Exception e)
448         {
449             e.printStackTrace();
450         }
451         return (null);
452     }
453
454     @Override
455     public ICameraHardwareStatus getHardwareStatus()
456     {
457         try
458         {
459             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
460             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
461             {
462                 return (olympus.getHardwareStatus());
463             }
464             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
465             {
466                 return (fujiX.getHardwareStatus());
467             }
468             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
469             {
470                 return (panasonic.getHardwareStatus());
471             }
472             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
473             {
474                 return (ricohGr2.getHardwareStatus());
475             }
476         }
477         catch (Exception e)
478         {
479             e.printStackTrace();
480         }
481         return (null);
482     }
483
484     @Override
485     public ICameraRunMode getCameraRunMode()
486     {
487         try
488         {
489             ICameraConnection.CameraConnectionMethod connectionMethod = getCammeraConnectionMethodImpl();
490             if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
491             {
492                 return (olympus.getCameraRunMode());
493             }
494             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
495             {
496                 return (fujiX.getCameraRunMode());
497             }
498             else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
499             {
500                 return (panasonic.getCameraRunMode());
501             }
502             else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
503             {
504                 return (ricohGr2.getCameraRunMode());
505             }
506         }
507         catch (Exception e)
508         {
509             e.printStackTrace();
510         }
511         return (null);
512     }
513
514     /**
515      *   OPC/GR2/SONY カメラを使用するかどうか
516      *
517      * @return OPC / SONY / RICOH  (ICameraConnection.CameraConnectionMethod)
518      */
519     public ICameraConnection.CameraConnectionMethod getCammeraConnectionMethod()
520     {
521         return (getCammeraConnectionMethodImpl());
522     }
523
524     /**
525      *
526      *
527      */
528     @Override
529     public void resetCameraConnectionMethod()
530     {
531         connectionMethod = ICameraConnection.CameraConnectionMethod.UNKNOWN;
532     }
533
534     /**
535      *
536      *
537      */
538     @Override
539     public IInformationReceiver getInformationReceiver()
540     {
541         return (informationReceiver);
542     }
543
544     @Override
545     public ICameraContentsRecognizer getCameraContentsRecognizer()
546     {
547         return (cameraContentsRecognizer);
548     }
549
550     /**
551      *
552      *
553      */
554     private ICameraConnection.CameraConnectionMethod getCammeraConnectionMethodImpl()
555     {
556         if (connectionMethod != ICameraConnection.CameraConnectionMethod.UNKNOWN)
557         {
558             return (connectionMethod);
559         }
560         ICameraConnection.CameraConnectionMethod ret;
561         try
562         {
563             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
564             String connectionMethod = preferences.getString(IPreferencePropertyAccessor.CONNECTION_METHOD, "RICOH");
565             if (connectionMethod.contains("RICOH"))
566             {
567                 ret = ICameraConnection.CameraConnectionMethod.RICOH;
568             }
569             else if (connectionMethod.contains("FUJI_X"))
570             {
571                 ret = ICameraConnection.CameraConnectionMethod.FUJI_X;
572             }
573             else if (connectionMethod.contains("PANASONIC"))
574             {
575                 ret = ICameraConnection.CameraConnectionMethod.PANASONIC;
576             }
577             else // if (connectionMethod.contains("OPC"))
578             {
579                 ret = ICameraConnection.CameraConnectionMethod.OPC;
580             }
581 /*
582             else if (connectionMethod.contains("SONY"))
583             {
584                 ret = ICameraConnection.CameraConnectionMethod.SONY;
585             }
586 */
587         }
588         catch (Exception e)
589         {
590             e.printStackTrace();
591             ret = ICameraConnection.CameraConnectionMethod.UNKNOWN;
592         }
593         connectionMethod = ret;
594         return (connectionMethod);
595     }
596 }