Search in sources :

Example 1 with PointerCoords

use of android.view.MotionEvent.PointerCoords in project android_frameworks_base by ParanoidAndroid.

the class TouchExplorer method sendMotionEvent.

/**
     * Sends an event.
     *
     * @param prototype The prototype from which to create the injected events.
     * @param action The action of the event.
     * @param pointerIdBits The bits of the pointers to send.
     * @param policyFlags The policy flags associated with the event.
     */
private void sendMotionEvent(MotionEvent prototype, int action, int pointerIdBits, int policyFlags) {
    prototype.setAction(action);
    MotionEvent event = null;
    if (pointerIdBits == ALL_POINTER_ID_BITS) {
        event = prototype;
    } else {
        event = prototype.split(pointerIdBits);
    }
    if (action == MotionEvent.ACTION_DOWN) {
        event.setDownTime(event.getEventTime());
    } else {
        event.setDownTime(mInjectedPointerTracker.getLastInjectedDownEventTime());
    }
    // on the wrong item since click and long press behave differently.
    if (mLongPressingPointerId >= 0) {
        final int remappedIndex = event.findPointerIndex(mLongPressingPointerId);
        final int pointerCount = event.getPointerCount();
        PointerProperties[] props = PointerProperties.createArray(pointerCount);
        PointerCoords[] coords = PointerCoords.createArray(pointerCount);
        for (int i = 0; i < pointerCount; i++) {
            event.getPointerProperties(i, props[i]);
            event.getPointerCoords(i, coords[i]);
            if (i == remappedIndex) {
                coords[i].x -= mLongPressingPointerDeltaX;
                coords[i].y -= mLongPressingPointerDeltaY;
            }
        }
        MotionEvent remapped = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(), event.getPointerCount(), props, coords, event.getMetaState(), event.getButtonState(), 1.0f, 1.0f, event.getDeviceId(), event.getEdgeFlags(), event.getSource(), event.getFlags());
        if (event != prototype) {
            event.recycle();
        }
        event = remapped;
    }
    if (DEBUG) {
        Slog.d(LOG_TAG, "Injecting event: " + event + ", policyFlags=0x" + Integer.toHexString(policyFlags));
    }
    // Make sure that the user will see the event.
    policyFlags |= WindowManagerPolicy.FLAG_PASS_TO_USER;
    if (mNext != null) {
        // TODO: For now pass null for the raw event since the touch
        //       explorer is the last event transformation and it does
        //       not care about the raw event.
        mNext.onMotionEvent(event, null, policyFlags);
    }
    mInjectedPointerTracker.onMotionEvent(event);
    if (event != prototype) {
        event.recycle();
    }
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) PointerProperties(android.view.MotionEvent.PointerProperties) GesturePoint(android.gesture.GesturePoint) MotionEvent(android.view.MotionEvent)

Example 2 with PointerCoords

use of android.view.MotionEvent.PointerCoords in project android_frameworks_base by ResurrectionRemix.

the class DocumentHolderTest method createEvent.

public MotionEvent createEvent(int tooltype) {
    long time = SystemClock.uptimeMillis();
    PointerProperties[] properties = new PointerProperties[] { new PointerProperties() };
    properties[0].toolType = tooltype;
    PointerCoords[] coords = new PointerCoords[] { new PointerCoords() };
    Rect rect = new Rect();
    mHolder.itemView.getHitRect(rect);
    coords[0].x = rect.left;
    coords[0].y = rect.top;
    return MotionEvent.obtain(// down time
    time, // event time
    time, // action
    MotionEvent.ACTION_UP, // pointer count
    1, // pointer properties
    properties, // pointer coords
    coords, // metastate
    0, // button state
    0, // xprecision
    0, // yprecision
    0, // deviceid
    0, // edgeflags
    0, // source
    0, // flags
    0);
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) Rect(android.graphics.Rect) PointerProperties(android.view.MotionEvent.PointerProperties)

Example 3 with PointerCoords

use of android.view.MotionEvent.PointerCoords in project android_frameworks_base by ResurrectionRemix.

the class MagnificationGestureHandler method getTempPointerCoordsWithMinSize.

private PointerCoords[] getTempPointerCoordsWithMinSize(int size) {
    final int oldSize = (mTempPointerCoords != null) ? mTempPointerCoords.length : 0;
    if (oldSize < size) {
        PointerCoords[] oldTempPointerCoords = mTempPointerCoords;
        mTempPointerCoords = new PointerCoords[size];
        if (oldTempPointerCoords != null) {
            System.arraycopy(oldTempPointerCoords, 0, mTempPointerCoords, 0, oldSize);
        }
    }
    for (int i = oldSize; i < size; i++) {
        mTempPointerCoords[i] = new PointerCoords();
    }
    return mTempPointerCoords;
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords)

