Skip to content

Commit

Permalink
chore: Format
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jun 4, 2024
1 parent 96d55e8 commit f4522af
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.mrousavy.camera.core
import androidx.camera.core.Preview.SurfaceProvider
import com.mrousavy.camera.core.types.CameraDeviceFormat
import com.mrousavy.camera.core.types.CodeType
import com.mrousavy.camera.core.types.Orientation
import com.mrousavy.camera.core.types.OutputOrientation
import com.mrousavy.camera.core.types.PixelFormat
import com.mrousavy.camera.core.types.QualityBalance
Expand All @@ -12,37 +11,37 @@ import com.mrousavy.camera.core.types.VideoStabilizationMode

data class CameraConfiguration(
// Input
var cameraId: String? = null,
var cameraId: String? = null,

// Outputs
var preview: Output<Preview> = Output.Disabled.create(),
var photo: Output<Photo> = Output.Disabled.create(),
var video: Output<Video> = Output.Disabled.create(),
var frameProcessor: Output<FrameProcessor> = Output.Disabled.create(),
var codeScanner: Output<CodeScanner> = Output.Disabled.create(),
var enableLocation: Boolean = false,
var preview: Output<Preview> = Output.Disabled.create(),
var photo: Output<Photo> = Output.Disabled.create(),
var video: Output<Video> = Output.Disabled.create(),
var frameProcessor: Output<FrameProcessor> = Output.Disabled.create(),
var codeScanner: Output<CodeScanner> = Output.Disabled.create(),
var enableLocation: Boolean = false,

// Orientation
var outputOrientation: OutputOrientation = OutputOrientation.DEVICE,
var outputOrientation: OutputOrientation = OutputOrientation.DEVICE,

// Format
var format: CameraDeviceFormat? = null,
var format: CameraDeviceFormat? = null,

// Side-Props
var fps: Int? = null,
var enableLowLightBoost: Boolean = false,
var torch: Torch = Torch.OFF,
var videoStabilizationMode: VideoStabilizationMode = VideoStabilizationMode.OFF,
var exposure: Double? = null,
var fps: Int? = null,
var enableLowLightBoost: Boolean = false,
var torch: Torch = Torch.OFF,
var videoStabilizationMode: VideoStabilizationMode = VideoStabilizationMode.OFF,
var exposure: Double? = null,

// Zoom
var zoom: Float = 1f,
var zoom: Float = 1f,

// isActive (Start/Stop)
var isActive: Boolean = false,
var isActive: Boolean = false,

// Audio Session
var audio: Output<Audio> = Output.Disabled.create()
var audio: Output<Audio> = Output.Disabled.create()
) {
// Output<T> types, those need to be comparable
data class CodeScanner(val codeTypes: List<CodeType>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import kotlinx.coroutines.sync.withLock
class CameraSession(private val context: Context, private val callback: Callback) :
Closeable,
LifecycleOwner,
OrientationManager.Callback {
OrientationManager.Callback {
companion object {
private const val TAG = "CameraSession"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class OrientationManager(private val context: Context, private val callback: Cal

// Physical Device Orientation listener
private var deviceRotation = Surface.ROTATION_0
private val orientationListener = object: OrientationEventListener(context) {
private val orientationListener = object : OrientationEventListener(context) {
override fun onOrientationChanged(rotationDegrees: Int) {
// Phone rotated!
deviceRotation = degreesToSurfaceRotation(rotationDegrees)
Expand Down Expand Up @@ -65,24 +65,28 @@ class OrientationManager(private val context: Context, private val callback: Cal
Log.i(TAG, "Starting streaming device orientation updates...")
orientationListener.enable()
}

OutputOrientation.PREVIEW -> {
Log.i(TAG, "Starting streaming screen rotation updates...")
displayManager.registerDisplayListener(displayListener, null)
}
OutputOrientation.PORTRAIT, OutputOrientation.LANDSCAPE_RIGHT, OutputOrientation.PORTRAIT_UPSIDE_DOWN, OutputOrientation.LANDSCAPE_LEFT -> {

OutputOrientation.PORTRAIT,
OutputOrientation.LANDSCAPE_RIGHT,
OutputOrientation.PORTRAIT_UPSIDE_DOWN,
OutputOrientation.LANDSCAPE_LEFT -> {
Log.i(TAG, "Setting output orientation to $targetOrientation. (locked)")
}
}
}

private fun degreesToSurfaceRotation(degrees: Int): Int {
return when (degrees) {
private fun degreesToSurfaceRotation(degrees: Int): Int =
when (degrees) {
in 45..135 -> Surface.ROTATION_270
in 135..225 -> Surface.ROTATION_180
in 225..315 -> Surface.ROTATION_90
else -> Surface.ROTATION_0
}
}

interface Callback {
fun onOutputOrientationChanged(outputOrientation: Orientation)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.mrousavy.camera.core.types

import android.view.Display
import android.view.Surface

// This orientation represents the orientation of the device home button.
Expand Down Expand Up @@ -40,12 +39,12 @@ enum class Orientation(override val unionValue: String) : JSUnionValue {
}

fun fromSurfaceRotation(rotation: Int): Orientation =
when (rotation) {
Surface.ROTATION_0 -> PORTRAIT
Surface.ROTATION_90 -> LANDSCAPE_RIGHT
Surface.ROTATION_180 -> PORTRAIT_UPSIDE_DOWN
Surface.ROTATION_270 -> LANDSCAPE_LEFT
else -> PORTRAIT
}
when (rotation) {
Surface.ROTATION_0 -> PORTRAIT
Surface.ROTATION_90 -> LANDSCAPE_RIGHT
Surface.ROTATION_180 -> PORTRAIT_UPSIDE_DOWN
Surface.ROTATION_270 -> LANDSCAPE_LEFT
else -> PORTRAIT
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum class OutputOrientation(override val unionValue: String) : JSUnionValue {

val lockedOrientation: Orientation?
get() {
return when(this) {
return when (this) {
PORTRAIT -> Orientation.PORTRAIT
LANDSCAPE_LEFT -> Orientation.LANDSCAPE_LEFT
PORTRAIT_UPSIDE_DOWN -> Orientation.PORTRAIT_UPSIDE_DOWN
Expand All @@ -21,14 +21,14 @@ enum class OutputOrientation(override val unionValue: String) : JSUnionValue {

companion object : JSUnionValue.Companion<OutputOrientation> {
override fun fromUnionValue(unionValue: String?): OutputOrientation =
when (unionValue) {
"device" -> DEVICE
"preview" -> PREVIEW
"portrait" -> PORTRAIT
"landscape-right" -> LANDSCAPE_RIGHT
"portrait-upside-down" -> PORTRAIT_UPSIDE_DOWN
"landscape-left" -> LANDSCAPE_LEFT
else -> PORTRAIT
}
when (unionValue) {
"device" -> DEVICE
"preview" -> PREVIEW
"portrait" -> PORTRAIT
"landscape-right" -> LANDSCAPE_RIGHT
"portrait-upside-down" -> PORTRAIT_UPSIDE_DOWN
"landscape-left" -> LANDSCAPE_LEFT
else -> PORTRAIT
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.mrousavy.camera.core.CameraSession
import com.mrousavy.camera.core.CodeScannerFrame
import com.mrousavy.camera.core.types.CameraDeviceFormat
import com.mrousavy.camera.core.types.CodeScannerOptions
import com.mrousavy.camera.core.types.Orientation
import com.mrousavy.camera.core.types.OutputOrientation
import com.mrousavy.camera.core.types.PixelFormat
import com.mrousavy.camera.core.types.PreviewViewType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.annotations.ReactProp
import com.mrousavy.camera.core.types.CameraDeviceFormat
import com.mrousavy.camera.core.types.CodeScannerOptions
import com.mrousavy.camera.core.types.Orientation
import com.mrousavy.camera.core.types.OutputOrientation
import com.mrousavy.camera.core.types.PixelFormat
import com.mrousavy.camera.core.types.PreviewViewType
Expand Down

0 comments on commit f4522af

Please sign in to comment.