From 4ca1220b189df17559adb38b96eb58c5c6cdb90f Mon Sep 17 00:00:00 2001 From: Daosheng Mu Date: Tue, 7 Jul 2020 16:10:42 -0700 Subject: [PATCH] Correct the keyboard layout when showing from the focus view. (#3650) --- .../vrbrowser/ui/widgets/KeyboardWidget.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java index 588be1a5d..2b09f2862 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java @@ -472,6 +472,7 @@ public void updateFocusedView(View aFocusedView) { if (showKeyboard != keyboardIsVisible) { if (showKeyboard) { mWidgetManager.pushBackHandler(mBackHandler); + handleShowKeyboard(mCurrentKeyboard.getAlphabeticKeyboard()); } else { mWidgetManager.popBackHandler(mBackHandler); mWidgetManager.keyboardDismissed(); @@ -972,31 +973,42 @@ private void handleDone() { } } - private void handleModeChange() { - Keyboard current = mKeyboardView.getKeyboard(); + private void handleShowKeyboard(Keyboard aKeyboard) { Keyboard alphabetic = mCurrentKeyboard.getAlphabeticKeyboard(); Keyboard alphabetiCap = mCurrentKeyboard.getAlphabeticCapKeyboard(); - final boolean isAlphabeticMode = current == alphabetic || current == alphabetiCap; + final boolean switchToAlphabeticMode = aKeyboard == alphabetic || aKeyboard == alphabetiCap; - mKeyboardView.setKeyboard(isAlphabeticMode ? getSymbolsKeyboard() : alphabetic); + mKeyboardView.setKeyboard(aKeyboard); mKeyboardView.setLayoutParams(mKeyboardView.getLayoutParams()); - if (current == alphabetic) { - mCurrentKeyboard.getAlphabeticKeyboard().setSpaceKeyLabel(""); - } // Adjust the layout of the keyboard container because it might be changed by alphabetic keyboards // which have various height. - if (isAlphabeticMode) { + if (switchToAlphabeticMode) { ViewGroup.LayoutParams params = mKeyboardContainer.getLayoutParams(); - params.height = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getSymbolKeyboardHeight()); + params.height = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getAlphabeticKeyboardHeight()); mKeyboardContainer.setLayoutParams(params); } else { ViewGroup.LayoutParams params = mKeyboardContainer.getLayoutParams(); - params.height = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getAlphabeticKeyboardHeight()); + params.height = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getSymbolKeyboardHeight()); mKeyboardContainer.setLayoutParams(params); } } + private void handleModeChange() { + Keyboard current = mKeyboardView.getKeyboard(); + Keyboard alphabetic = mCurrentKeyboard.getAlphabeticKeyboard(); + Keyboard alphabeticCap = mCurrentKeyboard.getAlphabeticCapKeyboard(); + final boolean switchToSymbolMode = current == alphabetic || current == alphabeticCap; + + // We currently don't need to take care of presenting the space key label + // on an alphabetic cap keyboard. + if (current == alphabetic) { + mCurrentKeyboard.getAlphabeticKeyboard().setSpaceKeyLabel(""); + } + + handleShowKeyboard(switchToSymbolMode ? getSymbolsKeyboard() : alphabetic); + } + private void handleKey(int primaryCode, int[] keyCodes) { if (mFocusedView == null || mInputConnection == null || primaryCode <= 0) { return;