Skip to content

Commit

Permalink
Fix AR view tap
Browse files Browse the repository at this point in the history
Closes #2112
  • Loading branch information
kylecorry31 committed Dec 11, 2023
1 parent 23ae204 commit 04f3f0c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ class CameraView(context: Context, attrs: AttributeSet?) : FrameLayout(context,
private val mScaleDetector = ScaleGestureDetector(context, scaleListener)

override fun onTouchEvent(event: MotionEvent): Boolean {
var consumed = mScaleDetector.onTouchEvent(event)
consumed = consumed || gestureDetector.onTouchEvent(event)
return consumed || super.onTouchEvent(event)
mScaleDetector.onTouchEvent(event)
gestureDetector.onTouchEvent(event)
return true
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class AugmentedRealityFragment : BoundFragment<FragmentAugmentedRealityBinding>(
binding.camera.setScaleType(PreviewView.ScaleType.FIT_CENTER)
binding.camera.setShowTorch(false)

binding.arView.bind(binding.camera)

binding.arView.setLayers(listOf(gridLayer, sunLayer, moonLayer, beaconLayer))

binding.cameraToggle.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.kylecorry.trail_sense.shared.declination.DeclinationUtils
import com.kylecorry.trail_sense.shared.sensors.SensorService
import com.kylecorry.trail_sense.shared.text
import com.kylecorry.trail_sense.shared.textDimensions
import com.kylecorry.trail_sense.shared.views.CameraView
import com.kylecorry.trail_sense.tools.augmented_reality.position.ARPoint
import java.time.Duration
import kotlin.math.atan2
Expand Down Expand Up @@ -418,9 +419,17 @@ class AugmentedRealityView : CanvasView {

private val mGestureDetector = GestureDetector(context, gestureListener)

private var camera: CameraView? = null

override fun onTouchEvent(event: MotionEvent): Boolean {
val consumed = mGestureDetector.onTouchEvent(event)
return consumed || super.onTouchEvent(event)
mGestureDetector.onTouchEvent(event)
camera?.onTouchEvent(event)
return true
}

fun bind(camera: CameraView){
this.camera = camera
// TODO: Listen for fov and size changes
}

data class HorizonCoordinate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class ClinometerFragment : BoundFragment<FragmentClinometerBinding>() {
binding.arView.showReticle = false
binding.arView.showPosition = false

binding.arView.bind(binding.camera)

observe(sideClinometer) { updateUI() }
observe(cameraClinometer) { updateUI() }
observe(deviceOrientation) { updateUI() }
Expand Down

0 comments on commit 04f3f0c

Please sign in to comment.