am 083a40b2: Merge "Move createKeyboardSetForSpellChecker to AndroidSpellCheckService"

* commit '083a40b291dbd4d63aabbcb4a1dc1ca27bb46863':
  Move createKeyboardSetForSpellChecker to AndroidSpellCheckService
main
Tadashi G. Takaoka 2013-08-07 03:35:08 -07:00 committed by Android Git Automerger
commit 72b5ff6645
2 changed files with 22 additions and 45 deletions

View File

@ -33,7 +33,6 @@ import android.util.Xml;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
import com.android.inputmethod.keyboard.internal.KeyboardParams;
@ -42,10 +41,8 @@ import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.InputTypeUtils;
import com.android.inputmethod.latin.utils.ResourceUtils;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import com.android.inputmethod.latin.utils.XmlParseUtils;
@ -71,8 +68,6 @@ public final class KeyboardLayoutSet {
private static final String TAG_ELEMENT = "Element";
private static final String KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX = "keyboard_layout_set_";
private static final int SPELLCHECKER_DUMMY_KEYBOARD_WIDTH = 480;
private static final int SPELLCHECKER_DUMMY_KEYBOARD_HEIGHT = 368;
private final Context mContext;
private final Params mParams;
@ -407,41 +402,4 @@ public final class KeyboardLayoutSet {
}
}
}
public static KeyboardLayoutSet createKeyboardSetForSpellChecker(final Context context,
final String locale, final String layout) {
final InputMethodSubtype subtype =
AdditionalSubtypeUtils.createAdditionalSubtype(locale, layout, null);
return createKeyboardSet(context, subtype, SPELLCHECKER_DUMMY_KEYBOARD_WIDTH,
SPELLCHECKER_DUMMY_KEYBOARD_HEIGHT, false /* testCasesHaveTouchCoordinates */,
true /* isSpellChecker */);
}
@UsedForTesting
public static KeyboardLayoutSet createKeyboardSetForTest(final Context context,
final InputMethodSubtype subtype, final int orientation,
final boolean testCasesHaveTouchCoordinates) {
final Resources res = context.getResources();
final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
return createKeyboardSet(context, subtype, keyboardWidth, keyboardHeight,
testCasesHaveTouchCoordinates, false /* isSpellChecker */);
}
private static KeyboardLayoutSet createKeyboardSet(final Context context,
final InputMethodSubtype subtype, final int keyboardWidth, final int keyboardHeight,
final boolean testCasesHaveTouchCoordinates, final boolean isSpellChecker) {
final EditorInfo editorInfo = new EditorInfo();
editorInfo.inputType = InputType.TYPE_CLASS_TEXT;
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(
context, editorInfo);
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
builder.setSubtype(subtype);
builder.setIsSpellChecker(isSpellChecker);
if (!testCasesHaveTouchCoordinates) {
// For spell checker and tests
builder.disableTouchPositionCorrectionData();
}
return builder.build();
}
}

View File

@ -20,7 +20,10 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.service.textservice.SpellCheckerService;
import android.text.InputType;
import android.util.Log;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;
import android.view.textservice.SuggestionsInfo;
import com.android.inputmethod.keyboard.KeyboardLayoutSet;
@ -33,6 +36,7 @@ import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SynchronouslyLoadedContactsBinaryDictionary;
import com.android.inputmethod.latin.SynchronouslyLoadedUserBinaryDictionary;
import com.android.inputmethod.latin.UserBinaryDictionary;
import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.LocaleUtils;
import com.android.inputmethod.latin.utils.StringUtils;
@ -58,6 +62,9 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
public static final String PREF_USE_CONTACTS_KEY = "pref_spellcheck_use_contacts";
private static final int SPELLCHECKER_DUMMY_KEYBOARD_WIDTH = 480;
private static final int SPELLCHECKER_DUMMY_KEYBOARD_HEIGHT = 368;
private final static String[] EMPTY_STRING_ARRAY = new String[0];
private Map<String, DictionaryPool> mDictionaryPools = CollectionUtils.newSynchronizedTreeMap();
private Map<String, UserBinaryDictionary> mUserDictionaries =
@ -401,9 +408,9 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
public DictAndKeyboard createDictAndKeyboard(final Locale locale) {
final int script = getScriptFromLocale(locale);
final String keyboardLayoutName = getKeyboardLayoutNameForScript(script);
final KeyboardLayoutSet keyboardLayoutSet =
KeyboardLayoutSet.createKeyboardSetForSpellChecker(this, locale.toString(),
keyboardLayoutName);
final InputMethodSubtype subtype = AdditionalSubtypeUtils.createAdditionalSubtype(
locale.toString(), keyboardLayoutName, null);
final KeyboardLayoutSet keyboardLayoutSet = createKeyboardSetForSpellChecker(subtype);
final DictionaryCollection dictionaryCollection =
DictionaryFactory.createMainDictionaryFromManager(this, locale,
@ -431,4 +438,16 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
}
return new DictAndKeyboard(dictionaryCollection, keyboardLayoutSet);
}
private KeyboardLayoutSet createKeyboardSetForSpellChecker(final InputMethodSubtype subtype) {
final EditorInfo editorInfo = new EditorInfo();
editorInfo.inputType = InputType.TYPE_CLASS_TEXT;
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(this, editorInfo);
builder.setKeyboardGeometry(
SPELLCHECKER_DUMMY_KEYBOARD_WIDTH, SPELLCHECKER_DUMMY_KEYBOARD_HEIGHT);
builder.setSubtype(subtype);
builder.setIsSpellChecker(true /* isSpellChecker */);
builder.disableTouchPositionCorrectionData();
return builder.build();
}
}