From 556a45da6b9bc9137d8c219856ad83e57c10e1d1 Mon Sep 17 00:00:00 2001 From: Kyle Corry Date: Sat, 4 Nov 2023 11:18:00 -0400 Subject: [PATCH] Disable camera toggle when no camera --- .../kylecorry/trail_sense/shared/views/CameraView.kt | 3 --- .../augmented_reality/AugmentedRealityFragment.kt | 10 ++++++++++ .../tools/augmented_reality/AugmentedRealityView.kt | 5 ++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/kylecorry/trail_sense/shared/views/CameraView.kt b/app/src/main/java/com/kylecorry/trail_sense/shared/views/CameraView.kt index 37c064951..1e9411120 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/shared/views/CameraView.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/shared/views/CameraView.kt @@ -90,8 +90,6 @@ class CameraView(context: Context, attrs: AttributeSet?) : FrameLayout(context, isStarted = true } - alpha = 1f - camera?.stop(this::onCameraUpdate) imageListener = onImage camera = Camera( @@ -110,7 +108,6 @@ class CameraView(context: Context, attrs: AttributeSet?) : FrameLayout(context, fun stop() { camera?.stop(this::onCameraUpdate) camera = null - alpha = 0f synchronized(startLock) { isStarted = false } diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt index 2e1bd9f19..1640d9abf 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt @@ -9,6 +9,9 @@ import android.view.ViewGroup import android.widget.FrameLayout import androidx.camera.view.PreviewView import androidx.core.graphics.drawable.toBitmapOrNull +import androidx.core.view.isInvisible +import androidx.core.view.isVisible +import com.kylecorry.andromeda.camera.Camera import com.kylecorry.andromeda.core.coroutines.onDefault import com.kylecorry.andromeda.core.system.Resources import com.kylecorry.andromeda.core.time.CoroutineTimer @@ -115,8 +118,12 @@ class AugmentedRealityFragment : BoundFragment( super.onResume() binding.arView.start() + isCameraEnabled = Camera.isAvailable(requireContext()) + binding.cameraToggle.isVisible = isCameraEnabled if (isCameraEnabled) { startCamera() + } else { + stopCamera() } updateAstronomyLayers() } @@ -128,10 +135,12 @@ class AugmentedRealityFragment : BoundFragment( binding.arView.backgroundFillColor = Color.TRANSPARENT requestCamera { if (it) { + binding.camera.isVisible = true binding.camera.start( readFrames = false, shouldStabilizePreview = false ) } else { + binding.camera.isInvisible = true isCameraEnabled = false binding.cameraToggle.setImageResource(R.drawable.ic_camera_off) binding.arView.backgroundFillColor = Color.BLACK @@ -145,6 +154,7 @@ class AugmentedRealityFragment : BoundFragment( isCameraEnabled = false binding.arView.backgroundFillColor = Color.BLACK binding.camera.stop() + binding.camera.isInvisible = true } override fun onPause() { diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityView.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityView.kt index 034dad107..a90248e33 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityView.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityView.kt @@ -63,7 +63,6 @@ class AugmentedRealityView : CanvasView { private var rotationMatrix = FloatArray(16) private val quaternion = FloatArray(4) private val orientation = FloatArray(3) - private val tempRotationResult = FloatArray(4) private val tempWorldVector = FloatArray(4) @@ -377,8 +376,8 @@ class AugmentedRealityView : CanvasView { tempWorldVector[1] = vector.y tempWorldVector[2] = vector.z tempWorldVector[3] = 1f - Matrix.multiplyMV(tempRotationResult, 0, rotationMatrix, 0, tempWorldVector, 0) - return Vector3(tempRotationResult[0], tempRotationResult[1], tempRotationResult[2]) + Matrix.multiplyMV(tempWorldVector, 0, rotationMatrix, 0, tempWorldVector, 0) + return Vector3(tempWorldVector[0], tempWorldVector[1], tempWorldVector[2]) } private fun toSpherical(vector: Vector3): Vector3 {