am dbb2182e
: Introduce subtype filter to unit test
* commit 'dbb2182e3928cb8d204290f83a01718d5ff9b162': Introduce subtype filter to unit test
This commit is contained in:
commit
6add006dd1
2 changed files with 58 additions and 24 deletions
|
@ -25,8 +25,8 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public class KeyboardLayoutSetSubtypesCountTests extends KeyboardLayoutSetTestsBase {
|
public class KeyboardLayoutSetSubtypesCountTests extends KeyboardLayoutSetTestsBase {
|
||||||
private static final int NUMBER_OF_SUBTYPES = 78;
|
private static final int NUMBER_OF_SUBTYPES = 80;
|
||||||
private static final int NUMBER_OF_ASCII_CAPABLE_SUBTYPES = 46;
|
private static final int NUMBER_OF_ASCII_CAPABLE_SUBTYPES = 48;
|
||||||
private static final int NUMBER_OF_PREDEFINED_ADDITIONAL_SUBTYPES = 2;
|
private static final int NUMBER_OF_PREDEFINED_ADDITIONAL_SUBTYPES = 2;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,13 +52,14 @@ public class KeyboardLayoutSetSubtypesCountTests extends KeyboardLayoutSetTestsB
|
||||||
|
|
||||||
public final void testAsciiCapableSubtypesCount() {
|
public final void testAsciiCapableSubtypesCount() {
|
||||||
final ArrayList<InputMethodSubtype> asciiCapableSubtypesList =
|
final ArrayList<InputMethodSubtype> asciiCapableSubtypesList =
|
||||||
getAsciiCapableSubtypesList();
|
getSubtypesFilteredBy(FILTER_IS_ASCII_CAPABLE);
|
||||||
assertEquals(toString(asciiCapableSubtypesList),
|
assertEquals(toString(asciiCapableSubtypesList),
|
||||||
NUMBER_OF_ASCII_CAPABLE_SUBTYPES, asciiCapableSubtypesList.size());
|
NUMBER_OF_ASCII_CAPABLE_SUBTYPES, asciiCapableSubtypesList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void testAdditionalSubtypesCount() {
|
public final void testAdditionalSubtypesCount() {
|
||||||
final ArrayList<InputMethodSubtype> additionalSubtypesList = getAdditionalSubtypesList();
|
final ArrayList<InputMethodSubtype> additionalSubtypesList =
|
||||||
|
getSubtypesFilteredBy(FILTER_IS_ADDITIONAL_SUBTYPE);
|
||||||
assertEquals(toString(additionalSubtypesList),
|
assertEquals(toString(additionalSubtypesList),
|
||||||
NUMBER_OF_PREDEFINED_ADDITIONAL_SUBTYPES, additionalSubtypesList.size());
|
NUMBER_OF_PREDEFINED_ADDITIONAL_SUBTYPES, additionalSubtypesList.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
package com.android.inputmethod.keyboard;
|
package com.android.inputmethod.keyboard;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
@ -30,6 +32,7 @@ import com.android.inputmethod.latin.Constants;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.RichInputMethodManager;
|
import com.android.inputmethod.latin.RichInputMethodManager;
|
||||||
import com.android.inputmethod.latin.RichInputMethodSubtype;
|
import com.android.inputmethod.latin.RichInputMethodSubtype;
|
||||||
|
import com.android.inputmethod.latin.settings.Settings;
|
||||||
import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
|
import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
|
||||||
import com.android.inputmethod.latin.utils.ResourceUtils;
|
import com.android.inputmethod.latin.utils.ResourceUtils;
|
||||||
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
|
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
|
||||||
|
@ -40,9 +43,27 @@ import java.util.Locale;
|
||||||
public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
||||||
// All input method subtypes of LatinIME.
|
// All input method subtypes of LatinIME.
|
||||||
private final ArrayList<InputMethodSubtype> mAllSubtypesList = new ArrayList<>();
|
private final ArrayList<InputMethodSubtype> mAllSubtypesList = new ArrayList<>();
|
||||||
private final ArrayList<InputMethodSubtype> mAsciiCapableSubtypesList = new ArrayList<>();
|
|
||||||
private final ArrayList<InputMethodSubtype> mAdditionalSubtypesList = new ArrayList<>();
|
|
||||||
|
|
||||||
|
public interface SubtypeFilter {
|
||||||
|
public boolean accept(final InputMethodSubtype subtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final SubtypeFilter FILTER_IS_ASCII_CAPABLE = new SubtypeFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(InputMethodSubtype subtype) {
|
||||||
|
return InputMethodSubtypeCompatUtils.isAsciiCapable(subtype);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final SubtypeFilter FILTER_IS_ADDITIONAL_SUBTYPE = new SubtypeFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(InputMethodSubtype subtype) {
|
||||||
|
return AdditionalSubtypeUtils.isAdditionalSubtype(subtype);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private SharedPreferences mSharedPreferences;
|
||||||
|
private String mSavedAdditionalSubtypes;
|
||||||
private int mScreenMetrics;
|
private int mScreenMetrics;
|
||||||
|
|
||||||
protected abstract int getKeyboardThemeForTests();
|
protected abstract int getKeyboardThemeForTests();
|
||||||
|
@ -50,41 +71,53 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
final Context context = getContext();
|
||||||
|
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
final Resources res = context.getResources();
|
||||||
|
|
||||||
|
// Save additional subtypes preference.
|
||||||
|
mSavedAdditionalSubtypes = Settings.readPrefAdditionalSubtypes(mSharedPreferences, res);
|
||||||
|
final String predefinedSubtypes = AdditionalSubtypeUtils.createPrefSubtypes(
|
||||||
|
res.getStringArray(R.array.predefined_subtypes));
|
||||||
|
// Reset additional subtypes to predefined ones.
|
||||||
|
Settings.writePrefAdditionalSubtypes(mSharedPreferences, predefinedSubtypes);
|
||||||
|
|
||||||
final KeyboardTheme keyboardTheme = KeyboardTheme.searchKeyboardThemeById(
|
final KeyboardTheme keyboardTheme = KeyboardTheme.searchKeyboardThemeById(
|
||||||
getKeyboardThemeForTests(), KeyboardTheme.KEYBOARD_THEMES);
|
getKeyboardThemeForTests(), KeyboardTheme.KEYBOARD_THEMES);
|
||||||
setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId));
|
setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId));
|
||||||
KeyboardLayoutSet.onKeyboardThemeChanged();
|
KeyboardLayoutSet.onKeyboardThemeChanged();
|
||||||
|
|
||||||
final Context context = getContext();
|
mScreenMetrics = res.getInteger(R.integer.config_screen_metrics);
|
||||||
mScreenMetrics = context.getResources().getInteger(R.integer.config_screen_metrics);
|
|
||||||
RichInputMethodManager.init(context);
|
RichInputMethodManager.init(context);
|
||||||
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
||||||
|
|
||||||
final InputMethodInfo imi = richImm.getInputMethodInfoOfThisIme();
|
final InputMethodInfo imi = richImm.getInputMethodInfoOfThisIme();
|
||||||
final int subtypeCount = imi.getSubtypeCount();
|
final int subtypeCount = imi.getSubtypeCount();
|
||||||
for (int index = 0; index < subtypeCount; index++) {
|
for (int index = 0; index < subtypeCount; index++) {
|
||||||
final InputMethodSubtype subtype = imi.getSubtypeAt(index);
|
mAllSubtypesList.add(imi.getSubtypeAt(index));
|
||||||
if (AdditionalSubtypeUtils.isAdditionalSubtype(subtype)) {
|
|
||||||
mAdditionalSubtypesList.add(subtype);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
mAllSubtypesList.add(subtype);
|
|
||||||
if (InputMethodSubtypeCompatUtils.isAsciiCapable(subtype)) {
|
|
||||||
mAsciiCapableSubtypesList.add(subtype);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
// Restore additional subtypes preference.
|
||||||
|
Settings.writePrefAdditionalSubtypes(mSharedPreferences, mSavedAdditionalSubtypes);
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
protected final ArrayList<InputMethodSubtype> getAllSubtypesList() {
|
protected final ArrayList<InputMethodSubtype> getAllSubtypesList() {
|
||||||
return mAllSubtypesList;
|
return mAllSubtypesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final ArrayList<InputMethodSubtype> getAsciiCapableSubtypesList() {
|
protected final ArrayList<InputMethodSubtype> getSubtypesFilteredBy(
|
||||||
return mAsciiCapableSubtypesList;
|
final SubtypeFilter filter) {
|
||||||
}
|
final ArrayList<InputMethodSubtype> list = new ArrayList<>();
|
||||||
|
for (final InputMethodSubtype subtype : mAllSubtypesList) {
|
||||||
protected final ArrayList<InputMethodSubtype> getAdditionalSubtypesList() {
|
if (filter.accept(subtype)) {
|
||||||
return mAdditionalSubtypesList;
|
list.add(subtype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean isPhone() {
|
protected final boolean isPhone() {
|
||||||
|
@ -102,7 +135,7 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
||||||
return subtype;
|
return subtype;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final InputMethodSubtype subtype : mAsciiCapableSubtypesList) {
|
for (final InputMethodSubtype subtype : getSubtypesFilteredBy(FILTER_IS_ASCII_CAPABLE)) {
|
||||||
final Locale subtypeLocale = SubtypeLocaleUtils.getSubtypeLocale(subtype);
|
final Locale subtypeLocale = SubtypeLocaleUtils.getSubtypeLocale(subtype);
|
||||||
if (locale.equals(subtypeLocale)) {
|
if (locale.equals(subtypeLocale)) {
|
||||||
// Create additional subtype.
|
// Create additional subtype.
|
||||||
|
|
Loading…
Reference in a new issue