aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-10-14 15:11:39 +0900
committerJean Chalard <jchalard@google.com>2014-10-14 15:13:35 +0900
commitd15f6e8c98f673dc38100e2fe3e359f46f7358a4 (patch)
treeeaad756686ef5e1d69e4f4b56e770271b1f0e9aa
parent59f5988a16bfd979f748ecd356b528f0b933a42c (diff)
downloadlatinime-d15f6e8c98f673dc38100e2fe3e359f46f7358a4.tar.gz
latinime-d15f6e8c98f673dc38100e2fe3e359f46f7358a4.tar.xz
latinime-d15f6e8c98f673dc38100e2fe3e359f46f7358a4.zip
Performance fix for multiple language subtypes
The code would iterate all enabled subtypes each time getCurrentSubtype() is called, which is really quite frequent. Bug: 11230254 Change-Id: I91feb36de6eca84967e848fc585aae04b350be89
-rw-r--r--java-overridable/src/com/android/inputmethod/latin/settings/AdditionalFeaturesSettingUtils.java2
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java4
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputMethodManager.java14
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java17
4 files changed, 20 insertions, 17 deletions
diff --git a/java-overridable/src/com/android/inputmethod/latin/settings/AdditionalFeaturesSettingUtils.java b/java-overridable/src/com/android/inputmethod/latin/settings/AdditionalFeaturesSettingUtils.java
index 204d5f357..747a3b06e 100644
--- a/java-overridable/src/com/android/inputmethod/latin/settings/AdditionalFeaturesSettingUtils.java
+++ b/java-overridable/src/com/android/inputmethod/latin/settings/AdditionalFeaturesSettingUtils.java
@@ -46,7 +46,7 @@ public class AdditionalFeaturesSettingUtils {
// do nothing.
}
- public static RichInputMethodSubtype getRichInputMethodSubtype(
+ public static RichInputMethodSubtype createRichInputMethodSubtype(
@Nonnull final RichInputMethodManager imm,
@Nonnull final InputMethodSubtype subtype) {
return new RichInputMethodSubtype(subtype);
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 3b995f9d9..77016cb8b 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -568,6 +568,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// TODO: Resolve mutual dependencies of {@link #loadSettings()} and
// {@link #resetDictionaryFacilitatorIfNecessary()}.
loadSettings();
+ mSubtypeSwitcher.onSubtypeChanged(mRichImm.getCurrentRawSubtype());
resetDictionaryFacilitatorIfNecessary();
// Register to receive ringer mode change and network state change.
@@ -837,8 +838,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void onCurrentInputMethodSubtypeChanged(final InputMethodSubtype subtype) {
// Note that the calling sequence of onCreate() and onCurrentInputMethodSubtypeChanged()
// is not guaranteed. It may even be called at the same time on a different thread.
- final RichInputMethodSubtype richSubtype = new RichInputMethodSubtype(subtype);
- mSubtypeSwitcher.onSubtypeChanged(richSubtype);
+ mSubtypeSwitcher.onSubtypeChanged(subtype);
mInputLogic.onSubtypeChanged(SubtypeLocaleUtils.getCombiningRulesExtraValue(subtype),
mSettings.getCurrent());
loadKeyboard();
diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
index b4ec8d674..3fcae58f1 100644
--- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
+++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
@@ -299,13 +299,13 @@ public class RichInputMethodManager {
return INDEX_NOT_FOUND;
}
- public RichInputMethodSubtype getCurrentInputMethodSubtype(
- final RichInputMethodSubtype defaultSubtype) {
- final InputMethodSubtype currentSubtype = mImmWrapper.mImm.getCurrentInputMethodSubtype();
- if (currentSubtype == null) {
- return defaultSubtype;
- }
- return AdditionalFeaturesSettingUtils.getRichInputMethodSubtype(this, currentSubtype);
+ public InputMethodSubtype getCurrentRawSubtype() {
+ return mImmWrapper.mImm.getCurrentInputMethodSubtype();
+ }
+
+ public RichInputMethodSubtype createCurrentRichInputMethodSubtype(
+ final InputMethodSubtype rawSubtype) {
+ return AdditionalFeaturesSettingUtils.createRichInputMethodSubtype(this, rawSubtype);
}
public boolean hasMultipleEnabledIMEsOrSubtypes(final boolean shouldIncludeAuxiliarySubtypes) {
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index c339e96fb..0d742e96d 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -58,6 +58,7 @@ public final class SubtypeSwitcher {
new LanguageOnSpacebarHelper();
private InputMethodInfo mShortcutInputMethodInfo;
private InputMethodSubtype mShortcutSubtype;
+ private RichInputMethodSubtype mCurrentRichInputMethodSubtype;
private RichInputMethodSubtype mNoLanguageSubtype;
private RichInputMethodSubtype mEmojiSubtype;
private boolean mIsNetworkConnected;
@@ -117,7 +118,7 @@ public final class SubtypeSwitcher {
final NetworkInfo info = connectivityManager.getActiveNetworkInfo();
mIsNetworkConnected = (info != null && info.isConnected());
- onSubtypeChanged(getCurrentSubtype());
+ onSubtypeChanged(mRichImm.getCurrentRawSubtype());
updateParametersOnStartInputView();
}
@@ -165,12 +166,14 @@ public final class SubtypeSwitcher {
}
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
- public void onSubtypeChanged(final RichInputMethodSubtype newSubtype) {
+ public void onSubtypeChanged(final InputMethodSubtype newSubtype) {
+ final RichInputMethodSubtype richSubtype =
+ mRichImm.createCurrentRichInputMethodSubtype(newSubtype);
if (DBG) {
- Log.w(TAG, "onSubtypeChanged: " + newSubtype.getNameForLogging());
+ Log.w(TAG, "onSubtypeChanged: " + richSubtype.getNameForLogging());
}
-
- final Locale[] newLocales = newSubtype.getLocales();
+ mCurrentRichInputMethodSubtype = richSubtype;
+ final Locale[] newLocales = richSubtype.getLocales();
if (newLocales.length > 1) {
// In multi-locales mode, the system language is never the same as the input language
// because there is no single input language.
@@ -181,7 +184,7 @@ public final class SubtypeSwitcher {
final boolean sameLocale = systemLocale.equals(newLocale);
final boolean sameLanguage = systemLocale.getLanguage().equals(newLocale.getLanguage());
final boolean implicitlyEnabled = mRichImm
- .checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(newSubtype.getRawSubtype());
+ .checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(newSubtype);
mLanguageOnSpacebarHelper.updateIsSystemLanguageSameAsInputLanguage(
sameLocale || (sameLanguage && implicitlyEnabled));
}
@@ -301,7 +304,7 @@ public final class SubtypeSwitcher {
if (null != sForcedSubtypeForTesting) {
return sForcedSubtypeForTesting;
}
- return mRichImm.getCurrentInputMethodSubtype(getNoLanguageSubtype());
+ return mCurrentRichInputMethodSubtype;
}
public RichInputMethodSubtype getNoLanguageSubtype() {