From 03dbc5042e566a573c9012f54d9e523fe97ad3e1 Mon Sep 17 00:00:00 2001 From: Daosheng Mu Date: Mon, 15 Jun 2020 18:30:52 -0700 Subject: [PATCH 1/2] Avoid showing candidate view when clicking special symbols in Traditional Chinese keyboard. --- .../ui/keyboards/ChineseZhuyinKeyboard.java | 26 +++++++++++++------ .../vrbrowser/ui/widgets/KeyboardWidget.java | 2 ++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/ChineseZhuyinKeyboard.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/ChineseZhuyinKeyboard.java index 19ab4841d..be0084f4b 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/ChineseZhuyinKeyboard.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/ChineseZhuyinKeyboard.java @@ -83,7 +83,8 @@ public CandidatesResult getCandidates(String aComposingText) { // If using non-Zhuyin symbols like numeric, abc, special symbols, // we just need to compose them. - if (aComposingText.matches(nonZhuyinReg)) { + String lastChar = "" + aComposingText.charAt(aComposingText.length() - 1); + if (lastChar.matches(nonZhuyinReg)) { CandidatesResult result = new CandidatesResult(); result.words = getDisplays(aComposingText); result.action = CandidatesResult.Action.AUTO_COMPOSE; @@ -224,12 +225,6 @@ public String getModeChangeKeyText() { return mContext.getString(R.string.zhuyin_keyboard_mode_change); } -// private String getNonZhuyinReg() { -// // For characters that not belong to Zhuyin input. -// final String reg = "[^ㄅ-ㄩ˙ˊˇˋˉ]"; -// return reg; -// } - private List getDisplays(String aKey) { // Allow completion of uppercase/lowercase letters numbers, and symbols // aKey.length() > 1 only happens when switching from other keyboard. @@ -242,7 +237,22 @@ private List getDisplays(String aKey) { code = GetTransCode(code); loadKeymapIfNotLoaded(code); KeyMap map = mKeymaps.get(code); - return map != null ? map.displays : null; + + if (map == null) { + return Collections.singletonList(new Words(1, aKey, aKey)); + } + // When detecting special symbols at the last character, and + // because special symbols are not defined in our code book. We + // need to add it back to our generated word for doing following + // AUTO_COMPOSE. + final String lastChar = "" + aKey.charAt(aKey.length()-1); + if (map != null && lastChar.matches(nonZhuyinReg)) + { + Words word = map.displays.get(0); + return Collections.singletonList(new Words(1, + word.code + lastChar, word.value + lastChar)); + } + return map.displays; } 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 8ad3b8566..49d1d6a05 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 @@ -1064,6 +1064,7 @@ private void updateCandidates() { setAutoCompletionVisible(candidates != null && candidates.words.size() > 0); mAutoCompletionView.setItems(candidates != null ? candidates.words : null); if (candidates != null && candidates.action == KeyboardInterface.CandidatesResult.Action.AUTO_COMPOSE) { + setAutoCompletionVisible(false); onAutoCompletionItemClick(candidates.words.get(0)); } else if (candidates != null) { postInputCommand(() -> displayComposingText(candidates.composing, ComposingAction.DO_NOT_FINISH)); @@ -1141,6 +1142,7 @@ private void displayComposingText(String aText, ComposingAction aAction) { mComposingDisplayText = aText; if (aAction == ComposingAction.FINISH) { mInputConnection.finishComposingText(); + mComposingText = ""; } } From ef3bc2f324e949c00d9af8737e7db03d2f8ba934 Mon Sep 17 00:00:00 2001 From: Daosheng Mu Date: Mon, 15 Jun 2020 18:44:42 -0700 Subject: [PATCH 2/2] Showing Simplified Chinese keyboard slash symbol correctly. --- .../ui/keyboards/ChinesePinyinKeyboard.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/ChinesePinyinKeyboard.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/ChinesePinyinKeyboard.java index a09279960..c5358d8fe 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/ChinesePinyinKeyboard.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/ChinesePinyinKeyboard.java @@ -36,9 +36,6 @@ public class ChinesePinyinKeyboard extends BaseKeyboard { private DBHelper mDB; private HashMap mKeymaps = new HashMap<>(); private HashMap mExtraKeymaps = new HashMap<>(); - private List mAutocompleteEndings = Arrays.asList( - ' ', ',', '。','!','?','ー' - ); public ChinesePinyinKeyboard(Context aContext) { super(aContext); @@ -78,15 +75,8 @@ public CandidatesResult getCandidates(String aComposingText) { } // Autocomplete when special characters are clicked - final char kBackslashCode = 92; - char lastChar = aComposingText.charAt(aComposingText.length() - 1); - - // When using backslashes ({@code \}) in the replacement string - // will cause crash at `replaceFirst()`, so we need to replace it first. - if (lastChar == kBackslashCode) { - aComposingText = aComposingText.replace("\\", "\\\\"); - } - boolean autocomponse = mAutocompleteEndings.indexOf(lastChar) >= 0; + final char lastChar = aComposingText.charAt(aComposingText.length() - 1); + final boolean autocompose = ("" + lastChar).matches("[^a-z]"); aComposingText = aComposingText.replaceAll("\\s",""); if (aComposingText.isEmpty()) { @@ -149,11 +139,21 @@ public CandidatesResult getCandidates(String aComposingText) { CandidatesResult result = new CandidatesResult(); result.words = words; - result.action = autocomponse ? CandidatesResult.Action.AUTO_COMPOSE : CandidatesResult.Action.SHOW_CANDIDATES; + result.action = autocompose ? CandidatesResult.Action.AUTO_COMPOSE : CandidatesResult.Action.SHOW_CANDIDATES; result.composing = aComposingText; if (result.words.size() > 0) { - String codeWithoutSpaces = StringUtils.removeSpaces(result.words.get(0).code); - result.composing = aComposingText.replaceFirst(Pattern.quote(codeWithoutSpaces), result.words.get(0).code); + final char kBackslashCode = 92; + String newCode = result.words.get(0).code; + + // When using backslashes ({@code \}) in the replacement string + // will cause crash at `replaceFirst()`, so we need to replace it first. + if (result.words.get(0).code.charAt(result.words.get(0).code.length() - 1) + == kBackslashCode) { + newCode = result.words.get(0).code.replace("\\", "\\\\"); + aComposingText = aComposingText.replace("\\", "\\\\"); + } + String codeWithoutSpaces = StringUtils.removeSpaces(newCode); + result.composing = aComposingText.replaceFirst(Pattern.quote(codeWithoutSpaces), newCode); } return result;