Refactor to utilize InputMethodSubtype

Change-Id: I76fbc8a395eb8dab996c02c86d7328f07865f8cf
This commit is contained in:
Tadashi G. Takaoka 2012-04-04 18:18:56 +09:00
parent 43ebd8a035
commit cb389ef0d6
5 changed files with 27 additions and 24 deletions

View file

@ -25,6 +25,7 @@ import android.text.InputType;
import android.util.Log;
import android.util.Xml;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.keyboard.KeyboardSet.Params.ElementParams;
@ -242,7 +243,10 @@ public class KeyboardSet {
return this;
}
public Builder setSubtype(Locale inputLocale, boolean asciiCapable) {
public Builder setSubtype(InputMethodSubtype subtype) {
final Locale inputLocale = SubtypeLocale.getSubtypeLocale(subtype);
final boolean asciiCapable = subtype.containsExtraValueKey(
LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE);
final boolean deprecatedForceAscii = StringUtils.inPrivateImeOptions(
mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo);
final boolean forceAscii = EditorInfoCompatUtils.hasFlagForceAscii(

View file

@ -137,10 +137,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
final KeyboardSet.Builder builder = new KeyboardSet.Builder(mThemeContext, editorInfo);
builder.setScreenGeometry(mThemeContext.getResources().getConfiguration().orientation,
mThemeContext.getResources().getDisplayMetrics().widthPixels);
builder.setSubtype(
mSubtypeSwitcher.getInputLocale(),
mSubtypeSwitcher.currentSubtypeContainsExtraValueKey(
LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE));
builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
builder.setOptions(
settingsValues.isVoiceKeyEnabled(editorInfo),
settingsValues.isVoiceKeyOnMain(),
@ -384,7 +381,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
public void onNetworkStateChanged() {
if (mKeyboardView != null) {
mKeyboardView.updateShortcutKey(SubtypeSwitcher.getInstance().isShortcutImeReady());
mKeyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
}
}

View file

@ -713,9 +713,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold);
}
if (mSubtypeSwitcher.isKeyboardMode()) {
switcher.loadKeyboard(editorInfo, mSettingsValues);
}
switcher.loadKeyboard(editorInfo, mSettingsValues);
if (mSuggestionsView != null)
mSuggestionsView.clear();

View file

@ -18,6 +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;
@ -120,4 +121,14 @@ public class SubtypeLocale {
// - 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));
}
}

View file

@ -419,30 +419,23 @@ public class SubtypeSwitcher {
}
}
public boolean isKeyboardMode() {
// TODO: Remove this method
private boolean isKeyboardMode() {
return KEYBOARD_MODE.equals(getCurrentSubtypeMode());
}
/////////////////////////////
// Other utility functions //
/////////////////////////////
public String getCurrentSubtypeExtraValue() {
// If null, return what an empty ExtraValue would return : the empty string.
return mCurrentSubtype.getExtraValue();
// TODO: Remove this method
private String getCurrentSubtypeMode() {
return mCurrentSubtype.getMode();
}
// TODO: Remove this method
public boolean currentSubtypeContainsExtraValueKey(String key) {
// If null, return what an empty ExtraValue would return : false.
return mCurrentSubtype.containsExtraValueKey(key);
}
public String getCurrentSubtypeExtraValueOf(String key) {
// If null, return what an empty ExtraValue would return : null.
return mCurrentSubtype.getExtraValueOf(key);
}
public String getCurrentSubtypeMode() {
return mCurrentSubtype.getMode();
public InputMethodSubtype getCurrentSubtype() {
return mCurrentSubtype;
}
}