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

Commit

Permalink
Adjusting zh-tw keyboard layout. (#2801)
Browse files Browse the repository at this point in the history
* Adjust zh-tw IME layout.

* Support Emoji symbols in Zhuyin keyboard.

* Adjust numeric keyboard layout.

* Making space bar be blank for Zhuyin input.
  • Loading branch information
daoshengmu authored Mar 23, 2020
1 parent d6079e9 commit 09d76ae
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Words> mEmojiList = null;
private DBWordHelper mWordDB;
private DBPhraseHelper mPhraseDB;
private HashMap<String, KeyMap> mKeymaps = new HashMap<>();
Expand All @@ -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) {
Expand Down Expand Up @@ -93,6 +111,31 @@ public CandidatesResult getCandidates(String aComposingText) {
return result;
}

@Override
public CandidatesResult getEmojiCandidates(String aComposingText) {
if (mEmojiList == null) {
List<Words> 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 = "";
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/res/values/dimen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<item name="keyboard_world_width" format="float" type="dimen">3.25</item>
<item name="keyboard_x" format="float" type="dimen">-0.15</item>
<item name="keyboard_y" format="float" type="dimen">-0.45</item>
<item name="zhuyin_keyboard_y" format="float" type="dimen">-0.63</item>
<item name="keyboard_z" format="float" type="dimen">-2.5</item>
<item name="keyboard_world_rotation" format="float" type="dimen">-35.0</item>
<dimen name="keyboard_height">188dp</dimen>
Expand All @@ -33,9 +34,10 @@
<dimen name="keyboard_alphabetic_width_norwegian">540dp</dimen>
<dimen name="keyboard_alphabetic_width_swedish">540dp</dimen>
<dimen name="keyboard_alphabetic_width_finnish">540dp</dimen>
<dimen name="keyboard_alphabetic_width_zhuyin">470dp</dimen>
<dimen name="keyboard_alphabetic_width_extra_column">564dp</dimen>
<dimen name="keyboard_numeric_width">144dp</dimen>
<dimen name="keyboard_zhuyin_height">250dp</dimen>
<dimen name="keyboard_zhuyin_height">228dp</dimen>
<dimen name="keyboard_horizontal_gap">4dp</dimen>
<dimen name="keyboard_vertical_gap">4dp</dimen>
<dimen name="keyboard_key_width">36dp</dimen>
Expand All @@ -44,10 +46,9 @@
<dimen name="keyboard_language_rounded_corner">8dp</dimen>
<dimen name="keyboard_key_space_width">166dp</dimen>
<dimen name="keyboard_key_german_space_width">178dp</dimen>
<dimen name="keyboard_key_zhuyin_space_width">30dp</dimen>
<dimen name="keyboard_key_zhuyin_space_height">36dp</dimen>
<dimen name="keyboard_key_zhuyin_space_margin">8dp</dimen>
<dimen name="keyboard_key_zhuyin_enter_margin">28dp</dimen>
<dimen name="keyboard_key_zhuyin_space_width">50dp</dimen>
<dimen name="keyboard_key_zhuyin_space_height">70dp</dimen>
<dimen name="keyboard_key_zhuyin_enter_width">74dp</dimen>
<dimen name="keyboard_key_backspace_width">50dp</dimen>
<dimen name="keyboard_key_enter_width">72dp</dimen>
<dimen name="keyboard_key_enter_width_small">62dp</dimen>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/non_L10n.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<string name="zhuyin_spacebar_selection" translatable="false">一聲</string>
<string name="zhuyin_spacebar_space" translatable="false">空格</string>
<string name="zhuyin_enter_completion" translatable="false">選定</string>
<string name="zhuyin_keyboard_mode_change" translatable="false">ㄅㄆㄇ</string>
<string name="zhuyin_keyboard_mode_change" translatable="false">注音</string>

<string name="japanese_spacebar_selection" translatable="false">次変換</string>
<string name="japanese_spacebar_space" translatable="false">空白</string>
Expand Down
13 changes: 6 additions & 7 deletions app/src/main/res/xml/keyboard_numeric.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
android:keyWidth="@dimen/keyboard_key_width"
android:keyHeight="@dimen/keyboard_key_height">
<Row>
<Key android:codes="49" android:keyLabel="1" android:keyEdgeFlags="left" android:horizontalGap="0dp"/>
<Key android:codes="50" android:keyLabel="2"/>
<Key android:codes="51" android:keyLabel="3"/>

<Key android:codes="55" android:keyLabel="7" android:keyEdgeFlags="left" android:horizontalGap="0dp"/>
<Key android:codes="56" android:keyLabel="8"/>
<Key android:codes="57" android:keyLabel="9"/>
</Row>
<Row>
<Key android:codes="52" android:keyLabel="4" android:keyEdgeFlags="left" android:horizontalGap="0dp"/>
<Key android:codes="53" android:keyLabel="5"/>
<Key android:codes="54" android:keyLabel="6"/>
</Row>
<Row>
<Key android:codes="55" android:keyLabel="7" android:keyEdgeFlags="left" android:horizontalGap="0dp"/>
<Key android:codes="56" android:keyLabel="8"/>
<Key android:codes="57" android:keyLabel="9"/>
<Key android:codes="49" android:keyLabel="1" android:keyEdgeFlags="left" android:horizontalGap="0dp"/>
<Key android:codes="50" android:keyLabel="2"/>
<Key android:codes="51" android:keyLabel="3"/>
</Row>
<Row>
<Key android:codes="35" android:keyLabel="#" android:keyEdgeFlags="left" android:horizontalGap="0dp"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<Row>
<Key android:codes="0x3105" android:keyLabel="" android:keyEdgeFlags="left"/>
<Key android:codes="0x3109" android:keyLabel=""/>
Expand All @@ -17,10 +16,10 @@
<Key android:codes="0x311E" android:keyLabel=""/>
<Key android:codes="0x3122" android:keyLabel=""/>
<Key android:codes="0x3126" android:keyLabel=""/>
<Key android:codes="-5" android:keyIcon="@drawable/ic_icon_keyboard_backspace" android:isRepeatable="true" android:keyWidth="@dimen/keyboard_key_zhuyin_space_width"/>
<Key android:codes="-5" android:keyIcon="@drawable/ic_icon_keyboard_backspace" android:keyWidth="@dimen/keyboard_key_zhuyin_space_width" android:isRepeatable="true"/>
</Row>
<Row>
<Key android:codes="0x3106" android:keyLabel="" android:horizontalGap="@dimen/keyboard_left_margin"/>
<Key android:codes="0x3106" android:keyLabel="" android:keyEdgeFlags="left" android:horizontalGap="@dimen/keyboard_left_margin"/>
<Key android:codes="0x310A" android:keyLabel=""/>
<Key android:codes="0x310D" android:keyLabel=""/>
<Key android:codes="0x3110" android:keyLabel=""/>
Expand All @@ -30,11 +29,12 @@
<Key android:codes="0x311B" android:keyLabel=""/>
<Key android:codes="0x311F" android:keyLabel=""/>
<Key android:codes="0x3123" android:keyLabel=""/>
<Key android:codes="-4" android:keyLabel="@string/keyboard_enter_label" android:keyWidth="@dimen/keyboard_key_zhuyin_space_width" android:horizontalGap="@dimen/keyboard_key_zhuyin_enter_margin" />
<Key android:codes="-4" android:keyLabel="@string/keyboard_enter_label" android:keyWidth="@dimen/keyboard_key_zhuyin_enter_width"/>
</Row>

<Row>
<Key android:codes="0x3107" android:keyLabel="" android:horizontalGap="@dimen/keyboard_left_margin_2x"/>
<Key android:codes="-2" android:keyLabel="@string/keyboard_symbol" android:keyEdgeFlags="left"/>
<Key android:codes="0x3107" android:keyLabel=""/>
<Key android:codes="0x310B" android:keyLabel=""/>
<Key android:codes="0x310E" android:keyLabel=""/>
<Key android:codes="0x3111" android:keyLabel=""/>
Expand All @@ -44,12 +44,11 @@
<Key android:codes="0x311C" android:keyLabel=""/>
<Key android:codes="0x3120" android:keyLabel=""/>
<Key android:codes="0x3124" android:keyLabel=""/>
<Key android:codes="32" android:keyLabel="" android:keyWidth="@dimen/keyboard_key_zhuyin_space_width" android:keyHeight="@dimen/keyboard_key_zhuyin_space_height" android:isRepeatable="true" android:horizontalGap="@dimen/keyboard_key_zhuyin_space_margin"/>
<Key android:codes="32" android:keyLabel="" android:keyWidth="@dimen/keyboard_key_zhuyin_space_width" android:keyHeight="@dimen/keyboard_key_zhuyin_space_height" android:isRepeatable="true"/>
</Row>

<Row>
<Key android:codes="-2" android:keyLabel="@string/keyboard_symbol" android:keyEdgeFlags="left"/>
<Key android:codes="-12" android:keyIcon="@drawable/ic_icon_keyboard_globe"/>
<Key android:codes="-12" android:keyIcon="@drawable/ic_icon_keyboard_globe" android:keyEdgeFlags="left"/>
<Key android:codes="0x3108" android:keyLabel=""/>
<Key android:codes="0x310C" android:keyLabel=""/>
<Key android:codes="0x310F" android:keyLabel=""/>
Expand Down
63 changes: 63 additions & 0 deletions app/src/main/res/xml/keyboard_symbols_zhuyin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:horizontalGap="@dimen/keyboard_horizontal_gap"
android:verticalGap="@dimen/keyboard_vertical_gap"
android:keyWidth="@dimen/keyboard_key_width"
android:keyHeight="@dimen/keyboard_key_height">
<Row>
<Key android:codes="8364" android:keyLabel="" android:keyEdgeFlags="left"/>
<Key android:codes="163" android:keyLabel="£"/>
<Key android:codes="165" android:keyLabel="¥"/>
<Key android:codes="36" android:keyLabel="$"/>
<Key android:codes="199" android:keyLabel="ç"/>
<Key android:codes="37" android:keyLabel="%"/>
<Key android:codes="38" android:keyLabel="&amp;"/>
<Key android:codes="40" android:keyLabel="("/>
<Key android:codes="41" android:keyLabel=")"/>
<Key android:codes="61" android:keyLabel="="/>
<Key android:codes="95" android:keyLabel="_"/>
<Key android:codes="-5" android:keyIcon="@drawable/ic_icon_keyboard_backspace" android:keyWidth="@dimen/keyboard_key_zhuyin_space_width" android:isRepeatable="true"/>
</Row>
<Row>
<Key android:codes="186" android:keyLabel="º" android:keyEdgeFlags="left" android:horizontalGap="@dimen/keyboard_left_margin"/>
<Key android:codes="94" android:keyLabel="^" />
<Key android:codes="0x22ef" android:keyLabel="" />
<Key android:codes="123" android:keyLabel="{"/>
<Key android:codes="125" android:keyLabel="}"/>
<Key android:codes="91" android:keyLabel="["/>
<Key android:codes="93" android:keyLabel="]"/>
<Key android:codes="124" android:keyLabel="|"/>
<Key android:codes="59" android:keyLabel=";"/>
<Key android:codes="58" android:keyLabel=":"/>
<Key android:codes="-4" android:keyLabel="@string/keyboard_enter_label" android:keyWidth="@dimen/keyboard_key_zhuyin_enter_width"/>
</Row>

<Row>
<Key android:codes="-2" android:keyLabel="@string/keyboard_symbol" android:keyEdgeFlags="left"/>
<Key android:codes="0x300a" android:keyLabel=""/>
<Key android:codes="0x300b" android:keyLabel=""/>
<Key android:codes="96" android:keyLabel="`"/>
<Key android:codes="126" android:keyLabel="~"/>
<Key android:codes="39" android:keyLabel="'"/>
<Key android:codes="34" android:keyLabel="&quot;"/>
<Key android:codes="92" android:keyLabel="\\" />
<Key android:codes="45" android:keyLabel="-" />
<Key android:codes="43" android:keyLabel="+" />
<Key android:codes="47" android:keyLabel="/" />
<Key android:codes="32" android:keyLabel="" android:keyWidth="@dimen/keyboard_key_zhuyin_space_width" android:keyHeight="@dimen/keyboard_key_zhuyin_space_height" android:isRepeatable="true"/>
</Row>

<Row>
<Key android:codes="-12" android:keyIcon="@drawable/ic_icon_keyboard_globe"/>
<Key android:codes="-13" android:keyLabel="^.^"/>
<Key android:codes="0x300C" android:keyLabel="" />
<Key android:codes="0x300D" android:keyLabel="" />
<Key android:codes="0xff64" android:keyLabel=""/>
<Key android:codes="0xff61" android:keyLabel=""/>
<Key android:codes="0xff0c" android:keyLabel=""/>
<Key android:codes="46" android:keyLabel="."/>
<Key android:codes="33" android:keyLabel="!" android:popupCharacters="" android:popupKeyboard="@xml/keyboard_popup" />
<Key android:codes="63" android:keyLabel="\?" android:popupCharacters="\?¿" android:popupKeyboard="@xml/keyboard_popup" />
<Key android:codes="64" android:keyLabel="\@"/>
</Row>
</Keyboard>

0 comments on commit 09d76ae

Please sign in to comment.