OSDN Git Service

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