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

Commit 2f05489b authored by Phil Tunstall's avatar Phil Tunstall
Browse files

Long-press menu key to search, configurable per device

Patch Set 3: Changed config value on which this depends to store the presence
             of all hardware 'face' keys on a device as a bit field.

Change-Id: I3a24b148e21197cfbc46683557291956e44b5feb
parent 6f45d53a
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -809,4 +809,17 @@

    <!-- True will enable the electron beam screen-off animation. -->
    <bool name="config_screenOffAnimation">true</bool>

    <!-- Hardware 'face' keys present on the device, stored as a bit field.
         This integer should equal the sum of the corresponding value for each
         of the following keys present:
             1 - Home
             2 - Back
             4 - Menu
             8 - Search
            16 - App switch
         For example, a device with Home, Back and Menu keys would set this
         config to 7. -->
    <integer name="config_deviceHardwareKeys">15</integer>

</resources>
+74 −19
Original line number Diff line number Diff line
@@ -187,6 +187,17 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    static final int LONG_PRESS_HOME_RECENT_DIALOG = 1;
    static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 2;

    static final int LONG_PRESS_MENU_NOTHING = 0;
    static final int LONG_PRESS_MENU_SEARCH = 1;

    // Masks for checking presence of hardware keys.
    // Must match values in core/res/res/values/config.xml
    private static final int KEY_MASK_HOME = 0x01;
    private static final int KEY_MASK_BACK = 0x02;
    private static final int KEY_MASK_MENU = 0x04;
    private static final int KEY_MASK_SEARCH = 0x08;
    private static final int KEY_MASK_APP_SWITCH = 0x10;

    // wallpaper is at the bottom, though the window manager may move it.
    static final int WALLPAPER_LAYER = 2;
    static final int APPLICATION_LAYER = 2;
@@ -466,6 +477,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    // What we do when the user long presses on home
    private int mLongPressOnHomeBehavior = -1;

    // What we do when the user long presses on menu
    private int mLongPressOnMenuBehavior = -1;

    // Screenshot trigger states
    // Time to volume and power must be pressed within this interval of each other.
    private static final long ACTION_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
@@ -855,6 +869,37 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    private void handleLongPressOnMenu() {
        if (mLongPressOnMenuBehavior < 0) {
            if ((mContext.getResources().getInteger(
                    R.integer.config_deviceHardwareKeys) & KEY_MASK_SEARCH) == 0) {
                // Hardware search key not present
                mLongPressOnMenuBehavior = LONG_PRESS_MENU_SEARCH;
            } else {
                mLongPressOnMenuBehavior = LONG_PRESS_MENU_NOTHING;
            }
        }

        if (mLongPressOnMenuBehavior == LONG_PRESS_MENU_SEARCH) {
            performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
            triggerVirtualKeypress(KeyEvent.KEYCODE_SEARCH);
        }
    }

    private void triggerVirtualKeypress(final int keyCode) {
        new Thread(new Runnable() {
            public void run() {
                try {
                    mWindowManager.injectKeyEvent(
                            new KeyEvent(KeyEvent.ACTION_DOWN, keyCode), true);
                    mWindowManager.injectKeyEvent(
                            new KeyEvent(KeyEvent.ACTION_UP, keyCode), true);
                } catch(RemoteException e) {
                }
            }
        }).start();
    }

    /**
     * Create (if necessary) and show or dismiss the recent apps dialog according
     * according to the requested behavior.
@@ -1782,7 +1827,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            // Hijack modified menu keys for debugging features
            final int chordBug = KeyEvent.META_SHIFT_ON;

            if (down && repeatCount == 0) {
            if (down) {
                if (repeatCount == 0) {
                    if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
                        Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
                        mContext.sendOrderedBroadcast(intent, null);
@@ -1803,6 +1849,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                                res, Settings.System.SHOW_PROCESSES, shown ? 0 : 1);
                        return -1;
                    }
                } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
                    if (!keyguardOn) {
                        handleLongPressOnMenu();
                        if (mLongPressOnMenuBehavior != LONG_PRESS_MENU_NOTHING) {
                            // Do not open menu when key is released
                            return -1;
                        }
                    }
                }
            }
        } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
            if (down) {