ultra
ultra

Reputation: 329

Using MotionEventCompat in android

I'm looking for an example of how to use MotionEventCompat in Android. I'm using API level 10, which doesn't support if a finger is 'hovering' or 'dragging' onto a view. I need to detect this, preferably from the view itself. Here's some code snippets regarding how I'm trying to use this:

**my class:** 
 import android.support.v4.view.MotionEventCompat;
        public class GridButton extends View 

    overriding onTouchEvent:
            @Override
        public boolean onTouchEvent(MotionEvent event) {
            super.onTouchEvent(event);
            switch (event.getAction() & MotionEventCompat.ACTION_MASK) {
            case (MotionEvent.ACTION_DOWN): {
                set_active(true);
                return true;
            }
            case (MotionEventCompat.ACTION_HOVER_ENTER): {
                set_active(true);
                break;
            }
            }
            return false;
        }

I based the MotionEventCompat.ACTION_MASK off an example I found somewhere, but it doesn't trigger my code for set_active().

Any help on using this would be appreciated. There's very little about this on the web.

Upvotes: 0

Views: 2418

Answers (1)

adamp
adamp

Reputation: 28932

Hover events are sent when the device supports a mouse or touchpad. When the cursor hovers over a view these events are sent to onGenericMotionEvent, not onTouchEvent. They won't help you detect a finger that isn't touching the surface of a capacitive touchscreen or a finger that touched down in a different position and then slid over the view in question. They will never be sent on an API 10 (Android 2.3) device.

Upvotes: 2

Related Questions