Java Code Examples for android.view.MotionEvent#TOOL_TYPE_STYLUS

The following examples show how to use android.view.MotionEvent#TOOL_TYPE_STYLUS . 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: ActionsTokenizer.java    From appium-uiautomator2-server with Apache License 2.0 6 votes vote down vote up
private static int actionToToolType(final W3CItemModel item) {
    if (item.parameters != null && item.parameters.pointerType != null) {
        switch (item.parameters.pointerType) {
            case POINTER_TYPE_MOUSE:
                return MotionEvent.TOOL_TYPE_MOUSE;
            case POINTER_TYPE_PEN:
                return MotionEvent.TOOL_TYPE_STYLUS;
            case POINTER_TYPE_TOUCH:
                return MotionEvent.TOOL_TYPE_FINGER;
            default:
                // use default
                break;
        }
    }
    return MotionEvent.TOOL_TYPE_FINGER;
}
 
Example 2
Source File: MotionEvents.java    From android-test with Apache License 2.0 6 votes vote down vote up
private static MotionEvent.PointerProperties[] getPointerProperties(int inputDevice) {
  MotionEvent.PointerProperties[] pointerProperties = {new MotionEvent.PointerProperties()};
  pointerProperties[0].clear();
  pointerProperties[0].id = 0;
  switch (inputDevice) {
    case InputDevice.SOURCE_MOUSE:
      pointerProperties[0].toolType = MotionEvent.TOOL_TYPE_MOUSE;
      break;
    case InputDevice.SOURCE_STYLUS:
      pointerProperties[0].toolType = MotionEvent.TOOL_TYPE_STYLUS;
      break;
    case InputDevice.SOURCE_TOUCHSCREEN:
      pointerProperties[0].toolType = MotionEvent.TOOL_TYPE_FINGER;
      break;
    default:
      pointerProperties[0].toolType = MotionEvent.TOOL_TYPE_UNKNOWN;
      break;
  }
  return pointerProperties;
}
 
Example 3
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 4
Source File: ActionsTokenizer.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
private static void assertPointersCount(int toolType, int pointerIndex) {
    if (toolType == MotionEvent.TOOL_TYPE_MOUSE && pointerIndex > 0) {
        throw new ActionsParseException(
                String.format("No more that one simultaneous pointer is supported for %s %s",
                        PARAMETERS_KEY_POINTER_TYPE, POINTER_TYPE_MOUSE));
    }
    if (toolType == MotionEvent.TOOL_TYPE_STYLUS && pointerIndex > 0) {
        throw new ActionsParseException(
                String.format("No more that one simultaneous pointer is supported for %s %s",
                        PARAMETERS_KEY_POINTER_TYPE, POINTER_TYPE_PEN));
    }
}
 
Example 5
Source File: ActionsExecutor.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
private static int toolTypeToInputSource(final int toolType) {
    switch (toolType) {
        case MotionEvent.TOOL_TYPE_MOUSE:
            return InputDevice.SOURCE_MOUSE;
        case MotionEvent.TOOL_TYPE_STYLUS:
            return InputDevice.SOURCE_STYLUS;
        default:
            return InputDevice.SOURCE_TOUCHSCREEN;
    }
}
 
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: 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 8
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);
}