Merge "Remove reference of SubtypeSwitcher and SettingsValues from KeyboardSet"

This commit is contained in:
Tadashi G. Takaoka 2012-01-13 01:39:50 -08:00 committed by Android (Google) Code Review
commit ca132ce8e2
3 changed files with 69 additions and 40 deletions

View file

@ -440,6 +440,19 @@ public class Keyboard {
} }
} }
public static String toThemeName(int themeId) {
// This should be aligned with theme-*.xml resource files' themeId attribute.
switch (themeId) {
case 0: return "Basic";
case 1: return "BasicHighContrast";
case 5: return "IceCreamSandwich";
case 6: return "Stone";
case 7: return "StoneBold";
case 8: return "GingerBread";
default: return null;
}
}
/** /**
* Keyboard Building helper. * Keyboard Building helper.
* *

View file

@ -17,6 +17,7 @@
package com.android.inputmethod.keyboard; package com.android.inputmethod.keyboard;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.content.res.XmlResourceParser; import android.content.res.XmlResourceParser;
@ -28,8 +29,6 @@ import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.LocaleUtils; import com.android.inputmethod.latin.LocaleUtils;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SettingsValues;
import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.Utils; import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.XmlParseUtils; import com.android.inputmethod.latin.XmlParseUtils;
@ -61,6 +60,7 @@ public class KeyboardSet {
int mMode; int mMode;
int mInputType; int mInputType;
int mImeOptions; int mImeOptions;
boolean mTouchPositionCorrectionEnabled;
boolean mSettingsKeyEnabled; boolean mSettingsKeyEnabled;
boolean mVoiceKeyEnabled; boolean mVoiceKeyEnabled;
boolean mVoiceKeyOnMain; boolean mVoiceKeyOnMain;
@ -115,9 +115,8 @@ public class KeyboardSet {
return Builder.getKeyboardId(elementState, false, mParams); return Builder.getKeyboardId(elementState, false, mParams);
} }
private static Keyboard getKeyboard(Context context, int xmlId, KeyboardId id) { private Keyboard getKeyboard(Context context, int xmlId, KeyboardId id) {
final Resources res = context.getResources(); final Resources res = context.getResources();
final SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance();
final SoftReference<Keyboard> ref = sKeyboardCache.get(id); final SoftReference<Keyboard> ref = sKeyboardCache.get(id);
Keyboard keyboard = (ref == null) ? null : ref.get(); Keyboard keyboard = (ref == null) ? null : ref.get();
if (keyboard == null) { if (keyboard == null) {
@ -126,9 +125,7 @@ public class KeyboardSet {
final Keyboard.Builder<Keyboard.Params> builder = final Keyboard.Builder<Keyboard.Params> builder =
new Keyboard.Builder<Keyboard.Params>(context, new Keyboard.Params()); new Keyboard.Builder<Keyboard.Params>(context, new Keyboard.Params());
builder.load(xmlId, id); builder.load(xmlId, id);
builder.setTouchPositionCorrectionEnabled( builder.setTouchPositionCorrectionEnabled(mParams.mTouchPositionCorrectionEnabled);
subtypeSwitcher.currentSubtypeContainsExtraValueKey(
LatinIME.SUBTYPE_EXTRA_VALUE_SUPPORT_TOUCH_POSITION_CORRECTION));
keyboard = builder.build(); keyboard = builder.build();
} finally { } finally {
LocaleUtils.setSystemLocale(res, savedLocale); LocaleUtils.setSystemLocale(res, savedLocale);
@ -151,15 +148,17 @@ public class KeyboardSet {
public static class Builder { public static class Builder {
private final Context mContext; private final Context mContext;
private final String mPackageName;
private final Resources mResources; private final Resources mResources;
private final EditorInfo mEditorInfo;
private final Params mParams = new Params(); private final Params mParams = new Params();
public Builder(Context context, EditorInfo editorInfo, SettingsValues settingsValues) { public Builder(Context context, EditorInfo editorInfo) {
mContext = context; mContext = context;
mPackageName = context.getPackageName();
mResources = context.getResources(); mResources = context.getResources();
final SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance(); mEditorInfo = editorInfo;
final String packageName = context.getPackageName();
final Params params = mParams; final Params params = mParams;
params.mMode = Utils.getKeyboardMode(editorInfo); params.mMode = Utils.getKeyboardMode(editorInfo);
@ -167,27 +166,45 @@ public class KeyboardSet {
params.mInputType = editorInfo.inputType; params.mInputType = editorInfo.inputType;
params.mImeOptions = editorInfo.imeOptions; params.mImeOptions = editorInfo.imeOptions;
} }
params.mSettingsKeyEnabled = settingsValues.isSettingsKeyEnabled(); params.mNoSettingsKey = Utils.inPrivateImeOptions(
mPackageName, LatinIME.IME_OPTION_NO_SETTINGS_KEY, mEditorInfo);
}
public Builder setScreenGeometry(int orientation, int widthPixels) {
mParams.mOrientation = orientation;
mParams.mWidth = widthPixels;
return this;
}
// TODO: Use InputMethodSubtype object as argument.
public Builder setSubtype(Locale inputLocale, boolean asciiCapable,
boolean touchPositionCorrectionEnabled) {
final boolean forceAscii = Utils.inPrivateImeOptions(
mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo);
mParams.mLocale = (forceAscii && !asciiCapable) ? Locale.US : inputLocale;
mParams.mTouchPositionCorrectionEnabled = touchPositionCorrectionEnabled;
return this;
}
public Builder setOptions(boolean settingsKeyEnabled, boolean voiceKeyEnabled,
boolean voiceKeyOnMain) {
mParams.mSettingsKeyEnabled = settingsKeyEnabled;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
final boolean noMicrophone = Utils.inPrivateImeOptions( final boolean noMicrophone = Utils.inPrivateImeOptions(
packageName, LatinIME.IME_OPTION_NO_MICROPHONE, editorInfo) mPackageName, LatinIME.IME_OPTION_NO_MICROPHONE, mEditorInfo)
|| Utils.inPrivateImeOptions( || Utils.inPrivateImeOptions(
null, LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo); null, LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, mEditorInfo);
params.mVoiceKeyEnabled = settingsValues.isVoiceKeyEnabled(editorInfo) && !noMicrophone; mParams.mVoiceKeyEnabled = voiceKeyEnabled && !noMicrophone;
params.mVoiceKeyOnMain = settingsValues.isVoiceKeyOnMain(); mParams.mVoiceKeyOnMain = voiceKeyOnMain;
params.mNoSettingsKey = Utils.inPrivateImeOptions( return this;
packageName, LatinIME.IME_OPTION_NO_SETTINGS_KEY, editorInfo);
final boolean forceAscii = Utils.inPrivateImeOptions(
packageName, LatinIME.IME_OPTION_FORCE_ASCII, editorInfo);
final boolean asciiCapable = subtypeSwitcher.currentSubtypeContainsExtraValueKey(
LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE);
params.mLocale = (forceAscii && !asciiCapable)
? Locale.US : subtypeSwitcher.getInputLocale();
params.mOrientation = mResources.getConfiguration().orientation;
params.mWidth = mResources.getDisplayMetrics().widthPixels;
} }
public KeyboardSet build() { public KeyboardSet build() {
if (mParams.mOrientation == Configuration.ORIENTATION_UNDEFINED)
throw new RuntimeException("Screen geometry is not specified");
if (mParams.mLocale == null)
throw new RuntimeException("KeyboardSet subtype is not specified");
final Locale savedLocale = LocaleUtils.setSystemLocale(mResources, mParams.mLocale); final Locale savedLocale = LocaleUtils.setSystemLocale(mResources, mParams.mLocale);
try { try {
parseKeyboardSet(mResources, R.xml.keyboard_set); parseKeyboardSet(mResources, R.xml.keyboard_set);

View file

@ -117,8 +117,20 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
} }
public void loadKeyboard(EditorInfo editorInfo, SettingsValues settingsValues) { public void loadKeyboard(EditorInfo editorInfo, SettingsValues settingsValues) {
mKeyboardSet = new KeyboardSet.Builder(mThemeContext, editorInfo, settingsValues) final KeyboardSet.Builder builder = new KeyboardSet.Builder(mThemeContext, editorInfo);
.build(); builder.setScreenGeometry(mThemeContext.getResources().getConfiguration().orientation,
mThemeContext.getResources().getDisplayMetrics().widthPixels);
builder.setSubtype(
mSubtypeSwitcher.getInputLocale(),
mSubtypeSwitcher.currentSubtypeContainsExtraValueKey(
LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE),
mSubtypeSwitcher.currentSubtypeContainsExtraValueKey(
LatinIME.SUBTYPE_EXTRA_VALUE_SUPPORT_TOUCH_POSITION_CORRECTION));
builder.setOptions(
settingsValues.isSettingsKeyEnabled(),
settingsValues.isVoiceKeyEnabled(editorInfo),
settingsValues.isVoiceKeyOnMain());
mKeyboardSet = builder.build();
final KeyboardId mainKeyboardId = mKeyboardSet.getMainKeyboardId(); final KeyboardId mainKeyboardId = mKeyboardSet.getMainKeyboardId();
try { try {
mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols), mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols),
@ -418,17 +430,4 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
} }
} }
} }
private static String themeName(int themeId) {
// This should be aligned with theme-*.xml resource files' themeId attribute.
switch (themeId) {
case 0: return "Basic";
case 1: return "BasicHighContrast";
case 5: return "IceCreamSandwich";
case 6: return "Stone";
case 7: return "StoneBold";
case 8: return "GingerBread";
default: return null;
}
}
} }