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

Commit d020fd33 authored by Michael Wright's avatar Michael Wright Committed by Android (Google) Code Review
Browse files

Merge changes Ib18c99b9,I9f42eeb9 into klp-modular-dev

* changes:
  Generate and respect ACTION_CANCEL for joystick fallbacks. DO NOT MERGE
  Adds API for determining confirm and cancel keys.
parents 594c73fc 1b10869f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -26836,8 +26836,10 @@ package android.view {
    method public final boolean hasModifiers(int);
    method public final boolean hasNoModifiers();
    method public final boolean isAltPressed();
    method public final boolean isCancelKey();
    method public final boolean isCanceled();
    method public final boolean isCapsLockOn();
    method public final boolean isConfirmKey();
    method public final boolean isCtrlPressed();
    method public final boolean isFunctionPressed();
    method public static final boolean isGamepadButton(int);
+23 −4
Original line number Diff line number Diff line
@@ -1847,13 +1847,32 @@ public class KeyEvent extends InputEvent implements Parcelable {
        }
    }

    /** Whether key will, by default, trigger a click on the focused view.
     * @hide
    /**
     * Returns true if the key event should be treated as a confirming action.
     * @return True for a confirmation key, such as {@link #KEYCODE_DPAD_CENTER},
     * {@link #KEYCODE_ENTER}, or {@link #KEYCODE_BUTTON_A}.
     */
    public static final boolean isConfirmKey(int keyCode) {
        switch (keyCode) {
    public final boolean isConfirmKey() {
        switch (mKeyCode) {
            case KeyEvent.KEYCODE_DPAD_CENTER:
            case KeyEvent.KEYCODE_ENTER:
            case KeyEvent.KEYCODE_BUTTON_A:
                return true;
            default:
                return false;
        }
    }

    /**
     * Returns true if the key event should be treated as a cancelling action.
     * @return True for a cancellation key, such as {@link #KEYCODE_ESCAPE},
     * {@link #KEYCODE_BACK}, or {@link #KEYCODE_BUTTON_B}.
     */
    public final boolean isCancelKey() {
        switch (mKeyCode) {
            case KeyEvent.KEYCODE_BUTTON_B:
            case KeyEvent.KEYCODE_ESCAPE:
            case KeyEvent.KEYCODE_BACK:
                return true;
            default:
                return false;
+4 −4
Original line number Diff line number Diff line
@@ -3372,11 +3372,11 @@ public final class MotionEvent extends InputEvent implements Parcelable {
                        throw new IllegalArgumentException("Axis out of range.");
                    }
                    final long bits = mPackedAxisBits;
                    final long axisBit = 1L << axis;
                    final long axisBit = 0x8000000000000000L >>> axis;
                    if ((bits & axisBit) == 0) {
                        return 0;
                    }
                    final int index = Long.bitCount(bits & (axisBit - 1L));
                    final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis));
                    return mPackedAxisValues[index];
                }
            }
@@ -3425,8 +3425,8 @@ public final class MotionEvent extends InputEvent implements Parcelable {
                        throw new IllegalArgumentException("Axis out of range.");
                    }
                    final long bits = mPackedAxisBits;
                    final long axisBit = 1L << axis;
                    final int index = Long.bitCount(bits & (axisBit - 1L));
                    final long axisBit = 0x8000000000000000L >>> axis;
                    final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis));
                    float[] values = mPackedAxisValues;
                    if ((bits & axisBit) == 0) {
                        if (values == null) {
+2 −2
Original line number Diff line number Diff line
@@ -8186,7 +8186,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        boolean result = false;
        if (KeyEvent.isConfirmKey(keyCode)) {
        if (event.isConfirmKey()) {
            if ((mViewFlags & ENABLED_MASK) == DISABLED) {
                return true;
            }
@@ -8228,7 +8228,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * @param event   The KeyEvent object that defines the button action.
     */
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (KeyEvent.isConfirmKey(keyCode)) {
        if (event.isConfirmKey()) {
            if ((mViewFlags & ENABLED_MASK) == DISABLED) {
                return true;
            }
+14 −2
Original line number Diff line number Diff line
@@ -4319,6 +4319,7 @@ public final class ViewRootImpl implements ViewParent,
     * Creates dpad events from unhandled joystick movements.
     */
    final class SyntheticJoystickHandler extends Handler {
        private final static String TAG = "SyntheticJoystickHandler";
        private final static int MSG_ENQUEUE_X_AXIS_KEY_REPEAT = 1;
        private final static int MSG_ENQUEUE_Y_AXIS_KEY_REPEAT = 2;

@@ -4351,10 +4352,21 @@ public final class ViewRootImpl implements ViewParent,
        }

        public void process(MotionEvent event) {
            switch(event.getActionMasked()) {
            case MotionEvent.ACTION_CANCEL:
                cancel(event);
                break;
            case MotionEvent.ACTION_MOVE:
                update(event, true);
                break;
            default:
                Log.w(TAG, "Unexpected action: " + event.getActionMasked());
            }
        }

        public void cancel(MotionEvent event) {
        private void cancel(MotionEvent event) {
            removeMessages(MSG_ENQUEUE_X_AXIS_KEY_REPEAT);
            removeMessages(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT);
            update(event, false);
        }

Loading