1 package net.osdn.gokigen.pkremote.camera.vendor.visionkids.wrapper.playback
3 import android.util.Log
4 import androidx.appcompat.app.AppCompatActivity
5 import androidx.preference.PreferenceManager
6 import net.osdn.gokigen.pkremote.IInformationReceiver
7 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContentListCallback
8 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraFileInfo
9 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IContentInfoCallback
10 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentCallback
11 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentListCallback
12 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadThumbnailImageCallback
13 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IPlaybackControl
14 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatusReceiver
15 import net.osdn.gokigen.pkremote.camera.playback.ProgressEvent
16 import net.osdn.gokigen.pkremote.camera.utils.SimpleHttpClient
17 import net.osdn.gokigen.pkremote.camera.utils.SimpleHttpClient.IReceivedMessageCallback
18 import net.osdn.gokigen.pkremote.camera.vendor.visionkids.wrapper.connection.IVisionKidsConnection
21 class VisionKidsPlaybackControl(activity: AppCompatActivity, private val provider: ICameraStatusReceiver, private val informationReceiver: IInformationReceiver, timeoutMs: Int = DEFAULT_TIMEOUT): IPlaybackControl, IVisionKidsConnection
23 private val contentProvider = VisionKidsCameraContentProvider(activity)
24 private val timeoutValue = Math.max(DEFAULT_TIMEOUT, timeoutMs)
26 override fun getRawFileSuffix(): String
31 override fun downloadContentList(callback: IDownloadContentListCallback?)
36 override fun getContentInfo(path: String?, name: String?, callback: IContentInfoCallback?)
38 Log.v(TAG, "getContentInfo($path, $name)")
43 callback?.onErrorOccurred(Exception())
46 val contentInfo = contentProvider.getCameraContent(name)
47 if (contentInfo != null)
49 callback?.onCompleted(VisionKidsCameraInfo(name, contentInfo.capturedDate))
53 callback?.onCompleted(VisionKidsCameraInfo(name, Date()))
63 override fun updateCameraFileInfo(info: ICameraFileInfo?)
68 override fun downloadContentScreennail(path: String?, callback: IDownloadThumbnailImageCallback?)
70 // サムネイルしか取得できないので統合する
71 downloadContentThumbnail(path, callback)
74 override fun downloadContentThumbnail(path: String?, callback: IDownloadThumbnailImageCallback?)
78 val address = contentProvider.getHostAddress()
79 val urlToGet = "http://$address/DCIM/T/$path".replace("//","/")
80 Log.v(TAG, "downloadContentThumbnail($path) : $urlToGet")
82 val bmp = SimpleHttpClient.httpGetBitmap(urlToGet, HashMap(), timeoutValue)
83 val map = HashMap<String, Any>()
84 map["Orientation"] = 0
85 callback?.onCompleted(bmp, map)
90 callback?.onErrorOccurred(e)
94 override fun downloadContent(path: String?, isSmallSize: Boolean, callback: IDownloadContentCallback?)
99 val dataType = if (isSmallSize) { "T" } else { "O" }
100 val address = contentProvider.getHostAddress()
101 val urlToGet = "http://$address/DCIM/$dataType/$path".replace("//","/")
102 Log.v(TAG, "downloadContent($path, $isSmallSize) : $urlToGet")
107 SimpleHttpClient.httpGetBytes(urlToGet, HashMap(), timeoutValue,
108 object : IReceivedMessageCallback {
109 override fun onCompleted() {
110 callback?.onCompleted()
112 override fun onErrorOccurred(e: java.lang.Exception) {
113 callback?.onErrorOccurred(e)
115 override fun onReceive(readBytes: Int, length: Int, size: Int, data: ByteArray) {
116 val percent = if (length == 0) 0.0f else readBytes.toFloat() / length.toFloat()
117 val event = ProgressEvent(percent, null)
118 callback?.onProgress(data, size, event)
125 callback?.onErrorOccurred(NullPointerException())
134 override fun getCameraContentList(callback: ICameraContentListCallback)
136 Log.v(TAG, "getCameraContentList()")
139 contentProvider.getContentList(callback)
147 override fun showPictureStarted()
149 Log.v(TAG, "showPictureStarted()")
152 override fun showPictureFinished()
154 Log.v(TAG, "showPictureFinished()")
157 override fun forceDisconnect()
159 contentProvider.forceDisconnect()
163 private val TAG = VisionKidsPlaybackControl::class.java.simpleName
164 private const val DEFAULT_TIMEOUT = 3000