Java Code Examples for android.view.MotionEvent#TOOL_TYPE_MOUSE

The following examples show how to use android.view.MotionEvent#TOOL_TYPE_MOUSE . 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: GameWebView.java    From kcanotify_h5-master with GNU General Public License v3.0 5 votes vote down vote up
private void buildMoveEvent(MotionEvent event){
    MotionEvent.PointerProperties[] pointerProperties = new MotionEvent.PointerProperties[]{new MotionEvent.PointerProperties()};
    event.getPointerProperties(0, pointerProperties[0]);
    MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[]{new MotionEvent.PointerCoords()};
    event.getPointerCoords(0, pointerCoords[0]);
    pointerProperties[0].toolType = MotionEvent.TOOL_TYPE_MOUSE;
    pointerCoords[0].x -= this.getX();
    pointerCoords[0].y -= this.getY();
    long touchTime = SystemClock.uptimeMillis();
    this.onTouchEvent(MotionEvent.obtain(touchTime, touchTime, MotionEvent.ACTION_MOVE, 1,
            pointerProperties, pointerCoords, 0, 0, 0f, 0f,
            InputDevice.KEYBOARD_TYPE_NON_ALPHABETIC, 0, InputDevice.SOURCE_TOUCHSCREEN, 0));
}
 
Example 5
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 6
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 7
Source File: ActionsExecutor.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
private static MotionEvent.PointerProperties[] filterPointerProperties(
        final List<MotionInputEventParams> motionEventsParams, final boolean shouldHovering) {
    final List<MotionEvent.PointerProperties> result = new ArrayList<>();
    for (final MotionInputEventParams eventParams : motionEventsParams) {
        if (shouldHovering && HOVERING_ACTIONS.contains(eventParams.actionCode)
                && eventParams.properties.toolType == MotionEvent.TOOL_TYPE_MOUSE) {
            result.add(eventParams.properties);
        } else if (!shouldHovering && !HOVERING_ACTIONS.contains(eventParams.actionCode)) {
            result.add(eventParams.properties);
        }
    }
    return result.toArray(new MotionEvent.PointerProperties[0]);
}
 
Example 8
Source File: ActionsExecutor.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
private static MotionEvent.PointerCoords[] filterPointerCoordinates(
        final List<MotionInputEventParams> motionEventsParams, final boolean shouldHovering) {
    final List<MotionEvent.PointerCoords> result = new ArrayList<>();
    for (final MotionInputEventParams eventParams : motionEventsParams) {
        if (shouldHovering && HOVERING_ACTIONS.contains(eventParams.actionCode) &&
                eventParams.properties.toolType == MotionEvent.TOOL_TYPE_MOUSE) {
            result.add(eventParams.coordinates);
        } else if (!shouldHovering && !HOVERING_ACTIONS.contains(eventParams.actionCode)) {
            result.add(eventParams.coordinates);
        }
    }
    return result.toArray(new MotionEvent.PointerCoords[0]);
}
 
Example 9
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 10
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 11
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 12
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 13
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;
}