aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/InputLanguageSelection.java24
-rw-r--r--java/src/com/android/inputmethod/latin/LanguageSwitcher.java8
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java36
-rw-r--r--java/src/com/android/inputmethod/latin/LatinKeyboard.java10
-rw-r--r--java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java11
-rw-r--r--java/src/com/android/inputmethod/latin/LatinKeyboardView.java2
-rwxr-xr-xjava/src/com/android/inputmethod/latin/Suggest.java12
7 files changed, 62 insertions, 41 deletions
diff --git a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java
index c32713983..26854399b 100644
--- a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java
+++ b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java
@@ -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);
}
}
diff --git a/java/src/com/android/inputmethod/latin/LanguageSwitcher.java b/java/src/com/android/inputmethod/latin/LanguageSwitcher.java
index 7b5c30491..226b4c690 100644
--- a/java/src/com/android/inputmethod/latin/LanguageSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/LanguageSwitcher.java
@@ -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);
}
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index b1689f886..4f3d3ba9f 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -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);
}
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java
index fbba55bad..1438d7da1 100644
--- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java
@@ -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
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java
index 008d37202..fece78689 100644
--- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java
+++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java
@@ -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;
}
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
index a5476e457..efe03a51f 100644
--- a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
@@ -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;
}
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 3b898941f..5015e9b3d 100755
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -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) {