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