am ec0d6bb9: Merge "Move current subtype management code to RichInputMethodManager"

* commit 'ec0d6bb9b708070c71981021712dfad0352a4cfe':
  Move current subtype management code to RichInputMethodManager
main
Tadashi G. Takaoka 2014-11-07 18:32:57 +00:00 committed by Android Git Automerger
commit 74346c0ba9
6 changed files with 51 additions and 47 deletions

View File

@ -47,6 +47,7 @@ public class AdditionalFeaturesSettingUtils {
// do nothing. // do nothing.
} }
@Nonnull
public static RichInputMethodSubtype createRichInputMethodSubtype( public static RichInputMethodSubtype createRichInputMethodSubtype(
@Nonnull final RichInputMethodManager imm, @Nonnull final RichInputMethodManager imm,
@Nonnull final InputMethodSubtype subtype, @Nonnull final InputMethodSubtype subtype,

View File

@ -114,7 +114,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
final int keyboardHeight = ResourceUtils.getKeyboardHeight(res, settingsValues); final int keyboardHeight = ResourceUtils.getKeyboardHeight(res, settingsValues);
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight); builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype()); builder.setSubtype(RichInputMethodManager.getInstance().getCurrentSubtype());
builder.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey); builder.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey);
builder.setLanguageSwitchKeyEnabled(mLatinIME.shouldShowLanguageSwitchKey()); builder.setLanguageSwitchKeyEnabled(mLatinIME.shouldShowLanguageSwitchKey());
builder.setSplitLayoutEnabledByUser(ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED builder.setSplitLayoutEnabledByUser(ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED
@ -123,7 +123,8 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
try { try {
mState.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState); mState.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState);
// TODO: revisit this for multi-lingual input // TODO: revisit this for multi-lingual input
mKeyboardTextsSet.setLocale(mSubtypeSwitcher.getCurrentSubtypeLocales()[0], mKeyboardTextsSet.setLocale(
RichInputMethodManager.getInstance().getCurrentSubtypeLocales()[0],
mThemeContext); mThemeContext);
} catch (KeyboardLayoutSetException e) { } catch (KeyboardLayoutSetException e) {
Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause()); Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause());

View File

@ -603,7 +603,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Has to be package-visible for unit tests // Has to be package-visible for unit tests
@UsedForTesting @UsedForTesting
void loadSettings() { void loadSettings() {
final Locale[] locales = mSubtypeSwitcher.getCurrentSubtypeLocales(); final Locale[] locales = mRichImm.getCurrentSubtypeLocales();
final EditorInfo editorInfo = getCurrentInputEditorInfo(); final EditorInfo editorInfo = getCurrentInputEditorInfo();
final InputAttributes inputAttributes = new InputAttributes( final InputAttributes inputAttributes = new InputAttributes(
editorInfo, isFullscreenMode(), getPackageName()); editorInfo, isFullscreenMode(), getPackageName());
@ -657,7 +657,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
void resetDictionaryFacilitatorIfNecessary() { void resetDictionaryFacilitatorIfNecessary() {
final Locale[] subtypeSwitcherLocales = mSubtypeSwitcher.getCurrentSubtypeLocales(); final Locale[] subtypeSwitcherLocales = mRichImm.getCurrentSubtypeLocales();
if (mDictionaryFacilitator.isForLocales(subtypeSwitcherLocales)) { if (mDictionaryFacilitator.isForLocales(subtypeSwitcherLocales)) {
return; return;
} }
@ -909,7 +909,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Update to a gesture consumer with the current editor and IME state. // Update to a gesture consumer with the current editor and IME state.
mGestureConsumer = GestureConsumer.newInstance(editorInfo, mGestureConsumer = GestureConsumer.newInstance(editorInfo,
mInputLogic.getPrivateCommandPerformer(), mInputLogic.getPrivateCommandPerformer(),
Arrays.asList(mSubtypeSwitcher.getCurrentSubtypeLocales()), Arrays.asList(mRichImm.getCurrentSubtypeLocales()),
switcher.getKeyboard()); switcher.getKeyboard());
// Forward this event to the accessibility utilities, if enabled. // Forward this event to the accessibility utilities, if enabled.
@ -947,7 +947,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// span, so we should reset our state unconditionally, even if restarting is true. // span, so we should reset our state unconditionally, even if restarting is true.
// We also tell the input logic about the combining rules for the current subtype, so // We also tell the input logic about the combining rules for the current subtype, so
// it can adjust its combiners if needed. // it can adjust its combiners if needed.
mInputLogic.startInput(mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype(), mInputLogic.startInput(mRichImm.getCombiningRulesExtraValueOfCurrentSubtype(),
currentSettingsValues); currentSettingsValues);
resetDictionaryFacilitatorIfNecessary(); resetDictionaryFacilitatorIfNecessary();
@ -1468,7 +1468,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void onStartBatchInput() { public void onStartBatchInput() {
mInputLogic.onStartBatchInput(mSettings.getCurrent(), mKeyboardSwitcher, mHandler); mInputLogic.onStartBatchInput(mSettings.getCurrent(), mKeyboardSwitcher, mHandler);
mGestureConsumer.onGestureStarted( mGestureConsumer.onGestureStarted(
Arrays.asList(mSubtypeSwitcher.getCurrentSubtypeLocales()), Arrays.asList(mRichImm.getCurrentSubtypeLocales()),
mKeyboardSwitcher.getKeyboard()); mKeyboardSwitcher.getKeyboard());
} }
@ -1590,7 +1590,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// We should clear the contextual strip if there is no suggestion from dictionaries. // We should clear the contextual strip if there is no suggestion from dictionaries.
|| noSuggestionsFromDictionaries) { || noSuggestionsFromDictionaries) {
mSuggestionStripView.setSuggestions(suggestedWords, mSuggestionStripView.setSuggestions(suggestedWords,
mSubtypeSwitcher.getCurrentSubtype().isRtlSubtype()); mRichImm.getCurrentSubtype().isRtlSubtype());
} }
} }

