aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java11
-rw-r--r--java/src/com/android/inputmethod/latin/StringUtils.java17
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeLocale.java36
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java27
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeUtils.java16
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java3
6 files changed, 60 insertions, 50 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 8a26d2b9e..f5c09974e 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -115,16 +115,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public static final String IME_OPTION_FORCE_ASCII = "forceAscii";
/**
- * The subtype extra value used to indicate that the subtype keyboard layout is capable for
- * typing ASCII characters.
+ * The subtype extra value used to indicate that the subtype keyboard layout set name.
*/
- public static final String SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE = "AsciiCapable";
+ public static final String SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET = "KeyboardLayoutSet";
/**
- * The subtype extra value used to indicate that the subtype keyboard layout should be loaded
- * from the specified locale.
+ * The subtype extra value used to indicate that the subtype keyboard layout is capable for
+ * typing ASCII characters.
*/
- public static final String SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE = "KeyboardLocale";
+ public static final String SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE = "AsciiCapable";
private static final int EXTENDED_TOUCHABLE_REGION_HEIGHT = 100;
diff --git a/java/src/com/android/inputmethod/latin/StringUtils.java b/java/src/com/android/inputmethod/latin/StringUtils.java
index 7000e4633..42fce53d0 100644
--- a/java/src/com/android/inputmethod/latin/StringUtils.java
+++ b/java/src/com/android/inputmethod/latin/StringUtils.java
@@ -22,6 +22,7 @@ import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.keyboard.Keyboard;
import java.util.ArrayList;
+import java.util.Locale;
public class StringUtils {
private StringUtils() {
@@ -149,4 +150,20 @@ public class StringUtils {
i++;
}
}
+
+ public static String toTitleCase(String s, Locale locale) {
+ if (s.length() <= 1) {
+ // TODO: is this really correct? Shouldn't this be s.toUpperCase()?
+ return s;
+ }
+ // TODO: fix the bugs below
+ // - This does not work for Greek, because it returns upper case instead of title case.
+ // - It does not work for Serbian, because it fails to account for the "lj" character,
+ // which should be "Lj" in title case and "LJ" in upper case.
+ // - It does not work for Dutch, because it fails to account for the "ij" digraph, which
+ // are two different characters but both should be capitalized as "IJ" as if they were
+ // a single letter.
+ // - It also does not work with unicode surrogate code points.
+ return s.toUpperCase(locale).charAt(0) + s.substring(1);
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java
index fac74f0b5..2bc22a6f9 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java
@@ -18,7 +18,7 @@ package com.android.inputmethod.latin;
import android.content.Context;
import android.content.res.Resources;
-import android.view.inputmethod.InputMethodSubtype;
+
import java.util.Locale;
@@ -69,10 +69,10 @@ public class SubtypeLocale {
}
final String value = lookupExceptionalLocale(key);
if (value == null) {
- return toTitleCase(locale.getDisplayName(locale), locale);
+ return StringUtils.toTitleCase(locale.getDisplayName(locale), locale);
}
if (value.indexOf("%s") >= 0) {
- final String languageName = toTitleCase(locale.getDisplayLanguage(locale), locale);
+ final String languageName = StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale);
return String.format(value, languageName);
}
return value;
@@ -88,7 +88,7 @@ public class SubtypeLocale {
if (NO_LANGUAGE.equals(locale.getLanguage())) {
return lookupExceptionalLocale(locale.getCountry());
} else {
- return toTitleCase(locale.getDisplayLanguage(locale), locale);
+ return StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale);
}
}
@@ -102,33 +102,7 @@ public class SubtypeLocale {
if (NO_LANGUAGE.equals(locale.getLanguage())) {
return locale.getCountry();
} else {
- return toTitleCase(locale.getLanguage(), locale);
- }
- }
-
- public static String toTitleCase(String s, Locale locale) {
- if (s.length() <= 1) {
- // TODO: is this really correct? Shouldn't this be s.toUpperCase()?
- return s;
+ return StringUtils.toTitleCase(locale.getLanguage(), locale);
}
- // TODO: fix the bugs below
- // - This does not work for Greek, because it returns upper case instead of title case.
- // - It does not work for Serbian, because it fails to account for the "lj" character,
- // which should be "Lj" in title case and "LJ" in upper case.
- // - It does not work for Dutch, because it fails to account for the "ij" digraph, which
- // are two different characters but both should be capitalized as "IJ" as if they were
- // a single letter.
- // - It also does not work with unicode surrogate code points.
- return s.toUpperCase(locale).charAt(0) + s.substring(1);
- }
-
- public static String getSubtypeLocaleString(InputMethodSubtype subtype) {
- final String keyboardLocale = subtype.getExtraValueOf(
- LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE);
- return keyboardLocale != null ? keyboardLocale : subtype.getLocale();
- }
-
- public static Locale getSubtypeLocale(InputMethodSubtype subtype) {
- return LocaleUtils.constructLocaleFromString(getSubtypeLocaleString(subtype));
}
}
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index 3ed7f8700..dfb01a24c 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -33,6 +33,7 @@ import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
+import com.android.inputmethod.keyboard.KeyboardLayoutSet;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
import java.util.ArrayList;
@@ -68,6 +69,7 @@ public class SubtypeSwitcher {
private InputMethodInfo mShortcutInputMethodInfo;
private InputMethodSubtype mShortcutSubtype;
private List<InputMethodSubtype> mAllEnabledSubtypesOfCurrentInputMethod;
+ private InputMethodSubtype mNoLanguageSubtype;
// Note: This variable is always non-null after {@link #initialize(LatinIME)}.
private InputMethodSubtype mCurrentSubtype;
private Locale mSystemLocale;
@@ -104,6 +106,8 @@ public class SubtypeSwitcher {
mInputLocaleStr = null;
mCurrentSubtype = mImm.getCurrentInputMethodSubtype();
mAllEnabledSubtypesOfCurrentInputMethod = null;
+ mNoLanguageSubtype = SubtypeUtils.findSubtypeByKeyboardLayoutSetLocale(
+ service, SubtypeLocale.LOCALE_NO_LANGUAGE_QWERTY);
final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
mIsNetworkConnected = (info != null && info.isConnected());
@@ -133,7 +137,7 @@ public class SubtypeSwitcher {
mEnabledLanguagesOfCurrentInputMethod.clear();
mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
for (InputMethodSubtype ims : mAllEnabledSubtypesOfCurrentInputMethod) {
- final String locale = getSubtypeLocale(ims);
+ final String locale = KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(ims);
final String mode = ims.getMode();
mLocaleSplitter.setString(locale);
if (mLocaleSplitter.hasNext()) {
@@ -162,7 +166,8 @@ public class SubtypeSwitcher {
Log.d(TAG, "Update shortcut IME from : "
+ (mShortcutInputMethodInfo == null
? "<null>" : mShortcutInputMethodInfo.getId()) + ", "
- + (mShortcutSubtype == null ? "<null>" : (getSubtypeLocale(mShortcutSubtype)
+ + (mShortcutSubtype == null ? "<null>" : (
+ KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(mShortcutSubtype)
+ ", " + mShortcutSubtype.getMode())));
}
// TODO: Update an icon for shortcut IME
@@ -184,20 +189,15 @@ public class SubtypeSwitcher {
Log.d(TAG, "Update shortcut IME to : "
+ (mShortcutInputMethodInfo == null
? "<null>" : mShortcutInputMethodInfo.getId()) + ", "
- + (mShortcutSubtype == null ? "<null>" : (getSubtypeLocale(mShortcutSubtype)
+ + (mShortcutSubtype == null ? "<null>" : (
+ KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(mShortcutSubtype)
+ ", " + mShortcutSubtype.getMode())));
}
}
- private static String getSubtypeLocale(InputMethodSubtype subtype) {
- final String keyboardLocale = subtype.getExtraValueOf(
- LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE);
- return keyboardLocale != null ? keyboardLocale : subtype.getLocale();
- }
-
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
public void updateSubtype(InputMethodSubtype newSubtype) {
- final String newLocale = getSubtypeLocale(newSubtype);
+ final String newLocale = KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(newSubtype);
final String newMode = newSubtype.getMode();
final String oldMode = getCurrentSubtypeMode();
if (DBG) {
@@ -301,7 +301,8 @@ public class SubtypeSwitcher {
final String imiPackageName = imi.getPackageName();
if (DBG) {
Log.d(TAG, "Update icons of IME: " + imiPackageName + ","
- + getSubtypeLocale(subtype) + "," + subtype.getMode());
+ + KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(subtype) + ","
+ + subtype.getMode());
}
if (subtype != null) {
return pm.getDrawable(imiPackageName, subtype.getIconResId(),
@@ -438,4 +439,8 @@ public class SubtypeSwitcher {
public InputMethodSubtype getCurrentSubtype() {
return mCurrentSubtype;
}
+
+ public InputMethodSubtype getNoLanguageSubtype() {
+ return mNoLanguageSubtype;
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/SubtypeUtils.java b/java/src/com/android/inputmethod/latin/SubtypeUtils.java
index 2c5d58200..a747c9ad7 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeUtils.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeUtils.java
@@ -21,9 +21,11 @@ import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
+import com.android.inputmethod.keyboard.KeyboardLayoutSet;
import java.util.Collections;
import java.util.List;
+import java.util.Locale;
public class SubtypeUtils {
private SubtypeUtils() {
@@ -129,4 +131,18 @@ public class SubtypeUtils {
}
throw new RuntimeException("Can not find input method id for " + packageName);
}
+
+ public static InputMethodSubtype findSubtypeByKeyboardLayoutSetLocale(
+ Context context, Locale locale) {
+ final String localeString = locale.toString();
+ final InputMethodInfo imi = SubtypeUtils.getInputMethodInfo(context.getPackageName());
+ final int count = imi.getSubtypeCount();
+ for (int i = 0; i < count; i++) {
+ final InputMethodSubtype subtype = imi.getSubtypeAt(i);
+ if (localeString.equals(KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(subtype))) {
+ return subtype;
+ }
+ }
+ throw new RuntimeException("Can not find subtype of locale " + localeString);
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index cd01bb146..1fc945f3c 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -37,7 +37,6 @@ import com.android.inputmethod.latin.Flag;
import com.android.inputmethod.latin.LocaleUtils;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.StringUtils;
-import com.android.inputmethod.latin.SubtypeLocale;
import com.android.inputmethod.latin.SynchronouslyLoadedContactsDictionary;
import com.android.inputmethod.latin.SynchronouslyLoadedUserDictionary;
import com.android.inputmethod.latin.WhitelistDictionary;
@@ -326,7 +325,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
} else if (CAPITALIZE_FIRST == capitalizeType) {
for (int i = 0; i < mSuggestions.size(); ++i) {
// Likewise
- mSuggestions.set(i, SubtypeLocale.toTitleCase(
+ mSuggestions.set(i, StringUtils.toTitleCase(
mSuggestions.get(i).toString(), locale));
}
}