Skip to content

Commit

Permalink
Add focus action to navigate
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Jan 17, 2024
1 parent d21f0d8 commit 848bda9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<FragmentAugmentedRealityBinding>() {

private var mode = ARMode.Normal
Expand Down Expand Up @@ -117,6 +116,10 @@ class AugmentedRealityFragment : BoundFragment<FragmentAugmentedRealityBinding>(
startCamera()
}
}

binding.arView.setOnFocusLostListener {
binding.focusActionButton.isVisible = false
}
}

override fun onResume() {
Expand Down Expand Up @@ -203,6 +206,18 @@ class AugmentedRealityFragment : BoundFragment<FragmentAugmentedRealityBinding>(
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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -212,6 +214,10 @@ class AugmentedRealityView : CanvasView {
onGuideReached = null
}

fun setOnFocusLostListener(listener: (() -> Unit)?) {
onFocusLostListener = listener
}

private fun onSensorUpdate(): Boolean {
return true
}
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/fragment_augmented_reality.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
app:srcCompat="@drawable/ic_camera"
app:tint="@color/white" />

<Button
android:id="@+id/focus_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/default_bottom_margin"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/guidance_panel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<FrameLayout
android:id="@+id/guidance_panel"
android:layout_width="match_parent"
Expand Down

0 comments on commit 848bda9

Please sign in to comment.