From 09d76aee488a531fdab6370b63a14f59eb18b8de Mon Sep 17 00:00:00 2001 From: Daosheng Mu Date: Mon, 23 Mar 2020 03:18:03 -0700 Subject: [PATCH] Adjusting zh-tw keyboard layout. (#2801) * Adjust zh-tw IME layout. * Support Emoji symbols in Zhuyin keyboard. * Adjust numeric keyboard layout. * Making space bar be blank for Zhuyin input. --- .../ui/keyboards/ChineseZhuyinKeyboard.java | 55 +++++++++++++++- .../vrbrowser/ui/widgets/KeyboardWidget.java | 2 + app/src/main/res/values/dimen.xml | 11 ++-- app/src/main/res/values/non_L10n.xml | 2 +- app/src/main/res/xml/keyboard_numeric.xml | 13 ++-- ..._zhuyin.xml => keyboard_qwerty_zhuyin.xml} | 17 +++-- .../main/res/xml/keyboard_symbols_zhuyin.xml | 63 +++++++++++++++++++ 7 files changed, 139 insertions(+), 24 deletions(-) rename app/src/main/res/xml/{keyboard_zhuyin.xml => keyboard_qwerty_zhuyin.xml} (84%) create mode 100644 app/src/main/res/xml/keyboard_symbols_zhuyin.xml 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 6105e6b65..adcc105f2 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 @@ -24,10 +24,17 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import jp.co.omronsoft.openwnn.ComposingText; +import jp.co.omronsoft.openwnn.SymbolList; +import jp.co.omronsoft.openwnn.WnnWord; + public class ChineseZhuyinKeyboard extends BaseKeyboard { private static final String LOGTAG = SystemUtils.createLogtag(ChineseZhuyinKeyboard.class); private static final String nonZhuyinReg = "[^ㄅ-ㄩ˙ˊˇˋˉ]"; private CustomKeyboard mKeyboard; + private CustomKeyboard mSymbolsKeyboard; + private SymbolList mSymbolsConverter; // For Emoji characters. + private List mEmojiList = null; private DBWordHelper mWordDB; private DBPhraseHelper mPhraseDB; private HashMap mKeymaps = new HashMap<>(); @@ -44,12 +51,23 @@ public ChineseZhuyinKeyboard(Context aContext) { @Override public CustomKeyboard getAlphabeticKeyboard() { if (mKeyboard == null) { - mKeyboard = new CustomKeyboard(mContext.getApplicationContext(), R.xml.keyboard_zhuyin); + mKeyboard = new CustomKeyboard(mContext.getApplicationContext(), R.xml.keyboard_qwerty_zhuyin); loadDatabase(); } return mKeyboard; } + @Nullable + @Override + public CustomKeyboard getSymbolsKeyboard() { + if (mSymbolsKeyboard == null) { + mSymbolsKeyboard = new CustomKeyboard(mContext.getApplicationContext(), R.xml.keyboard_symbols_zhuyin); + // We use openwnn to provide us Emoji character although we are not using JPN keyboard. + mSymbolsConverter = new SymbolList(mContext, SymbolList.LANG_JA); + } + return mSymbolsKeyboard; + } + @Nullable @Override public CandidatesResult getCandidates(String aComposingText) { @@ -93,6 +111,31 @@ public CandidatesResult getCandidates(String aComposingText) { return result; } + @Override + public CandidatesResult getEmojiCandidates(String aComposingText) { + if (mEmojiList == null) { + List words = new ArrayList<>(); + ComposingText text = new ComposingText(); + mSymbolsConverter.convert(text); + + int candidates = mSymbolsConverter.predict(text, 0, -1); + if (candidates > 0) { + WnnWord word; + while ((word = mSymbolsConverter.getNextCandidate()) != null) { + words.add(new Words(1, word.stroke, word.candidate)); + } + mEmojiList = words; + } + } + + CandidatesResult result = new CandidatesResult(); + result.words = mEmojiList; + result.action = CandidatesResult.Action.SHOW_CANDIDATES; + result.composing = aComposingText; + + return result; + } + private String GetTransCode(String aText) { String code = aText; String transCode = ""; @@ -114,6 +157,14 @@ public String getComposingText(String aComposing, String aCode) { return aComposing.replaceFirst(Pattern.quote(aCode), ""); } + if (mEmojiList != null) { + for (Words word : mEmojiList) { + if (word.code.equals(aCode)) { + return ""; + } + } + } + for (int i = 0; i <= aCode.length() - shift; i += shift) { sub = aCode.substring(i, i + shift); @@ -153,7 +204,7 @@ public Locale getLocale() { @Override public String getSpaceKeyText(String aComposingText) { if (aComposingText == null || aComposingText.trim().isEmpty()) { - return StringUtils.getStringByLocale(mContext, R.string.settings_language_traditional_chinese, getLocale()); + return ""; } else { return mContext.getString(R.string.zhuyin_spacebar_selection); } 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 1211f8090..54ad51f7f 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 @@ -1079,8 +1079,10 @@ private void updateCandidates() { private void updateSpecialKeyLabels() { String enterText = mCurrentKeyboard.getEnterKeyText(mEditorInfo.imeOptions, mComposingText); + String spaceText = mCurrentKeyboard.getSpaceKeyText(mComposingText); String modeChangeText = mCurrentKeyboard.getModeChangeKeyText(); boolean changed = mCurrentKeyboard.getAlphabeticKeyboard().setEnterKeyLabel(enterText); + changed |= mCurrentKeyboard.getAlphabeticKeyboard().setSpaceKeyLabel(spaceText); CustomKeyboard symbolsKeyboard = getSymbolsKeyboard(); changed |= symbolsKeyboard.setModeChangeKeyLabel(modeChangeText); symbolsKeyboard.setEnterKeyLabel(enterText); diff --git a/app/src/main/res/values/dimen.xml b/app/src/main/res/values/dimen.xml index f36ad3333..05c2b8691 100644 --- a/app/src/main/res/values/dimen.xml +++ b/app/src/main/res/values/dimen.xml @@ -25,6 +25,7 @@ 3.25 -0.15 -0.45 + -0.63 -2.5 -35.0 188dp @@ -33,9 +34,10 @@ 540dp 540dp 540dp + 470dp 564dp 144dp - 250dp + 228dp 4dp 4dp 36dp @@ -44,10 +46,9 @@ 8dp 166dp 178dp - 30dp - 36dp - 8dp - 28dp + 50dp + 70dp + 74dp 50dp 72dp 62dp diff --git a/app/src/main/res/values/non_L10n.xml b/app/src/main/res/values/non_L10n.xml index 8738d5430..4f4cd5eed 100644 --- a/app/src/main/res/values/non_L10n.xml +++ b/app/src/main/res/values/non_L10n.xml @@ -83,7 +83,7 @@ 一聲 空格 選定 - ㄅㄆㄇ + 注音 次変換 空白 diff --git a/app/src/main/res/xml/keyboard_numeric.xml b/app/src/main/res/xml/keyboard_numeric.xml index a2f9eaae5..546567c0d 100644 --- a/app/src/main/res/xml/keyboard_numeric.xml +++ b/app/src/main/res/xml/keyboard_numeric.xml @@ -5,10 +5,9 @@ android:keyWidth="@dimen/keyboard_key_width" android:keyHeight="@dimen/keyboard_key_height"> - - - - + + + @@ -16,9 +15,9 @@ - - - + + + diff --git a/app/src/main/res/xml/keyboard_zhuyin.xml b/app/src/main/res/xml/keyboard_qwerty_zhuyin.xml similarity index 84% rename from app/src/main/res/xml/keyboard_zhuyin.xml rename to app/src/main/res/xml/keyboard_qwerty_zhuyin.xml index 62cf21eb4..443cd3f40 100644 --- a/app/src/main/res/xml/keyboard_zhuyin.xml +++ b/app/src/main/res/xml/keyboard_qwerty_zhuyin.xml @@ -3,8 +3,7 @@ android:horizontalGap="@dimen/keyboard_horizontal_gap" android:verticalGap="@dimen/keyboard_vertical_gap" android:keyWidth="@dimen/keyboard_key_width" - android:keyHeight="@dimen/keyboard_key_height" - android:layout_height="@dimen/keyboard_zhuyin_height"> + android:keyHeight="@dimen/keyboard_key_height"> @@ -17,10 +16,10 @@ - + - + @@ -30,11 +29,12 @@ - + - + + @@ -44,12 +44,11 @@ - + - - + diff --git a/app/src/main/res/xml/keyboard_symbols_zhuyin.xml b/app/src/main/res/xml/keyboard_symbols_zhuyin.xml new file mode 100644 index 000000000..2fec589ba --- /dev/null +++ b/app/src/main/res/xml/keyboard_symbols_zhuyin.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +