From 35f20916e5348d7fa485ba8eb0a5cf2e67f4f354 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 21 Jun 2011 16:00:58 +0900 Subject: [PATCH] Support Turkish keyboard I left TODOs in Suggest.java because we must pay attention to locale when changing character's case. Filed another Bug: 4769095 to track that. Bug: 4768050 Change-Id: I1ae2c4ffd2208403a8c2a25dd3a56b71dcefc826 --- java/res/values/strings.xml | 2 ++ java/res/xml-tr/kbd_qwerty.xml | 27 +++++++++++++++++++ java/res/xml/method.xml | 7 ++++- .../keyboard/LatinKeyboardView.java | 2 +- .../android/inputmethod/latin/LatinIME.java | 14 +++++----- .../inputmethod/latin/SubtypeSwitcher.java | 14 +++++----- .../android/inputmethod/latin/Suggest.java | 3 +++ 7 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 java/res/xml-tr/kbd_qwerty.xml diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index 93da13756..465d0fdbd 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -289,6 +289,8 @@ Serbian Keyboard Swedish Keyboard + + Turkish Keyboard Afrikaans Voice diff --git a/java/res/xml-tr/kbd_qwerty.xml b/java/res/xml-tr/kbd_qwerty.xml new file mode 100644 index 000000000..d2c38f60a --- /dev/null +++ b/java/res/xml-tr/kbd_qwerty.xml @@ -0,0 +1,27 @@ + + + + + + diff --git a/java/res/xml/method.xml b/java/res/xml/method.xml index 9c416170d..59b5b9d3f 100644 --- a/java/res/xml/method.xml +++ b/java/res/xml/method.xml @@ -20,7 +20,7 @@ - + @@ -185,6 +185,11 @@ android:imeSubtypeLocale="sv" android:imeSubtypeMode="keyboard" /> + diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 185f1f8f7..901df6ab7 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -120,7 +120,7 @@ public class LatinKeyboardView extends KeyboardView { && keyboard.isShiftedOrShiftLocked() && !TextUtils.isEmpty(label) && label.length() < 3 && Character.isLowerCase(label.charAt(0))) { - return label.toString().toUpperCase(); + return label.toString().toUpperCase(keyboard.mId.mLocale); } return label; } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index dd97db34e..1645b1678 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1274,7 +1274,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar clearSuggestions(); } } - KeyboardSwitcher switcher = mKeyboardSwitcher; + final KeyboardSwitcher switcher = mKeyboardSwitcher; if (switcher.isShiftedOrShiftLocked()) { if (keyCodes == null || keyCodes[0] < Character.MIN_CODE_POINT || keyCodes[0] > Character.MAX_CODE_POINT) { @@ -1282,13 +1282,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } code = keyCodes[0]; if (switcher.isAlphabetMode() && Character.isLowerCase(code)) { - int upperCaseCode = Character.toUpperCase(code); - if (upperCaseCode != code) { - code = upperCaseCode; + // In some locales, such as Turkish, Character.toUpperCase() may return a wrong + // character because it doesn't take care of locale. + final String upperCaseString = new String(new int[] {code}, 0, 1) + .toUpperCase(mSubtypeSwitcher.getInputLocale()); + if (upperCaseString.codePointCount(0, upperCaseString.length()) == 1) { + code = upperCaseString.codePointAt(0); } else { // Some keys, such as [eszett], have upper case as multi-characters. - String upperCase = new String(new int[] {code}, 0, 1).toUpperCase(); - onTextInput(upperCase); + onTextInput(upperCaseString); return; } } diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 8b51af880..6ca12c0c5 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -577,30 +577,30 @@ public class SubtypeSwitcher { public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) { if (returnsNameInThisLocale) { - return toTitleCase(SubtypeLocale.getFullDisplayName(locale)); + return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); } else { - return toTitleCase(locale.getDisplayName()); + return toTitleCase(locale.getDisplayName(), locale); } } public static String getDisplayLanguage(Locale locale) { - return toTitleCase(SubtypeLocale.getFullDisplayName(locale)); + return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); } public static String getMiddleDisplayLanguage(Locale locale) { return toTitleCase((Utils.constructLocaleFromString( - locale.getLanguage()).getDisplayLanguage(locale))); + locale.getLanguage()).getDisplayLanguage(locale)), locale); } public static String getShortDisplayLanguage(Locale locale) { - return toTitleCase(locale.getLanguage()); + return toTitleCase(locale.getLanguage(), locale); } - private static String toTitleCase(String s) { + private static String toTitleCase(String s, Locale locale) { if (s.length() == 0) { return s; } - return Character.toUpperCase(s.charAt(0)) + s.substring(1); + return s.toUpperCase(locale).charAt(0) + s.substring(1); } public String getInputLanguageName() { diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index d01e3e9c2..eb5ed5a65 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -250,6 +250,7 @@ public class Suggest implements Dictionary.WordCallback { poolSize > 0 ? (StringBuilder) mStringPool.remove(poolSize - 1) : new StringBuilder(getApproxMaxWordLength()); sb.setLength(0); + // TODO: Must pay attention to locale when changing case. if (all) { sb.append(word.toString().toUpperCase()); } else if (first) { @@ -315,6 +316,7 @@ public class Suggest implements Dictionary.WordCallback { } else { // Word entered: return only bigrams that match the first char of the typed word final char currentChar = typedWord.charAt(0); + // TODO: Must pay attention to locale when changing case. final char currentCharUpper = Character.toUpperCase(currentChar); int count = 0; final int bigramSuggestionSize = mBigramSuggestions.size(); @@ -518,6 +520,7 @@ public class Suggest implements Dictionary.WordCallback { StringBuilder sb = poolSize > 0 ? (StringBuilder) mStringPool.remove(poolSize - 1) : new StringBuilder(getApproxMaxWordLength()); sb.setLength(0); + // TODO: Must pay attention to locale when changing case. if (mIsAllUpperCase) { sb.append(new String(word, offset, length).toUpperCase()); } else if (mIsFirstCharCapitalized) {