Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Correct the keyboard layout when showing from the focus view. (#3650)
Browse files Browse the repository at this point in the history
  • Loading branch information
daoshengmu authored and bluemarvin committed Jul 7, 2020
1 parent 5e2f309 commit 4ca1220
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4ca1220

Please sign in to comment.