View File

@ -34,6 +34,7 @@ import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.latin.settings.AdditionalFeaturesSettingUtils; import com.android.inputmethod.latin.settings.AdditionalFeaturesSettingUtils;
@ -68,6 +69,7 @@ public class RichInputMethodManager {
private Context mContext; private Context mContext;
private InputMethodManagerCompatWrapper mImmWrapper; private InputMethodManagerCompatWrapper mImmWrapper;
private InputMethodInfoCache mInputMethodInfoCache; private InputMethodInfoCache mInputMethodInfoCache;
private RichInputMethodSubtype mCurrentRichInputMethodSubtype;
private InputMethodInfo mShortcutInputMethodInfo; private InputMethodInfo mShortcutInputMethodInfo;
private InputMethodSubtype mShortcutSubtype; private InputMethodSubtype mShortcutSubtype;
private boolean mIsNetworkConnected; private boolean mIsNetworkConnected;
@ -323,11 +325,48 @@ public class RichInputMethodManager {
return INDEX_NOT_FOUND; return INDEX_NOT_FOUND;
} }
@Nonnull
public RichInputMethodSubtype onSubtypeChanged(@Nonnull final InputMethodSubtype newSubtype) {
final RichInputMethodSubtype richSubtype = createCurrentRichInputMethodSubtype(newSubtype);
if (DEBUG) {
Log.w(TAG, "onSubtypeChanged: " + richSubtype.getNameForLogging());
}
mCurrentRichInputMethodSubtype = richSubtype;
return richSubtype;
}
private static RichInputMethodSubtype sForcedSubtypeForTesting = null;
@UsedForTesting
static void forceSubtype(final InputMethodSubtype subtype) {
sForcedSubtypeForTesting = new RichInputMethodSubtype(subtype);
}
public Locale[] getCurrentSubtypeLocales() {
if (null != sForcedSubtypeForTesting) {
return sForcedSubtypeForTesting.getLocales();
}
return getCurrentSubtype().getLocales();
}
public RichInputMethodSubtype getCurrentSubtype() {
if (null != sForcedSubtypeForTesting) {
return sForcedSubtypeForTesting;
}
return mCurrentRichInputMethodSubtype;
}
public String getCombiningRulesExtraValueOfCurrentSubtype() {
return SubtypeLocaleUtils.getCombiningRulesExtraValue(getCurrentSubtype().getRawSubtype());
}
@Nonnull @Nonnull
public InputMethodSubtype getCurrentRawSubtype() { public InputMethodSubtype getCurrentRawSubtype() {
return mImmWrapper.mImm.getCurrentInputMethodSubtype(); return mImmWrapper.mImm.getCurrentInputMethodSubtype();
} }
@Nonnull
public RichInputMethodSubtype createCurrentRichInputMethodSubtype( public RichInputMethodSubtype createCurrentRichInputMethodSubtype(
@Nonnull final InputMethodSubtype rawSubtype) { @Nonnull final InputMethodSubtype rawSubtype) {
return AdditionalFeaturesSettingUtils.createRichInputMethodSubtype(this, rawSubtype, return AdditionalFeaturesSettingUtils.createRichInputMethodSubtype(this, rawSubtype,

View File

@ -18,12 +18,9 @@ package com.android.inputmethod.latin;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.util.Log;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.internal.LanguageOnSpacebarHelper; import com.android.inputmethod.keyboard.internal.LanguageOnSpacebarHelper;
import com.android.inputmethod.latin.define.DebugFlags;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import java.util.List; import java.util.List;
@ -32,9 +29,6 @@ import java.util.Locale;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public final class SubtypeSwitcher { public final class SubtypeSwitcher {
private static boolean DBG = DebugFlags.DEBUG_ENABLED;
private static final String TAG = SubtypeSwitcher.class.getSimpleName();
private static final SubtypeSwitcher sInstance = new SubtypeSwitcher(); private static final SubtypeSwitcher sInstance = new SubtypeSwitcher();
private /* final */ RichInputMethodManager mRichImm; private /* final */ RichInputMethodManager mRichImm;
@ -42,7 +36,6 @@ public final class SubtypeSwitcher {
private final LanguageOnSpacebarHelper mLanguageOnSpacebarHelper = private final LanguageOnSpacebarHelper mLanguageOnSpacebarHelper =
new LanguageOnSpacebarHelper(); new LanguageOnSpacebarHelper();
private RichInputMethodSubtype mCurrentRichInputMethodSubtype;
public static SubtypeSwitcher getInstance() { public static SubtypeSwitcher getInstance() {
return sInstance; return sInstance;
@ -82,12 +75,7 @@ public final class SubtypeSwitcher {
// 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 InputMethodSubtype newSubtype) {
final RichInputMethodSubtype richSubtype = final RichInputMethodSubtype richSubtype = mRichImm.onSubtypeChanged(newSubtype);
mRichImm.createCurrentRichInputMethodSubtype(newSubtype);
if (DBG) {
Log.w(TAG, "onSubtypeChanged: " + richSubtype.getNameForLogging());
}
mCurrentRichInputMethodSubtype = richSubtype;
final Locale[] newLocales = richSubtype.getLocales(); final Locale[] newLocales = richSubtype.getLocales();
if (newLocales.length > 1) { if (newLocales.length > 1) {
// In multi-locales mode, the system language is never the same as the input language // In multi-locales mode, the system language is never the same as the input language
@ -109,29 +97,4 @@ public final class SubtypeSwitcher {
public int getLanguageOnSpacebarFormatType(final RichInputMethodSubtype subtype) { public int getLanguageOnSpacebarFormatType(final RichInputMethodSubtype subtype) {
return mLanguageOnSpacebarHelper.getLanguageOnSpacebarFormatType(subtype); return mLanguageOnSpacebarHelper.getLanguageOnSpacebarFormatType(subtype);
} }
private static RichInputMethodSubtype sForcedSubtypeForTesting = null;
@UsedForTesting
static void forceSubtype(final InputMethodSubtype subtype) {
sForcedSubtypeForTesting = new RichInputMethodSubtype(subtype);
}
public Locale[] getCurrentSubtypeLocales() {
if (null != sForcedSubtypeForTesting) {
return sForcedSubtypeForTesting.getLocales();
}
return getCurrentSubtype().getLocales();
}
public RichInputMethodSubtype getCurrentSubtype() {
if (null != sForcedSubtypeForTesting) {
return sForcedSubtypeForTesting;
}
return mCurrentRichInputMethodSubtype;
}
public String getCombiningRulesExtraValueOfCurrentSubtype() {
return SubtypeLocaleUtils.getCombiningRulesExtraValue(getCurrentSubtype().getRawSubtype());
}
} }

View File

@ -387,7 +387,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
false /* isAuxiliary */, false /* isAuxiliary */,
false /* overridesImplicitlyEnabledSubtype */, false /* overridesImplicitlyEnabledSubtype */,
0 /* id */); 0 /* id */);
SubtypeSwitcher.forceSubtype(subtype); RichInputMethodManager.forceSubtype(subtype);
mLatinIME.onCurrentInputMethodSubtypeChanged(subtype); mLatinIME.onCurrentInputMethodSubtypeChanged(subtype);
runMessages(); runMessages();
mKeyboard = mLatinIME.mKeyboardSwitcher.getKeyboard(); mKeyboard = mLatinIME.mKeyboardSwitcher.getKeyboard();