Java Code Examples for android.view.MotionEvent#getSize()

The following examples show how to use android.view.MotionEvent#getSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TouchPoint.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static int createTouchPoints(MotionEvent event, TouchPoint[] pts) {
    int type;
    int defaultState;

    switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            type = TOUCH_EVENT_TYPE_START;
            defaultState = TOUCH_POINT_STATE_PRESSED;
            break;
        case MotionEvent.ACTION_MOVE:
            type = TOUCH_EVENT_TYPE_MOVE;
            defaultState = TOUCH_POINT_STATE_MOVED;
            break;
        case MotionEvent.ACTION_UP:
            type = TOUCH_EVENT_TYPE_END;
            defaultState = TOUCH_POINT_STATE_RELEASED;
            break;
        case MotionEvent.ACTION_CANCEL:
            type = TOUCH_EVENT_TYPE_CANCEL;
            defaultState = TOUCH_POINT_STATE_CANCELLED;
            break;
        case MotionEvent.ACTION_POINTER_DOWN:  // fall through.
        case MotionEvent.ACTION_POINTER_UP:
            type = TOUCH_EVENT_TYPE_MOVE;
            defaultState = TOUCH_POINT_STATE_STATIONARY;
            break;
        default:
            Log.e("Chromium", "Unknown motion event action: " + event.getActionMasked());
            return CONVERSION_ERROR;
    }

    for (int i = 0; i < pts.length; ++i) {
        int state = defaultState;
        if (defaultState == TOUCH_POINT_STATE_STATIONARY && event.getActionIndex() == i) {
            // An additional pointer has started or ended. Map this pointer state as
            // required, and all other pointers as "stationary".
            state = event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN ?
                TOUCH_POINT_STATE_PRESSED : TOUCH_POINT_STATE_RELEASED;
        }
        pts[i] = new TouchPoint(state, event.getPointerId(i),
                                event.getX(i), event.getY(i),
                                event.getSize(i), event.getPressure(i));
    }

    return type;
}
 
Example 2
Source File: TouchPoint.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static int createTouchPoints(MotionEvent event, TouchPoint[] pts) {
    int type;
    int defaultState;

    switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            type = TOUCH_EVENT_TYPE_START;
            defaultState = TOUCH_POINT_STATE_PRESSED;
            break;
        case MotionEvent.ACTION_MOVE:
            type = TOUCH_EVENT_TYPE_MOVE;
            defaultState = TOUCH_POINT_STATE_MOVED;
            break;
        case MotionEvent.ACTION_UP:
            type = TOUCH_EVENT_TYPE_END;
            defaultState = TOUCH_POINT_STATE_RELEASED;
            break;
        case MotionEvent.ACTION_CANCEL:
            type = TOUCH_EVENT_TYPE_CANCEL;
            defaultState = TOUCH_POINT_STATE_CANCELLED;
            break;
        case MotionEvent.ACTION_POINTER_DOWN:  // fall through.
        case MotionEvent.ACTION_POINTER_UP:
            type = TOUCH_EVENT_TYPE_MOVE;
            defaultState = TOUCH_POINT_STATE_STATIONARY;
            break;
        default:
            Log.e("Chromium", "Unknown motion event action: " + event.getActionMasked());
            return CONVERSION_ERROR;
    }

    for (int i = 0; i < pts.length; ++i) {
        int state = defaultState;
        if (defaultState == TOUCH_POINT_STATE_STATIONARY && event.getActionIndex() == i) {
            // An additional pointer has started or ended. Map this pointer state as
            // required, and all other pointers as "stationary".
            state = event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN ?
                TOUCH_POINT_STATE_PRESSED : TOUCH_POINT_STATE_RELEASED;
        }
        pts[i] = new TouchPoint(state, event.getPointerId(i),
                                event.getX(i), event.getY(i),
                                event.getSize(i), event.getPressure(i));
    }

    return type;
}