am 5ac8b040: Merge "Remove RichInputMethodManager.updateShortcutIME call from SubtypeSwitcher"

* commit '5ac8b040e8ddfd9e33370efd8f5b15372c499c3c':
  Remove RichInputMethodManager.updateShortcutIME call from SubtypeSwitcher
main
Tadashi G. Takaoka 2014-12-06 01:48:54 +00:00 committed by Android Git Automerger
commit bf6b55853d
4 changed files with 34 additions and 40 deletions

View File

@ -591,7 +591,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// TODO: Resolve mutual dependencies of {@link #loadSettings()} and // TODO: Resolve mutual dependencies of {@link #loadSettings()} and
// {@link #resetDictionaryFacilitatorIfNecessary()}. // {@link #resetDictionaryFacilitatorIfNecessary()}.
loadSettings(); loadSettings();
mSubtypeSwitcher.onSubtypeChanged(mRichImm.getCurrentRawSubtype());
resetDictionaryFacilitatorIfNecessary(); resetDictionaryFacilitatorIfNecessary();
// Register to receive ringer mode change and network state change. // Register to receive ringer mode change and network state change.
@ -867,7 +866,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
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.onSubtypeChanged(subtype); mRichImm.onSubtypeChanged(subtype);
mSubtypeSwitcher.onSubtypeChanged(mRichImm.getCurrentSubtype());
mInputLogic.onSubtypeChanged(SubtypeLocaleUtils.getCombiningRulesExtraValue(subtype), mInputLogic.onSubtypeChanged(SubtypeLocaleUtils.getCombiningRulesExtraValue(subtype),
mSettings.getCurrent()); mSettings.getCurrent());
loadKeyboard(); loadKeyboard();
@ -883,8 +883,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Switch to the null consumer to handle cases leading to early exit below, for which we // Switch to the null consumer to handle cases leading to early exit below, for which we
// also wouldn't be consuming gesture data. // also wouldn't be consuming gesture data.
mGestureConsumer = GestureConsumer.NULL_GESTURE_CONSUMER; mGestureConsumer = GestureConsumer.NULL_GESTURE_CONSUMER;
mRichImm.clearSubtypeCaches(); mRichImm.refreshSubtypeCaches();
mSubtypeSwitcher.onSubtypeChanged(mRichImm.getCurrentRawSubtype()); mSubtypeSwitcher.onSubtypeChanged(mRichImm.getCurrentSubtype());
final KeyboardSwitcher switcher = mKeyboardSwitcher; final KeyboardSwitcher switcher = mKeyboardSwitcher;
switcher.updateKeyboardTheme(); switcher.updateKeyboardTheme();
final MainKeyboardView mainKeyboardView = switcher.getMainKeyboardView(); final MainKeyboardView mainKeyboardView = switcher.getMainKeyboardView();
@ -1453,7 +1453,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// completely replace #onCodeInput. // completely replace #onCodeInput.
public void onEvent(@Nonnull final Event event) { public void onEvent(@Nonnull final Event event) {
if (Constants.CODE_SHORTCUT == event.mKeyCode) { if (Constants.CODE_SHORTCUT == event.mKeyCode) {
mRichImm.switchToShortcutIME(this); mRichImm.switchToShortcutIme(this);
} }
final InputTransaction completeInputTransaction = final InputTransaction completeInputTransaction =
mInputLogic.onCodeInput(mSettings.getCurrent(), event, mInputLogic.onCodeInput(mSettings.getCurrent(), event,

View File

@ -111,7 +111,11 @@ public class RichInputMethodManager {
// Initialize additional subtypes. // Initialize additional subtypes.
SubtypeLocaleUtils.init(context); SubtypeLocaleUtils.init(context);
final InputMethodSubtype[] additionalSubtypes = getAdditionalSubtypes(); final InputMethodSubtype[] additionalSubtypes = getAdditionalSubtypes();
setAdditionalInputMethodSubtypes(additionalSubtypes); mImmWrapper.mImm.setAdditionalInputMethodSubtypes(
getInputMethodIdOfThisIme(), additionalSubtypes);
// Initialize the current input method subtype and the shortcut IME.
refreshSubtypeCaches();
final ConnectivityManager connectivityManager = final ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
@ -324,23 +328,22 @@ public class RichInputMethodManager {
return INDEX_NOT_FOUND; return INDEX_NOT_FOUND;
} }
@Nonnull public void onSubtypeChanged(@Nonnull final InputMethodSubtype newSubtype) {
public RichInputMethodSubtype onSubtypeChanged(@Nonnull final InputMethodSubtype newSubtype) { updateCurrentSubtype(newSubtype);
final RichInputMethodSubtype richSubtype = createCurrentRichInputMethodSubtype(newSubtype); updateShortcutIme();
if (DEBUG) { if (DEBUG) {
Log.w(TAG, "onSubtypeChanged: " + richSubtype.getNameForLogging()); Log.w(TAG, "onSubtypeChanged: " + mCurrentRichInputMethodSubtype.getNameForLogging());
} }
mCurrentRichInputMethodSubtype = richSubtype;
return richSubtype;
} }
private static RichInputMethodSubtype sForcedSubtypeForTesting = null; private static RichInputMethodSubtype sForcedSubtypeForTesting = null;
@UsedForTesting @UsedForTesting
static void forceSubtype(final InputMethodSubtype subtype) { static void forceSubtype(@Nonnull final InputMethodSubtype subtype) {
sForcedSubtypeForTesting = new RichInputMethodSubtype(subtype); sForcedSubtypeForTesting = new RichInputMethodSubtype(subtype);
} }
@Nonnull
public Locale[] getCurrentSubtypeLocales() { public Locale[] getCurrentSubtypeLocales() {
if (null != sForcedSubtypeForTesting) { if (null != sForcedSubtypeForTesting) {
return sForcedSubtypeForTesting.getLocales(); return sForcedSubtypeForTesting.getLocales();
@ -348,6 +351,7 @@ public class RichInputMethodManager {
return getCurrentSubtype().getLocales(); return getCurrentSubtype().getLocales();
} }
@Nonnull
public RichInputMethodSubtype getCurrentSubtype() { public RichInputMethodSubtype getCurrentSubtype() {
if (null != sForcedSubtypeForTesting) { if (null != sForcedSubtypeForTesting) {
return sForcedSubtypeForTesting; return sForcedSubtypeForTesting;
@ -360,18 +364,6 @@ public class RichInputMethodManager {
return SubtypeLocaleUtils.getCombiningRulesExtraValue(getCurrentSubtype().getRawSubtype()); return SubtypeLocaleUtils.getCombiningRulesExtraValue(getCurrentSubtype().getRawSubtype());
} }
@Nonnull
public InputMethodSubtype getCurrentRawSubtype() {
return mImmWrapper.mImm.getCurrentInputMethodSubtype();
}
@Nonnull
public RichInputMethodSubtype createCurrentRichInputMethodSubtype(
@Nonnull final InputMethodSubtype rawSubtype) {
return AdditionalFeaturesSettingUtils.createRichInputMethodSubtype(this, rawSubtype,
mContext);
}
public boolean hasMultipleEnabledIMEsOrSubtypes(final boolean shouldIncludeAuxiliarySubtypes) { public boolean hasMultipleEnabledIMEsOrSubtypes(final boolean shouldIncludeAuxiliarySubtypes) {
final List<InputMethodInfo> enabledImis = mImmWrapper.mImm.getEnabledInputMethodList(); final List<InputMethodInfo> enabledImis = mImmWrapper.mImm.getEnabledInputMethodList();
return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, enabledImis); return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, enabledImis);
@ -457,7 +449,7 @@ public class RichInputMethodManager {
getInputMethodIdOfThisIme(), subtypes); getInputMethodIdOfThisIme(), subtypes);
// Clear the cache so that we go read the {@link InputMethodInfo} of this IME and list of // Clear the cache so that we go read the {@link InputMethodInfo} of this IME and list of
// subtypes again next time. // subtypes again next time.
clearSubtypeCaches(); refreshSubtypeCaches();
} }
private List<InputMethodSubtype> getEnabledInputMethodSubtypeList(final InputMethodInfo imi, private List<InputMethodSubtype> getEnabledInputMethodSubtypeList(final InputMethodInfo imi,
@ -474,10 +466,12 @@ public class RichInputMethodManager {
return result; return result;
} }
public void clearSubtypeCaches() { public void refreshSubtypeCaches() {
mSubtypeListCacheWithImplicitlySelectedSubtypes.clear(); mSubtypeListCacheWithImplicitlySelectedSubtypes.clear();
mSubtypeListCacheWithoutImplicitlySelectedSubtypes.clear(); mSubtypeListCacheWithoutImplicitlySelectedSubtypes.clear();
mInputMethodInfoCache.clear(); mInputMethodInfoCache.clear();
updateCurrentSubtype(mImmWrapper.mImm.getCurrentInputMethodSubtype());
updateShortcutIme();
} }
public boolean shouldOfferSwitchingToNextInputMethod(final IBinder binder, public boolean shouldOfferSwitchingToNextInputMethod(final IBinder binder,
@ -516,8 +510,13 @@ public class RichInputMethodManager {
return true; return true;
} }
// TODO: Make this private private void updateCurrentSubtype(@Nonnull final InputMethodSubtype subtype) {
void updateShortcutIME() { final RichInputMethodSubtype richSubtype = AdditionalFeaturesSettingUtils
.createRichInputMethodSubtype(this, subtype, mContext);
mCurrentRichInputMethodSubtype = richSubtype;
}
private void updateShortcutIme() {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Update shortcut IME from : " Log.d(TAG, "Update shortcut IME from : "
+ (mShortcutInputMethodInfo == null + (mShortcutInputMethodInfo == null
@ -549,7 +548,7 @@ public class RichInputMethodManager {
} }
} }
public void switchToShortcutIME(final InputMethodService context) { public void switchToShortcutIme(final InputMethodService context) {
if (mShortcutInputMethodInfo == null) { if (mShortcutInputMethodInfo == null) {
return; return;
} }
@ -575,19 +574,16 @@ public class RichInputMethodManager {
} }
public boolean isShortcutImeEnabled() { public boolean isShortcutImeEnabled() {
updateShortcutIME();
if (mShortcutInputMethodInfo == null) { if (mShortcutInputMethodInfo == null) {
return false; return false;
} }
if (mShortcutSubtype == null) { if (mShortcutSubtype == null) {
return true; return true;
} }
return checkIfSubtypeBelongsToImeAndEnabled( return checkIfSubtypeBelongsToImeAndEnabled(mShortcutInputMethodInfo, mShortcutSubtype);
mShortcutInputMethodInfo, mShortcutSubtype);
} }
public boolean isShortcutImeReady() { public boolean isShortcutImeReady() {
updateShortcutIME();
if (mShortcutInputMethodInfo == null) { if (mShortcutInputMethodInfo == null) {
return false; return false;
} }

View File

@ -57,7 +57,7 @@ public final class SubtypeSwitcher {
mResources = context.getResources(); mResources = context.getResources();
mRichImm = RichInputMethodManager.getInstance(); mRichImm = RichInputMethodManager.getInstance();
onSubtypeChanged(mRichImm.getCurrentRawSubtype()); onSubtypeChanged(mRichImm.getCurrentSubtype());
updateParametersOnStartInputView(); updateParametersOnStartInputView();
} }
@ -69,17 +69,14 @@ public final class SubtypeSwitcher {
final List<InputMethodSubtype> enabledSubtypesOfThisIme = final List<InputMethodSubtype> enabledSubtypesOfThisIme =
mRichImm.getMyEnabledInputMethodSubtypeList(true); mRichImm.getMyEnabledInputMethodSubtypeList(true);
mLanguageOnSpacebarHelper.onUpdateEnabledSubtypes(enabledSubtypesOfThisIme); mLanguageOnSpacebarHelper.onUpdateEnabledSubtypes(enabledSubtypesOfThisIme);
mRichImm.updateShortcutIME();
} }
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function. // Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
public void onSubtypeChanged(@Nonnull final InputMethodSubtype newSubtype) { public void onSubtypeChanged(@Nonnull final RichInputMethodSubtype richSubtype) {
final RichInputMethodSubtype richSubtype = mRichImm.onSubtypeChanged(newSubtype);
final boolean implicitlyEnabledSubtype = mRichImm final boolean implicitlyEnabledSubtype = mRichImm
.checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(newSubtype); .checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(richSubtype.getRawSubtype());
mLanguageOnSpacebarHelper.onSubtypeChanged( mLanguageOnSpacebarHelper.onSubtypeChanged(
richSubtype, implicitlyEnabledSubtype, mResources.getConfiguration().locale); richSubtype, implicitlyEnabledSubtype, mResources.getConfiguration().locale);
mRichImm.updateShortcutIME();
} }
public int getLanguageOnSpacebarFormatType(final RichInputMethodSubtype subtype) { public int getLanguageOnSpacebarFormatType(final RichInputMethodSubtype subtype) {

View File

@ -71,6 +71,7 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
super.onResume(); super.onResume();
final Preference voiceInputKeyOption = findPreference(Settings.PREF_VOICE_INPUT_KEY); final Preference voiceInputKeyOption = findPreference(Settings.PREF_VOICE_INPUT_KEY);
if (voiceInputKeyOption != null) { if (voiceInputKeyOption != null) {
RichInputMethodManager.getInstance().refreshSubtypeCaches();
final boolean isShortcutImeEnabled = RichInputMethodManager.getInstance() final boolean isShortcutImeEnabled = RichInputMethodManager.getInstance()
.isShortcutImeEnabled(); .isShortcutImeEnabled();
voiceInputKeyOption.setEnabled(isShortcutImeEnabled); voiceInputKeyOption.setEnabled(isShortcutImeEnabled);