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

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

源代码1 项目: input-samples   文件: GestureListener.java
/**
 * Returns a human-readable string describing the type of touch that triggered a MotionEvent.
 */

private static String getTouchType(MotionEvent e){

    String touchTypeDescription = " ";
    int touchType = e.getToolType(0);

    switch (touchType) {
        case MotionEvent.TOOL_TYPE_FINGER:
            touchTypeDescription += "(finger)";
            break;
        case MotionEvent.TOOL_TYPE_STYLUS:
            touchTypeDescription += "(stylus, ";
            //Get some additional information about the stylus touch
            float stylusPressure = e.getPressure();
            touchTypeDescription += "pressure: " + stylusPressure;

            if(Build.VERSION.SDK_INT >= 21) {
                touchTypeDescription += ", buttons pressed: " + getButtonsPressed(e);
            }

            touchTypeDescription += ")";
            break;
        case MotionEvent.TOOL_TYPE_ERASER:
            touchTypeDescription += "(eraser)";
            break;
        case MotionEvent.TOOL_TYPE_MOUSE:
            touchTypeDescription += "(mouse)";
            break;
        default:
            touchTypeDescription += "(unknown tool)";
            break;
    }

    return touchTypeDescription;
}
 
源代码2 项目: kcanotify_h5-master   文件: GameWebView.java
public void handleTouch(MotionEvent event) {
    Log.d("touchEvent", event.getToolType(0) + ":" + event.getActionMasked());
    if(event.getToolType(0) == MotionEvent.TOOL_TYPE_FINGER) {
        if(event.getAction() == MotionEvent.ACTION_MOVE) {
            buildMoveEvent(event);
        } else if(event.getAction() == MotionEvent.ACTION_DOWN && changeTouchEvent){
            buildMoveEvent(event);
        } else if(event.getAction() == MotionEvent.ACTION_UP && changeTouchEvent){
            buildMoveEvent(event);
        }
    }
}
 
源代码3 项目: FirefoxReality   文件: ServoPanZoomController.java
@Override
public boolean onMouseEvent(final MotionEvent event) {
    if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
        return handleMouseEvent(event);
    }
    return handleMotionEvent(event);
}
 
源代码4 项目: 365browser   文件: ContentViewCore.java
/**
 * @see View#onGenericMotionEvent(MotionEvent)
 */
public boolean onGenericMotionEvent(MotionEvent event) {
    if (GamepadList.onGenericMotionEvent(event)) return true;
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getActionMasked()) {
            case MotionEvent.ACTION_SCROLL:
                getEventForwarder().onMouseWheelEvent(event.getEventTime(), event.getX(),
                        event.getY(), event.getAxisValue(MotionEvent.AXIS_HSCROLL),
                        event.getAxisValue(MotionEvent.AXIS_VSCROLL),
                        mRenderCoordinates.getWheelScrollFactor());
                return true;
            case MotionEvent.ACTION_BUTTON_PRESS:
            case MotionEvent.ACTION_BUTTON_RELEASE:
                // TODO(mustaq): Should we include MotionEvent.TOOL_TYPE_STYLUS here?
                // crbug.com/592082
                if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
                    return getEventForwarder().onMouseEvent(event);
                }
        }
    } else if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
        if (mJoystickScrollEnabled) {
            float velocityX = getFilteredAxisValue(event, MotionEvent.AXIS_X);
            float velocityY = getFilteredAxisValue(event, MotionEvent.AXIS_Y);
            flingViewport(event.getEventTime(), -velocityX, -velocityY, true);
            return true;
        }
    }
    return mContainerViewInternals.super_onGenericMotionEvent(event);
}
 
源代码5 项目: 365browser   文件: EventForwarder.java
/**
 * @see View#onTouchEvent(MotionEvent)
 */
public boolean onTouchEvent(MotionEvent event) {
    // TODO(mustaq): Should we include MotionEvent.TOOL_TYPE_STYLUS here?
    // crbug.com/592082
    if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
        // Mouse button info is incomplete on L and below
        int apiVersion = Build.VERSION.SDK_INT;
        if (apiVersion >= android.os.Build.VERSION_CODES.M) {
            return onMouseEvent(event);
        }
    }

    final boolean isTouchHandleEvent = false;
    return sendTouchEvent(event, isTouchHandleEvent);
}
 
/**
 * Returns a human-readable string describing the type of touch that triggered a MotionEvent.
 */

private static String getTouchType(MotionEvent e){

    String touchTypeDescription = " ";
    int touchType = e.getToolType(0);

    switch (touchType) {
        case MotionEvent.TOOL_TYPE_FINGER:
            touchTypeDescription += "(finger)";
            break;
        case MotionEvent.TOOL_TYPE_STYLUS:
            touchTypeDescription += "(stylus, ";
            //Get some additional information about the stylus touch
            float stylusPressure = e.getPressure();
            touchTypeDescription += "pressure: " + stylusPressure;

            if(Build.VERSION.SDK_INT >= 21) {
                touchTypeDescription += ", buttons pressed: " + getButtonsPressed(e);
            }

            touchTypeDescription += ")";
            break;
        case MotionEvent.TOOL_TYPE_ERASER:
            touchTypeDescription += "(eraser)";
            break;
        case MotionEvent.TOOL_TYPE_MOUSE:
            touchTypeDescription += "(mouse)";
            break;
        default:
            touchTypeDescription += "(unknown tool)";
            break;
    }

    return touchTypeDescription;
}
 
源代码7 项目: FairEmail   文件: MotionEvents.java
static boolean isMouseEvent(@NonNull MotionEvent e) {
    return e.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE;
}
 
源代码8 项目: FairEmail   文件: MotionEvents.java
static boolean isFingerEvent(@NonNull MotionEvent e) {
    return e.getToolType(0) == MotionEvent.TOOL_TYPE_FINGER;
}
 
源代码9 项目: LaunchEnr   文件: StylusEventHelper.java
/**
 * Identifies if the provided {@link MotionEvent} is a stylus with the primary stylus button
 * pressed.
 *
 * @param event The event to check.
 * @return Whether a stylus button press occurred.
 */
private static boolean isStylusButtonPressed(MotionEvent event) {
    return event.getToolType(0) == MotionEvent.TOOL_TYPE_STYLUS
            && ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY)
                    == MotionEvent.BUTTON_SECONDARY);
}
 
源代码10 项目: Trebuchet   文件: StylusEventHelper.java
/**
 * Identifies if the provided {@link MotionEvent} is a stylus with the primary stylus button
 * pressed.
 *
 * @param event The event to check.
 * @return Whether a stylus button press occurred.
 */
private static boolean isStylusButtonPressed(MotionEvent event) {
    return event.getToolType(0) == MotionEvent.TOOL_TYPE_STYLUS
            && ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY)
                    == MotionEvent.BUTTON_SECONDARY);
}