From 93ff987efaf62f7631586b1e4d21a67c404cf0e3 Mon Sep 17 00:00:00 2001 From: Daosheng Mu Date: Mon, 6 Jul 2020 02:06:49 -0700 Subject: [PATCH] Fixes Thai alphabetic cap keyboard switch (#3602) * Fixes Thai alphabetic cap keyboard switch * Adjust Thai keyboard container layout. * Refine slash symbol in Thai keyobard. --- .../vrbrowser/ui/keyboards/BaseKeyboard.java | 4 ++ .../ui/keyboards/KeyboardInterface.java | 1 + .../vrbrowser/ui/widgets/KeyboardWidget.java | 37 ++++++++++++++++--- app/src/main/res/xml/keyboard_qwerty_thai.xml | 2 +- .../main/res/xml/keyboard_symbols_thai.xml | 2 +- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/BaseKeyboard.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/BaseKeyboard.java index 97ccc476f..cd305cd37 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/BaseKeyboard.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/BaseKeyboard.java @@ -67,6 +67,10 @@ public float getAlphabeticKeyboardHeight() { return WidgetPlacement.dpDimension(mContext, R.dimen.keyboard_height); } + public float getSymbolKeyboardHeight() { + return WidgetPlacement.dpDimension(mContext, R.dimen.keyboard_height); + } + @Override public String[] getDomains(String... domains) { return Stream.of(new String[]{".com", ".net", ".org", ".co"}, domains).flatMap(Stream::of) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/KeyboardInterface.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/KeyboardInterface.java index 8f30fc2df..c3e56a54a 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/KeyboardInterface.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/KeyboardInterface.java @@ -31,6 +31,7 @@ public enum Action { @NonNull CustomKeyboard getAlphabeticKeyboard(); float getAlphabeticKeyboardWidth(); float getAlphabeticKeyboardHeight(); + float getSymbolKeyboardHeight(); float getKeyboardTranslateYInWorld(); float getKeyboardWorldWidth(); default @Nullable CustomKeyboard getAlphabeticCapKeyboard() { return null; } 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 84a35e150..391d669e7 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 @@ -744,7 +744,7 @@ private void cleanComposingText() { private void handleShift(boolean isShifted) { final boolean statusChanged = mKeyboardView.isShifted() != isShifted; - if (mCurrentKeyboard.getAlphabeticCapKeyboard() != null) { + if (mKeyboardView.getKeyboard() != getSymbolsKeyboard()) { if (isShifted || mIsCapsLock) { mKeyboardView.setKeyboard(mCurrentKeyboard.getAlphabeticCapKeyboard()); } else { @@ -875,11 +875,19 @@ private void handleLanguageChange(KeyboardInterface aKeyboard) { cleanComposingText(); mCurrentKeyboard = aKeyboard; + + // For the case when switching from a symbol keyboard to a alphabetic keyboard. + float currentHeight = 0.0f; + if (mKeyboardView.getKeyboard() == mCurrentKeyboard.getSymbolsKeyboard()) { + currentHeight = mCurrentKeyboard.getSymbolKeyboardHeight(); + } else { + currentHeight = mCurrentKeyboard.getAlphabeticKeyboardHeight(); + } final int width = getKeyboardWidth(mCurrentKeyboard.getAlphabeticKeyboardWidth()); - final int height = getKeyboardHeight(mCurrentKeyboard.getAlphabeticKeyboardHeight()); + final int height = getKeyboardHeight(currentHeight); if (width != mWidgetPlacement.width || height != mWidgetPlacement.height) { mWidgetPlacement.width = width; - mWidgetPlacement.height = height; + mWidgetPlacement.height = getKeyboardHeight(mCurrentKeyboard.getAlphabeticKeyboardHeight()); mWidgetPlacement.translationY = mCurrentKeyboard.getKeyboardTranslateYInWorld() - WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_y); float defaultWorldWidth = mCurrentKeyboard.getKeyboardWorldWidth(); @@ -964,11 +972,26 @@ private void handleDone() { private void handleModeChange() { Keyboard current = mKeyboardView.getKeyboard(); Keyboard alphabetic = mCurrentKeyboard.getAlphabeticKeyboard(); - mKeyboardView.setKeyboard(current == alphabetic ? getSymbolsKeyboard() : alphabetic); + Keyboard alphabetiCap = mCurrentKeyboard.getAlphabeticCapKeyboard(); + final boolean isAlphabeticMode = current == alphabetic || current == alphabetiCap; + + mKeyboardView.setKeyboard(isAlphabeticMode ? getSymbolsKeyboard() : alphabetic); 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) { + ViewGroup.LayoutParams params = mKeyboardContainer.getLayoutParams(); + params.height = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getSymbolKeyboardHeight()); + mKeyboardContainer.setLayoutParams(params); + } else { + ViewGroup.LayoutParams params = mKeyboardContainer.getLayoutParams(); + params.height = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getAlphabeticKeyboardHeight()); + mKeyboardContainer.setLayoutParams(params); + } } private void handleKey(int primaryCode, int[] keyCodes) { @@ -1023,7 +1046,7 @@ private void handleText(String aText, boolean skipCase) { postInputCommand(() -> connection.commitText(text, 1)); } - if (!mIsCapsLock) { + if (!mIsCapsLock && mCurrentKeyboard.getAlphabeticCapKeyboard() == null) { handleShift(false); } @@ -1118,6 +1141,10 @@ private void updateSpecialKeyLabels() { String enterText = mCurrentKeyboard.getEnterKeyText(mEditorInfo.imeOptions, mComposingText); String modeChangeText = mCurrentKeyboard.getModeChangeKeyText(); boolean changed = mCurrentKeyboard.getAlphabeticKeyboard().setEnterKeyLabel(enterText); + + if (mCurrentKeyboard.getAlphabeticCapKeyboard() != null) { + mCurrentKeyboard.getAlphabeticCapKeyboard().setEnterKeyLabel(enterText); + } CustomKeyboard symbolsKeyboard = getSymbolsKeyboard(); changed |= symbolsKeyboard.setModeChangeKeyLabel(modeChangeText); symbolsKeyboard.setEnterKeyLabel(enterText); diff --git a/app/src/main/res/xml/keyboard_qwerty_thai.xml b/app/src/main/res/xml/keyboard_qwerty_thai.xml index f142ca1b9..bee4f6892 100644 --- a/app/src/main/res/xml/keyboard_qwerty_thai.xml +++ b/app/src/main/res/xml/keyboard_qwerty_thai.xml @@ -6,7 +6,7 @@ android:keyHeight="@dimen/keyboard_key_height"> - + diff --git a/app/src/main/res/xml/keyboard_symbols_thai.xml b/app/src/main/res/xml/keyboard_symbols_thai.xml index c2d240ffc..b7137e4ef 100644 --- a/app/src/main/res/xml/keyboard_symbols_thai.xml +++ b/app/src/main/res/xml/keyboard_symbols_thai.xml @@ -31,7 +31,7 @@ - +