Nevernmind I created this OnTouchListener that when applied to the surface works:
private class DataPointTapDetector(
private val context: Context,
private val renderableSeries: XyRenderableSeriesBase,
private val data: Pair<List<Date>, List<Double>>,
private val onDataPointTapped: (date: Date, value: Double) -> Unit
) : OnTouchListener {
private var downX = 0f
private var downY = 0f
private val tapThreshold = 10
@SuppressLint("ClickableViewAccessibility")
override fun onTouch(v: View, event: MotionEvent): Boolean {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
downX = event.x
downY = event.y
}
MotionEvent.ACTION_UP -> {
val upX = event.x
val upY = event.y
val deltaX = abs(downX - upX)
val deltaY = abs(downY - upY)
if (deltaX < tapThreshold && deltaY < tapThreshold) {
val hitTestInfo = HitTestInfo()
val hitTestRadius =
context.resources.getDimension(R.dimen.min_button_size) / 2
renderableSeries.hitTest(
hitTestInfo,
upX,
upY,
hitTestRadius
)
if (hitTestInfo.isHit) {
val index = hitTestInfo.dataSeriesIndex
val date = data.first[index]
val value = data.second[index]
onDataPointTapped(date, value)
}
}
}
}
return false
}
}
- Marcela Guerra answered 4 weeks ago
- You must login to post comments
Your Answer
Please login first to submit.