0

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.

Dinesh Anuruddha
  • 7,137
  • 6
  • 32
  • 45
ultra
  • 329
  • 1
  • 4
  • 15

1 Answers1

2

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.

adamp
  • 28,862
  • 9
  • 81
  • 69
  • 1
    Thanks for keeping me off the wrong path. I found a solution by tracking finger location from the parent. – ultra Aug 23 '12 at 12:05