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

Commit 74e4156e authored by Michael Wright's avatar Michael Wright
Browse files

Add InputDevice#isFromSource convenience method

Change-Id: If2d2e37bc3fff5a862ea3652c7ef9778018e7ecc
parent e70748e7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -24194,6 +24194,7 @@ package android.view {
    method public float getMin();
    method public float getRange();
    method public int getSource();
    method public boolean isFromSource(int);
  }
  public abstract class InputEvent implements android.os.Parcelable {
@@ -24202,6 +24203,7 @@ package android.view {
    method public abstract int getDeviceId();
    method public abstract long getEventTime();
    method public abstract int getSource();
    method public boolean isFromSource(int);
    field public static final android.os.Parcelable.Creator CREATOR;
  }
+13 −0
Original line number Diff line number Diff line
@@ -633,6 +633,19 @@ public final class InputDevice implements Parcelable {
            return mSource;
        }


        /**
         * Determines whether the event is from the given source.
         *
         * @param source The input source to check against. This can be a specific device type,
         * such as {@link InputDevice#SOURCE_TOUCH_NAVIGATION}, or a more generic device class,
         * such as {@link InputDevice#SOURCE_CLASS_POINTER}.
         * @return Whether the event is from the given source.
         */
        public boolean isFromSource(int source) {
            return (getSource() & source) == source;
        }

        /**
         * Gets the inclusive minimum value for the axis.
         * @return The inclusive minimum value.
+12 −0
Original line number Diff line number Diff line
@@ -82,6 +82,18 @@ public abstract class InputEvent implements Parcelable {
     */
    public abstract void setSource(int source);

    /**
     * Determines whether the event is from the given source.
     *
     * @param source The input source to check against. This can be a specific device type, such as
     * {@link InputDevice#SOURCE_TOUCH_NAVIGATION}, or a more generic device class, such as
     * {@link InputDevice#SOURCE_CLASS_POINTER}.
     * @return Whether the event is from the given source.
     */
    public boolean isFromSource(int source) {
        return (getSource() & source) == source;
    }

    /**
     * Copies the event.
     *
+2 −2
Original line number Diff line number Diff line
@@ -8112,13 +8112,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * delivered to the focused view.
     * </p>
     * <pre> public boolean onGenericMotionEvent(MotionEvent event) {
     *     if ((event.getSource() &amp; InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
     *     if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) {
     *         if (event.getAction() == MotionEvent.ACTION_MOVE) {
     *             // process the joystick movement...
     *             return true;
     *         }
     *     }
     *     if ((event.getSource() &amp; InputDevice.SOURCE_CLASS_POINTER) != 0) {
     *     if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) {
     *         switch (event.getAction()) {
     *             case MotionEvent.ACTION_HOVER_MOVE:
     *                 // process the mouse hover movement...