Support Turkish keyboard (DO NOT MERGE)
Basically this change is back port from Master I1ae2c4ff. Bug: 4435347 Change-Id: Ide1a46bbf5584d8783bb93bbe64328f514c6ab79
This commit is contained in:
parent
f5e20452ea
commit
52fbad8875
8 changed files with 71 additions and 50 deletions
|
@ -18,14 +18,14 @@
|
|||
*/
|
||||
-->
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<string name="alternates_for_a">àáâãäåæ</string>
|
||||
<string name="alternates_for_e">3èéêë</string>
|
||||
<string name="alternates_for_i">ìíîï8</string>
|
||||
<string name="alternates_for_o">öòóôõœø9</string>
|
||||
<string name="alternates_for_u">üùúû7</string>
|
||||
<string name="alternates_for_s">ş§ß</string>
|
||||
<string name="alternates_for_n">ñ</string>
|
||||
<string name="alternates_for_c">ç</string>
|
||||
<string name="alternates_for_y">ýÿ6</string>
|
||||
<string name="alternates_for_a">â</string>
|
||||
<string name="alternates_for_e">3</string>
|
||||
<string name="alternates_for_i">īįíìïîı8</string>
|
||||
<string name="alternates_for_o">ōøõóòœôö9</string>
|
||||
<string name="alternates_for_u">ūúùûü7</string>
|
||||
<string name="alternates_for_s">śşßš</string>
|
||||
<string name="alternates_for_n"></string>
|
||||
<string name="alternates_for_c">čćç</string>
|
||||
<string name="alternates_for_y">6</string>
|
||||
<string name="alternates_for_g">ğ</string>
|
||||
</resources>
|
|
@ -16,11 +16,6 @@
|
|||
|
||||
package com.android.inputmethod.latin;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.res.Configuration;
|
||||
|
@ -32,13 +27,19 @@ import android.preference.PreferenceGroup;
|
|||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
public class InputLanguageSelection extends PreferenceActivity {
|
||||
|
||||
private String mSelectedLanguages;
|
||||
private ArrayList<Loc> mAvailableLanguages = new ArrayList<Loc>();
|
||||
|
||||
private static final String[] WHITELIST_LANGUAGES = {
|
||||
"cs", "da", "de", "en_GB", "en_US", "es", "es_US", "fr", "it", "nb", "nl", "pl", "pt", "ru"
|
||||
"cs", "da", "de", "en_GB", "en_US", "es", "es_US", "fr", "it", "nb", "nl", "pl", "pt",
|
||||
"ru", "tr",
|
||||
};
|
||||
|
||||
private static boolean isWhitelisted(String lang) {
|
||||
|
@ -84,7 +85,7 @@ public class InputLanguageSelection extends PreferenceActivity {
|
|||
for (int i = 0; i < mAvailableLanguages.size(); i++) {
|
||||
CheckBoxPreference pref = new CheckBoxPreference(this);
|
||||
Locale locale = mAvailableLanguages.get(i).locale;
|
||||
pref.setTitle(LanguageSwitcher.toTitleCase(locale.getDisplayName(locale)));
|
||||
pref.setTitle(LanguageSwitcher.toTitleCase(locale.getDisplayName(locale), locale));
|
||||
boolean checked = isLocaleIn(locale, languageList);
|
||||
pref.setChecked(checked);
|
||||
if (hasDictionary(locale)) {
|
||||
|
@ -184,7 +185,7 @@ public class InputLanguageSelection extends PreferenceActivity {
|
|||
|
||||
if (finalSize == 0) {
|
||||
preprocess[finalSize++] =
|
||||
new Loc(LanguageSwitcher.toTitleCase(l.getDisplayName(l)), l);
|
||||
new Loc(LanguageSwitcher.toTitleCase(l.getDisplayName(l), l), l);
|
||||
} else {
|
||||
// check previous entry:
|
||||
// same lang and a country -> upgrade to full name and
|
||||
|
@ -193,14 +194,15 @@ public class InputLanguageSelection extends PreferenceActivity {
|
|||
if (preprocess[finalSize-1].locale.getLanguage().equals(
|
||||
language)) {
|
||||
preprocess[finalSize-1].label = LanguageSwitcher.toTitleCase(
|
||||
preprocess[finalSize-1].locale.getDisplayName());
|
||||
preprocess[finalSize-1].locale.getDisplayName(),
|
||||
preprocess[finalSize-1].locale);
|
||||
preprocess[finalSize++] =
|
||||
new Loc(LanguageSwitcher.toTitleCase(l.getDisplayName()), l);
|
||||
new Loc(LanguageSwitcher.toTitleCase(l.getDisplayName(), l), l);
|
||||
} else {
|
||||
String displayName;
|
||||
if (s.equals("zz_ZZ")) {
|
||||
} else {
|
||||
displayName = LanguageSwitcher.toTitleCase(l.getDisplayName(l));
|
||||
displayName = LanguageSwitcher.toTitleCase(l.getDisplayName(l), l);
|
||||
preprocess[finalSize++] = new Loc(displayName, l);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
|
||||
package com.android.inputmethod.latin;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Keeps track of list of selected input languages and the current
|
||||
* input language that the user has selected.
|
||||
|
@ -191,11 +191,11 @@ public class LanguageSwitcher {
|
|||
SharedPreferencesCompat.apply(editor);
|
||||
}
|
||||
|
||||
static String toTitleCase(String s) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,13 +16,6 @@
|
|||
|
||||
package com.android.inputmethod.latin;
|
||||
|
||||
import com.android.inputmethod.latin.LatinIMEUtil.RingCharBuffer;
|
||||
import com.android.inputmethod.voice.FieldContext;
|
||||
import com.android.inputmethod.voice.SettingsUtil;
|
||||
import com.android.inputmethod.voice.VoiceInput;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
|
@ -65,6 +58,13 @@ import android.view.inputmethod.InputConnection;
|
|||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.inputmethod.latin.LatinIMEUtil.RingCharBuffer;
|
||||
import com.android.inputmethod.voice.FieldContext;
|
||||
import com.android.inputmethod.voice.SettingsUtil;
|
||||
import com.android.inputmethod.voice.VoiceInput;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
@ -1413,13 +1413,15 @@ public class LatinIME extends InputMethodService
|
|||
}
|
||||
primaryCode = keyCodes[0];
|
||||
if (mKeyboardSwitcher.isAlphabetMode() && Character.isLowerCase(primaryCode)) {
|
||||
int upperCaseCode = Character.toUpperCase(primaryCode);
|
||||
if (upperCaseCode != primaryCode) {
|
||||
primaryCode = 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[] {primaryCode}, 0, 1)
|
||||
.toUpperCase(mLanguageSwitcher.getInputLocale());
|
||||
if (upperCaseString.codePointCount(0, upperCaseString.length()) == 1) {
|
||||
primaryCode = upperCaseString.codePointAt(0);
|
||||
} else {
|
||||
// Some keys, such as [eszett], have upper case as multi-characters.
|
||||
String upperCase = new String(new int[] {primaryCode}, 0, 1).toUpperCase();
|
||||
onText(upperCase);
|
||||
onText(upperCaseString);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1983,13 +1985,14 @@ public class LatinIME extends InputMethodService
|
|||
* word.
|
||||
*/
|
||||
private void pickSuggestion(CharSequence suggestion, boolean correcting) {
|
||||
LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
|
||||
final LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
|
||||
final Locale inputLocale = mLanguageSwitcher.getInputLocale();
|
||||
if (mCapsLock) {
|
||||
suggestion = suggestion.toString().toUpperCase();
|
||||
suggestion = suggestion.toString().toUpperCase(inputLocale);
|
||||
} else if (preferCapitalization()
|
||||
|| (mKeyboardSwitcher.isAlphabetMode()
|
||||
&& inputView.isShifted())) {
|
||||
suggestion = suggestion.toString().toUpperCase().charAt(0)
|
||||
suggestion = suggestion.toString().toUpperCase(inputLocale).charAt(0)
|
||||
+ suggestion.subSequence(1, suggestion.length()).toString();
|
||||
}
|
||||
InputConnection ic = getCurrentInputConnection();
|
||||
|
@ -2026,9 +2029,10 @@ public class LatinIME extends InputMethodService
|
|||
// If the first letter of touching is capitalized, make all the suggestions
|
||||
// start with a capital letter.
|
||||
if (Character.isUpperCase(touching.word.charAt(0))) {
|
||||
final Locale inputLocale = mLanguageSwitcher.getInputLocale();
|
||||
for (int i = 0; i < suggestions.size(); i++) {
|
||||
String origSugg = (String) suggestions.get(i);
|
||||
String capsSugg = origSugg.toUpperCase().charAt(0)
|
||||
String capsSugg = origSugg.toUpperCase(inputLocale).charAt(0)
|
||||
+ origSugg.subSequence(1, origSugg.length()).toString();
|
||||
suggestions.set(i, capsSugg);
|
||||
}
|
||||
|
|
|
@ -513,7 +513,7 @@ public class LatinKeyboard extends Keyboard {
|
|||
final Rect bounds = new Rect();
|
||||
|
||||
// Estimate appropriate language name text size to fit in maxTextWidth.
|
||||
String language = LanguageSwitcher.toTitleCase(locale.getDisplayLanguage(locale));
|
||||
String language = LanguageSwitcher.toTitleCase(locale.getDisplayLanguage(locale), locale);
|
||||
int textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
||||
// Assuming text width and text size are proportional to each other.
|
||||
float textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f);
|
||||
|
@ -529,7 +529,7 @@ public class LatinKeyboard extends Keyboard {
|
|||
textSize = origTextSize;
|
||||
}
|
||||
if (useShortName) {
|
||||
language = LanguageSwitcher.toTitleCase(locale.getLanguage());
|
||||
language = LanguageSwitcher.toTitleCase(locale.getLanguage(), locale);
|
||||
textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
||||
textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f);
|
||||
}
|
||||
|
@ -646,6 +646,10 @@ public class LatinKeyboard extends Keyboard {
|
|||
setColorOfSymbolIcons(isAutoCompletion, isBlackSym);
|
||||
}
|
||||
|
||||
public Locale getInputLocale() {
|
||||
return (mLocale != null) ? mLocale : mLanguageSwitcher.getSystemLocale();
|
||||
}
|
||||
|
||||
boolean isCurrentlyInSpace() {
|
||||
return mCurrentlyInSpace;
|
||||
}
|
||||
|
@ -955,7 +959,7 @@ public class LatinKeyboard extends Keyboard {
|
|||
}
|
||||
|
||||
private String getLanguageName(Locale locale) {
|
||||
return LanguageSwitcher.toTitleCase(locale.getDisplayLanguage(locale));
|
||||
return LanguageSwitcher.toTitleCase(locale.getDisplayLanguage(locale), locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -50,6 +50,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
|
@ -705,10 +706,18 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx
|
|||
return mKeyDetector.isProximityCorrectionEnabled();
|
||||
}
|
||||
|
||||
protected Locale getKeyboardLocale() {
|
||||
if (mKeyboard instanceof LatinKeyboard) {
|
||||
return ((LatinKeyboard)mKeyboard).getInputLocale();
|
||||
} else {
|
||||
return getContext().getResources().getConfiguration().locale;
|
||||
}
|
||||
}
|
||||
|
||||
protected CharSequence adjustCase(CharSequence label) {
|
||||
if (mKeyboard.isShifted() && label != null && label.length() < 3
|
||||
&& Character.isLowerCase(label.charAt(0))) {
|
||||
label = label.toString().toUpperCase();
|
||||
return label.toString().toUpperCase(getKeyboardLocale());
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
|
|||
&& ((LatinKeyboard) keyboard).isAlphaKeyboard()
|
||||
&& !TextUtils.isEmpty(label) && label.length() < 3
|
||||
&& Character.isLowerCase(label.charAt(0))) {
|
||||
label = label.toString().toUpperCase();
|
||||
return label.toString().toUpperCase(getKeyboardLocale());
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
|
|
@ -16,17 +16,17 @@
|
|||
|
||||
package com.android.inputmethod.latin;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.AutoText;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class loads a dictionary and provides a list of suggestions for a given sequence of
|
||||
* characters. This includes corrections and completions.
|
||||
|
@ -265,6 +265,7 @@ public class Suggest implements Dictionary.WordCallback {
|
|||
mNextLettersFrequencies);
|
||||
}
|
||||
char currentChar = wordComposer.getTypedWord().charAt(0);
|
||||
// TODO: Must pay attention to locale when changing case.
|
||||
char currentCharUpper = Character.toUpperCase(currentChar);
|
||||
int count = 0;
|
||||
int bigramSuggestionSize = mBigramSuggestions.size();
|
||||
|
@ -457,6 +458,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) {
|
||||
|
|
Loading…
Reference in a new issue