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

The following examples show how to use android.view.MotionEvent#getToolType() . 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: GestureListener.java    From input-samples with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: GameWebView.java    From kcanotify_h5-master with GNU General Public License v3.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 3
Source File: ServoPanZoomController.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public boolean onMouseEvent(final MotionEvent event) {
    if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
        return handleMouseEvent(event);
    }
    return handleMotionEvent(event);
}
 
Example 4
Source File: ContentViewCore.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example 5
Source File: EventForwarder.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example 6
Source File: GestureListener.java    From android-BasicGestureDetect with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: MotionEvents.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
static boolean isMouseEvent(@NonNull MotionEvent e) {
    return e.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE;
}
 
Example 8
Source File: MotionEvents.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
static boolean isFingerEvent(@NonNull MotionEvent e) {
    return e.getToolType(0) == MotionEvent.TOOL_TYPE_FINGER;
}
 
Example 9
Source File: StylusEventHelper.java    From LaunchEnr with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 10
Source File: StylusEventHelper.java    From Trebuchet with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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);
}