OSDN Git Service

Nikon対応の開始。
[gokigen/PKRemote.git] / app / src / main / java / net / osdn / gokigen / pkremote / camera / vendor / nikon / wrapper / NikonInterfaceProvider.java
1 package net.osdn.gokigen.pkremote.camera.vendor.nikon.wrapper;
2
3 import android.app.Activity;
4 import android.content.SharedPreferences;
5 import android.util.Log;
6
7 import androidx.annotation.NonNull;
8 import androidx.preference.PreferenceManager;
9
10 import net.osdn.gokigen.pkremote.IInformationReceiver;
11 import net.osdn.gokigen.pkremote.camera.interfaces.control.ICameraButtonControl;
12 import net.osdn.gokigen.pkremote.camera.interfaces.control.ICameraConnection;
13 import net.osdn.gokigen.pkremote.camera.interfaces.control.ICameraRunMode;
14 import net.osdn.gokigen.pkremote.camera.interfaces.control.ICaptureControl;
15 import net.osdn.gokigen.pkremote.camera.interfaces.control.IFocusingControl;
16 import net.osdn.gokigen.pkremote.camera.interfaces.control.IFocusingModeNotify;
17 import net.osdn.gokigen.pkremote.camera.interfaces.control.IZoomLensControl;
18 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.IAutoFocusFrameDisplay;
19 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.ICameraStatusUpdateNotify;
20 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.IDisplayInjector;
21 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.IIndicatorControl;
22 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.ILiveViewControl;
23 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.ILiveViewListener;
24 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IPlaybackControl;
25 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraHardwareStatus;
26 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraInformation;
27 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatus;
28 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatusReceiver;
29 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatusWatcher;
30 import net.osdn.gokigen.pkremote.camera.vendor.nikon.INikonInterfaceProvider;
31 import net.osdn.gokigen.pkremote.camera.vendor.nikon.wrapper.playback.NikonPlaybackControl;
32 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.IPtpIpInterfaceProvider;
33 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.operation.PtpIpZoomControl;
34 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.PtpIpButtonControl;
35 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.PtpIpHardwareStatus;
36 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.PtpIpRunMode;
37 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandCallback;
38 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandPublisher;
39 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommunication;
40 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.PtpIpAsyncResponseReceiver;
41 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.PtpIpCommandPublisher;
42 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.connection.NikonConnection;
43 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.liveview.PtpIpLiveViewControl;
44 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.status.IPtpIpRunModeHolder;
45 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.status.PtpIpStatusChecker;
46
47 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.NIKON_CAMERA_IP_ADDRESS;
48 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.NIKON_CAMERA_IP_ADDRESS_DEFAULT_VALUE;
49
50 public class NikonInterfaceProvider implements INikonInterfaceProvider, IDisplayInjector
51 {
52     private final String TAG = toString();
53
54     private static final int STREAM_PORT = 15742;   // ??
55     private static final int ASYNC_RESPONSE_PORT = 15741;  // ??
56     private static final int CONTROL_PORT = 15740;
57     private static final int EVENT_PORT = 15740;
58     private static final String DEFAULT_CAMERA_IP_ADDR = "192.168.1.1";
59
60     private final Activity activity;
61     private final PtpIpRunMode runmode;
62     private final PtpIpHardwareStatus hardwareStatus;
63     private PtpIpButtonControl ptpIpButtonControl;
64     private NikonConnection nikonConnection;
65     private PtpIpCommandPublisher commandPublisher;
66     private PtpIpLiveViewControl liveViewControl;
67     private PtpIpAsyncResponseReceiver asyncReceiver;
68     private PtpIpZoomControl zoomControl;
69     //private PtpIpCaptureControl captureControl;
70     //private PtpIpFocusingControl focusingControl;
71     private PtpIpStatusChecker statusChecker;
72     private ICameraStatusUpdateNotify statusListener;
73     private NikonPlaybackControl playbackControl;
74     private IInformationReceiver informationReceiver;
75
76     public NikonInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider, @NonNull ICameraStatusUpdateNotify statusListener, @NonNull IInformationReceiver informationReceiver)
77     {
78         this.activity = context;
79         String ipAddress = DEFAULT_CAMERA_IP_ADDR;
80         try
81         {
82             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
83             ipAddress = preferences.getString(NIKON_CAMERA_IP_ADDRESS, NIKON_CAMERA_IP_ADDRESS_DEFAULT_VALUE);
84         }
85         catch (Exception e)
86         {
87             e.printStackTrace();
88         }
89         commandPublisher = new PtpIpCommandPublisher(ipAddress, CONTROL_PORT);
90         liveViewControl = new PtpIpLiveViewControl(context, ipAddress, STREAM_PORT);
91         asyncReceiver = new PtpIpAsyncResponseReceiver(ipAddress, ASYNC_RESPONSE_PORT);
92         statusChecker = new PtpIpStatusChecker(activity, commandPublisher, ipAddress, EVENT_PORT);
93         nikonConnection = new NikonConnection(context, provider, this, statusChecker);
94         zoomControl = new PtpIpZoomControl();
95         this.statusListener = statusListener;
96         this.runmode = new PtpIpRunMode();
97         this.hardwareStatus = new PtpIpHardwareStatus();
98         this.ptpIpButtonControl = new PtpIpButtonControl();
99         this.playbackControl = new NikonPlaybackControl(activity, this);
100         this.informationReceiver = informationReceiver;
101     }
102
103     @Override
104     public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
105     {
106         Log.v(TAG, "injectDisplay()");
107         //captureControl = new FujiXCaptureControl(commandPublisher, frameDisplayer);
108         //focusingControl = new FujiXFocusingControl(activity, commandPublisher, frameDisplayer, indicator);
109     }
110
111     @Override
112     public ICameraConnection getPtpIpCameraConnection()
113     {
114         return (nikonConnection);
115     }
116
117     @Override
118     public ILiveViewControl getLiveViewControl()
119     {
120         return (liveViewControl);
121     }
122
123     @Override
124     public ILiveViewListener getLiveViewListener()
125     {
126         return (liveViewControl.getLiveViewListener());
127     }
128
129     @Override
130     public IFocusingControl getFocusingControl()
131     {
132         return (null);
133     }
134
135     @Override
136     public ICameraInformation getCameraInformation()
137     {
138         return null;
139     }
140
141     @Override
142     public IZoomLensControl getZoomLensControl()
143     {
144         return (zoomControl);
145     }
146
147     @Override
148     public ICaptureControl getCaptureControl()
149     {
150         return (null);
151     }
152
153     @Override
154     public IDisplayInjector getDisplayInjector()
155     {
156         return (this);
157     }
158
159     @Override
160     public IPtpIpRunModeHolder getRunModeHolder()
161     {
162         return (runmode);
163     }
164
165     @Override
166     public IPtpIpCommandCallback getStatusHolder() {
167         return (statusChecker);
168     }
169
170     @Override
171     public IPtpIpCommandPublisher getCommandPublisher()
172     {
173         return (commandPublisher);
174     }
175
176     @Override
177     public IPtpIpCommunication getLiveviewCommunication()
178     {
179         return (liveViewControl);
180     }
181
182     @Override
183     public IPtpIpCommunication getAsyncEventCommunication()
184     {
185         return (asyncReceiver);
186     }
187
188     @Override
189     public IPtpIpCommunication getCommandCommunication()
190     {
191         return (commandPublisher);
192     }
193
194     @Override
195     public ICameraStatusWatcher getCameraStatusWatcher()
196     {
197         return (statusChecker);
198     }
199
200     @Override
201     public ICameraStatusUpdateNotify getStatusListener()
202     {
203         return (statusListener);
204     }
205
206     @Override
207     public ICameraStatus getCameraStatusListHolder()
208     {
209         return (statusChecker);
210     }
211
212     @Override
213     public ICameraButtonControl getButtonControl()
214     {
215         return (ptpIpButtonControl);
216     }
217
218     @Override
219     public IPlaybackControl getPlaybackControl()
220     {
221         return (playbackControl);
222     }
223
224     @Override
225     public ICameraHardwareStatus getHardwareStatus()
226     {
227         return (hardwareStatus);
228     }
229
230     @Override
231     public ICameraRunMode getCameraRunMode()
232     {
233         return (runmode);
234     }
235
236     @Override
237     public IInformationReceiver getInformationReceiver()
238     {
239         // ちょっとこの引き回しは気持ちがよくない...
240         return (informationReceiver);
241     }
242
243     @Override
244     public void setAsyncEventReceiver(@NonNull IPtpIpCommandCallback receiver)
245     {
246         asyncReceiver.setEventSubscriber(receiver);
247     }
248
249 }