Android How can I catch a right click (tap 2 fingers on touch pad of a chromebook)?

68 views Asked by At

This is my touch listener:

var touchListener = OnTouchListener { view, motionEvent ->
            val action = motionEvent.action
            when (action and MotionEvent.ACTION_MASK) {
                MotionEvent.ACTION_POINTER_DOWN -> {
                    Toast.makeText(activity, " Two Fingers Tapped Once. Yeeeyy :)", Toast.LENGTH_SHORT).show()

                    // set the mTwoFingersTapped flag to TRUE when we tap with 2 fingers at once
                    twoFingers = true
                }
            }
            false
        }

And in my click listener I do this:

 if (!twoFingers) {
                    todoListener.onCommunicationInfoClicked(addressableReference)
            } else {
                todoListener.onLongClicked(todoItem)
                twoFingers = false
                Toast.makeText(activity, " Two Fingers Tapped Once. Yeeeyy :)", Toast.LENGTH_SHORT).show()
            }

This works on android phone, if I tap with 2 fingers and I get desired effect. However I tap with 2 fingers on chromebook touchpad and nothing happens

1

There are 1 answers

0
rosu alin On

After listening and posting the finger counter and events and etc. I did manage to make it work like this:

   var touchListener = OnTouchListener { view, motionEvent ->
            val action = motionEvent.action
            if (action == MotionEvent.ACTION_CANCEL && previousEvent == MotionEvent.ACTION_DOWN) //DO STUFF
            previousEvent = action
            false
        }

But not quite happy with it.