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 0c16aca08..3c59bcb75 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 @@ -35,7 +35,6 @@ import com.kylecorry.trail_sense.tools.augmented_reality.guide.NavigationARGuide import java.time.ZonedDateTime import kotlin.math.hypot -// TODO: Support arguments for default layer visibility (ex. coming from astronomy, enable only sun/moon) class AugmentedRealityFragment : BoundFragment() { private var mode = ARMode.Normal @@ -117,6 +116,10 @@ class AugmentedRealityFragment : BoundFragment( startCamera() } } + + binding.arView.setOnFocusLostListener { + binding.focusActionButton.isVisible = false + } } override fun onResume() { @@ -203,6 +206,18 @@ class AugmentedRealityFragment : BoundFragment( strict = false ) binding.arView.focusText = beacon.name + "\n" + formattedDistance + + // If the beacon isn't the destination, show the navigate button + if (navigator.getDestinationId() != beacon.id) { + binding.focusActionButton.text = getString(R.string.navigate) + binding.focusActionButton.setOnClickListener { + navigator.navigateTo(beacon) + } + binding.focusActionButton.isVisible = true + } else { + binding.focusActionButton.isVisible = false + } + return true } 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 e18e76cd4..1d295ec2f 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 @@ -62,6 +62,8 @@ class AugmentedRealityView : CanvasView { var fov: Size = Size(45f, 45f) var focusText: String? = null + private var hadFocus = false + private var onFocusLostListener: (() -> Unit)? = null var backgroundFillColor: Int = Color.TRANSPARENT @@ -212,6 +214,10 @@ class AugmentedRealityView : CanvasView { onGuideReached = null } + fun setOnFocusLostListener(listener: (() -> Unit)?) { + onFocusLostListener = listener + } + private fun onSensorUpdate(): Boolean { return true } @@ -239,9 +245,14 @@ class AugmentedRealityView : CanvasView { // TODO: Should the onFocus method just return a string? if (!hasFocus) { + if (hadFocus){ + onFocusLostListener?.invoke() + } focusText = null } + hadFocus = hasFocus + if (showReticle) { drawGuidance() drawReticle() diff --git a/app/src/main/res/layout/fragment_augmented_reality.xml b/app/src/main/res/layout/fragment_augmented_reality.xml index b3d9512f5..ead796b27 100644 --- a/app/src/main/res/layout/fragment_augmented_reality.xml +++ b/app/src/main/res/layout/fragment_augmented_reality.xml @@ -31,6 +31,16 @@ app:srcCompat="@drawable/ic_camera" app:tint="@color/white" /> +