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

Commit 93ff987

Browse files
daoshengmubluemarvin
authored andcommitted
Fixes Thai alphabetic cap keyboard switch (#3602)
* Fixes Thai alphabetic cap keyboard switch * Adjust Thai keyboard container layout. * Refine slash symbol in Thai keyobard.
1 parent f645302 commit 93ff987

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/BaseKeyboard.java

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public float getAlphabeticKeyboardHeight() {
6767
return WidgetPlacement.dpDimension(mContext, R.dimen.keyboard_height);
6868
}
6969

70+
public float getSymbolKeyboardHeight() {
71+
return WidgetPlacement.dpDimension(mContext, R.dimen.keyboard_height);
72+
}
73+
7074
@Override
7175
public String[] getDomains(String... domains) {
7276
return Stream.of(new String[]{".com", ".net", ".org", ".co"}, domains).flatMap(Stream::of)

app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/KeyboardInterface.java

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public enum Action {
3131
@NonNull CustomKeyboard getAlphabeticKeyboard();
3232
float getAlphabeticKeyboardWidth();
3333
float getAlphabeticKeyboardHeight();
34+
float getSymbolKeyboardHeight();
3435
float getKeyboardTranslateYInWorld();
3536
float getKeyboardWorldWidth();
3637
default @Nullable CustomKeyboard getAlphabeticCapKeyboard() { return null; }

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java

+32-5
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ private void cleanComposingText() {
744744
private void handleShift(boolean isShifted) {
745745
final boolean statusChanged = mKeyboardView.isShifted() != isShifted;
746746

747-
if (mCurrentKeyboard.getAlphabeticCapKeyboard() != null) {
747+
if (mKeyboardView.getKeyboard() != getSymbolsKeyboard()) {
748748
if (isShifted || mIsCapsLock) {
749749
mKeyboardView.setKeyboard(mCurrentKeyboard.getAlphabeticCapKeyboard());
750750
} else {
@@ -875,11 +875,19 @@ private void handleLanguageChange(KeyboardInterface aKeyboard) {
875875
cleanComposingText();
876876

877877
mCurrentKeyboard = aKeyboard;
878+
879+
// For the case when switching from a symbol keyboard to a alphabetic keyboard.
880+
float currentHeight = 0.0f;
881+
if (mKeyboardView.getKeyboard() == mCurrentKeyboard.getSymbolsKeyboard()) {
882+
currentHeight = mCurrentKeyboard.getSymbolKeyboardHeight();
883+
} else {
884+
currentHeight = mCurrentKeyboard.getAlphabeticKeyboardHeight();
885+
}
878886
final int width = getKeyboardWidth(mCurrentKeyboard.getAlphabeticKeyboardWidth());
879-
final int height = getKeyboardHeight(mCurrentKeyboard.getAlphabeticKeyboardHeight());
887+
final int height = getKeyboardHeight(currentHeight);
880888
if (width != mWidgetPlacement.width || height != mWidgetPlacement.height) {
881889
mWidgetPlacement.width = width;
882-
mWidgetPlacement.height = height;
890+
mWidgetPlacement.height = getKeyboardHeight(mCurrentKeyboard.getAlphabeticKeyboardHeight());
883891
mWidgetPlacement.translationY = mCurrentKeyboard.getKeyboardTranslateYInWorld() -
884892
WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_y);
885893
float defaultWorldWidth = mCurrentKeyboard.getKeyboardWorldWidth();
@@ -964,11 +972,26 @@ private void handleDone() {
964972
private void handleModeChange() {
965973
Keyboard current = mKeyboardView.getKeyboard();
966974
Keyboard alphabetic = mCurrentKeyboard.getAlphabeticKeyboard();
967-
mKeyboardView.setKeyboard(current == alphabetic ? getSymbolsKeyboard() : alphabetic);
975+
Keyboard alphabetiCap = mCurrentKeyboard.getAlphabeticCapKeyboard();
976+
final boolean isAlphabeticMode = current == alphabetic || current == alphabetiCap;
977+
978+
mKeyboardView.setKeyboard(isAlphabeticMode ? getSymbolsKeyboard() : alphabetic);
968979
mKeyboardView.setLayoutParams(mKeyboardView.getLayoutParams());
969980
if (current == alphabetic) {
970981
mCurrentKeyboard.getAlphabeticKeyboard().setSpaceKeyLabel("");
971982
}
983+
984+
// Adjust the layout of the keyboard container because it might be changed by alphabetic keyboards
985+
// which have various height.
986+
if (isAlphabeticMode) {
987+
ViewGroup.LayoutParams params = mKeyboardContainer.getLayoutParams();
988+
params.height = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getSymbolKeyboardHeight());
989+
mKeyboardContainer.setLayoutParams(params);
990+
} else {
991+
ViewGroup.LayoutParams params = mKeyboardContainer.getLayoutParams();
992+
params.height = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getAlphabeticKeyboardHeight());
993+
mKeyboardContainer.setLayoutParams(params);
994+
}
972995
}
973996

974997
private void handleKey(int primaryCode, int[] keyCodes) {
@@ -1023,7 +1046,7 @@ private void handleText(String aText, boolean skipCase) {
10231046
postInputCommand(() -> connection.commitText(text, 1));
10241047
}
10251048

1026-
if (!mIsCapsLock) {
1049+
if (!mIsCapsLock && mCurrentKeyboard.getAlphabeticCapKeyboard() == null) {
10271050
handleShift(false);
10281051
}
10291052

@@ -1118,6 +1141,10 @@ private void updateSpecialKeyLabels() {
11181141
String enterText = mCurrentKeyboard.getEnterKeyText(mEditorInfo.imeOptions, mComposingText);
11191142
String modeChangeText = mCurrentKeyboard.getModeChangeKeyText();
11201143
boolean changed = mCurrentKeyboard.getAlphabeticKeyboard().setEnterKeyLabel(enterText);
1144+
1145+
if (mCurrentKeyboard.getAlphabeticCapKeyboard() != null) {
1146+
mCurrentKeyboard.getAlphabeticCapKeyboard().setEnterKeyLabel(enterText);
1147+
}
11211148
CustomKeyboard symbolsKeyboard = getSymbolsKeyboard();
11221149
changed |= symbolsKeyboard.setModeChangeKeyLabel(modeChangeText);
11231150
symbolsKeyboard.setEnterKeyLabel(enterText);

app/src/main/res/xml/keyboard_qwerty_thai.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
android:keyHeight="@dimen/keyboard_key_height">
77
<Row>
88
<Key android:keyLabel="" android:keyEdgeFlags="left"/>
9-
<Key android:keyLabel="/" android:popupCharacters="/\\" android:popupKeyboard="@xml/keyboard_popup"/>
9+
<Key android:keyLabel="/"/>
1010
<Key android:keyLabel="-"/>
1111
<Key android:keyLabel=""/>
1212
<Key android:keyLabel=""/>

app/src/main/res/xml/keyboard_symbols_thai.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<Key android:codes="124" android:keyLabel="|"/>
3232
<Key android:codes="39" android:keyLabel="'"/>
3333
<Key android:codes="0x2022" android:keyLabel=""/>
34-
<Key android:codes="58" android:keyLabel="/"/>
34+
<Key android:codes="47" android:keyLabel="/"/>
3535
<Key android:codes="-4" android:keyLabel="@string/keyboard_enter_label" android:keyWidth="@dimen/keyboard_key_enter_width" />
3636
</Row>
3737

0 commit comments

Comments
 (0)