OSDN Git Service

不要な importを削除。
[gokigen/PKRemote.git] / app / src / main / java / net / osdn / gokigen / pkremote / camera / vendor / fujix / wrapper / FujiXInterfaceProvider.java
1 package net.osdn.gokigen.pkremote.camera.vendor.fujix.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.fujix.IFujiXInterfaceProvider;
31 import net.osdn.gokigen.pkremote.camera.vendor.fujix.operation.FujiXCaptureControl;
32 import net.osdn.gokigen.pkremote.camera.vendor.fujix.operation.FujiXFocusingControl;
33 import net.osdn.gokigen.pkremote.camera.vendor.fujix.operation.FujiXZoomControl;
34 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.FujiXAsyncResponseReceiver;
35 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.FujiXCommandPublisher;
36 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.IFujiXCommandCallback;
37 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.IFujiXCommandPublisher;
38 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.IFujiXCommunication;
39 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.connection.FujiXConnection;
40 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.liveview.FujiXLiveViewControl;
41 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.status.FujiXStatusChecker;
42 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.status.IFujiXRunModeHolder;
43
44 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.FUJIX_COMMAND_POLLING_WAIT;
45 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.FUJIX_COMMAND_POLLING_WAIT_DEFAULT_VALUE;
46
47 public class FujiXInterfaceProvider implements IFujiXInterfaceProvider, IDisplayInjector
48 {
49     private final String TAG = toString();
50
51     private static final int STREAM_PORT = 55742;
52     private static final int ASYNC_RESPONSE_PORT = 55741;
53     private static final int CONTROL_PORT = 55740;
54     private static final String CAMERA_IP = "192.168.0.1";
55
56     private static final int COMMAND_POLL_QUEUE_DEFAULT_MS = 50;
57     private static final int COMMAND_POLL_QUEUE_MAX_MS = 499;
58     private static final int COMMAND_POLL_QUEUE_MIN_MS = 10;
59
60     private final Activity activity;
61     private final FujiXRunMode runmode;
62     private final FujiXHardwareStatus hardwareStatus;
63     private FujiXButtonControl fujiXButtonControl;
64     private FujiXConnection fujiXConnection;
65     private FujiXCommandPublisher commandPublisher;
66     private FujiXLiveViewControl liveViewControl;
67     private FujiXAsyncResponseReceiver asyncReceiver;
68     private FujiXZoomControl zoomControl;
69     private FujiXCaptureControl captureControl;
70     private FujiXFocusingControl focusingControl;
71     private FujiXStatusChecker statusChecker;
72     private ICameraStatusUpdateNotify statusListener;
73     private FujiXPlaybackControl playbackControl;
74     private IInformationReceiver informationReceiver;
75
76     public FujiXInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider, @NonNull ICameraStatusUpdateNotify statusListener, @NonNull IInformationReceiver informationReceiver)
77     {
78         this.activity = context;
79         int duration = COMMAND_POLL_QUEUE_DEFAULT_MS;
80         try
81         {
82             // コマンド送信間隔を取得する
83             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
84             duration = Integer.parseInt(preferences.getString(FUJIX_COMMAND_POLLING_WAIT, FUJIX_COMMAND_POLLING_WAIT_DEFAULT_VALUE));
85         }
86         catch (Exception e)
87         {
88             e.printStackTrace();
89         }
90         if ((duration < COMMAND_POLL_QUEUE_MIN_MS)|| (duration > COMMAND_POLL_QUEUE_MAX_MS))
91         {
92             // 設定の上下限値を超えたらデフォルト値(の半分程度の値)に変更する。
93             duration = COMMAND_POLL_QUEUE_DEFAULT_MS;
94         }
95         commandPublisher = new FujiXCommandPublisher(CAMERA_IP, CONTROL_PORT, duration);
96         liveViewControl = new FujiXLiveViewControl(context, CAMERA_IP, STREAM_PORT);
97         asyncReceiver = new FujiXAsyncResponseReceiver(CAMERA_IP, ASYNC_RESPONSE_PORT);
98         fujiXConnection = new FujiXConnection(context, provider, this);
99         zoomControl = new FujiXZoomControl();
100         statusChecker = new FujiXStatusChecker(activity, commandPublisher);
101         this.statusListener = statusListener;
102         this.runmode = new FujiXRunMode();
103         this.hardwareStatus = new FujiXHardwareStatus();
104         this.fujiXButtonControl = new FujiXButtonControl();
105         this.playbackControl = new FujiXPlaybackControl(activity, this);
106         this.informationReceiver = informationReceiver;
107     }
108
109     @Override
110     public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
111     {
112         Log.v(TAG, "injectDisplay()");
113         captureControl = new FujiXCaptureControl(commandPublisher, frameDisplayer);
114         focusingControl = new FujiXFocusingControl(activity, commandPublisher, frameDisplayer, indicator);
115     }
116
117     @Override
118     public ICameraConnection getFujiXCameraConnection()
119     {
120         return (fujiXConnection);
121     }
122
123     @Override
124     public ILiveViewControl getLiveViewControl()
125     {
126         return (liveViewControl);
127     }
128
129     @Override
130     public ILiveViewListener getLiveViewListener()
131     {
132         return (liveViewControl.getLiveViewListener());
133     }
134
135     @Override
136     public IFocusingControl getFocusingControl()
137     {
138         return (focusingControl);
139     }
140
141     @Override
142     public ICameraInformation getCameraInformation()
143     {
144         return null;
145     }
146
147     @Override
148     public IZoomLensControl getZoomLensControl()
149     {
150         return (zoomControl);
151     }
152
153     @Override
154     public ICaptureControl getCaptureControl()
155     {
156         return (captureControl);
157     }
158
159     @Override
160     public IDisplayInjector getDisplayInjector()
161     {
162         return (this);
163     }
164
165     @Override
166     public IFujiXRunModeHolder getRunModeHolder()
167     {
168         return (runmode);
169     }
170
171     @Override
172     public IFujiXCommandCallback getStatusHolder() {
173         return (statusChecker);
174     }
175
176     @Override
177     public IFujiXCommandPublisher getCommandPublisher()
178     {
179         return (commandPublisher);
180     }
181
182     @Override
183     public IFujiXCommunication getLiveviewCommunication()
184     {
185         return (liveViewControl);
186     }
187
188     @Override
189     public IFujiXCommunication getAsyncEventCommunication()
190     {
191         return (asyncReceiver);
192     }
193
194     @Override
195     public IFujiXCommunication getCommandCommunication()
196     {
197         return (commandPublisher);
198     }
199
200     @Override
201     public ICameraStatusWatcher getCameraStatusWatcher()
202     {
203         return (statusChecker);
204     }
205
206     @Override
207     public ICameraStatusUpdateNotify getStatusListener()
208     {
209         return (statusListener);
210     }
211
212     @Override
213     public ICameraStatus getCameraStatusListHolder()
214     {
215         return (statusChecker);
216     }
217
218     @Override
219     public ICameraButtonControl getButtonControl()
220     {
221         return (fujiXButtonControl);
222     }
223
224     @Override
225     public IPlaybackControl getPlaybackControl()
226     {
227         return (playbackControl);
228     }
229
230     @Override
231     public ICameraHardwareStatus getHardwareStatus()
232     {
233         return (hardwareStatus);
234     }
235
236     @Override
237     public ICameraRunMode getCameraRunMode()
238     {
239         return (runmode);
240     }
241
242     @Override
243     public IInformationReceiver getInformationReceiver()
244     {
245         // ちょっとこの引き回しは気持ちがよくない...
246         return (informationReceiver);
247     }
248
249     @Override
250     public void setAsyncEventReceiver(@NonNull IFujiXCommandCallback receiver)
251     {
252         asyncReceiver.setEventSubscriber(receiver);
253     }
254
255 }