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