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
This commit is contained in:
Tadashi G. Takaoka 2011-06-21 16:00:58 +09:00
parent 05c0fc6136
commit 35f20916e5
7 changed files with 54 additions and 15 deletions

View file

@ -289,6 +289,8 @@
<string name="subtype_mode_sr_keyboard">Serbian Keyboard</string> <string name="subtype_mode_sr_keyboard">Serbian Keyboard</string>
<!-- Description for Swedish keyboard subtype [CHAR LIMIT=35] --> <!-- Description for Swedish keyboard subtype [CHAR LIMIT=35] -->
<string name="subtype_mode_sv_keyboard">Swedish Keyboard</string> <string name="subtype_mode_sv_keyboard">Swedish Keyboard</string>
<!-- Description for Turkish keyboard subtype [CHAR LIMIT=35] -->
<string name="subtype_mode_tr_keyboard">Turkish Keyboard</string>
<!-- Description for Afrikaans voice input subtype [CHAR LIMIT=35] --> <!-- Description for Afrikaans voice input subtype [CHAR LIMIT=35] -->
<string name="subtype_mode_af_voice">Afrikaans Voice</string> <string name="subtype_mode_af_voice">Afrikaans Voice</string>
<!-- Description for Czech voice input subtype [CHAR LIMIT=35] --> <!-- Description for Czech voice input subtype [CHAR LIMIT=35] -->

View file

@ -0,0 +1,27 @@
<?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"
latin:keyboardLocale="tr"
>
<include
latin:keyboardLayout="@xml/kbd_rows_qwerty" />
</Keyboard>

View file

@ -20,7 +20,7 @@
<!-- The attributes in this XML file provide configuration information --> <!-- The attributes in this XML file provide configuration information -->
<!-- for the Input Method Manager. --> <!-- for the Input Method Manager. -->
<!-- Keyboard: en_US, en_GB, ar, cs, da, de, es, es_US, fi, fr, fr_CA, fr_CH, hr, hu, it, iw, nb, nl, pl, pt, ru, sr, sv --> <!-- Keyboard: en_US, en_GB, ar, cs, da, de, es, es_US, fi, fr, fr_CA, fr_CH, hr, hu, it, iw, nb, nl, pl, pt, ru, sr, sv, tr -->
<!-- Voice: af, cs, da, de, en, es, fr, it, ja, ko, nl, pl, pt, ru, tr, yue, zh, zu --> <!-- Voice: af, cs, da, de, en, es, fr, it, ja, ko, nl, pl, pt, ru, tr, yue, zh, zu -->
<!-- TODO: use <lang>_keyboard icon instead of a common keyboard icon. --> <!-- TODO: use <lang>_keyboard icon instead of a common keyboard icon. -->
<!-- TODO: use <lang>_mic icon instead of a common mic icon. --> <!-- TODO: use <lang>_mic icon instead of a common mic icon. -->
@ -185,6 +185,11 @@
android:imeSubtypeLocale="sv" android:imeSubtypeLocale="sv"
android:imeSubtypeMode="keyboard" android:imeSubtypeMode="keyboard"
/> />
<subtype android:icon="@drawable/ic_subtype_keyboard"
android:label="@string/subtype_mode_tr_keyboard"
android:imeSubtypeLocale="tr"
android:imeSubtypeMode="keyboard"
/>
<!-- <subtype android:icon="@drawable/ic_subtype_mic" --> <!-- <subtype android:icon="@drawable/ic_subtype_mic" -->
<!-- android:label="@string/subtype_mode_af_voice" --> <!-- android:label="@string/subtype_mode_af_voice" -->
<!-- android:imeSubtypeLocale="af" --> <!-- android:imeSubtypeLocale="af" -->

View file

@ -120,7 +120,7 @@ public class LatinKeyboardView extends KeyboardView {
&& keyboard.isShiftedOrShiftLocked() && keyboard.isShiftedOrShiftLocked()
&& !TextUtils.isEmpty(label) && label.length() < 3 && !TextUtils.isEmpty(label) && label.length() < 3
&& Character.isLowerCase(label.charAt(0))) { && Character.isLowerCase(label.charAt(0))) {
return label.toString().toUpperCase(); return label.toString().toUpperCase(keyboard.mId.mLocale);
} }
return label; return label;
} }

View file

