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

Commit 4aed78b5 authored by Jeff Brown's avatar Jeff Brown
Browse files

Disable soft keyboard when keyboard attached.

Also hide menu shortcuts everywhere until we can get around to
redesigning the menu UI to be more consistent.

Bug: 3306545
Bug: 3330748
Change-Id: I4d4e19525cdfc93d9aae0dcaa1e6266fb552c5bc
parent 1c9d06e0
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -353,8 +353,7 @@ public class MenuBuilder implements Menu {
        mNonActionItems = new ArrayList<MenuItemImpl>();
        mIsActionItemsStale = true;
        
        mShortcutsVisible =
                (mResources.getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS);
        setShortcutsVisibleInner(true);
    }
    
    public MenuBuilder setDefaultShowAsAction(int defaultShowAsAction) {
@@ -783,13 +782,17 @@ public class MenuBuilder implements Menu {
    public void setShortcutsVisible(boolean shortcutsVisible) {
        if (mShortcutsVisible == shortcutsVisible) return;

        mShortcutsVisible =
            (mResources.getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS)
            && shortcutsVisible;
        
        setShortcutsVisibleInner(shortcutsVisible);
        refreshShortcuts(mShortcutsVisible, isQwertyMode());
    }

    private void setShortcutsVisibleInner(boolean shortcutsVisible) {
        mShortcutsVisible = shortcutsVisible
                && mResources.getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS
                && mResources.getBoolean(
                        com.android.internal.R.bool.config_showMenuShortcutsWhenKeyboardPresent);
    }

    /**
     * @return Whether shortcuts should be visible on menus.
     */
+4 −0
Original line number Diff line number Diff line
@@ -529,4 +529,8 @@
    <!-- When a database query is executed, the results retuned are paginated
         in pages of size (in KB) indicated by this value -->
    <integer name="config_cursorWindowSize">2048</integer>

    <!-- Sets whether menu shortcuts should be displayed on panel menus when
         a keyboard is present. -->
    <bool name="config_showMenuShortcutsWhenKeyboardPresent">false</bool>
</resources>
+14 −18
Original line number Diff line number Diff line
@@ -1624,24 +1624,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
                // First handle chording of panel key: if a panel key is held
                // but not released, try to execute a shortcut in it.
                if ((mPanelChordingKey > 0) && (mPanelChordingKey != keyCode)) {
                    // Perform the shortcut (mPreparedPanel can be null since
                    // global shortcuts (such as search) don't rely on a
                    // prepared panel or menu).
                    boolean handled = performPanelShortcut(mPreparedPanel, keyCode, event,
                            Menu.FLAG_PERFORM_NO_CLOSE);

                    if (!handled) {
                        /*
                         * If not handled, then pass it to the view hierarchy
                         * and anyone else that may be interested.
                         */
                        handled = dispatchKeyShortcutEvent(event);

                        if (handled && mPreparedPanel != null) {
                            mPreparedPanel.isHandled = true;
                        }
                    }

                    boolean handled = dispatchKeyShortcutEvent(event);
                    if (handled) {
                        return true;
                    }
@@ -1676,6 +1659,19 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {

        @Override
        public boolean dispatchKeyShortcutEvent(KeyEvent ev) {
            // Perform the shortcut (mPreparedPanel can be null since
            // global shortcuts (such as search) don't rely on a
            // prepared panel or menu).
            boolean handled = performPanelShortcut(mPreparedPanel, ev.getKeyCode(), ev,
                    Menu.FLAG_PERFORM_NO_CLOSE);
            if (handled) {
                if (mPreparedPanel != null) {
                    mPreparedPanel.isHandled = true;
                }
                return true;
            }

            // Shortcut not handled by the panel.  Dispatch to the view hierarchy.
            final Callback cb = getCallback();
            return cb != null && mFeatureId < 0 ? cb.dispatchKeyShortcutEvent(ev) : super
                    .dispatchKeyShortcutEvent(ev);
+33 −19
Original line number Diff line number Diff line
@@ -240,8 +240,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    RecentApplicationsDialog mRecentAppsDialog;
    Handler mHandler;

    private static final int LID_ABSENT = -1;
    private static final int LID_CLOSED = 0;
    private static final int LID_OPEN = 1;

    int mLidOpen = LID_ABSENT;

    boolean mSystemReady;
    boolean mLidOpen;
    boolean mHdmiPlugged;
    int mUiMode = Configuration.UI_MODE_TYPE_NORMAL;
    int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
@@ -896,21 +901,31 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    void readLidState() {
        try {
            int sw = mWindowManager.getSwitchState(SW_LID);
            if (sw >= 0) {
                mLidOpen = sw == 0;
            if (sw > 0) {
                mLidOpen = LID_OPEN;
            } else if (sw == 0) {
                mLidOpen = LID_CLOSED;
            } else {
                mLidOpen = LID_ABSENT;
            }
        } catch (RemoteException e) {
            // Ignore
        }
    }
    
    private int determineHiddenState(boolean lidOpen,
            int mode, int hiddenValue, int visibleValue) {
    private int determineHiddenState(int mode, int hiddenValue, int visibleValue) {
        if (KEYBOARD_ALWAYS_HIDDEN) {
            return hiddenValue;
        }
        if (mLidOpen == LID_ABSENT) {
            return visibleValue;
        }

        switch (mode) {
            case 1:
                return lidOpen ? visibleValue : hiddenValue;
                return mLidOpen == LID_OPEN ? visibleValue : hiddenValue;
            case 2:
                return lidOpen ? hiddenValue : visibleValue;
                return mLidOpen == LID_OPEN ? hiddenValue : visibleValue;
        }
        return visibleValue;
    }
@@ -918,12 +933,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    /** {@inheritDoc} */
    public void adjustConfigurationLw(Configuration config) {
        readLidState();
        final boolean lidOpen = !KEYBOARD_ALWAYS_HIDDEN && mLidOpen;
        mPowerManager.setKeyboardVisibility(lidOpen);
        config.hardKeyboardHidden = determineHiddenState(lidOpen,
        mPowerManager.setKeyboardVisibility(mLidOpen == LID_OPEN);
        config.hardKeyboardHidden = determineHiddenState(
                mLidKeyboardAccessibility, Configuration.HARDKEYBOARDHIDDEN_YES,
                Configuration.HARDKEYBOARDHIDDEN_NO);
        config.navigationHidden = determineHiddenState(lidOpen,
        config.navigationHidden = determineHiddenState(
                mLidNavigationAccessibility, Configuration.NAVIGATIONHIDDEN_YES,
                Configuration.NAVIGATIONHIDDEN_NO);
        config.keyboardHidden = (config.hardKeyboardHidden
@@ -1973,8 +1987,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    /** {@inheritDoc} */
    public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
        // lid changed state
        mLidOpen = lidOpen;
        boolean awakeNow = mKeyguardMediator.doLidChangeTq(mLidOpen);
        mLidOpen = lidOpen ? LID_OPEN : LID_CLOSED;
        boolean awakeNow = mKeyguardMediator.doLidChangeTq(lidOpen);
        updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
        if (awakeNow) {
            // If the lid is opening and we don't have to keep the
@@ -1982,7 +1996,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            // immediately.
            mKeyguardMediator.pokeWakelock();
        } else if (keyguardIsShowingTq()) {
            if (mLidOpen) {
            if (lidOpen) {
                // If we are opening the lid and not hiding the
                // keyguard, then we need to have it turn on the
                // screen once it is shown.
@@ -1991,7 +2005,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }
        } else {
            // Light up the keyboard if we are sliding up.
            if (mLidOpen) {
            if (lidOpen) {
                mPowerManager.userActivity(SystemClock.uptimeMillis(), false,
                        LocalPowerManager.BUTTON_EVENT);
            } else {
@@ -2473,7 +2487,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            //or case.unspecified
            if (mHdmiPlugged) {
                return Surface.ROTATION_0;
            } else if (mLidOpen) {
            } else if (mLidOpen == LID_OPEN) {
                return mLidOpenRotation;
            } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {
                return mCarDockRotation;
@@ -2639,11 +2653,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    }

    void updateRotation(int animFlags) {
        mPowerManager.setKeyboardVisibility(mLidOpen);
        mPowerManager.setKeyboardVisibility(mLidOpen == LID_OPEN);
        int rotation = Surface.ROTATION_0;
        if (mHdmiPlugged) {
            rotation = Surface.ROTATION_0;
        } else if (mLidOpen) {
        } else if (mLidOpen == LID_OPEN) {
            rotation = mLidOpenRotation;
        } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {
            rotation = mCarDockRotation;