Example 4 with PointerCoords

use of android.view.MotionEvent.PointerCoords in project android_frameworks_base by ResurrectionRemix.

the class TouchExplorer method offsetEvent.

/**
     * Offsets all pointers in the given event by adding the specified X and Y
     * offsets.
     *
     * @param event The event to offset.
     * @param offsetX The X offset.
     * @param offsetY The Y offset.
     * @return An event with the offset pointers or the original event if both
     *         offsets are zero.
     */
private MotionEvent offsetEvent(MotionEvent event, int offsetX, int offsetY) {
    if (offsetX == 0 && offsetY == 0) {
        return event;
    }
    final int remappedIndex = event.findPointerIndex(mLongPressingPointerId);
    final int pointerCount = event.getPointerCount();
    PointerProperties[] props = PointerProperties.createArray(pointerCount);
    PointerCoords[] coords = PointerCoords.createArray(pointerCount);
    for (int i = 0; i < pointerCount; i++) {
        event.getPointerProperties(i, props[i]);
        event.getPointerCoords(i, coords[i]);
        if (i == remappedIndex) {
            coords[i].x += offsetX;
            coords[i].y += offsetY;
        }
    }
    return MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(), event.getPointerCount(), props, coords, event.getMetaState(), event.getButtonState(), 1.0f, 1.0f, event.getDeviceId(), event.getEdgeFlags(), event.getSource(), event.getFlags());
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) PointerProperties(android.view.MotionEvent.PointerProperties) Point(android.graphics.Point)

Example 5 with PointerCoords

use of android.view.MotionEvent.PointerCoords in project android_frameworks_base by ResurrectionRemix.

the class TouchExplorer method onDoubleTap.

@Override
public boolean onDoubleTap(MotionEvent event, int policyFlags) {
    // Ignore the event if we aren't touch exploring.
    if (mCurrentState != STATE_TOUCH_EXPLORING) {
        return false;
    }
    // Remove pending event deliveries.
    mSendHoverEnterAndMoveDelayed.cancel();
    mSendHoverExitDelayed.cancel();
    if (mSendTouchExplorationEndDelayed.isPending()) {
        mSendTouchExplorationEndDelayed.forceSendAndRemove();
    }
    if (mSendTouchInteractionEndDelayed.isPending()) {
        mSendTouchInteractionEndDelayed.forceSendAndRemove();
    }
    final int pointerIndex = event.getActionIndex();
    final int pointerId = event.getPointerId(pointerIndex);
    Point clickLocation = mTempPoint;
    final int result = computeClickLocation(clickLocation);
    if (result == CLICK_LOCATION_NONE) {
        // consumed.
        return true;
    }
    // Do the click.
    PointerProperties[] properties = new PointerProperties[1];
    properties[0] = new PointerProperties();
    event.getPointerProperties(pointerIndex, properties[0]);
    PointerCoords[] coords = new PointerCoords[1];
    coords[0] = new PointerCoords();
    coords[0].x = clickLocation.x;
    coords[0].y = clickLocation.y;
    MotionEvent click_event = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), MotionEvent.ACTION_DOWN, 1, properties, coords, 0, 0, 1.0f, 1.0f, event.getDeviceId(), 0, event.getSource(), event.getFlags());
    final boolean targetAccessibilityFocus = (result == CLICK_LOCATION_ACCESSIBILITY_FOCUS);
    sendActionDownAndUp(click_event, policyFlags, targetAccessibilityFocus);
    click_event.recycle();
    return true;
}
Also used : PointerCoords(android.view.MotionEvent.PointerCoords) Point(android.graphics.Point) PointerProperties(android.view.MotionEvent.PointerProperties) Point(android.graphics.Point) MotionEvent(android.view.MotionEvent)

Aggregations

PointerCoords (android.view.MotionEvent.PointerCoords)56 PointerProperties (android.view.MotionEvent.PointerProperties)29 Point (android.graphics.Point)20 MotionEvent (android.view.MotionEvent)17 Paint (android.graphics.Paint)7 Test (org.junit.Test)6 Rect (android.graphics.Rect)5 InputDevice (android.view.InputDevice)5 HiddenApi (org.robolectric.annotation.HiddenApi)2 Implementation (org.robolectric.annotation.Implementation)2 GesturePoint (android.gesture.GesturePoint)1 Matrix (android.graphics.Matrix)1