@ -1274,7 +1274,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
clearSuggestions(); clearSuggestions();
} }
} }
KeyboardSwitcher switcher = mKeyboardSwitcher; final KeyboardSwitcher switcher = mKeyboardSwitcher;
if (switcher.isShiftedOrShiftLocked()) { if (switcher.isShiftedOrShiftLocked()) {
if (keyCodes == null || keyCodes[0] < Character.MIN_CODE_POINT if (keyCodes == null || keyCodes[0] < Character.MIN_CODE_POINT
|| keyCodes[0] > Character.MAX_CODE_POINT) { || keyCodes[0] > Character.MAX_CODE_POINT) {
@ -1282,13 +1282,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
code = keyCodes[0]; code = keyCodes[0];
if (switcher.isAlphabetMode() && Character.isLowerCase(code)) { if (switcher.isAlphabetMode() && Character.isLowerCase(code)) {
int upperCaseCode = Character.toUpperCase(code); // In some locales, such as Turkish, Character.toUpperCase() may return a wrong
if (upperCaseCode != code) { // character because it doesn't take care of locale.
code = upperCaseCode; 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 { } else {
// Some keys, such as [eszett], have upper case as multi-characters. // Some keys, such as [eszett], have upper case as multi-characters.
String upperCase = new String(new int[] {code}, 0, 1).toUpperCase(); onTextInput(upperCaseString);
onTextInput(upperCase);
return; return;
} }
} }

View file

@ -577,30 +577,30 @@ public class SubtypeSwitcher {
public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) { public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) {
if (returnsNameInThisLocale) { if (returnsNameInThisLocale) {
return toTitleCase(SubtypeLocale.getFullDisplayName(locale)); return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale);
} else { } else {
return toTitleCase(locale.getDisplayName()); return toTitleCase(locale.getDisplayName(), locale);
} }
} }
public static String getDisplayLanguage(Locale locale) { public static String getDisplayLanguage(Locale locale) {
return toTitleCase(SubtypeLocale.getFullDisplayName(locale)); return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale);
} }
public static String getMiddleDisplayLanguage(Locale locale) { public static String getMiddleDisplayLanguage(Locale locale) {
return toTitleCase((Utils.constructLocaleFromString( return toTitleCase((Utils.constructLocaleFromString(
locale.getLanguage()).getDisplayLanguage(locale))); locale.getLanguage()).getDisplayLanguage(locale)), locale);
} }
public static String getShortDisplayLanguage(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) { if (s.length() == 0) {
return s; return s;
} }
return Character.toUpperCase(s.charAt(0)) + s.substring(1); return s.toUpperCase(locale).charAt(0) + s.substring(1);
} }
public String getInputLanguageName() { public String getInputLanguageName() {

View file

@ -250,6 +250,7 @@ public class Suggest implements Dictionary.WordCallback {
poolSize > 0 ? (StringBuilder) mStringPool.remove(poolSize - 1) poolSize > 0 ? (StringBuilder) mStringPool.remove(poolSize - 1)
: new StringBuilder(getApproxMaxWordLength()); : new StringBuilder(getApproxMaxWordLength());
sb.setLength(0); sb.setLength(0);
// TODO: Must pay attention to locale when changing case.
if (all) { if (all) {
sb.append(word.toString().toUpperCase()); sb.append(word.toString().toUpperCase());
} else if (first) { } else if (first) {
@ -315,6 +316,7 @@ public class Suggest implements Dictionary.WordCallback {
} else { } else {
// Word entered: return only bigrams that match the first char of the typed word // Word entered: return only bigrams that match the first char of the typed word
final char currentChar = typedWord.charAt(0); final char currentChar = typedWord.charAt(0);
// TODO: Must pay attention to locale when changing case.
final char currentCharUpper = Character.toUpperCase(currentChar); final char currentCharUpper = Character.toUpperCase(currentChar);
int count = 0; int count = 0;
final int bigramSuggestionSize = mBigramSuggestions.size(); final int bigramSuggestionSize = mBigramSuggestions.size();
@ -518,6 +520,7 @@ public class Suggest implements Dictionary.WordCallback {
StringBuilder sb = poolSize > 0 ? (StringBuilder) mStringPool.remove(poolSize - 1) StringBuilder sb = poolSize > 0 ? (StringBuilder) mStringPool.remove(poolSize - 1)
: new StringBuilder(getApproxMaxWordLength()); : new StringBuilder(getApproxMaxWordLength());
sb.setLength(0); sb.setLength(0);
// TODO: Must pay attention to locale when changing case.
if (mIsAllUpperCase) { if (mIsAllUpperCase) {
sb.append(new String(word, offset, length).toUpperCase()); sb.append(new String(word, offset, length).toUpperCase());
} else if (mIsFirstCharCapitalized) { } else if (mIsFirstCharCapitalized) {