@@ -52,6 +52,7 @@ import java.util.concurrent.Executors
5252import java.util.concurrent.Semaphore
5353import kotlin.math.max
5454import kotlin.math.min
55+ import kotlin.math.roundToInt
5556
5657/* *
5758 * Created by pedro on 4/03/17.
@@ -115,7 +116,7 @@ class Camera2ApiManager(context: Context) : CameraDevice.StateCallback() {
115116 private var imageReader: ImageReader ? = null
116117
117118 init {
118- cameraId = try { getCameraIdForFacing(Facing .BACK ) } catch (e : Exception ) { " 0" }
119+ cameraId = try { getCameraIdForFacing(Facing .BACK ) } catch (_ : Exception ) { " 0" }
119120 }
120121
121122 fun prepareCamera (surfaceTexture : SurfaceTexture , width : Int , height : Int , fps : Int ) {
@@ -158,13 +159,10 @@ class Camera2ApiManager(context: Context) : CameraDevice.StateCallback() {
158159 try {
159160 it.setRepeatingRequest(
160161 captureRequest,
161- if (faceDetectionEnabled || frameCapturedCallback != null ){
162- cb
163- } else {
164- null
165- }, cameraHandler
162+ if (faceDetectionEnabled || frameCapturedCallback != null ) cb else null ,
163+ cameraHandler
166164 )
167- } catch (e : IllegalStateException ) {
165+ } catch (_ : IllegalStateException ) {
168166 reOpenCamera(cameraId)
169167 } catch (e: Exception ) {
170168 cameraCallbacks?.onCameraError(" Create capture session failed: " + e.message)
@@ -178,7 +176,7 @@ class Camera2ApiManager(context: Context) : CameraDevice.StateCallback() {
178176 },
179177 cameraHandler
180178 )
181- } catch (e : IllegalStateException ) {
179+ } catch (_ : IllegalStateException ) {
182180 reOpenCamera(cameraId)
183181 } catch (e: Exception ) {
184182 cameraCallbacks?.onCameraError(" Create capture session failed: " + e.message)
@@ -506,7 +504,7 @@ class Camera2ApiManager(context: Context) : CameraDevice.StateCallback() {
506504 session.capture(builderInputSurface.build(), captureCallbackHandler, null )
507505 isAutoFocusEnabled = true
508506 return true
509- } catch (e : Exception ) {
507+ } catch (_ : Exception ) {
510508 return false
511509 }
512510 }
@@ -763,8 +761,8 @@ class Camera2ApiManager(context: Context) : CameraDevice.StateCallback() {
763761 // This ratio is the ratio of cropped Rect to Camera's original(Maximum) Rect
764762 val ratio = 1f / l
765763 // croppedWidth and croppedHeight are the pixels cropped away, not pixels after cropped
766- val croppedWidth = rect.width() - Math .round (rect.width().toFloat() * ratio)
767- val croppedHeight = rect.height() - Math .round (rect.height().toFloat() * ratio)
764+ val croppedWidth = rect.width() - (rect.width().toFloat() * ratio).roundToInt( )
765+ val croppedHeight = rect.height() - (rect.height().toFloat() * ratio).roundToInt( )
768766 // Finally, zoom represents the zoomed visible area
769767 val zoom = Rect (
770768 croppedWidth / 2 , croppedHeight / 2 , rect.width() - croppedWidth / 2 ,
@@ -903,7 +901,7 @@ class Camera2ApiManager(context: Context) : CameraDevice.StateCallback() {
903901 }
904902 }
905903 return Facing .BACK
906- } catch (e : Exception ) {
904+ } catch (_ : Exception ) {
907905 return Facing .BACK
908906 }
909907 }
0 commit comments