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

Commit 29f27e8d authored by arthurhung's avatar arthurhung
Browse files

Introduce SingleKeyGestureDetector to PhoneWindowManager

The SingleKeyGestureDetector is used to detect the single key gesture
such as short press, long press or multi presses.

If the key has been handled by other policy, it should call 'cancel'
to reset all gesture states.

This patch refactor the power key and back key (long press behavior
enabled), it can detect below gestures:
- single press
- long press
- very long press
- multiple press ( <= 3)

Bug: 169058831
Bug: 127687575
Test: atest KeyEventTest SingleKeyGestureTests
Test: manual (short press power, long press power, double tap power)
Change-Id: I1c042e693e9844e30ce568eded7681fa4101daf9
parent f6ed5fc5
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -102,9 +102,11 @@ public class KeyCombinationManager {
    }

    /**
     * Check if the key event could be triggered by combine key rule before dispatching to a window.
     * Check if the key event could be intercepted by combination key rule before it is dispatched
     * to a window.
     * Return true if any active rule could be triggered by the key event, otherwise false.
     */
    void interceptKey(KeyEvent event, boolean interactive) {
    boolean interceptKey(KeyEvent event, boolean interactive) {
        final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
        final int keyCode = event.getKeyCode();
        final int count = mActiveRules.size();
@@ -117,9 +119,9 @@ public class KeyCombinationManager {
                    // exceed time from first key down.
                    forAllRules(mActiveRules, (rule)-> rule.cancel());
                    mActiveRules.clear();
                    return;
                    return false;
                } else if (count == 0) { // has some key down but no active rule exist.
                    return;
                    return false;
                }
            }

@@ -127,7 +129,7 @@ public class KeyCombinationManager {
                mDownTimes.put(keyCode, eventTime);
            } else {
                // ignore old key, maybe a repeat key.
                return;
                return false;
            }

            if (mDownTimes.size() == 1) {
@@ -141,7 +143,7 @@ public class KeyCombinationManager {
            } else {
                // Ignore if rule already triggered.
                if (mTriggeredRule != null) {
                    return;
                    return true;
                }

                // check if second key can trigger rule, or remove the non-match rule.
@@ -156,6 +158,7 @@ public class KeyCombinationManager {
                mActiveRules.clear();
                if (mTriggeredRule != null) {
                    mActiveRules.add(mTriggeredRule);
                    return true;
                }
            }
        } else {
@@ -168,6 +171,7 @@ public class KeyCombinationManager {
                }
            }
        }
        return false;
    }

    /**
+163 −186

File changed.

Preview size limit exceeded, changes collapsed.

+356 −0

File added.

Preview size limit exceeded, changes collapsed.

+152 −0

File added.

Preview size limit exceeded, changes collapsed.