2021-02-19 20:41:49 +01:00
package com.mrousavy.camera.utils
2021-02-19 16:28:14 +01:00
import android.util.Range
import android.util.Size
import com.facebook.react.bridge.ReadableMap
class DeviceFormat ( map : ReadableMap ) {
2021-02-26 10:56:20 +01:00
val frameRateRanges : List < Range < Int > >
val photoSize : Size
val videoSize : Size
2021-02-19 16:28:14 +01:00
2021-02-26 10:56:20 +01:00
init {
frameRateRanges = map . getArray ( " frameRateRanges " ) !! . toArrayList ( ) . map { range ->
if ( range is HashMap < * , * > )
rangeFactory ( range [ " minFrameRate " ] , range [ " maxFrameRate " ] )
else
2021-02-26 17:34:28 +01:00
throw IllegalArgumentException ( " DeviceFormat: frameRateRanges contained a Range that was not of type HashMap<*,*>! Actual Type: ${range?.javaClass?.name} " )
2021-02-19 16:28:14 +01:00
}
2021-02-26 10:56:20 +01:00
photoSize = Size ( map . getInt ( " photoWidth " ) , map . getInt ( " photoHeight " ) )
videoSize = Size ( map . getInt ( " videoWidth " ) , map . getInt ( " videoHeight " ) )
}
2021-02-19 16:28:14 +01:00
}
fun rangeFactory ( minFrameRate : Any ? , maxFrameRate : Any ? ) : Range < Int > {
2021-02-26 10:56:20 +01:00
return when ( minFrameRate ) {
is Int -> Range ( minFrameRate , maxFrameRate as Int )
is Double -> Range ( minFrameRate . toInt ( ) , ( maxFrameRate as Double ) . toInt ( ) )
2021-02-26 17:34:28 +01:00
else -> throw IllegalArgumentException (
" DeviceFormat: frameRateRanges contained a Range that didn't have minFrameRate/maxFrameRate of types Int/Double! " +
" Actual Type: ${minFrameRate?.javaClass?.name} & ${maxFrameRate?.javaClass?.name} "
)
2021-02-26 10:56:20 +01:00
}
2021-02-19 16:28:14 +01:00
}