OSDN Git Service

THETA S/SCでは、Video撮影モード時にライブビューができないのに対応。
[gokigen/A01c.git] / wear / src / main / java / jp / sfjp / gokigen / a01c / thetacamerawrapper / ThetaCameraController.kt
1 package jp.sfjp.gokigen.a01c.thetacamerawrapper
2
3 import android.util.Log
4 import android.view.MotionEvent
5 import androidx.appcompat.app.AppCompatActivity
6 import androidx.preference.PreferenceDataStore
7 import jp.sfjp.gokigen.a01c.ICameraConnection
8 import jp.sfjp.gokigen.a01c.ICameraController
9 import jp.sfjp.gokigen.a01c.ICameraFeatureDispatcher
10 import jp.sfjp.gokigen.a01c.IShowInformation
11 import jp.sfjp.gokigen.a01c.liveview.CameraLiveViewListenerImpl
12 import jp.sfjp.gokigen.a01c.liveview.IAutoFocusFrameDisplay
13 import jp.sfjp.gokigen.a01c.liveview.ICameraStatusReceiver
14 import jp.sfjp.gokigen.a01c.liveview.ILiveImageStatusNotify
15 import jp.sfjp.gokigen.a01c.olycamerawrapper.ICameraRunMode
16 import jp.sfjp.gokigen.a01c.olycamerawrapper.IIndicatorControl
17 import jp.sfjp.gokigen.a01c.olycamerawrapper.ILevelGauge
18 import jp.sfjp.gokigen.a01c.olycamerawrapper.IZoomLensHolder
19 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.ICameraPropertyLoadSaveOperations
20 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.ILoadSaveCameraProperties
21 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.IOlyCameraPropertyProvider
22 import jp.sfjp.gokigen.a01c.preference.PreferenceAccessWrapper
23 import jp.sfjp.gokigen.a01c.thetacamerawrapper.connection.ThetaCameraConnection
24 import jp.sfjp.gokigen.a01c.thetacamerawrapper.liveview.ThetaLiveViewControl
25 import jp.sfjp.gokigen.a01c.thetacamerawrapper.operation.ThetaDummyOperation
26 import jp.sfjp.gokigen.a01c.thetacamerawrapper.operation.ThetaMovieRecordingControl
27 import jp.sfjp.gokigen.a01c.thetacamerawrapper.operation.ThetaOptionUpdateControl
28 import jp.sfjp.gokigen.a01c.thetacamerawrapper.operation.ThetaSingleShotControl
29
30 class ThetaCameraController(val context: AppCompatActivity, private val focusFrameDisplay: IAutoFocusFrameDisplay, private val showInformation: IShowInformation, private val receiver: ICameraStatusReceiver, private val preferences: PreferenceAccessWrapper) : ICameraController, IIndicatorControl
31 {
32     private lateinit var featureDispatcher : ThetaFeatureDispatcher
33     private lateinit var liveViewControl : ThetaLiveViewControl
34     private val dummyOperation = ThetaDummyOperation()
35     private val sessionIdHolder = ThetaSessionHolder()
36     private val cameraConnection = ThetaCameraConnection(context, receiver, sessionIdHolder)
37     private val singleShot = ThetaSingleShotControl(sessionIdHolder, this, this)
38     private val movieShot = ThetaMovieRecordingControl(context, sessionIdHolder, this, showInformation, this)
39     private val optionSet = ThetaOptionUpdateControl(sessionIdHolder, this, this)
40
41     override fun connectFinished()
42     {
43         try
44         {
45             // スチルモードに切り替える
46             changeCaptureImageMode(sessionIdHolder.isApiLevelV21())
47         }
48         catch (e : Exception)
49         {
50             e.printStackTrace()
51         }
52     }
53
54     override fun setLiveViewListener(listener: CameraLiveViewListenerImpl)
55     {
56         Log.v(TAG, " setLiveViewListener() : ${sessionIdHolder.isApiLevelV21()} ")
57         this.liveViewControl = ThetaLiveViewControl(listener)
58     }
59
60     override fun changeLiveViewSize(size: String?)
61     {
62         // ログだけ残す
63         Log.v(toString(), " changeLiveViewSize: $size")
64     }
65
66     override fun startLiveView()
67     {
68         try
69         {
70             // ライブビューの表示...
71             if (::liveViewControl.isInitialized)
72             {
73                 liveViewControl.startLiveView(sessionIdHolder)
74             }
75         }
76         catch (e : Exception)
77         {
78             e.printStackTrace()
79         }
80     }
81
82     override fun stopLiveView()
83     {
84         if (::liveViewControl.isInitialized)
85         {
86             liveViewControl.stopLiveView()
87         }
88     }
89
90     override fun updateTakeMode()
91     {
92         if (::featureDispatcher.isInitialized)
93         {
94             when (featureDispatcher.takeMode)
95             {
96                 "P" -> changeCaptureImageMode(sessionIdHolder.isApiLevelV21())
97                 "Movie" -> changeCaptureVideoMode(sessionIdHolder.isApiLevelV21())
98             }
99         }
100     }
101
102     private fun changeCaptureImageMode(apiV21 : Boolean)
103     {
104         try
105         {
106             optionSet.setOptions("\"captureMode\" : \"image\"", apiV21)
107             waitMs(200);
108             startLiveView()
109         }
110         catch (e : Exception)
111         {
112             e.printStackTrace()
113         }
114     }
115
116     private fun changeCaptureVideoMode(apiV21 : Boolean)
117     {
118         try
119         {
120             if (apiV21)
121             {
122                 optionSet.setOptions("\"captureMode\" : \"video\"", apiV21)
123             }
124             else
125             {
126                 optionSet.setOptions("\"captureMode\" : \"_video\"", apiV21)
127
128                 // API Level 1 の対応機種では、Videoモードでライブビューが動かないので止める
129                 waitMs(200);
130                 stopLiveView()
131             }
132         }
133         catch (e : Exception)
134         {
135             e.printStackTrace()
136         }
137     }
138
139     override fun driveAutoFocus(event: MotionEvent?): Boolean
140     {
141         return (true)
142     }
143
144     override fun unlockAutoFocus()
145     {
146         // なにもしない
147     }
148
149     override fun isContainsAutoFocusPoint(event: MotionEvent?): Boolean
150     {
151         return (false)
152     }
153
154     override fun singleShot()
155     {
156         singleShot.singleShot(sessionIdHolder.isApiLevelV21())
157     }
158
159     override fun movieControl()
160     {
161         movieShot.movieControl(sessionIdHolder.isApiLevelV21())
162     }
163
164     override fun bracketingShot(bracketingStyle: Int, bracketingCount: Int, durationSeconds: Int)
165     {
166         // TODO("Not yet implemented")
167     }
168
169     override fun setRecViewMode(isRecViewMode: Boolean)
170     {
171         // なにもしない
172     }
173
174     override fun toggleAutoExposure()
175     {
176         // なにもしない
177     }
178
179     override fun toggleManualFocus()
180     {
181         // なにもしない
182     }
183
184     override fun isManualFocus(): Boolean
185     {
186         return (false)
187     }
188
189     override fun isAFLock(): Boolean
190     {
191         return (false)
192     }
193
194     override fun isAELock(): Boolean
195     {
196         return (false)
197     }
198
199     override fun updateStatusAll()
200     {
201         // なにもしない
202     }
203
204     override fun getCameraPropertyProvider(): IOlyCameraPropertyProvider
205     {
206         return (dummyOperation)
207     }
208
209     override fun getCameraPropertyLoadSaveOperations(): ICameraPropertyLoadSaveOperations
210     {
211         return (dummyOperation)
212     }
213
214     override fun getLoadSaveCameraProperties(): ILoadSaveCameraProperties
215     {
216         return (dummyOperation)
217     }
218
219     override fun getChangeRunModeExecutor(): ICameraRunMode
220     {
221         return (dummyOperation)
222     }
223
224     override fun getConnectionInterface(): ICameraConnection
225     {
226         return (cameraConnection)
227     }
228
229     override fun getZoomLensHolder(): IZoomLensHolder
230     {
231         return (dummyOperation)
232     }
233
234     override fun getLevelGauge(): ILevelGauge
235     {
236         return (dummyOperation)
237     }
238
239     override fun getFeatureDispatcher(context: AppCompatActivity, statusDrawer: IShowInformation, camera: ICameraController, accessWrapper: PreferenceDataStore, liveImageView: ILiveImageStatusNotify): ICameraFeatureDispatcher
240     {
241         if (!(::featureDispatcher.isInitialized))
242         {
243             featureDispatcher = ThetaFeatureDispatcher(context, statusDrawer, camera, accessWrapper, liveImageView)
244         }
245         return (featureDispatcher)
246     }
247
248     override fun onAfLockUpdate(isAfLocked: Boolean)
249     {
250         //TODO("Not yet implemented")
251     }
252
253     override fun onShootingStatusUpdate(status: IIndicatorControl.shootingStatus?)
254     {
255         //TODO("Not yet implemented")
256     }
257
258     private fun waitMs(waitMs: Int)
259     {
260         try
261         {
262             Thread.sleep(waitMs.toLong())
263         }
264         catch (e: Exception)
265         {
266             e.printStackTrace()
267         }
268     }
269
270     companion object
271     {
272         private val TAG = ThetaCameraController::class.java.simpleName
273     }
274 }