1.打开method.xml
要创建什么语言的键盘就查找对应的缩写词,这里以巴西为例修改KeyboardLayoutSet=brazil
2.attrs.xml文件supportedScript枚举项添加对应的支持
3.创建对应的键盘布局文件keyboard_layout_set_brazil.xml
keyboard_layout_set_xxxx.xml 后缀要接定义的brazil字段,需要制作自己需要的键盘布局就可以了
<KeyboardLayoutSet
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin">
<Feature
latin:supportedScript="brazil" />
<Element
latin:elementName="alphabet"
latin:elementKeyboard="@xml/kbd_brazil"
latin:enableProximityCharsCorrection="true" />
<Element
latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" />
<Element
latin:elementName="symbolsShifted"
latin:elementKeyboard="@xml/kbd_symbols_shift" />
<Element
latin:elementName="phone"
latin:elementKeyboard="@xml/kbd_phone" />
<Element
latin:elementName="phoneSymbols"
latin:elementKeyboard="@xml/kbd_phone_symbols" />
<Element
latin:elementName="number"
latin:elementKeyboard="@xml/kbd_number" />
</KeyboardLayoutSet>
4.在ScriptUtils.java文件也需要增加相应的字段,不然会报错
最后附上diff
From 5fcbfdf3a6f1780afb46d84685980f0f83fd4b38 Mon Sep 17 00:00:00 2001
From: zhouweiyang <weiyang.zhou@stellamore.cn>
Date: Sat, 15 Jun 2024 11:12:56 +0800
Subject: [PATCH] =?UTF-8?q?feat=20[LatinIME]=20LatinIME=E8=BE=93=E5=85=A5?=
=?UTF-8?q?=E6=B3=95=E5=A2=9E=E5=8A=A0=E5=B7=B4=E8=A5=BF=E9=94=AE=E7=9B=98?=
=?UTF-8?q?=E9=80=82=E9=85=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../LatinIME/java/res/values-pt-rPT/bools.xml | 24 ++++++++
.../LatinIME/java/res/values/attrs.xml | 1 +
.../LatinIME/java/res/xml/kbd_brazil.xml | 26 ++++++++
.../res/xml/keyboard_layout_set_brazil.xml | 44 ++++++++++++++
.../LatinIME/java/res/xml/method.xml | 2 +-
.../LatinIME/java/res/xml/rowkeys_brazil2.xml | 30 ++++++++++
.../java/res/xml/rowkeys_brazil2_left5.xml | 38 ++++++++++++
.../java/res/xml/rowkeys_brazil2_right4.xml | 40 +++++++++++++
.../LatinIME/java/res/xml/rows_brazil.xml | 59 +++++++++++++++++++
.../keyboard/KeyboardLayoutSet.java | 2 +
.../inputmethod/latin/utils/ScriptUtils.java | 8 +++
11 files changed, 273 insertions(+), 1 deletion(-)
create mode 100755 packages/inputmethods/LatinIME/java/res/values-pt-rPT/bools.xml
create mode 100755 packages/inputmethods/LatinIME/java/res/xml/kbd_brazil.xml
create mode 100755 packages/inputmethods/LatinIME/java/res/xml/keyboard_layout_set_brazil.xml
create mode 100755 packages/inputmethods/LatinIME/java/res/xml/rowkeys_brazil2.xml
create mode 100755 packages/inputmethods/LatinIME/java/res/xml/rowkeys_brazil2_left5.xml
create mode 100755 packages/inputmethods/LatinIME/java/res/xml/rowkeys_brazil2_right4.xml
create mode 100755 packages/inputmethods/LatinIME/java/res/xml/rows_brazil.xml
diff --git a/packages/inputmethods/LatinIME/java/res/values-pt-rPT/bools.xml b/packages/inputmethods/LatinIME/java/res/values-pt-rPT/bools.xml
new file mode 100755
index 00000000000..840d20c2187
--- /dev/null
+++ b/packages/inputmethods/LatinIME/java/res/values-pt-rPT/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+<resources>
+ <!-- Whether this input method should be used as the default for a locale. Override it
+ for supported languages. -->
+ <bool name="im_is_default">true</bool>
+</resources>
diff --git a/packages/inputmethods/LatinIME/java/res/values/attrs.xml b/packages/inputmethods/LatinIME/java/res/values/attrs.xml
index 8ff5a87cd2d..56fa9785791 100644
--- a/packages/inputmethods/LatinIME/java/res/values/attrs.xml
+++ b/packages/inputmethods/LatinIME/java/res/values/attrs.xml
@@ -591,6 +591,7 @@
<enum name="tamil" value="15" />
<enum name="telugu" value="16" />
<enum name="thai" value="17" />
+ <enum name="brazil" value="18" />
</attr>
</declare-styleable>
diff --git a/packages/inputmethods/LatinIME/java/res/xml/kbd_brazil.xml b/packages/inputmethods/LatinIME/java/res/xml/kbd_brazil.xml
new file mode 100755
index 00000000000..4d405c01b98
--- /dev/null
+++ b/packages/inputmethods/LatinIME/java/res/xml/kbd_brazil.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<Keyboard
+ xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+ <include
+ latin:keyboardLayout="@xml/rows_brazil" />
+</Keyboard>
diff --git a/packages/inputmethods/LatinIME/java/res/xml/keyboard_layout_set_brazil.xml b/packages/inputmethods/LatinIME/java/res/xml/keyboard_layout_set_brazil.xml
new file mode 100755
index 00000000000..e0eef3062b3
--- /dev/null
+++ b/packages/inputmethods/LatinIME/java/res/xml/keyboard_layout_set_brazil.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<KeyboardLayoutSet
+ xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin">
+ <Feature
+ latin:supportedScript="brazil" />
+ <Element
+ latin:elementName="alphabet"
+ latin:elementKeyboard="@xml/kbd_brazil"
+ latin:enableProximityCharsCorrection="true" />
+ <Element
+ latin:elementName="symbols"
+ latin:elementKeyboard="@xml/kbd_symbols" />
+ <Element
+ latin:elementName="symbolsShifted"
+ latin:elementKeyboard="@xml/kbd_symbols_shift" />
+ <Element
+ latin:elementName="phone"
+ latin:elementKeyboard="@xml/kbd_phone" />
+ <Element
+ latin:elementName="phoneSymbols"
+ latin:elementKeyboard="@xml/kbd_phone_symbols" />
+ <Element
+ latin:elementName="number"
+ latin:elementKeyboard="@xml/kbd_number" />
+</KeyboardLayoutSet>
diff --git a/packages/inputmethods/LatinIME/java/res/xml/method.xml b/packages/inputmethods/LatinIME/java/res/xml/method.xml
index 3ab25430715..e3a3a98717e 100644
--- a/packages/inputmethods/LatinIME/java/res/xml/method.xml
+++ b/packages/inputmethods/LatinIME/java/res/xml/method.xml
@@ -604,7 +604,7 @@
android:subtypeId="0xcafff4a6"
android:imeSubtypeLocale="pt_BR"
android:imeSubtypeMode="keyboard"
- android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
+ android:imeSubtypeExtraValue="KeyboardLayoutSet=brazil,AsciiCapable,EmojiCapable"
android:isAsciiCapable="true"
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
diff --git a/packages/inputmethods/LatinIME/java/res/xml/rowkeys_brazil2.xml b/packages/inputmethods/LatinIME/java/res/xml/rowkeys_brazil2.xml
new file mode 100755
index 00000000000..fc18e830232
--- /dev/null
+++ b/packages/inputmethods/LatinIME/java/res/xml/rowkeys_brazil2.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<merge
+ xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+ <!-- a,s,d,f,g -->
+ <include
+ latin:keyboardLayout="@xml/rowkeys_brazil2_left5" />
+ <!-- h,j,k,l -->
+ <include
+ latin:keyboardLayout="@xml/rowkeys_brazil2_right4" />
+</merge>
diff --git a/packages/inputmethods/LatinIME/java/res/xml/rowkeys_brazil2_left5.xml b/packages/inputmethods/LatinIME/java/res/xml/rowkeys_brazil2_left5.xml
new file mode 100755
index 00000000000..1803bf203e2
--- /dev/null
+++ b/packages/inputmethods/LatinIME/java/res/xml/rowkeys_brazil2_left5.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2014, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<merge
+ xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+ <Key
+ latin:keySpec="a"
+ latin:moreKeys="!text/morekeys_a" />
+ <Key
+ latin:keySpec="s"
+ latin:moreKeys="!text/morekeys_s" />
+ <Key
+ latin:keySpec="d"
+ latin:moreKeys="!text/morekeys_d" />
+ <Key
+ latin:keySpec="f" />
+ <Key
+ latin:keySpec="g"
+ latin:moreKeys="!text/morekeys_g" />
+</merge>
diff --git a/packages/inputmethods/LatinIME/java/res/xml/rowkeys_brazil2_right4.xml b/packages/inputmethods/LatinIME/java/res/xml/rowkeys_brazil2_right4.xml
new file mode 100755
index 00000000000..732ec9b7aac
--- /dev/null
+++ b/packages/inputmethods/LatinIME/java/res/xml/rowkeys_brazil2_right4.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2014, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<merge
+ xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+ <Key
+ latin:keySpec="h"
+ latin:moreKeys="!text/morekeys_h" />
+ <Key
+ latin:keySpec="j"
+ latin:moreKeys="!text/morekeys_j" />
+ <Key
+ latin:keySpec="k"
+ latin:moreKeys="!text/morekeys_k" />
+ <Key
+ latin:keySpec="l"
+ latin:moreKeys="!text/morekeys_l" />
+
+ <!-- U+00BF: "รง" INVERTED QUESTION MARK -->
+ <Key
+ latin:keySpec="ç" />
+</merge>
diff --git a/packages/inputmethods/LatinIME/java/res/xml/rows_brazil.xml b/packages/inputmethods/LatinIME/java/res/xml/rows_brazil.xml
new file mode 100755
index 00000000000..efb85c88cda
--- /dev/null
+++ b/packages/inputmethods/LatinIME/java/res/xml/rows_brazil.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2010, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<merge
+ xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+ <include
+ latin:keyboardLayout="@xml/key_styles_common" />
+ <Row
+ latin:keyWidth="10%p"
+ >
+ <include
+ latin:keyboardLayout="@xml/rowkeys_qwerty1" />
+ </Row>
+ <Row
+ latin:keyWidth="9.0%p"
+ >
+ <include
+ latin:keyboardLayout="@xml/rowkeys_brazil2"
+ />
+ <!--latin:keyXPos="5%p"-->
+ <Key
+ latin:keyStyle="enterKeyStyle"
+ latin:keyWidth="9.0%p" />
+ </Row>
+ <Row
+ latin:keyWidth="10%p"
+ >
+ <Key
+ latin:keyStyle="shiftKeyStyle"
+ latin:keyWidth="15%p"
+ latin:visualInsetsRight="1%p" />
+ <include
+ latin:keyboardLayout="@xml/rowkeys_qwerty3" />
+ <Key
+ latin:keyStyle="deleteKeyStyle"
+ latin:keyWidth="fillRight"
+ latin:visualInsetsLeft="1%p" />
+ </Row>
+ <include
+ latin:keyboardLayout="@xml/row_qwerty4" />
+</merge>
diff --git a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
index 26ff051bb47..c6999d9c765 100644
--- a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
+++ b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
@@ -393,11 +393,13 @@ public final class KeyboardLayoutSet {
private static int getXmlId(final Resources resources, final String keyboardLayoutSetName) {
final String packageName = resources.getResourcePackageName(
R.xml.keyboard_layout_set_qwerty);
+ Log.d(TAG, "zwycode: keyboardLayoutSetName="+keyboardLayoutSetName+"---packageName="+packageName);
return resources.getIdentifier(keyboardLayoutSetName, "xml", packageName);
}
private void parseKeyboardLayoutSet(final Resources res, final int resId)
throws XmlPullParserException, IOException {
+ Log.d(TAG, "zwycode: resId="+resId);
final XmlResourceParser parser = res.getXml(resId);
try {
while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
diff --git a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/utils/ScriptUtils.java b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/utils/ScriptUtils.java
index 537713091a4..494b8874b7d 100644
--- a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/utils/ScriptUtils.java
+++ b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/utils/ScriptUtils.java
@@ -16,6 +16,8 @@
package com.android.inputmethod.latin.utils;
+import android.util.Log;
+
import java.util.Locale;
import java.util.TreeMap;
@@ -45,6 +47,7 @@ public class ScriptUtils {
public static final int SCRIPT_TAMIL = 15;
public static final int SCRIPT_TELUGU = 16;
public static final int SCRIPT_THAI = 17;
+ public static final int SCRIPT_HRAZIL = 18;
private static final TreeMap<String, Integer> mLanguageCodeToScriptCode;
@@ -68,6 +71,7 @@ public class ScriptUtils {
mLanguageCodeToScriptCode.put("ta", SCRIPT_TAMIL);
mLanguageCodeToScriptCode.put("te", SCRIPT_TELUGU);
mLanguageCodeToScriptCode.put("th", SCRIPT_THAI);
+ mLanguageCodeToScriptCode.put("pt", SCRIPT_HRAZIL);
}
/*
@@ -79,6 +83,7 @@ public class ScriptUtils {
* as appropriate, and explicitly excludes CJK, Arabic and Hebrew characters.
*/
public static boolean isLetterPartOfScript(final int codePoint, final int scriptId) {
+ Log.d("zwycode", "isLetterPartOfScript: codePoint="+codePoint+"---scriptId="+scriptId);
switch (scriptId) {
case SCRIPT_ARABIC:
// Arabic letters can be in any of the following blocks:
@@ -170,6 +175,9 @@ public class ScriptUtils {
case SCRIPT_THAI:
// Thai unicode block is U+0E00..U+0E7F
return (codePoint >= 0xE00 && codePoint <= 0xE7F);
+ case SCRIPT_HRAZIL:
+ // Thai unicode block is U+0E00..U+0E7F
+ return true;
case SCRIPT_UNKNOWN:
return true;
default:
--
2.34.1