am 0856ceef
: Merge "Get rid of current subtype and system locale cache from SubtypeSwitcher"
* commit '0856ceef9add40f3dbaa81d33bf9994c7543cd17': Get rid of current subtype and system locale cache from SubtypeSwitcher
This commit is contained in:
commit
cf0c01a7aa
3 changed files with 17 additions and 80 deletions
|
@ -582,10 +582,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(final Configuration conf) {
|
public void onConfigurationChanged(final Configuration conf) {
|
||||||
// System locale has been changed. Needs to reload keyboard.
|
|
||||||
if (mSubtypeSwitcher.onConfigurationChanged(conf)) {
|
|
||||||
loadKeyboard();
|
|
||||||
}
|
|
||||||
// If orientation changed while predicting, commit the change
|
// If orientation changed while predicting, commit the change
|
||||||
if (mDisplayOrientation != conf.orientation) {
|
if (mDisplayOrientation != conf.orientation) {
|
||||||
mDisplayOrientation = conf.orientation;
|
mDisplayOrientation = conf.orientation;
|
||||||
|
@ -651,7 +647,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
public void onCurrentInputMethodSubtypeChanged(final InputMethodSubtype subtype) {
|
public void onCurrentInputMethodSubtypeChanged(final InputMethodSubtype subtype) {
|
||||||
// Note that the calling sequence of onCreate() and onCurrentInputMethodSubtypeChanged()
|
// 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.
|
// is not guaranteed. It may even be called at the same time on a different thread.
|
||||||
mSubtypeSwitcher.updateSubtype(subtype);
|
mSubtypeSwitcher.onSubtypeChanged(subtype);
|
||||||
loadKeyboard();
|
loadKeyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -719,15 +715,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
final boolean inputTypeChanged = !mCurrentSettings.isSameInputType(editorInfo);
|
final boolean inputTypeChanged = !mCurrentSettings.isSameInputType(editorInfo);
|
||||||
final boolean isDifferentTextField = !restarting || inputTypeChanged;
|
final boolean isDifferentTextField = !restarting || inputTypeChanged;
|
||||||
if (isDifferentTextField) {
|
if (isDifferentTextField) {
|
||||||
final boolean currentSubtypeEnabled = mSubtypeSwitcher
|
mSubtypeSwitcher.updateParametersOnStartInputView();
|
||||||
.updateParametersOnStartInputViewAndReturnIfCurrentSubtypeEnabled();
|
|
||||||
if (!currentSubtypeEnabled) {
|
|
||||||
// Current subtype is disabled. Needs to update subtype and keyboard.
|
|
||||||
final InputMethodSubtype newSubtype = mRichImm.getCurrentInputMethodSubtype(
|
|
||||||
mSubtypeSwitcher.getNoLanguageSubtype());
|
|
||||||
mSubtypeSwitcher.updateSubtype(newSubtype);
|
|
||||||
loadKeyboard();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The EditorInfo might have a flag that affects fullscreen mode.
|
// The EditorInfo might have a flag that affects fullscreen mode.
|
||||||
|
|
|
@ -20,7 +20,6 @@ import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.REQ_NET
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.inputmethodservice.InputMethodService;
|
import android.inputmethodservice.InputMethodService;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
@ -53,9 +52,6 @@ public final class SubtypeSwitcher {
|
||||||
private InputMethodInfo mShortcutInputMethodInfo;
|
private InputMethodInfo mShortcutInputMethodInfo;
|
||||||
private InputMethodSubtype mShortcutSubtype;
|
private InputMethodSubtype mShortcutSubtype;
|
||||||
private InputMethodSubtype mNoLanguageSubtype;
|
private InputMethodSubtype mNoLanguageSubtype;
|
||||||
// Note: This variable is always non-null after {@link #initialize(LatinIME)}.
|
|
||||||
private InputMethodSubtype mCurrentSubtype;
|
|
||||||
private Locale mCurrentSystemLocale;
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
private boolean mIsNetworkConnected;
|
private boolean mIsNetworkConnected;
|
||||||
|
@ -84,7 +80,6 @@ public final class SubtypeSwitcher {
|
||||||
public static void init(final Context context) {
|
public static void init(final Context context) {
|
||||||
SubtypeLocale.init(context);
|
SubtypeLocale.init(context);
|
||||||
sInstance.initialize(context);
|
sInstance.initialize(context);
|
||||||
sInstance.updateAllParameters();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private SubtypeSwitcher() {
|
private SubtypeSwitcher() {
|
||||||
|
@ -96,60 +91,28 @@ public final class SubtypeSwitcher {
|
||||||
mRichImm = RichInputMethodManager.getInstance();
|
mRichImm = RichInputMethodManager.getInstance();
|
||||||
mConnectivityManager = (ConnectivityManager) service.getSystemService(
|
mConnectivityManager = (ConnectivityManager) service.getSystemService(
|
||||||
Context.CONNECTIVITY_SERVICE);
|
Context.CONNECTIVITY_SERVICE);
|
||||||
mCurrentSystemLocale = mResources.getConfiguration().locale;
|
|
||||||
mNoLanguageSubtype = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
mNoLanguageSubtype = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
||||||
SubtypeLocale.NO_LANGUAGE, SubtypeLocale.QWERTY);
|
SubtypeLocale.NO_LANGUAGE, SubtypeLocale.QWERTY);
|
||||||
mCurrentSubtype = mRichImm.getCurrentInputMethodSubtype(mNoLanguageSubtype);
|
|
||||||
if (mNoLanguageSubtype == null) {
|
if (mNoLanguageSubtype == null) {
|
||||||
throw new RuntimeException("Can't find no lanugage with QWERTY subtype");
|
throw new RuntimeException("Can't find no lanugage with QWERTY subtype");
|
||||||
}
|
}
|
||||||
|
|
||||||
final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
|
final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
|
||||||
mIsNetworkConnected = (info != null && info.isConnected());
|
mIsNetworkConnected = (info != null && info.isConnected());
|
||||||
}
|
|
||||||
|
|
||||||
// Update all parameters stored in SubtypeSwitcher.
|
onSubtypeChanged(getCurrentSubtype());
|
||||||
// Only configuration changed event is allowed to call this because this is heavy.
|
updateParametersOnStartInputView();
|
||||||
private void updateAllParameters() {
|
|
||||||
mCurrentSystemLocale = mResources.getConfiguration().locale;
|
|
||||||
updateSubtype(mRichImm.getCurrentInputMethodSubtype(mNoLanguageSubtype));
|
|
||||||
updateParametersOnStartInputViewAndReturnIfCurrentSubtypeEnabled();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update parameters which are changed outside LatinIME. This parameters affect UI so they
|
* Update parameters which are changed outside LatinIME. This parameters affect UI so that they
|
||||||
* should be updated every time onStartInputView.
|
* should be updated every time onStartInputView is called.
|
||||||
*
|
|
||||||
* @return true if the current subtype is enabled.
|
|
||||||
*/
|
*/
|
||||||
public boolean updateParametersOnStartInputViewAndReturnIfCurrentSubtypeEnabled() {
|
public void updateParametersOnStartInputView() {
|
||||||
final boolean currentSubtypeEnabled =
|
|
||||||
updateEnabledSubtypesAndReturnIfEnabled(mCurrentSubtype);
|
|
||||||
updateShortcutIME();
|
|
||||||
return currentSubtypeEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update enabled subtypes from the framework.
|
|
||||||
*
|
|
||||||
* @param subtype the subtype to be checked
|
|
||||||
* @return true if the {@code subtype} is enabled.
|
|
||||||
*/
|
|
||||||
private boolean updateEnabledSubtypesAndReturnIfEnabled(final InputMethodSubtype subtype) {
|
|
||||||
final List<InputMethodSubtype> enabledSubtypesOfThisIme =
|
final List<InputMethodSubtype> enabledSubtypesOfThisIme =
|
||||||
mRichImm.getInputMethodManager().getEnabledInputMethodSubtypeList(null, true);
|
mRichImm.getInputMethodManager().getEnabledInputMethodSubtypeList(null, true);
|
||||||
mNeedsToDisplayLanguage.updateEnabledSubtypeCount(enabledSubtypesOfThisIme.size());
|
mNeedsToDisplayLanguage.updateEnabledSubtypeCount(enabledSubtypesOfThisIme.size());
|
||||||
|
updateShortcutIME();
|
||||||
for (final InputMethodSubtype ims : enabledSubtypesOfThisIme) {
|
|
||||||
if (ims.equals(subtype)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (DBG) {
|
|
||||||
Log.w(TAG, "Subtype: " + subtype.getLocale() + "/" + subtype.getExtraValue()
|
|
||||||
+ " was disabled");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateShortcutIME() {
|
private void updateShortcutIME() {
|
||||||
|
@ -185,25 +148,21 @@ public final class SubtypeSwitcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
|
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
|
||||||
public void updateSubtype(InputMethodSubtype newSubtype) {
|
public void onSubtypeChanged(final InputMethodSubtype newSubtype) {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.w(TAG, "onCurrentInputMethodSubtypeChanged: to: "
|
Log.w(TAG, "onSubtypeChanged: " + SubtypeLocale.getSubtypeDisplayName(
|
||||||
+ newSubtype.getLocale() + "/" + newSubtype.getExtraValue() + ", from: "
|
newSubtype, mResources));
|
||||||
+ mCurrentSubtype.getLocale() + "/" + mCurrentSubtype.getExtraValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final Locale newLocale = SubtypeLocale.getSubtypeLocale(newSubtype);
|
final Locale newLocale = SubtypeLocale.getSubtypeLocale(newSubtype);
|
||||||
final boolean sameLocale = mCurrentSystemLocale.equals(newLocale);
|
final Locale systemLocale = mResources.getConfiguration().locale;
|
||||||
final boolean sameLanguage = mCurrentSystemLocale.getLanguage().equals(
|
final boolean sameLocale = systemLocale.equals(newLocale);
|
||||||
newLocale.getLanguage());
|
final boolean sameLanguage = systemLocale.getLanguage().equals(newLocale.getLanguage());
|
||||||
final boolean implicitlyEnabled =
|
final boolean implicitlyEnabled =
|
||||||
mRichImm.checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(newSubtype);
|
mRichImm.checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(newSubtype);
|
||||||
mNeedsToDisplayLanguage.updateIsSystemLanguageSameAsInputLanguage(
|
mNeedsToDisplayLanguage.updateIsSystemLanguageSameAsInputLanguage(
|
||||||
sameLocale || (sameLanguage && implicitlyEnabled));
|
sameLocale || (sameLanguage && implicitlyEnabled));
|
||||||
|
|
||||||
if (newSubtype.equals(mCurrentSubtype)) return;
|
|
||||||
|
|
||||||
mCurrentSubtype = newSubtype;
|
|
||||||
updateShortcutIME();
|
updateShortcutIME();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,21 +240,11 @@ public final class SubtypeSwitcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Locale getCurrentSubtypeLocale() {
|
public Locale getCurrentSubtypeLocale() {
|
||||||
return SubtypeLocale.getSubtypeLocale(mCurrentSubtype);
|
return SubtypeLocale.getSubtypeLocale(getCurrentSubtype());
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onConfigurationChanged(final Configuration conf) {
|
|
||||||
final Locale systemLocale = conf.locale;
|
|
||||||
final boolean systemLocaleChanged = !systemLocale.equals(mCurrentSystemLocale);
|
|
||||||
// If system configuration was changed, update all parameters.
|
|
||||||
if (systemLocaleChanged) {
|
|
||||||
updateAllParameters();
|
|
||||||
}
|
|
||||||
return systemLocaleChanged;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputMethodSubtype getCurrentSubtype() {
|
public InputMethodSubtype getCurrentSubtype() {
|
||||||
return mCurrentSubtype;
|
return mRichImm.getCurrentInputMethodSubtype(mNoLanguageSubtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputMethodSubtype getNoLanguageSubtype() {
|
public InputMethodSubtype getNoLanguageSubtype() {
|
||||||
|
|
|
@ -275,7 +275,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> {
|
||||||
if (subtype == null) {
|
if (subtype == null) {
|
||||||
fail("InputMethodSubtype for locale " + locale + " is not enabled");
|
fail("InputMethodSubtype for locale " + locale + " is not enabled");
|
||||||
}
|
}
|
||||||
SubtypeSwitcher.getInstance().updateSubtype(subtype);
|
SubtypeSwitcher.getInstance().onSubtypeChanged(subtype);
|
||||||
mLatinIME.loadKeyboard();
|
mLatinIME.loadKeyboard();
|
||||||
mKeyboard = mLatinIME.mKeyboardSwitcher.getKeyboard();
|
mKeyboard = mLatinIME.mKeyboardSwitcher.getKeyboard();
|
||||||
waitForDictionaryToBeLoaded();
|
waitForDictionaryToBeLoaded();
|
||||||
|
|
Loading…
Reference in a new issue