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

Commit 920f68e

Browse files
committed
Support Emoji symbols in Zhuyin keyboard.
1 parent 8c6f3ce commit 920f68e

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@
2424
import androidx.annotation.NonNull;
2525
import androidx.annotation.Nullable;
2626

27+
import jp.co.omronsoft.openwnn.ComposingText;
28+
import jp.co.omronsoft.openwnn.SymbolList;
29+
import jp.co.omronsoft.openwnn.WnnWord;
30+
2731
public class ChineseZhuyinKeyboard extends BaseKeyboard {
2832
private static final String LOGTAG = SystemUtils.createLogtag(ChineseZhuyinKeyboard.class);
2933
private static final String nonZhuyinReg = "[^ㄅ-ㄩ˙ˊˇˋˉ]";
3034
private CustomKeyboard mKeyboard;
35+
private CustomKeyboard mSymbolsKeyboard;
36+
private SymbolList mSymbolsConverter; // For Emoji characters.
37+
private List<Words> mEmojiList = null;
3138
private DBWordHelper mWordDB;
3239
private DBPhraseHelper mPhraseDB;
3340
private HashMap<String, KeyMap> mKeymaps = new HashMap<>();
@@ -50,6 +57,17 @@ public CustomKeyboard getAlphabeticKeyboard() {
5057
return mKeyboard;
5158
}
5259

60+
@Nullable
61+
@Override
62+
public CustomKeyboard getSymbolsKeyboard() {
63+
if (mSymbolsKeyboard == null) {
64+
mSymbolsKeyboard = new CustomKeyboard(mContext.getApplicationContext(), R.xml.keyboard_symbols_zhuyin);
65+
// We use openwnn to provide us Emoji character although we are not using JPN keyboard.
66+
mSymbolsConverter = new SymbolList(mContext, SymbolList.LANG_JA);
67+
}
68+
return mSymbolsKeyboard;
69+
}
70+
5371
@Nullable
5472
@Override
5573
public CandidatesResult getCandidates(String aComposingText) {
@@ -93,6 +111,31 @@ public CandidatesResult getCandidates(String aComposingText) {
93111
return result;
94112
}
95113

114+
@Override
115+
public CandidatesResult getEmojiCandidates(String aComposingText) {
116+
if (mEmojiList == null) {
117+
List<Words> words = new ArrayList<>();
118+
ComposingText text = new ComposingText();
119+
mSymbolsConverter.convert(text);
120+
121+
int candidates = mSymbolsConverter.predict(text, 0, -1);
122+
if (candidates > 0) {
123+
WnnWord word;
124+
while ((word = mSymbolsConverter.getNextCandidate()) != null) {
125+
words.add(new Words(1, word.stroke, word.candidate));
126+
}
127+
mEmojiList = words;
128+
}
129+
}
130+
131+
CandidatesResult result = new CandidatesResult();
132+
result.words = mEmojiList;
133+
result.action = CandidatesResult.Action.SHOW_CANDIDATES;
134+
result.composing = aComposingText;
135+
136+
return result;
137+
}
138+
96139
private String GetTransCode(String aText) {
97140
String code = aText;
98141
String transCode = "";
@@ -114,6 +157,14 @@ public String getComposingText(String aComposing, String aCode) {
114157
return aComposing.replaceFirst(Pattern.quote(aCode), "");
115158
}
116159

160+
if (mEmojiList != null) {
161+
for (Words word : mEmojiList) {
162+
if (word.code.equals(aCode)) {
163+
return "";
164+
}
165+
}
166+
}
167+
117168
for (int i = 0; i <= aCode.length() - shift; i += shift) {
118169
sub = aCode.substring(i, i + shift);
119170

0 commit comments

Comments
 (0)