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

Correct the keyboard layout when showing from the focus view. #3650

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Looks like alphabetiCap should be alphabeticCap. Can be addressed in follow up since it is preexisting.

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