OSDN Git Service

androidx対応。
[gokigen/A01d.git] / app / src / main / java / net / osdn / gokigen / a01d / camera / CameraInterfaceProvider.java
1 package net.osdn.gokigen.a01d.camera;
2
3 import android.app.Activity;
4 import android.content.SharedPreferences;
5
6 import net.osdn.gokigen.a01d.camera.olympus.wrapper.IOlympusLiveViewListener;
7 import net.osdn.gokigen.a01d.camera.olympus.IOlympusInterfaceProvider;
8 import net.osdn.gokigen.a01d.camera.olympus.wrapper.OlympusInterfaceProvider;
9 import net.osdn.gokigen.a01d.camera.ricohgr2.IRicohGr2InterfaceProvider;
10 import net.osdn.gokigen.a01d.camera.ricohgr2.wrapper.RicohGr2InterfaceProvider;
11 import net.osdn.gokigen.a01d.camera.sony.ISonyInterfaceProvider;
12 import net.osdn.gokigen.a01d.camera.sony.wrapper.SonyCameraWrapper;
13 import net.osdn.gokigen.a01d.liveview.ICameraStatusUpdateNotify;
14 import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
15
16 import androidx.annotation.NonNull;
17 import androidx.preference.PreferenceManager;
18
19 public class CameraInterfaceProvider implements IInterfaceProvider
20 {
21     private final Activity context;
22     private final OlympusInterfaceProvider olympus;
23     private final SonyCameraWrapper sony;
24     private final RicohGr2InterfaceProvider ricohGr2;
25     private final CameraStatusListener statusListener;
26
27     public CameraInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider)
28     {
29         this.context = context;
30         this.statusListener = new CameraStatusListener();
31         olympus = new OlympusInterfaceProvider(context, provider);
32         sony = new SonyCameraWrapper(context, provider, statusListener);
33         ricohGr2 = new RicohGr2InterfaceProvider(context, provider);
34     }
35
36     @Override
37     public void setUpdateReceiver(@NonNull ICameraStatusUpdateNotify receiver)
38     {
39         try
40         {
41             statusListener.setUpdateReceiver(receiver);
42         }
43         catch (Exception e)
44         {
45             e.printStackTrace();
46         }
47     }
48
49     @Override
50     public IOlympusInterfaceProvider getOlympusInterface()
51     {
52         return (olympus);
53     }
54
55     @Override
56     public IOlympusLiveViewListener getOlympusLiveViewListener()
57     {
58         return (olympus.getLiveViewListener());
59     }
60
61     @Override
62     public ISonyInterfaceProvider getSonyInterface()
63     {
64         return (sony);
65     }
66
67     @Override
68     public IRicohGr2InterfaceProvider getRicohGr2Infterface()
69     {
70         return (ricohGr2);
71     }
72
73     /**
74      *   OPCカメラを使用するかどうか
75      *
76      * @return OPC / SONY / RICOH_GR2  (ICameraConnection.CameraConnectionMethod)
77      */
78     public ICameraConnection.CameraConnectionMethod getCammeraConnectionMethod()
79     {
80         ICameraConnection.CameraConnectionMethod ret = ICameraConnection.CameraConnectionMethod.OPC;
81         try
82         {
83             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
84             String connectionMethod = preferences.getString(IPreferencePropertyAccessor.CONNECTION_METHOD, "OPC");
85             if (connectionMethod.contains("SONY"))
86             {
87                 ret = ICameraConnection.CameraConnectionMethod.SONY;
88             }
89             else if (connectionMethod.contains("RICOH_GR2"))
90             {
91                 ret = ICameraConnection.CameraConnectionMethod.RICOH_GR2;
92             }
93         }
94         catch (Exception e)
95         {
96             e.printStackTrace();
97         }
98         return (ret);
99     }
100 }