Skip to content

Commit

Permalink
Disable camera toggle when no camera
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Nov 4, 2023
1 parent 23ad6d0 commit 556a45d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ class CameraView(context: Context, attrs: AttributeSet?) : FrameLayout(context,
isStarted = true
}

alpha = 1f

camera?.stop(this::onCameraUpdate)
imageListener = onImage
camera = Camera(
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -115,8 +118,12 @@ class AugmentedRealityFragment : BoundFragment<FragmentAugmentedRealityBinding>(
super.onResume()

binding.arView.start()
isCameraEnabled = Camera.isAvailable(requireContext())
binding.cameraToggle.isVisible = isCameraEnabled
if (isCameraEnabled) {
startCamera()
} else {
stopCamera()
}
updateAstronomyLayers()
}
Expand All @@ -128,10 +135,12 @@ class AugmentedRealityFragment : BoundFragment<FragmentAugmentedRealityBinding>(
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
Expand All @@ -145,6 +154,7 @@ class AugmentedRealityFragment : BoundFragment<FragmentAugmentedRealityBinding>(
isCameraEnabled = false
binding.arView.backgroundFillColor = Color.BLACK
binding.camera.stop()
binding.camera.isInvisible = true
}

override fun onPause() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 556a45d

Please sign in to comment.