android.view.MotionEvent.PointerCoords源码实例Demo

类android.view.MotionEvent.PointerCoords源码实例Demo

下面列出了android.view.MotionEvent.PointerCoords 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/** Helper function to obtain a MotionEvent. */
private static MotionEvent getMotionEvent(long downTime, long eventTime, int action,
    float x, float y) {

  PointerProperties properties = new PointerProperties();
  properties.id = 0;
  properties.toolType = Configurator.getInstance().getToolType();

  PointerCoords coords = new PointerCoords();
  coords.pressure = 1;
  coords.size = 1;
  coords.x = x;
  coords.y = y;

  return MotionEvent.obtain(downTime, eventTime, action, 1,
      new PointerProperties[] { properties }, new PointerCoords[] { coords },
      0, 0, 1.0f, 1.0f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
}
 
源代码2 项目: 365browser   文件: MotionEventSynthesizer.java
@CalledByNative
void setPointer(int index, int x, int y, int id) {
    assert (0 <= index && index < MAX_NUM_POINTERS);

    // Convert coordinates from density independent pixels to density dependent pixels.
    float scaleFactor = getDisplay().getDipScale();

    PointerCoords coords = new PointerCoords();
    coords.x = scaleFactor * x;
    coords.y = scaleFactor * y;
    coords.pressure = 1.0f;
    mPointerCoords[index] = coords;

    PointerProperties properties = new PointerProperties();
    properties.id = id;
    mPointerProperties[index] = properties;
}
 
源代码3 项目: android-test   文件: MotionEventBuilder.java
/** Returns a MotionEvent with the provided data or reasonable defaults. */
public MotionEvent build() {
  if (pointerPropertiesList.size() == 0) {
    setPointer(0, 0);
  }
  if (actionIndex != -1) {
    action = action | (actionIndex << MotionEvent.ACTION_POINTER_INDEX_SHIFT);
  }
  return MotionEvent.obtain(
      downTime,
      eventTime,
      action,
      pointerPropertiesList.size(),
      pointerPropertiesList.toArray(new PointerProperties[pointerPropertiesList.size()]),
      pointerCoordsList.toArray(new MotionEvent.PointerCoords[pointerCoordsList.size()]),
      metaState,
      buttonState,
      xPrecision,
      yPrecision,
      deviceId,
      edgeFlags,
      source,
      flags);
}
 
源代码4 项目: android-chromium   文件: GenericTouchGesture.java
GenericTouchGesture(ContentViewCore contentViewCore,
        int startX, int startY, int deltaX, int deltaY) {
    mContentViewCore = contentViewCore;

    float scale = mContentViewCore.getRenderCoordinates().getDeviceScaleFactor();
    int scaledTouchSlop = getScaledTouchSlop();

    mPointers = new TouchPointer[1];
    mPointers[0] = new TouchPointer(startX, startY, deltaX, deltaY, 0,
        scale, scaledTouchSlop);

    mPointerProperties = new PointerProperties[1];
    mPointerProperties[0] = mPointers[0].getProperties();

    mPointerCoords = new PointerCoords[1];
    mPointerCoords[0] = mPointers[0].getCoords();
}
 
源代码5 项目: android-chromium   文件: GenericTouchGesture.java
GenericTouchGesture(ContentViewCore contentViewCore,
        int startX0, int startY0, int deltaX0, int deltaY0,
        int startX1, int startY1, int deltaX1, int deltaY1) {
    mContentViewCore = contentViewCore;

    float scale = mContentViewCore.getRenderCoordinates().getDeviceScaleFactor();
    int scaledTouchSlop = getScaledTouchSlop();

    mPointers = new TouchPointer[2];
    mPointers[0] = new TouchPointer(startX0, startY0, deltaX0, deltaY0, 0,
        scale, scaledTouchSlop);
    mPointers[1] = new TouchPointer(startX1, startY1, deltaX1, deltaY1, 1,
        scale, scaledTouchSlop);

    mPointerProperties = new PointerProperties[2];
    mPointerProperties[0] = mPointers[0].getProperties();
    mPointerProperties[1] = mPointers[1].getProperties();

    mPointerCoords = new PointerCoords[2];
    mPointerCoords[0] = mPointers[0].getCoords();
    mPointerCoords[1] = mPointers[1].getCoords();
}
 
源代码6 项目: android-chromium   文件: GenericTouchGesture.java
GenericTouchGesture(ContentViewCore contentViewCore,
        int startX, int startY, int deltaX, int deltaY) {
    mContentViewCore = contentViewCore;

    float scale = mContentViewCore.getRenderCoordinates().getDeviceScaleFactor();
    int scaledTouchSlop = getScaledTouchSlop();

    mPointers = new TouchPointer[1];
    mPointers[0] = new TouchPointer(startX, startY, deltaX, deltaY, 0,
        scale, scaledTouchSlop);

    mPointerProperties = new PointerProperties[1];
    mPointerProperties[0] = mPointers[0].getProperties();

    mPointerCoords = new PointerCoords[1];
    mPointerCoords[0] = mPointers[0].getCoords();
}
 
源代码7 项目: android-chromium   文件: GenericTouchGesture.java
GenericTouchGesture(ContentViewCore contentViewCore,
        int startX0, int startY0, int deltaX0, int deltaY0,
        int startX1, int startY1, int deltaX1, int deltaY1) {
    mContentViewCore = contentViewCore;

    float scale = mContentViewCore.getRenderCoordinates().getDeviceScaleFactor();
    int scaledTouchSlop = getScaledTouchSlop();

    mPointers = new TouchPointer[2];
    mPointers[0] = new TouchPointer(startX0, startY0, deltaX0, deltaY0, 0,
        scale, scaledTouchSlop);
    mPointers[1] = new TouchPointer(startX1, startY1, deltaX1, deltaY1, 1,
        scale, scaledTouchSlop);

    mPointerProperties = new PointerProperties[2];
    mPointerProperties[0] = mPointers[0].getProperties();
    mPointerProperties[1] = mPointers[1].getProperties();

    mPointerCoords = new PointerCoords[2];
    mPointerCoords[0] = mPointers[0].getCoords();
    mPointerCoords[1] = mPointers[1].getCoords();
}
 
源代码8 项目: za-Farmer   文件: GestureController.java
/** Helper function to obtain a MotionEvent. */
private static MotionEvent getMotionEvent(long downTime, long eventTime, int action,
        List<PointerProperties> properties, List<PointerCoords> coordinates) {

    PointerProperties[] props = properties.toArray(new PointerProperties[properties.size()]);
    PointerCoords[] coords = coordinates.toArray(new PointerCoords[coordinates.size()]);
    return MotionEvent.obtain(downTime, eventTime, action, props.length, props, coords,
            0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
}
 
源代码9 项目: za-Farmer   文件: GestureController.java
public Pointer(int id, Point point) {
    prop = new PointerProperties();
    prop.id = id;
    prop.toolType = MotionEvent.TOOL_TYPE_FINGER;
    coords = new PointerCoords();
    coords.pressure = 1;
    coords.size = 1;
    coords.x = point.x;
    coords.y = point.y;
}
 
源代码10 项目: JsDroidCmd   文件: GestureController.java
/** Helper function to obtain a MotionEvent. */
private static MotionEvent getMotionEvent(long downTime, long eventTime, int action,
        List<PointerProperties> properties, List<PointerCoords> coordinates) {

    PointerProperties[] props = properties.toArray(new PointerProperties[properties.size()]);
    PointerCoords[] coords = coordinates.toArray(new PointerCoords[coordinates.size()]);
    return MotionEvent.obtain(downTime, eventTime, action, props.length, props, coords,
            0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
}
 
源代码11 项目: JsDroidCmd   文件: GestureController.java
public Pointer(int id, Point point) {
    prop = new PointerProperties();
    prop.id = id;
    prop.toolType = MotionEvent.TOOL_TYPE_FINGER;
    coords = new PointerCoords();
    coords.pressure = 1;
    coords.size = 1;
    coords.x = point.x;
    coords.y = point.y;
}
 
源代码12 项目: ViewSupport   文件: MotionEventHelper.java
private static MotionEvent transformEventOld(MotionEvent e, Matrix m) {
    long downTime = e.getDownTime();
    long eventTime = e.getEventTime();
    int action = e.getAction();
    int pointerCount = e.getPointerCount();
    int[] pointerIds = getPointerIds(e);
    PointerCoords[] pointerCoords = getPointerCoords(e);
    int metaState = e.getMetaState();
    float xPrecision = e.getXPrecision();
    float yPrecision = e.getYPrecision();
    int deviceId = e.getDeviceId();
    int edgeFlags = e.getEdgeFlags();
    int source = e.getSource();
    int flags = e.getFlags();
    // Copy the x and y coordinates into an array, map them, and copy back.
    float[] xy = new float[pointerCoords.length * 2];
    for (int i = 0; i < pointerCount;i++) {
        xy[2 * i] = pointerCoords[i].x;
        xy[2 * i + 1] = pointerCoords[i].y;
    }
    m.mapPoints(xy);
    for (int i = 0; i < pointerCount;i++) {
        pointerCoords[i].x = xy[2 * i];
        pointerCoords[i].y = xy[2 * i + 1];
        pointerCoords[i].orientation = transformAngle(
                m, pointerCoords[i].orientation);
    }
    MotionEvent n = MotionEvent.obtain(downTime, eventTime, action,
            pointerCount, pointerIds, pointerCoords, metaState, xPrecision,
            yPrecision, deviceId, edgeFlags, source, flags);
    return n;
}
 
源代码13 项目: ViewSupport   文件: MotionEventHelper.java
private static PointerCoords[] getPointerCoords(MotionEvent e) {
    int n = e.getPointerCount();
    PointerCoords[] r = new PointerCoords[n];
    for (int i = 0; i < n; i++) {
        r[i] = new PointerCoords();
        e.getPointerCoords(i, r[i]);
    }
    return r;
}
 
@Override
protected AppiumResponse safeHandle(IHttpRequest request) {
    final PointerCoords[][] pcs = parsePointerCoords(request);
    if (!UiAutomatorBridge.getInstance().getInteractionController().performMultiPointerGesture(pcs)) {
        throw new InvalidElementStateException("Unable to perform multi pointer gesture");
    }
    return new AppiumResponse(getSessionId(request));
}
 
private PointerCoords[][] parsePointerCoords(final IHttpRequest request) {
    TouchActionsModel model = toModel(request, TouchActionsModel.class);
    final double time = computeLongestTime(model.actions);
    final PointerCoords[][] pcs = new PointerCoords[model.actions.size()][];
    for (int i = 0; i < model.actions.size(); i++) {
        final List<TouchGestureModel> gestures = model.actions.get(i);
        pcs[i] = gesturesToPointerCoords(time, gestures);
    }
    return pcs;
}
 
private PointerCoords[] gesturesToPointerCoords(final double maxTime, List<TouchGestureModel> gestures) {
    // gestures, e.g.:
    // [
    // {"touch":{"y":529.5,"x":120},"time":0.2},
    // {"touch":{"y":529.5,"x":130},"time":0.4},
    // {"touch":{"y":454.5,"x":140},"time":0.6},
    // {"touch":{"y":304.5,"x":150},"time":0.8}
    // ]

    // From the docs:
    // "Steps are injected about 5 milliseconds apart, so 100 steps may take
    // around 0.5 seconds to complete."
    final int steps = (int) (maxTime * 200) + 2;
    final PointerCoords[] pc = new PointerCoords[steps];
    TouchGestureModel current = gestures.get(0);
    int gestureIndex = 1;
    double currentTime = current.time;
    double runningTime = 0.0;
    for (int step = 0; step < steps; step++) {
        if (runningTime > currentTime && gestureIndex < gestures.size()) {
            current = gestures.get(gestureIndex++);
            currentTime = current.time;
        }
        pc[step] = toPointerCoords(current);
        runningTime += INTERSTEP_DELAY_SEC;
    }
    return pc;
}
 
private PointerCoords toPointerCoords(TouchGestureModel gesture) {
    final TouchLocationModel touch = gesture.touch;
    final PointerCoords p = new PointerCoords();
    p.size = 1;
    p.pressure = 1;
    p.x = touch.x.intValue();
    p.y = touch.y.intValue();
    return p;
}
 
public Boolean performMultiPointerGesture(final PointerCoords[][] pcs) throws UiAutomator2Exception {
    if (shouldTrackScrollEvents()) {
        return EventRegister.runAndRegisterScrollEvents(new ReturningRunnable<Boolean>() {
            @Override
            public void run() {
                setResult(doPerformMultiPointerGesture(pcs));
            }
        });
    } else {
        return doPerformMultiPointerGesture(pcs);
    }
}
 
源代码19 项目: android-test   文件: MotionEventBuilder.java
/**
 * Simple mechanism to add a pointer to the MotionEvent.
 *
 * <p>Can be called multiple times to add multiple pointers to the event.
 */
public MotionEventBuilder setPointer(float x, float y) {
  PointerProperties pointerProperties = new PointerProperties();
  pointerProperties.id = pointerPropertiesList.size();
  PointerCoords pointerCoords = new PointerCoords();
  pointerCoords.x = x;
  pointerCoords.y = y;
  return setPointer(pointerProperties, pointerCoords);
}
 
源代码20 项目: android-test   文件: MotionEventBuilder.java
/**
 * An expanded variant of {@link #setPointer(float, float)} that supports specifying all pointer
 * properties and coords data.
 */
public MotionEventBuilder setPointer(
    PointerProperties pointerProperties, PointerCoords pointerCoords) {
  pointerPropertiesList.add(pointerProperties);
  pointerCoordsList.add(pointerCoords);
  return this;
}
 
源代码21 项目: android-test   文件: PointerCoordsBuilder.java
public PointerCoords build() {
  final PointerCoords pointerCoords = new PointerCoords();
  pointerCoords.x = x;
  pointerCoords.y = y;
  pointerCoords.pressure = pressure;
  pointerCoords.size = size;
  pointerCoords.touchMajor = touchMajor;
  pointerCoords.touchMinor = touchMinor;
  pointerCoords.toolMajor = toolMajor;
  pointerCoords.toolMinor = toolMinor;
  pointerCoords.orientation = orientation;
  return pointerCoords;
}
 
源代码22 项目: android-test   文件: MotionEventSubject.java
public PointerCoordsSubject historicalPointerCoords(int pointerIndex, int pos) {
  PointerCoords outPointerCoords = new PointerCoords();
  actual.getHistoricalPointerCoords(pointerIndex, pos, outPointerCoords);
  return check("getHistoricalPointerCoords(%s, %s)", pointerIndex, pos)
      .about(PointerCoordsSubject.pointerCoords())
      .that(outPointerCoords);
}
 
源代码23 项目: android-test   文件: MotionEventSubject.java
public PointerCoordsSubject pointerCoords(int pointerIndex) {
  PointerCoords outPointerCoords = new PointerCoords();
  actual.getPointerCoords(pointerIndex, outPointerCoords);
  return check("getPointerCoords(%s)", pointerIndex)
      .about(PointerCoordsSubject.pointerCoords())
      .that(outPointerCoords);
}
 
源代码24 项目: android-chromium   文件: GenericTouchGesture.java
TouchPointer(int startX, int startY, int deltaX, int deltaY,
        int id, float scale, int scaledTouchSlop) {
    mStartX = startX * scale;
    mStartY = startY * scale;

    float scaledDeltaX = deltaX * scale;
    float scaledDeltaY = deltaY * scale;

    if (scaledDeltaX != 0 || scaledDeltaY != 0) {
        // The touch handler only considers a pointer as moving once
        // it's been moved by more than scaledTouchSlop pixels. We
        // thus increase the delta distance so the move is actually
        // registered as covering the specified distance.
        float distance = (float)Math.sqrt(scaledDeltaX * scaledDeltaX +
                scaledDeltaY * scaledDeltaY);
        mDeltaX = scaledDeltaX * (1 + scaledTouchSlop / distance);
        mDeltaY = scaledDeltaY * (1 + scaledTouchSlop / distance);
    }
    else {
        mDeltaX = scaledDeltaX;
        mDeltaY = scaledDeltaY;
    }

    if (deltaX != 0 || deltaY != 0) {
        mStepX = mDeltaX / Math.abs(mDeltaX + mDeltaY);
        mStepY = mDeltaY / Math.abs(mDeltaX + mDeltaY);
    } else {
        mStepX = 0;
        mStepY = 0;
    }

    mProperties = new PointerProperties();
    mProperties.id = id;
    mProperties.toolType = MotionEvent.TOOL_TYPE_FINGER;

    mCoords = new PointerCoords();
    mCoords.x = mStartX;
    mCoords.y = mStartY;
    mCoords.pressure = 1.0f;
}
 
源代码25 项目: android-chromium   文件: GenericTouchGesture.java
TouchPointer(int startX, int startY, int deltaX, int deltaY,
        int id, float scale, int scaledTouchSlop) {
    mStartX = startX * scale;
    mStartY = startY * scale;

    float scaledDeltaX = deltaX * scale;
    float scaledDeltaY = deltaY * scale;

    if (scaledDeltaX != 0 || scaledDeltaY != 0) {
        // The touch handler only considers a pointer as moving once
        // it's been moved by more than scaledTouchSlop pixels. We
        // thus increase the delta distance so the move is actually
        // registered as covering the specified distance.
        float distance = (float)Math.sqrt(scaledDeltaX * scaledDeltaX +
                scaledDeltaY * scaledDeltaY);
        mDeltaX = scaledDeltaX * (1 + scaledTouchSlop / distance);
        mDeltaY = scaledDeltaY * (1 + scaledTouchSlop / distance);
    }
    else {
        mDeltaX = scaledDeltaX;
        mDeltaY = scaledDeltaY;
    }

    if (deltaX != 0 || deltaY != 0) {
        mStepX = mDeltaX / Math.abs(mDeltaX + mDeltaY);
        mStepY = mDeltaY / Math.abs(mDeltaX + mDeltaY);
    } else {
        mStepX = 0;
        mStepY = 0;
    }

    mProperties = new PointerProperties();
    mProperties.id = id;
    mProperties.toolType = MotionEvent.TOOL_TYPE_FINGER;

    mCoords = new PointerCoords();
    mCoords.x = mStartX;
    mCoords.y = mStartY;
    mCoords.pressure = 1.0f;
}
 
源代码26 项目: za-Farmer   文件: InteractionController.java
/**
 * Performs a multi-touch gesture
 *
 * Takes a series of touch coordinates for at least 2 pointers. Each pointer must have
 * all of its touch steps defined in an array of {@link PointerCoords}. By having the ability
 * to specify the touch points along the path of a pointer, the caller is able to specify
 * complex gestures like circles, irregular shapes etc, where each pointer may take a
 * different path.
 *
 * To create a single point on a pointer's touch path
 * <code>
 *       PointerCoords p = new PointerCoords();
 *       p.x = stepX;
 *       p.y = stepY;
 *       p.pressure = 1;
 *       p.size = 1;
 * </code>
 * @param touches each array of {@link PointerCoords} constitute a single pointer's touch path.
 *        Multiple {@link PointerCoords} arrays constitute multiple pointers, each with its own
 *        path. Each {@link PointerCoords} in an array constitute a point on a pointer's path.
 * @return <code>true</code> if all points on all paths are injected successfully, <code>false
 *        </code>otherwise
 * @since API Level 18
 */
public boolean performMultiPointerGesture(PointerCoords[] ... touches) {
    boolean ret = true;
    if (touches.length < 2) {
        throw new IllegalArgumentException("Must provide coordinates for at least 2 pointers");
    }

    // Get the pointer with the max steps to inject.
    int maxSteps = 0;
    for (int x = 0; x < touches.length; x++)
        maxSteps = (maxSteps < touches[x].length) ? touches[x].length : maxSteps;

    // specify the properties for each pointer as finger touch
    PointerProperties[] properties = new PointerProperties[touches.length];
    PointerCoords[] pointerCoords = new PointerCoords[touches.length];
    for (int x = 0; x < touches.length; x++) {
        PointerProperties prop = new PointerProperties();
        prop.id = x;
        prop.toolType = MotionEvent.TOOL_TYPE_FINGER;
        properties[x] = prop;

        // for each pointer set the first coordinates for touch down
        pointerCoords[x] = touches[x][0];
    }

    // Touch down all pointers
    long downTime = SystemClock.uptimeMillis();
    MotionEvent event;
    event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 1,
            properties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    ret &= injectEventSync(event);

    for (int x = 1; x < touches.length; x++) {
        event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(),
                getPointerAction(MotionEvent.ACTION_POINTER_DOWN, x), x + 1, properties,
                pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
        ret &= injectEventSync(event);
    }

    // Move all pointers
    for (int i = 1; i < maxSteps - 1; i++) {
        // for each pointer
        for (int x = 0; x < touches.length; x++) {
            // check if it has coordinates to move
            if (touches[x].length > i)
                pointerCoords[x] = touches[x][i];
            else
                pointerCoords[x] = touches[x][touches[x].length - 1];
        }

        event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(),
                MotionEvent.ACTION_MOVE, touches.length, properties, pointerCoords, 0, 0, 1, 1,
                0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);

        ret &= injectEventSync(event);
        SystemClock.sleep(MOTION_EVENT_INJECTION_DELAY_MILLIS);
    }

    // For each pointer get the last coordinates
    for (int x = 0; x < touches.length; x++)
        pointerCoords[x] = touches[x][touches[x].length - 1];

    // touch up
    for (int x = 1; x < touches.length; x++) {
        event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(),
                getPointerAction(MotionEvent.ACTION_POINTER_UP, x), x + 1, properties,
                pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
        ret &= injectEventSync(event);
    }

    Log.i(LOG_TAG, "x " + pointerCoords[0].x);
    // first to touch down is last up
    event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 1,
            properties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
    ret &= injectEventSync(event);
    return ret;
}
 
源代码27 项目: AndroidRipper   文件: Tapper.java
public void generateTapGesture(int numTaps, PointF... points)
{
    MotionEvent event;

    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();

    // pointer 1
    float x1 = points[0].x;
    float y1 = points[0].y;

    float x2 = 0;
    float y2 = 0;
    if (points.length == 2)
    {
        // pointer 2
        x2 = points[1].x;
        y2 = points[1].y;
    }

    PointerCoords[] pointerCoords = new PointerCoords[points.length];
    PointerCoords pc1 = new PointerCoords();
    pc1.x = x1;
    pc1.y = y1;
    pc1.pressure = 1;
    pc1.size = 1;
    pointerCoords[0] = pc1;
    PointerCoords pc2 = new PointerCoords();
    if (points.length == 2)
    {
        pc2.x = x2;
        pc2.y = y2;
        pc2.pressure = 1;
        pc2.size = 1;
        pointerCoords[1] = pc2;
    }

    PointerProperties[] pointerProperties = new PointerProperties[points.length];
    PointerProperties pp1 = new PointerProperties();
    pp1.id = 0;
    pp1.toolType = MotionEvent.TOOL_TYPE_FINGER;
    pointerProperties[0] = pp1;
    PointerProperties pp2 = new PointerProperties();
    if (points.length == 2)
    {
        pp2.id = 1;
        pp2.toolType = MotionEvent.TOOL_TYPE_FINGER;
        pointerProperties[1] = pp2;
    }

    int i = 0;
    while (i != numTaps)
    {
        event = MotionEvent.obtain(downTime, eventTime,
                MotionEvent.ACTION_DOWN, points.length, pointerProperties,
                pointerCoords, 0, 0, 1, 1, 0, 0,
                InputDevice.SOURCE_TOUCHSCREEN, 0);
        _instrument.sendPointerSync(event);

        if (points.length == 2)
        {
            event = MotionEvent
                    .obtain(downTime,
                            eventTime,
                            MotionEvent.ACTION_POINTER_DOWN
                                    + (pp2.id << MotionEvent.ACTION_POINTER_INDEX_SHIFT),
                            points.length, pointerProperties,
                            pointerCoords, 0, 0, 1, 1, 0, 0,
                            InputDevice.SOURCE_TOUCHSCREEN, 0);
            _instrument.sendPointerSync(event);

            eventTime += EVENT_TIME_INTERVAL_MS;
            event = MotionEvent
                    .obtain(downTime,
                            eventTime,
                            MotionEvent.ACTION_POINTER_UP
                                    + (pp2.id << MotionEvent.ACTION_POINTER_INDEX_SHIFT),
                            points.length, pointerProperties,
                            pointerCoords, 0, 0, 1, 1, 0, 0,
                            InputDevice.SOURCE_TOUCHSCREEN, 0);
            _instrument.sendPointerSync(event);
        }

        eventTime += EVENT_TIME_INTERVAL_MS;
        event = MotionEvent.obtain(downTime, eventTime,
                MotionEvent.ACTION_UP, points.length, pointerProperties,
                pointerCoords, 0, 0, 1, 1, 0, 0,
                InputDevice.SOURCE_TOUCHSCREEN, 0);
        _instrument.sendPointerSync(event);

        i++;
    }
}
 
源代码28 项目: AndroidRipper   文件: Swiper.java
public void generateSwipeGesture(PointF startPoint1, PointF startPoint2,
        PointF endPoint1, PointF endPoint2)
{

    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();

    float startX1 = startPoint1.x;
    float startY1 = startPoint1.y;
    float startX2 = startPoint2.x;
    float startY2 = startPoint2.y;

    float endX1 = endPoint1.x;
    float endY1 = endPoint1.y;
    float endX2 = endPoint2.x;
    float endY2 = endPoint2.y;

    // pointer 1
    float x1 = startX1;
    float y1 = startY1;

    // pointer 2
    float x2 = startX2;
    float y2 = startY2;

    PointerCoords[] pointerCoords = new PointerCoords[2];
    PointerCoords pc1 = new PointerCoords();
    PointerCoords pc2 = new PointerCoords();
    pc1.x = x1;
    pc1.y = y1;
    pc1.pressure = 1;
    pc1.size = 1;
    pc2.x = x2;
    pc2.y = y2;
    pc2.pressure = 1;
    pc2.size = 1;
    pointerCoords[0] = pc1;
    pointerCoords[1] = pc2;

    PointerProperties[] pointerProperties = new PointerProperties[2];
    PointerProperties pp1 = new PointerProperties();
    PointerProperties pp2 = new PointerProperties();
    pp1.id = 0;
    pp1.toolType = MotionEvent.TOOL_TYPE_FINGER;
    pp2.id = 1;
    pp2.toolType = MotionEvent.TOOL_TYPE_FINGER;
    pointerProperties[0] = pp1;
    pointerProperties[1] = pp2;

    MotionEvent event;
    // send the initial touches
    event = MotionEvent.obtain(downTime, eventTime,
            MotionEvent.ACTION_DOWN, 1, pointerProperties, pointerCoords,
            0, 0, // metaState, buttonState
            1, // x precision
            1, // y precision
            0, 0, 0, 0); // deviceId, edgeFlags, source, flags
    _instrument.sendPointerSync(event);

    event = MotionEvent.obtain(downTime, eventTime,
            MotionEvent.ACTION_POINTER_DOWN
                    + (pp2.id << MotionEvent.ACTION_POINTER_INDEX_SHIFT),
            2, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, 0, 0);
    _instrument.sendPointerSync(event);

    int numMoves = GESTURE_DURATION_MS / EVENT_TIME_INTERVAL_MS;

    float stepX1 = (endX1 - startX1) / numMoves;
    float stepY1 = (endY1 - startY1) / numMoves;
    float stepX2 = (endX2 - startX2) / numMoves;
    float stepY2 = (endY2 - startY2) / numMoves;

    // send the zoom
    for (int i = 0; i < numMoves; i++)
    {
        eventTime += EVENT_TIME_INTERVAL_MS;
        pointerCoords[0].x += stepX1;
        pointerCoords[0].y += stepY1;
        pointerCoords[1].x += stepX2;
        pointerCoords[1].y += stepY2;

        event = MotionEvent.obtain(downTime, eventTime,
                MotionEvent.ACTION_MOVE, 2, pointerProperties,
                pointerCoords, 0, 0, 1, 1, 0, 0, 0, 0);
        _instrument.sendPointerSync(event);
    }
}
 
private boolean doPerformMultiPointerGesture(final PointerCoords[][] pcs) {
    return (Boolean) invoke(method(CLASS_INTERACTION_CONTROLLER,
            METHOD_PERFORM_MULTI_POINTER_GESTURE, PointerCoords[][].class),
            interactionController, (Object) pcs);
}
 
public Boolean performMultiPointerGesture(PointerCoords[][] pcs) throws UiAutomator2Exception {
    return (Boolean) ReflectionUtils.invoke(ReflectionUtils.method(CLASS_INTERACTION_CONTROLLER, METHOD_PERFORM_MULTI_POINTER_GESTURE, PointerCoords[][].class), interactionController, (Object) pcs);
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 同包方法