am 6e565332: Merge "Fixing keyboard theme selection"
* commit '6e565332df385d67d58543879f9d81263e667c06': Fixing keyboard theme selectionmain
commit
287d2dcab5
|
@ -22,7 +22,6 @@ import android.os.Build.VERSION_CODES;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.inputmethod.annotations.UsedForTesting;
|
|
||||||
import com.android.inputmethod.compat.BuildCompatUtils;
|
import com.android.inputmethod.compat.BuildCompatUtils;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
|
|
||||||
|
@ -45,7 +44,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
|
|
||||||
private static KeyboardTheme[] AVAILABLE_KEYBOARD_THEMES;
|
private static KeyboardTheme[] AVAILABLE_KEYBOARD_THEMES;
|
||||||
|
|
||||||
@UsedForTesting
|
/* package private for testing */
|
||||||
static final KeyboardTheme[] KEYBOARD_THEMES = {
|
static final KeyboardTheme[] KEYBOARD_THEMES = {
|
||||||
new KeyboardTheme(THEME_ID_ICS, "ICS", R.style.KeyboardTheme_ICS,
|
new KeyboardTheme(THEME_ID_ICS, "ICS", R.style.KeyboardTheme_ICS,
|
||||||
// This has never been selected because we support ICS or later.
|
// This has never been selected because we support ICS or later.
|
||||||
|
@ -57,6 +56,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
// Default theme for LXX.
|
// Default theme for LXX.
|
||||||
BuildCompatUtils.VERSION_CODES_LXX),
|
BuildCompatUtils.VERSION_CODES_LXX),
|
||||||
new KeyboardTheme(THEME_ID_LXX_DARK, "LXXDark", R.style.KeyboardTheme_LXX_Dark,
|
new KeyboardTheme(THEME_ID_LXX_DARK, "LXXDark", R.style.KeyboardTheme_LXX_Dark,
|
||||||
|
// This has never been selected as default theme.
|
||||||
VERSION_CODES.BASE),
|
VERSION_CODES.BASE),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
public final int mThemeId;
|
public final int mThemeId;
|
||||||
public final int mStyleId;
|
public final int mStyleId;
|
||||||
public final String mThemeName;
|
public final String mThemeName;
|
||||||
private final int mMinApiVersion;
|
public final int mMinApiVersion;
|
||||||
|
|
||||||
// Note: The themeId should be aligned with "themeId" attribute of Keyboard style
|
// Note: The themeId should be aligned with "themeId" attribute of Keyboard style
|
||||||
// in values/themes-<style>.xml.
|
// in values/themes-<style>.xml.
|
||||||
|
@ -98,7 +98,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
return mThemeId;
|
return mThemeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@UsedForTesting
|
/* package private for testing */
|
||||||
static KeyboardTheme searchKeyboardThemeById(final int themeId,
|
static KeyboardTheme searchKeyboardThemeById(final int themeId,
|
||||||
final KeyboardTheme[] availableThemeIds) {
|
final KeyboardTheme[] availableThemeIds) {
|
||||||
// TODO: This search algorithm isn't optimal if there are many themes.
|
// TODO: This search algorithm isn't optimal if there are many themes.
|
||||||
|
@ -110,7 +110,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@UsedForTesting
|
/* package private for testing */
|
||||||
static KeyboardTheme getDefaultKeyboardTheme(final SharedPreferences prefs,
|
static KeyboardTheme getDefaultKeyboardTheme(final SharedPreferences prefs,
|
||||||
final int sdkVersion, final KeyboardTheme[] availableThemeArray) {
|
final int sdkVersion, final KeyboardTheme[] availableThemeArray) {
|
||||||
final String klpThemeIdString = prefs.getString(KLP_KEYBOARD_THEME_KEY, null);
|
final String klpThemeIdString = prefs.getString(KLP_KEYBOARD_THEME_KEY, null);
|
||||||
|
@ -150,7 +150,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
saveKeyboardThemeId(themeId, prefs, BuildCompatUtils.EFFECTIVE_SDK_INT);
|
saveKeyboardThemeId(themeId, prefs, BuildCompatUtils.EFFECTIVE_SDK_INT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UsedForTesting
|
/* package private for testing */
|
||||||
static String getPreferenceKey(final int sdkVersion) {
|
static String getPreferenceKey(final int sdkVersion) {
|
||||||
if (sdkVersion <= VERSION_CODES.KITKAT) {
|
if (sdkVersion <= VERSION_CODES.KITKAT) {
|
||||||
return KLP_KEYBOARD_THEME_KEY;
|
return KLP_KEYBOARD_THEME_KEY;
|
||||||
|
@ -158,7 +158,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
return LXX_KEYBOARD_THEME_KEY;
|
return LXX_KEYBOARD_THEME_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@UsedForTesting
|
/* package private for testing */
|
||||||
static void saveKeyboardThemeId(final int themeId, final SharedPreferences prefs,
|
static void saveKeyboardThemeId(final int themeId, final SharedPreferences prefs,
|
||||||
final int sdkVersion) {
|
final int sdkVersion) {
|
||||||
final String prefKey = getPreferenceKey(sdkVersion);
|
final String prefKey = getPreferenceKey(sdkVersion);
|
||||||
|
@ -171,6 +171,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
return getKeyboardTheme(prefs, BuildCompatUtils.EFFECTIVE_SDK_INT, availableThemeArray);
|
return getKeyboardTheme(prefs, BuildCompatUtils.EFFECTIVE_SDK_INT, availableThemeArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* package private for testing */
|
||||||
static KeyboardTheme[] getAvailableThemeArray(final Context context) {
|
static KeyboardTheme[] getAvailableThemeArray(final Context context) {
|
||||||
if (AVAILABLE_KEYBOARD_THEMES == null) {
|
if (AVAILABLE_KEYBOARD_THEMES == null) {
|
||||||
final int[] availableThemeIdStringArray = context.getResources().getIntArray(
|
final int[] availableThemeIdStringArray = context.getResources().getIntArray(
|
||||||
|
@ -184,11 +185,12 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
}
|
}
|
||||||
AVAILABLE_KEYBOARD_THEMES = availableThemeList.toArray(
|
AVAILABLE_KEYBOARD_THEMES = availableThemeList.toArray(
|
||||||
new KeyboardTheme[availableThemeList.size()]);
|
new KeyboardTheme[availableThemeList.size()]);
|
||||||
|
Arrays.sort(AVAILABLE_KEYBOARD_THEMES);
|
||||||
}
|
}
|
||||||
return AVAILABLE_KEYBOARD_THEMES;
|
return AVAILABLE_KEYBOARD_THEMES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@UsedForTesting
|
/* package private for testing */
|
||||||
static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs, final int sdkVersion,
|
static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs, final int sdkVersion,
|
||||||
final KeyboardTheme[] availableThemeArray) {
|
final KeyboardTheme[] availableThemeArray) {
|
||||||
final String lxxThemeIdString = prefs.getString(LXX_KEYBOARD_THEME_KEY, null);
|
final String lxxThemeIdString = prefs.getString(LXX_KEYBOARD_THEME_KEY, null);
|
||||||
|
|
|
@ -347,6 +347,31 @@ public class KeyboardThemeTests extends AndroidTestCase {
|
||||||
oldSdkVersion, newSdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX_LIGHT);
|
oldSdkVersion, newSdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX_LIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test that KeyboardTheme array should be sorted by descending order of
|
||||||
|
* {@link KeyboardTheme#mMinApiVersion}.
|
||||||
|
*/
|
||||||
|
private static void assertSortedKeyboardThemeArray(final KeyboardTheme[] array) {
|
||||||
|
assertNotNull(array);
|
||||||
|
final int length = array.length;
|
||||||
|
assertTrue("array length=" + length, length > 0);
|
||||||
|
for (int index = 0; index < length - 1; index++) {
|
||||||
|
final KeyboardTheme theme = array[index];
|
||||||
|
final KeyboardTheme nextTheme = array[index + 1];
|
||||||
|
assertTrue("sorted MinApiVersion: "
|
||||||
|
+ theme.mThemeName + ": minApiVersion=" + theme.mMinApiVersion,
|
||||||
|
theme.mMinApiVersion >= nextTheme.mMinApiVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSortedKeyboardTheme() {
|
||||||
|
assertSortedKeyboardThemeArray(KeyboardTheme.KEYBOARD_THEMES);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSortedAvailableKeyboardTheme() {
|
||||||
|
assertSortedKeyboardThemeArray(KeyboardTheme.getAvailableThemeArray(getContext()));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test for missing selected theme.
|
* Test for missing selected theme.
|
||||||
*/
|
*/
|
||||||
|
@ -356,6 +381,7 @@ public class KeyboardThemeTests extends AndroidTestCase {
|
||||||
};
|
};
|
||||||
static {
|
static {
|
||||||
Arrays.sort(LIMITED_THEMES);
|
Arrays.sort(LIMITED_THEMES);
|
||||||
|
assertSortedKeyboardThemeArray(LIMITED_THEMES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMissingSelectedThemeIcs() {
|
public void testMissingSelectedThemeIcs() {
|
||||||
|
|
Loading…
Reference in New Issue