Code example for MotionEvent

Methods: getActiongetXgetYsetLocation

0
        // f=core/java/android/view/TouchDelegate.java;hb=eclair#l98 
 
        final Rect sourcePartial = mSourcePartial;
        final View target = mTarget;
 
        int x = (int)event.getX();
        int y = (int)event.getY();
 
        boolean sendToDelegate = false;
        boolean hit = true;
        boolean handled = false;
 
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            if (sourcePartial.contains(x, y)) {
                mDelegateTargeted = true;
                sendToDelegate = true;
            } 
            break; 
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_MOVE:
            sendToDelegate = mDelegateTargeted;
            if (sendToDelegate) {
                if (!sourcePartial.contains(x, y)) {
                    hit = false;
                } 
            } 
            break; 
        case MotionEvent.ACTION_CANCEL:
            sendToDelegate = mDelegateTargeted;
            mDelegateTargeted = false;
            break; 
        } 
 
        if (sendToDelegate) {
            if (hit) {
                event.setLocation(target.getWidth() / 2, target.getHeight() / 2);
            } else { 
                event.setLocation(-1, -1);
            } 
            handled = target.dispatchTouchEvent(event);
        } 
        return handled;
    }