Skip to content

Commit

Permalink
Fixes Thai alphabetic cap keyboard switch (#3602)
Browse files Browse the repository at this point in the history
* Fixes Thai alphabetic cap keyboard switch

* Adjust Thai keyboard container layout.

* Refine slash symbol in Thai keyobard.
  • Loading branch information
daoshengmu authored and bluemarvin committed Jul 6, 2020
1 parent f645302 commit 93ff987
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/keyboard_qwerty_thai.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:keyHeight="@dimen/keyboard_key_height">
<Row>
<Key android:keyLabel="" android:keyEdgeFlags="left"/>
<Key android:keyLabel="/" android:popupCharacters="/\\" android:popupKeyboard="@xml/keyboard_popup"/>
<Key android:keyLabel="/"/>
<Key android:keyLabel="-"/>
<Key android:keyLabel=""/>
<Key android:keyLabel=""/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/keyboard_symbols_thai.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<Key android:codes="124" android:keyLabel="|"/>
<Key android:codes="39" android:keyLabel="'"/>
<Key android:codes="0x2022" android:keyLabel=""/>
<Key android:codes="58" android:keyLabel="/"/>
<Key android:codes="47" android:keyLabel="/"/>
<Key android:codes="-4" android:keyLabel="@string/keyboard_enter_label" android:keyWidth="@dimen/keyboard_key_enter_width" />
</Row>

Expand Down

0 comments on commit 93ff987

Please sign in to comment.