Skip to content

Commit

Permalink
feat : 전면 카메라 스위칭 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
HamBP committed Jan 7, 2025
1 parent dcb34f1 commit 61eb6ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.nexters.boolti.presentation

import android.Manifest
import android.content.Context
import android.hardware.Camera
import android.os.Build
import android.os.Bundle
import android.os.VibrationEffect
Expand Down Expand Up @@ -29,6 +30,7 @@ import kotlinx.coroutines.launch

@AndroidEntryPoint
class QrScanActivity : ComponentActivity() {
var isBackCamera = true

private val barcodeView: DecoratedBarcodeView by lazy {
DecoratedBarcodeView(this).apply {
Expand Down Expand Up @@ -78,7 +80,8 @@ class QrScanActivity : ComponentActivity() {
BooltiTheme {
QrScanScreen(
barcodeView = barcodeView,
onClickClose = { finish() }
onClickClose = { finish() },
onClickSwitchCamera = ::switchCamera
)
}
}
Expand All @@ -97,4 +100,15 @@ class QrScanActivity : ComponentActivity() {
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
return barcodeView.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event)
}

private fun switchCamera() {
barcodeView.pause()
isBackCamera = !isBackCamera
barcodeView.cameraSettings.requestedCameraId = if (isBackCamera) {
Camera.CameraInfo.CAMERA_FACING_BACK
} else {
Camera.CameraInfo.CAMERA_FACING_FRONT
}
barcodeView.resume()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fun QrScanScreen(
barcodeView: DecoratedBarcodeView,
viewModel: QrScanViewModel = hiltViewModel(),
onClickClose: () -> Unit,
onClickSwitchCamera: () -> Unit,
) {
var showEntryCodeDialog by remember { mutableStateOf(false) }
val snackbarHostState = remember { SnackbarHostState() }
Expand Down Expand Up @@ -103,7 +104,7 @@ fun QrScanScreen(
},
actionButtons = {
BtAppBarDefaults.AppBarIconButton(
onClick = {},
onClick = onClickSwitchCamera,
iconRes = R.drawable.ic_camera_flip,
)
}
Expand Down

0 comments on commit 61eb6ec

Please sign in to comment.