I need to intercept on Touch Event, so I created a CustomSupportMapFragment, but never get the onTouchEvent, I have the same code for the GMS version and goes fine. So I don't know. Here is my code:
class TCSupportMapFragment: SupportMapFragment() {
private var mListener: OnTouchListener? = null
override fun onCreateView(inflater: LayoutInflater, parent: ViewGroup?, savedInstanceState: Bundle?): View {
val layout = super.onCreateView(inflater, parent, savedInstanceState)
val frameLayout = TouchableWrapper(requireContext())
frameLayout.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.transparent))
(layout as ViewGroup).addView(frameLayout, ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
return layout
}
fun setListener(listener: OnTouchListener?) {
mListener = listener
}
interface OnTouchListener {
fun onTouch()
}
inner class TouchableWrapper(context: Context) : FrameLayout(context) {
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
when (event.action) {
MotionEvent.ACTION_DOWN -> mListener?.onTouch()
MotionEvent.ACTION_UP -> mListener?.onTouch()
}
return super.dispatchTouchEvent(event)
}
}
}
In Activity:
override fun onTouchListener() {
this.binding.nestedScroll.requestDisallowInterceptTouchEvent(true)
}