Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe9f8ab0 authored by Jeff Brown's avatar Jeff Brown
Browse files

Add initial API for stylus and mouse buttons.

Added the concept of pointer properties in a MotionEvent.
This is currently used to track the pointer tool type to enable
applications to distinguish finger touches from a stylus.

Button states are also reported to application as part of touch events.

There are no new actions for detecting changes in button states.
The application should instead query the button state from the
MotionEvent and take appropriate action as needed.

A good time to check the button state is on ACTION_DOWN.

As a side-effect, applications that do not support multiple buttons
will treat primary, secondary and tertiary buttons identically
for all touch events.

The back button on the mouse is mapped to KEYCODE_BACK
and the forward button is mapped to KEYCODE_FORWARD.

Added basic plumbing for the secondary mouse button to invoke
the context menu, particularly in lists.

Added clamp and split methods on MotionEvent to take care of
common filtering operations so we don't have them scattered
in multiple places across the framework.

Bug: 4260011
Change-Id: Ie992b4d4e00c8f2e76b961da0a902145b27f6d83
parent 1abf1c59
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -20158,6 +20158,7 @@ package android.view {
    field public static final int SOURCE_JOYSTICK = 16777232; // 0x1000010
    field public static final int SOURCE_KEYBOARD = 257; // 0x101
    field public static final int SOURCE_MOUSE = 8194; // 0x2002
    field public static final int SOURCE_STYLUS = 16386; // 0x4002
    field public static final int SOURCE_TOUCHPAD = 1048584; // 0x100008
    field public static final int SOURCE_TOUCHSCREEN = 4098; // 0x1002
    field public static final int SOURCE_TRACKBALL = 65540; // 0x10004
@@ -20690,6 +20691,7 @@ package android.view {
    method public final int getActionMasked();
    method public final float getAxisValue(int);
    method public final float getAxisValue(int, int);
    method public final int getButtonState();
    method public final int getDeviceId();
    method public final long getDownTime();
    method public final int getEdgeFlags();
@@ -20724,6 +20726,7 @@ package android.view {
    method public final void getPointerCoords(int, android.view.MotionEvent.PointerCoords);
    method public final int getPointerCount();
    method public final int getPointerId(int);
    method public final void getPointerProperties(int, android.view.MotionEvent.PointerProperties);
    method public final float getPressure();
    method public final float getPressure(int);
    method public final float getRawX();
@@ -20735,6 +20738,7 @@ package android.view {
    method public final float getToolMajor(int);
    method public final float getToolMinor();
    method public final float getToolMinor(int);
    method public final int getToolType(int);
    method public final float getTouchMajor();
    method public final float getTouchMajor(int);
    method public final float getTouchMinor();
@@ -20745,7 +20749,8 @@ package android.view {
    method public final float getY();
    method public final float getY(int);
    method public final float getYPrecision();
    method public static android.view.MotionEvent obtain(long, long, int, int, int[], android.view.MotionEvent.PointerCoords[], int, float, float, int, int, int, int);
    method public static android.view.MotionEvent obtain(long, long, int, int, android.view.MotionEvent.PointerProperties[], android.view.MotionEvent.PointerCoords[], int, int, float, float, int, int, int, int);
    method public static deprecated android.view.MotionEvent obtain(long, long, int, int, int[], android.view.MotionEvent.PointerCoords[], int, float, float, int, int, int, int);
    method public static android.view.MotionEvent obtain(long, long, int, float, float, float, float, int, float, float, int, int);
    method public static deprecated android.view.MotionEvent obtain(long, long, int, int, float, float, float, float, int, float, float, int, int);
    method public static android.view.MotionEvent obtain(long, long, int, float, float, int);
@@ -20782,6 +20787,7 @@ package android.view {
    field public static final int ACTION_SCROLL = 8; // 0x8
    field public static final int ACTION_UP = 1; // 0x1
    field public static final int AXIS_BRAKE = 23; // 0x17
    field public static final int AXIS_DISTANCE = 24; // 0x18
    field public static final int AXIS_GAS = 22; // 0x16
    field public static final int AXIS_GENERIC_1 = 32; // 0x20
    field public static final int AXIS_GENERIC_10 = 41; // 0x29
@@ -20821,12 +20827,25 @@ package android.view {
    field public static final int AXIS_X = 0; // 0x0
    field public static final int AXIS_Y = 1; // 0x1
    field public static final int AXIS_Z = 11; // 0xb
    field public static final int BUTTON_BACK = 8; // 0x8
    field public static final int BUTTON_ERASER = 32; // 0x20
    field public static final int BUTTON_FORWARD = 16; // 0x10
    field public static final int BUTTON_PRIMARY = 1; // 0x1
    field public static final int BUTTON_SECONDARY = 2; // 0x2
    field public static final int BUTTON_TERTIARY = 4; // 0x4
    field public static final android.os.Parcelable.Creator CREATOR;
    field public static final int EDGE_BOTTOM = 2; // 0x2
    field public static final int EDGE_LEFT = 4; // 0x4
    field public static final int EDGE_RIGHT = 8; // 0x8
    field public static final int EDGE_TOP = 1; // 0x1
    field public static final int FLAG_WINDOW_IS_OBSCURED = 1; // 0x1
    field public static final int INVALID_POINTER_ID = -1; // 0xffffffff
    field public static final int TOOL_TYPE_FINGER = 1; // 0x1
    field public static final int TOOL_TYPE_INDIRECT_FINGER = 4; // 0x4
    field public static final int TOOL_TYPE_INDIRECT_STYLUS = 5; // 0x5
    field public static final int TOOL_TYPE_MOUSE = 3; // 0x3
    field public static final int TOOL_TYPE_STYLUS = 2; // 0x2
    field public static final int TOOL_TYPE_UNKNOWN = 0; // 0x0
  }
  public static final class MotionEvent.PointerCoords {
@@ -20847,6 +20866,15 @@ package android.view {
    field public float y;
  }
  public static final class MotionEvent.PointerProperties {
    ctor public MotionEvent.PointerProperties();
    ctor public MotionEvent.PointerProperties(android.view.MotionEvent.PointerProperties);
    method public void clear();
    method public void copyFrom(android.view.MotionEvent.PointerProperties);
    field public int id;
    field public int toolType;
  }
  public abstract class OrientationEventListener {
    ctor public OrientationEventListener(android.content.Context);
    ctor public OrientationEventListener(android.content.Context, int);
+11 −46
Original line number Diff line number Diff line
@@ -73,8 +73,17 @@ class SoftInputWindow extends Dialog {
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        getWindow().getDecorView().getHitRect(mBounds);
        final MotionEvent event = clipMotionEvent(ev, mBounds);
        return super.dispatchTouchEvent(event);

        if (ev.isWithinBoundsNoHistory(mBounds.left, mBounds.top,
                mBounds.right - 1, mBounds.bottom - 1)) {
            return super.dispatchTouchEvent(ev);
        } else {
            MotionEvent temp = ev.clampNoHistory(mBounds.left, mBounds.top,
                    mBounds.right - 1, mBounds.bottom - 1);
            boolean handled = super.dispatchTouchEvent(temp);
            temp.recycle();
            return handled;
        }
    }

    /**
@@ -163,48 +172,4 @@ class SoftInputWindow extends Dialog {
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
                WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }

    private static MotionEvent clipMotionEvent(MotionEvent me, Rect bounds) {
        final int pointerCount = me.getPointerCount();
        boolean shouldClip = false;
        for (int pointerIndex = 0; pointerIndex < pointerCount; pointerIndex++) {
            final int x = (int)me.getX(pointerIndex);
            final int y = (int)me.getY(pointerIndex);
            if (!bounds.contains(x, y)) {
                shouldClip = true;
                break;
            }
        }
        if (!shouldClip)
            return me;

        if (pointerCount == 1) {
            final int x = (int)me.getX();
            final int y = (int)me.getY();
            me.setLocation(
                    Math.max(bounds.left, Math.min(x, bounds.right - 1)),
                    Math.max(bounds.top, Math.min(y, bounds.bottom - 1)));
            return me;
        }

        final int[] pointerIds = new int[pointerCount];
        final MotionEvent.PointerCoords[] pointerCoords =
            new MotionEvent.PointerCoords[pointerCount];
        for (int pointerIndex = 0; pointerIndex < pointerCount; pointerIndex++) {
            pointerIds[pointerIndex] = me.getPointerId(pointerIndex);
            final MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords();
            me.getPointerCoords(pointerIndex, coords);
            pointerCoords[pointerIndex] = coords;
            final int x = (int)coords.x;
            final int y = (int)coords.y;
            if (!bounds.contains(x, y)) {
                coords.x = Math.max(bounds.left, Math.min(x, bounds.right - 1));
                coords.y = Math.max(bounds.top, Math.min(y, bounds.bottom - 1));
            }
        }
        return MotionEvent.obtain(
                me.getDownTime(), me.getEventTime(), me.getAction(), pointerCount, pointerIds,
                pointerCoords, me.getMetaState(), me.getXPrecision(), me.getYPrecision(),
                me.getDeviceId(), me.getEdgeFlags(), me.getSource(), me.getFlags());
    }
}
+9 −1
Original line number Diff line number Diff line
@@ -154,6 +154,13 @@ public final class InputDevice implements Parcelable {
     */
    public static final int SOURCE_MOUSE = 0x00002000 | SOURCE_CLASS_POINTER;

    /**
     * The input source is a stylus pointing device.
     *
     * @see #SOURCE_CLASS_POINTER
     */
    public static final int SOURCE_STYLUS = 0x00004000 | SOURCE_CLASS_POINTER;

    /**
     * The input source is a trackball.
     * 
@@ -585,6 +592,7 @@ public final class InputDevice implements Parcelable {
        appendSourceDescriptionIfApplicable(description, SOURCE_DPAD, "dpad");
        appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHSCREEN, "touchscreen");
        appendSourceDescriptionIfApplicable(description, SOURCE_MOUSE, "mouse");
        appendSourceDescriptionIfApplicable(description, SOURCE_STYLUS, "stylus");
        appendSourceDescriptionIfApplicable(description, SOURCE_TRACKBALL, "trackball");
        appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHPAD, "touchpad");
        appendSourceDescriptionIfApplicable(description, SOURCE_JOYSTICK, "joystick");
+16 −9
Original line number Diff line number Diff line
@@ -2672,15 +2672,22 @@ public class KeyEvent extends InputEvent implements Parcelable {

    @Override
    public String toString() {
        return "KeyEvent{action=" + actionToString(mAction)
                + " keycode=" + keyCodeToString(mKeyCode)
                + " scancode=" + mScanCode
                + " metaState=" + metaStateToString(mMetaState)
                + " flags=0x" + Integer.toHexString(mFlags)
                + " repeat=" + mRepeatCount
                + " device=" + mDeviceId
                + " source=0x" + Integer.toHexString(mSource)
                + "}";
        StringBuilder msg = new StringBuilder();
        msg.append("KeyEvent { action=").append(actionToString(mAction));
        msg.append(", keyCode=").append(keyCodeToString(mKeyCode));
        msg.append(", scanCode=").append(mScanCode);
        if (mCharacters != null) {
            msg.append(", characters=\"").append(mCharacters).append("\"");
        }
        msg.append(", metaState=").append(metaStateToString(mMetaState));
        msg.append(", flags=0x").append(Integer.toHexString(mFlags));
        msg.append(", repeatCount=").append(mRepeatCount);
        msg.append(", eventTime=").append(mEventTime);
        msg.append(", downTime=").append(mDownTime);
        msg.append(", deviceId=").append(mDeviceId);
        msg.append(", source=0x").append(Integer.toHexString(mSource));
        msg.append(" }");
        return msg.toString();
    }

    /**
+852 −168

File changed.

Preview size limit exceeded, changes collapsed.

Loading