android.view.MotionEvent#getDeviceId ( )源码实例Demo

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

源代码1 项目: FirefoxReality   文件: CustomKeyboardView.java
@Override
public boolean onHoverEvent(MotionEvent event) {
    boolean result = super.onHoverEvent(event);

    int keyIndex = NOT_A_KEY;
    if (event.getAction() != MotionEvent.ACTION_HOVER_EXIT) {
        int touchX = (int) event.getX() - getPaddingLeft();
        int touchY = (int) event.getY() - getPaddingTop();
        if (touchY >= -mVerticalCorrection) {
            touchY += mVerticalCorrection;
        }
        keyIndex = getKeyIndices(touchX, touchY, null);
    }

    mPrevHoveredKey[event.getDeviceId()] = mHoveredKey[event.getDeviceId()];
    mHoveredKey[event.getDeviceId()] = keyIndex;
    int prevHovered = mPrevHoveredKey[event.getDeviceId()];
    int currentHovered = mHoveredKey[event.getDeviceId()];
    if (currentHovered != NOT_A_KEY && prevHovered != currentHovered) {
        invalidateKey(currentHovered);
    }
    if (prevHovered != NOT_A_KEY && prevHovered != currentHovered) {
        invalidateKey(prevHovered);
    }
    return result;
}
 
源代码2 项目: bluetooth   文件: GameView.java
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    mInputManager.onGenericMotionEvent(event);

    // Check that the event came from a joystick or gamepad since a generic
    // motion event could be almost anything. API level 18 adds the useful
    // event.isFromSource() helper function.
    int eventSource = event.getSource();
    if ((((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
            ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK))
            && event.getAction() == MotionEvent.ACTION_MOVE) {
        int id = event.getDeviceId();
        if (-1 != id) {
            Ship curShip = getShipForId(id);
            if (curShip.onGenericMotionEvent(event)) {
                return true;
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
源代码3 项目: o2oa   文件: StickyGridHeadersGridView.java
private MotionEvent transformEvent(MotionEvent e, int headerPosition) {
    if (headerPosition == MATCHED_STICKIED_HEADER) {
        return e;
    }

    long downTime = e.getDownTime();
    long eventTime = e.getEventTime();
    int action = e.getAction();
    int pointerCount = e.getPointerCount();
    int[] pointerIds = getPointerIds(e);
    MotionEvent.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();

    View headerHolder = getChildAt(headerPosition);
    for (int i = 0; i < pointerCount;i++) {
        pointerCoords[i].y -= headerHolder.getTop();
    }
    MotionEvent n = MotionEvent.obtain(downTime, eventTime, action,
            pointerCount, pointerIds, pointerCoords, metaState, xPrecision,
            yPrecision, deviceId, edgeFlags, source, flags);
    return n;
}
 
源代码4 项目: 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;
}
 
源代码5 项目: jmonkeyengine   文件: AndroidJoystickJoyInput14.java
public boolean onGenericMotion(MotionEvent event) {
        boolean consumed = false;
//        logger.log(Level.INFO, "onGenericMotion event: {0}", event);
        event.getDeviceId();
        event.getSource();
//        logger.log(Level.INFO, "deviceId: {0}, source: {1}", new Object[]{event.getDeviceId(), event.getSource()});
        AndroidJoystick joystick = joystickIndex.get(event.getDeviceId());
        if (joystick != null) {
            for (int androidAxis: joystick.getAndroidAxes()) {
                String axisName = MotionEvent.axisToString(androidAxis);
                float value = event.getAxisValue(androidAxis);
                int action = event.getAction();
                if (action == MotionEvent.ACTION_MOVE) {
//                    logger.log(Level.INFO, "MOVE axis num: {0}, axisName: {1}, value: {2}",
//                            new Object[]{androidAxis, axisName, value});
                    JoystickAxis axis = joystick.getAxis(androidAxis);
                    if (axis != null) {
//                        logger.log(Level.INFO, "MOVE axis num: {0}, axisName: {1}, value: {2}, deadzone: {3}",
//                                new Object[]{androidAxis, axisName, value, axis.getDeadZone()});
                        JoyAxisEvent axisEvent = new JoyAxisEvent(axis, value);
                        joyInput.addEvent(axisEvent);
                        consumed = true;
                    } else {
//                        logger.log(Level.INFO, "axis was null for axisName: {0}", axisName);
                    }
                } else {
//                    logger.log(Level.INFO, "action: {0}", action);
                }
            }
        }

        return consumed;
    }
 
private MotionEvent transformEvent(MotionEvent e, int headerPosition) {
    if (headerPosition == MATCHED_STICKIED_HEADER) {
        return e;
    }

    long downTime = e.getDownTime();
    long eventTime = e.getEventTime();
    int action = e.getAction();
    int pointerCount = e.getPointerCount();
    int[] pointerIds = getPointerIds(e);
    MotionEvent.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();

    View headerHolder = getChildAt(headerPosition);
    for (int i = 0; i < pointerCount;i++) {
        pointerCoords[i].y -= headerHolder.getTop();
    }
    MotionEvent n = MotionEvent.obtain(downTime, eventTime, action,
            pointerCount, pointerIds, pointerCoords, metaState, xPrecision,
            yPrecision, deviceId, edgeFlags, source, flags);
    return n;
}
 
源代码7 项目: bluetooth   文件: InputManagerV9.java
@Override
public void onGenericMotionEvent(MotionEvent event) {
    // detect new devices
    int id = event.getDeviceId();
    long[] timeArray = mDevices.get(id);
    if (null == timeArray) {
        notifyListeners(ON_DEVICE_ADDED, id);
        timeArray = new long[1];
        mDevices.put(id, timeArray);
    }
    long time = SystemClock.elapsedRealtime();
    timeArray[0] = time;
}
 
private MotionEvent transformEvent(MotionEvent e, int headerPosition) {
    if (headerPosition == MATCHED_STICKIED_HEADER) {
        return e;
    }

    long downTime = e.getDownTime();
    long eventTime = e.getEventTime();
    int action = e.getAction();
    int pointerCount = e.getPointerCount();
    int[] pointerIds = getPointerIds(e);
    MotionEvent.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();

    View headerHolder = getChildAt(headerPosition);
    for (int i = 0; i < pointerCount;i++) {
        pointerCoords[i].y -= headerHolder.getTop();
    }
    MotionEvent n = MotionEvent.obtain(downTime, eventTime, action,
            pointerCount, pointerIds, pointerCoords, metaState, xPrecision,
            yPrecision, deviceId, edgeFlags, source, flags);
    return n;
}
 
源代码9 项目: codeexamples-android   文件: GameView.java
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    ensureInitialized();

    // Check that the event came from a joystick since a generic motion event
    // could be almost anything.
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0
            && event.getAction() == MotionEvent.ACTION_MOVE) {
        // Cache the most recently obtained device information.
        // The device information may change over time but it can be
        // somewhat expensive to query.
        if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) {
            mLastInputDevice = event.getDevice();
            // It's possible for the device id to be invalid.
            // In that case, getDevice() will return null.
            if (mLastInputDevice == null) {
                return false;
            }
        }

        // Ignore joystick while the DPad is pressed to avoid conflicting motions.
        if (mDPadState != 0) {
            return true;
        }

        // Process all historical movement samples in the batch.
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize; i++) {
            processJoystickInput(event, i);
        }

        // Process the current movement sample in the batch.
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}