Use KeyboardSet for unit test
Change-Id: I6a08e04628bac0222140e5b1b108f6bcb39859a2
This commit is contained in:
parent
ca132ce8e2
commit
4cabb04971
5 changed files with 25 additions and 19 deletions
|
@ -21,7 +21,7 @@ import android.text.TextUtils;
|
|||
|
||||
import com.android.inputmethod.keyboard.KeyDetector;
|
||||
import com.android.inputmethod.keyboard.Keyboard;
|
||||
import com.android.inputmethod.keyboard.KeyboardId;
|
||||
import com.android.inputmethod.keyboard.KeyboardSet;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
|
@ -32,24 +32,20 @@ public class SuggestHelper {
|
|||
protected final Keyboard mKeyboard;
|
||||
private final KeyDetector mKeyDetector;
|
||||
|
||||
public static final int ALPHABET_KEYBOARD = com.android.inputmethod.latin.R.xml.kbd_qwerty;
|
||||
|
||||
public SuggestHelper(Context context, int dictionaryId, KeyboardId keyboardId) {
|
||||
public SuggestHelper(Context context, int dictionaryId, KeyboardSet keyboardSet) {
|
||||
// Use null as the locale for Suggest so as to force it to use the internal dictionary
|
||||
// (and not try to find a dictionary provider for a specified locale)
|
||||
mSuggest = new Suggest(context, dictionaryId, null);
|
||||
mKeyboard = new Keyboard.Builder<Keyboard.Params>(context, new Keyboard.Params())
|
||||
.load(ALPHABET_KEYBOARD, keyboardId).build();
|
||||
mKeyboard = keyboardSet.getMainKeyboard();
|
||||
mKeyDetector = new KeyDetector(0);
|
||||
init();
|
||||
}
|
||||
|
||||
protected SuggestHelper(final Context context, final File dictionaryPath,
|
||||
final long startOffset, final long length, final KeyboardId keyboardId,
|
||||
final long startOffset, final long length, final KeyboardSet keyboardSet,
|
||||
final Locale locale) {
|
||||
mSuggest = new Suggest(context, dictionaryPath, startOffset, length, null, locale);
|
||||
mKeyboard = new Keyboard.Builder<Keyboard.Params>(context, new Keyboard.Params())
|
||||
.load(ALPHABET_KEYBOARD, keyboardId).build();
|
||||
mKeyboard = keyboardSet.getMainKeyboard();
|
||||
mKeyDetector = new KeyDetector(0);
|
||||
init();
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class SuggestTests extends SuggestTestsBase {
|
|||
final Locale locale = Locale.US;
|
||||
mHelper = new SuggestHelper(
|
||||
getContext(), mTestPackageFile, dict.getStartOffset(), dict.getLength(),
|
||||
createKeyboardId(locale, Configuration.ORIENTATION_PORTRAIT), locale);
|
||||
createKeyboardSet(locale, Configuration.ORIENTATION_PORTRAIT), locale);
|
||||
mHelper.setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,9 @@ import android.test.AndroidTestCase;
|
|||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
|
||||
import com.android.inputmethod.keyboard.KeyboardId;
|
||||
import com.android.inputmethod.keyboard.KeyboardSet;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
@ -38,7 +39,12 @@ public class SuggestTestsBase extends AndroidTestCase {
|
|||
mTestPackageFile = new File(getTestContext().getApplicationInfo().sourceDir);
|
||||
}
|
||||
|
||||
protected KeyboardId createKeyboardId(Locale locale, int orientation) {
|
||||
protected KeyboardSet createKeyboardSet(Locale locale, int orientation) {
|
||||
return createKeyboardSet(locale, orientation, false);
|
||||
}
|
||||
|
||||
protected KeyboardSet createKeyboardSet(Locale locale, int orientation,
|
||||
boolean touchPositionCorrectionEnabled) {
|
||||
final DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
|
||||
final int width;
|
||||
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
|
@ -50,8 +56,12 @@ public class SuggestTestsBase extends AndroidTestCase {
|
|||
+ "orientation=" + orientation);
|
||||
return null;
|
||||
}
|
||||
return new KeyboardId(KeyboardId.ELEMENT_ALPHABET, locale, orientation, width,
|
||||
KeyboardId.MODE_TEXT, InputType.TYPE_CLASS_TEXT, 0, false, false, false, false);
|
||||
final EditorInfo editorInfo = new EditorInfo();
|
||||
editorInfo.inputType = InputType.TYPE_CLASS_TEXT;
|
||||
final KeyboardSet.Builder builder = new KeyboardSet.Builder(getContext(), editorInfo);
|
||||
builder.setScreenGeometry(orientation, width);
|
||||
builder.setSubtype(locale, true, touchPositionCorrectionEnabled);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected InputStream openTestRawResource(int resIdInTest) {
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
|
||||
package com.android.inputmethod.latin;
|
||||
|
||||
import com.android.inputmethod.keyboard.KeyboardId;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.inputmethod.keyboard.KeyboardSet;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
import java.util.StringTokenizer;
|
||||
|
@ -31,8 +31,8 @@ public class UserBigramSuggestHelper extends SuggestHelper {
|
|||
|
||||
public UserBigramSuggestHelper(final Context context, final File dictionaryPath,
|
||||
final long startOffset, final long length, final int userBigramMax,
|
||||
final int userBigramDelete, final KeyboardId keyboardId, final Locale locale) {
|
||||
super(context, dictionaryPath, startOffset, length, keyboardId, locale);
|
||||
final int userBigramDelete, final KeyboardSet keyboardSet, final Locale locale) {
|
||||
super(context, dictionaryPath, startOffset, length, keyboardSet, locale);
|
||||
mContext = context;
|
||||
mUserBigram = new UserBigramDictionary(context, null, locale.toString(),
|
||||
Suggest.DIC_USER);
|
||||
|
|
|
@ -37,7 +37,7 @@ public class UserBigramSuggestTests extends SuggestTestsBase {
|
|||
mHelper = new UserBigramSuggestHelper(
|
||||
getContext(), mTestPackageFile, dict.getStartOffset(), dict.getLength(),
|
||||
MAX_DATA, DELETE_DATA,
|
||||
createKeyboardId(locale, Configuration.ORIENTATION_PORTRAIT), locale);
|
||||
createKeyboardSet(locale, Configuration.ORIENTATION_PORTRAIT), locale);
|
||||
}
|
||||
|
||||
/************************** Tests ************************/
|
||||
|
|
Loading…
Reference in a new issue