FileDocCategorySizeDatePackage
StackTapPointerEventListener.javaAPI DocAndroid 5.1 API3741Thu Mar 12 22:22:42 GMT 2015com.android.server.wm

StackTapPointerEventListener

public class StackTapPointerEventListener extends Object implements android.view.WindowManagerPolicy.PointerEventListener

Fields Summary
private static final int
TAP_TIMEOUT_MSEC
private static final float
TAP_MOTION_SLOP_INCHES
private final int
mMotionSlop
private float
mDownX
private float
mDownY
private int
mPointerId
private final android.graphics.Region
mTouchExcludeRegion
private final WindowManagerService
mService
private final DisplayContent
mDisplayContent
Constructors Summary
public StackTapPointerEventListener(WindowManagerService service, DisplayContent displayContent)


      
              
        mService = service;
        mDisplayContent = displayContent;
        mTouchExcludeRegion = displayContent.mTouchExcludeRegion;
        DisplayInfo info = displayContent.getDisplayInfo();
        mMotionSlop = (int)(info.logicalDensityDpi * TAP_MOTION_SLOP_INCHES);
    
Methods Summary
public voidonPointerEvent(android.view.MotionEvent motionEvent)

        final int action = motionEvent.getAction();
        switch (action & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                mPointerId = motionEvent.getPointerId(0);
                mDownX = motionEvent.getX();
                mDownY = motionEvent.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                if (mPointerId >= 0) {
                    int index = motionEvent.findPointerIndex(mPointerId);
                    if ((motionEvent.getEventTime() - motionEvent.getDownTime()) > TAP_TIMEOUT_MSEC
                            || index < 0
                            || (motionEvent.getX(index) - mDownX) > mMotionSlop
                            || (motionEvent.getY(index) - mDownY) > mMotionSlop) {
                        mPointerId = -1;
                    }
                }
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_POINTER_UP: {
                int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK)
                        >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
                // Extract the index of the pointer that left the touch sensor
                if (mPointerId == motionEvent.getPointerId(index)) {
                    final int x = (int)motionEvent.getX(index);
                    final int y = (int)motionEvent.getY(index);
                    if ((motionEvent.getEventTime() - motionEvent.getDownTime())
                            < TAP_TIMEOUT_MSEC
                            && (x - mDownX) < mMotionSlop && (y - mDownY) < mMotionSlop
                            && !mTouchExcludeRegion.contains(x, y)) {
                        mService.mH.obtainMessage(H.TAP_OUTSIDE_STACK, x, y,
                                mDisplayContent).sendToTarget();
                    }
                    mPointerId = -1;
                }
                break;
            }
        }