Merge "Fall back to default keyboard theme"
commit
e2a396eef0
|
@ -26,10 +26,10 @@
|
||||||
<item>@string/keyboard_theme_holo_blue</item>
|
<item>@string/keyboard_theme_holo_blue</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<!-- An element must be a keyboard theme id of {@link KeyboardTheme#THEME_ID_*}. -->
|
<!-- An element must be a keyboard theme id of {@link KeyboardTheme#THEME_ID_*}. -->
|
||||||
<string-array name="keyboard_theme_ids" translatable="false">
|
<integer-array name="keyboard_theme_ids" translatable="false">
|
||||||
<item>3</item>
|
<item>3</item>
|
||||||
<item>4</item>
|
<item>4</item>
|
||||||
<item>2</item>
|
<item>2</item>
|
||||||
<item>0</item>
|
<item>0</item>
|
||||||
</string-array>
|
</integer-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -17,9 +17,7 @@
|
||||||
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.util.Log;
|
import android.util.Log;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -47,7 +45,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
private static final String TAG = KeyboardSwitcher.class.getSimpleName();
|
private static final String TAG = KeyboardSwitcher.class.getSimpleName();
|
||||||
|
|
||||||
private SubtypeSwitcher mSubtypeSwitcher;
|
private SubtypeSwitcher mSubtypeSwitcher;
|
||||||
private SharedPreferences mPrefs;
|
|
||||||
|
|
||||||
private InputView mCurrentInputView;
|
private InputView mCurrentInputView;
|
||||||
private View mMainKeyboardFrame;
|
private View mMainKeyboardFrame;
|
||||||
|
@ -76,13 +73,11 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(final LatinIME latinIme) {
|
public static void init(final LatinIME latinIme) {
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(latinIme);
|
sInstance.initInternal(latinIme);
|
||||||
sInstance.initInternal(latinIme, prefs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initInternal(final LatinIME latinIme, final SharedPreferences prefs) {
|
private void initInternal(final LatinIME latinIme) {
|
||||||
mLatinIME = latinIme;
|
mLatinIME = latinIme;
|
||||||
mPrefs = prefs;
|
|
||||||
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
||||||
mState = new KeyboardState(this);
|
mState = new KeyboardState(this);
|
||||||
mIsHardwareAcceleratedDrawingEnabled =
|
mIsHardwareAcceleratedDrawingEnabled =
|
||||||
|
@ -91,7 +86,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
|
|
||||||
public void updateKeyboardTheme() {
|
public void updateKeyboardTheme() {
|
||||||
final boolean themeUpdated = updateKeyboardThemeAndContextThemeWrapper(
|
final boolean themeUpdated = updateKeyboardThemeAndContextThemeWrapper(
|
||||||
mLatinIME, KeyboardTheme.getKeyboardTheme(mPrefs));
|
mLatinIME, KeyboardTheme.getKeyboardTheme(mLatinIME /* context */));
|
||||||
if (themeUpdated && mKeyboardView != null) {
|
if (themeUpdated && mKeyboardView != null) {
|
||||||
mLatinIME.setInputView(onCreateInputView(mIsHardwareAcceleratedDrawingEnabled));
|
mLatinIME.setInputView(onCreateInputView(mIsHardwareAcceleratedDrawingEnabled));
|
||||||
}
|
}
|
||||||
|
@ -348,7 +343,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateKeyboardThemeAndContextThemeWrapper(
|
updateKeyboardThemeAndContextThemeWrapper(
|
||||||
mLatinIME, KeyboardTheme.getKeyboardTheme(mPrefs));
|
mLatinIME, KeyboardTheme.getKeyboardTheme(mLatinIME /* context */));
|
||||||
mCurrentInputView = (InputView)LayoutInflater.from(mThemeContext).inflate(
|
mCurrentInputView = (InputView)LayoutInflater.from(mThemeContext).inflate(
|
||||||
R.layout.input_view, null);
|
R.layout.input_view, null);
|
||||||
mMainKeyboardFrame = mCurrentInputView.findViewById(R.id.main_keyboard_frame);
|
mMainKeyboardFrame = mCurrentInputView.findViewById(R.id.main_keyboard_frame);
|
||||||
|
|
|
@ -16,14 +16,17 @@
|
||||||
|
|
||||||
package com.android.inputmethod.keyboard;
|
package com.android.inputmethod.keyboard;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build.VERSION_CODES;
|
import android.os.Build.VERSION_CODES;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.inputmethod.annotations.UsedForTesting;
|
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;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
|
@ -40,7 +43,10 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
public static final int THEME_ID_LXX_DARK = 4;
|
public static final int THEME_ID_LXX_DARK = 4;
|
||||||
public static final int DEFAULT_THEME_ID = THEME_ID_KLP;
|
public static final int DEFAULT_THEME_ID = THEME_ID_KLP;
|
||||||
|
|
||||||
private static final KeyboardTheme[] KEYBOARD_THEMES = {
|
private static KeyboardTheme[] AVAILABLE_KEYBOARD_THEMES;
|
||||||
|
|
||||||
|
@UsedForTesting
|
||||||
|
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.
|
||||||
VERSION_CODES.BASE),
|
VERSION_CODES.BASE),
|
||||||
|
@ -93,9 +99,10 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
static KeyboardTheme searchKeyboardThemeById(final int themeId) {
|
static KeyboardTheme searchKeyboardThemeById(final int themeId,
|
||||||
|
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.
|
||||||
for (final KeyboardTheme theme : KEYBOARD_THEMES) {
|
for (final KeyboardTheme theme : availableThemeIds) {
|
||||||
if (theme.mThemeId == themeId) {
|
if (theme.mThemeId == themeId) {
|
||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
@ -105,13 +112,14 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
static KeyboardTheme getDefaultKeyboardTheme(final SharedPreferences prefs,
|
static KeyboardTheme getDefaultKeyboardTheme(final SharedPreferences prefs,
|
||||||
final int sdkVersion) {
|
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);
|
||||||
if (klpThemeIdString != null) {
|
if (klpThemeIdString != null) {
|
||||||
if (sdkVersion <= VERSION_CODES.KITKAT) {
|
if (sdkVersion <= VERSION_CODES.KITKAT) {
|
||||||
try {
|
try {
|
||||||
final int themeId = Integer.parseInt(klpThemeIdString);
|
final int themeId = Integer.parseInt(klpThemeIdString);
|
||||||
final KeyboardTheme theme = searchKeyboardThemeById(themeId);
|
final KeyboardTheme theme = searchKeyboardThemeById(themeId,
|
||||||
|
availableThemeArray);
|
||||||
if (theme != null) {
|
if (theme != null) {
|
||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
@ -125,22 +133,21 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
prefs.edit().remove(KLP_KEYBOARD_THEME_KEY).apply();
|
prefs.edit().remove(KLP_KEYBOARD_THEME_KEY).apply();
|
||||||
}
|
}
|
||||||
// TODO: This search algorithm isn't optimal if there are many themes.
|
// TODO: This search algorithm isn't optimal if there are many themes.
|
||||||
for (final KeyboardTheme theme : KEYBOARD_THEMES) {
|
for (final KeyboardTheme theme : availableThemeArray) {
|
||||||
if (sdkVersion >= theme.mMinApiVersion) {
|
if (sdkVersion >= theme.mMinApiVersion) {
|
||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return searchKeyboardThemeById(DEFAULT_THEME_ID);
|
return searchKeyboardThemeById(DEFAULT_THEME_ID, availableThemeArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getKeyboardThemeName(final int themeId) {
|
public static String getKeyboardThemeName(final int themeId) {
|
||||||
final KeyboardTheme theme = searchKeyboardThemeById(themeId);
|
final KeyboardTheme theme = searchKeyboardThemeById(themeId, KEYBOARD_THEMES);
|
||||||
return theme.mThemeName;
|
return theme.mThemeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveKeyboardThemeId(final String themeIdString,
|
public static void saveKeyboardThemeId(final int themeId, final SharedPreferences prefs) {
|
||||||
final SharedPreferences prefs) {
|
saveKeyboardThemeId(themeId, prefs, BuildCompatUtils.EFFECTIVE_SDK_INT);
|
||||||
saveKeyboardThemeId(themeIdString, prefs, BuildCompatUtils.EFFECTIVE_SDK_INT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
|
@ -152,25 +159,45 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
static void saveKeyboardThemeId(final String themeIdString,
|
static void saveKeyboardThemeId(final int themeId, final SharedPreferences prefs,
|
||||||
final SharedPreferences prefs, final int sdkVersion) {
|
final int sdkVersion) {
|
||||||
final String prefKey = getPreferenceKey(sdkVersion);
|
final String prefKey = getPreferenceKey(sdkVersion);
|
||||||
prefs.edit().putString(prefKey, themeIdString).apply();
|
prefs.edit().putString(prefKey, Integer.toString(themeId)).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs) {
|
public static KeyboardTheme getKeyboardTheme(final Context context) {
|
||||||
return getKeyboardTheme(prefs, BuildCompatUtils.EFFECTIVE_SDK_INT);
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
final KeyboardTheme[] availableThemeArray = getAvailableThemeArray(context);
|
||||||
|
return getKeyboardTheme(prefs, BuildCompatUtils.EFFECTIVE_SDK_INT, availableThemeArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
static KeyboardTheme[] getAvailableThemeArray(final Context context) {
|
||||||
|
if (AVAILABLE_KEYBOARD_THEMES == null) {
|
||||||
|
final int[] availableThemeIdStringArray = context.getResources().getIntArray(
|
||||||
|
R.array.keyboard_theme_ids);
|
||||||
|
final ArrayList<KeyboardTheme> availableThemeList = new ArrayList<>();
|
||||||
|
for (final int id : availableThemeIdStringArray) {
|
||||||
|
final KeyboardTheme theme = searchKeyboardThemeById(id, KEYBOARD_THEMES);
|
||||||
|
if (theme != null) {
|
||||||
|
availableThemeList.add(theme);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AVAILABLE_KEYBOARD_THEMES = availableThemeList.toArray(
|
||||||
|
new KeyboardTheme[availableThemeList.size()]);
|
||||||
|
}
|
||||||
|
return AVAILABLE_KEYBOARD_THEMES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs, final int sdkVersion) {
|
static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs, final int sdkVersion,
|
||||||
|
final KeyboardTheme[] availableThemeArray) {
|
||||||
final String lxxThemeIdString = prefs.getString(LXX_KEYBOARD_THEME_KEY, null);
|
final String lxxThemeIdString = prefs.getString(LXX_KEYBOARD_THEME_KEY, null);
|
||||||
if (lxxThemeIdString == null) {
|
if (lxxThemeIdString == null) {
|
||||||
return getDefaultKeyboardTheme(prefs, sdkVersion);
|
return getDefaultKeyboardTheme(prefs, sdkVersion, availableThemeArray);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final int themeId = Integer.parseInt(lxxThemeIdString);
|
final int themeId = Integer.parseInt(lxxThemeIdString);
|
||||||
final KeyboardTheme theme = searchKeyboardThemeById(themeId);
|
final KeyboardTheme theme = searchKeyboardThemeById(themeId, availableThemeArray);
|
||||||
if (theme != null) {
|
if (theme != null) {
|
||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
@ -180,6 +207,6 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||||
}
|
}
|
||||||
// Remove preference that contains unknown or illegal theme id.
|
// Remove preference that contains unknown or illegal theme id.
|
||||||
prefs.edit().remove(LXX_KEYBOARD_THEME_KEY).apply();
|
prefs.edit().remove(LXX_KEYBOARD_THEME_KEY).apply();
|
||||||
return getDefaultKeyboardTheme(prefs, sdkVersion);
|
return getDefaultKeyboardTheme(prefs, sdkVersion, availableThemeArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package com.android.inputmethod.latin.settings;
|
package com.android.inputmethod.latin.settings;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
|
@ -32,12 +31,12 @@ import com.android.inputmethod.latin.settings.RadioButtonPreference.OnRadioButto
|
||||||
*/
|
*/
|
||||||
public final class ThemeSettingsFragment extends SubScreenFragment
|
public final class ThemeSettingsFragment extends SubScreenFragment
|
||||||
implements OnRadioButtonClickedListener {
|
implements OnRadioButtonClickedListener {
|
||||||
private String mSelectedThemeId;
|
private int mSelectedThemeId;
|
||||||
|
|
||||||
static class KeyboardThemePreference extends RadioButtonPreference {
|
static class KeyboardThemePreference extends RadioButtonPreference {
|
||||||
final String mThemeId;
|
final int mThemeId;
|
||||||
|
|
||||||
KeyboardThemePreference(final Context context, final String name, final String id) {
|
KeyboardThemePreference(final Context context, final String name, final int id) {
|
||||||
super(context);
|
super(context);
|
||||||
setTitle(name);
|
setTitle(name);
|
||||||
mThemeId = id;
|
mThemeId = id;
|
||||||
|
@ -45,14 +44,13 @@ public final class ThemeSettingsFragment extends SubScreenFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateKeyboardThemeSummary(final Preference pref) {
|
static void updateKeyboardThemeSummary(final Preference pref) {
|
||||||
final Resources res = pref.getContext().getResources();
|
final Context context = pref.getContext();
|
||||||
final SharedPreferences prefs = pref.getSharedPreferences();
|
final Resources res = context.getResources();
|
||||||
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(prefs);
|
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
|
||||||
final String keyboardThemeId = String.valueOf(keyboardTheme.mThemeId);
|
|
||||||
final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
|
final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
|
||||||
final String[] keyboardThemeIds = res.getStringArray(R.array.keyboard_theme_ids);
|
final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
|
||||||
for (int index = 0; index < keyboardThemeNames.length; index++) {
|
for (int index = 0; index < keyboardThemeNames.length; index++) {
|
||||||
if (keyboardThemeId.equals(keyboardThemeIds[index])) {
|
if (keyboardTheme.mThemeId == keyboardThemeIds[index]) {
|
||||||
pref.setSummary(keyboardThemeNames[index]);
|
pref.setSummary(keyboardThemeNames[index]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -64,18 +62,18 @@ public final class ThemeSettingsFragment extends SubScreenFragment
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
addPreferencesFromResource(R.xml.prefs_screen_theme);
|
addPreferencesFromResource(R.xml.prefs_screen_theme);
|
||||||
final PreferenceScreen screen = getPreferenceScreen();
|
final PreferenceScreen screen = getPreferenceScreen();
|
||||||
|
final Context context = getActivity();
|
||||||
final Resources res = getResources();
|
final Resources res = getResources();
|
||||||
final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
|
final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names);
|
||||||
final String[] keyboardThemeIds = res.getStringArray(R.array.keyboard_theme_ids);
|
final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids);
|
||||||
for (int index = 0; index < keyboardThemeNames.length; index++) {
|
for (int index = 0; index < keyboardThemeNames.length; index++) {
|
||||||
final KeyboardThemePreference pref = new KeyboardThemePreference(
|
final KeyboardThemePreference pref = new KeyboardThemePreference(
|
||||||
getActivity(), keyboardThemeNames[index], keyboardThemeIds[index]);
|
context, keyboardThemeNames[index], keyboardThemeIds[index]);
|
||||||
screen.addPreference(pref);
|
screen.addPreference(pref);
|
||||||
pref.setOnRadioButtonClickedListener(this);
|
pref.setOnRadioButtonClickedListener(this);
|
||||||
}
|
}
|
||||||
final SharedPreferences prefs = getSharedPreferences();
|
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
|
||||||
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(prefs);
|
mSelectedThemeId = keyboardTheme.mThemeId;
|
||||||
mSelectedThemeId = String.valueOf(keyboardTheme.mThemeId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -106,7 +104,7 @@ public final class ThemeSettingsFragment extends SubScreenFragment
|
||||||
final Preference preference = screen.getPreference(index);
|
final Preference preference = screen.getPreference(index);
|
||||||
if (preference instanceof KeyboardThemePreference) {
|
if (preference instanceof KeyboardThemePreference) {
|
||||||
final KeyboardThemePreference pref = (KeyboardThemePreference)preference;
|
final KeyboardThemePreference pref = (KeyboardThemePreference)preference;
|
||||||
final boolean selected = mSelectedThemeId.equals(pref.mThemeId);
|
final boolean selected = (mSelectedThemeId == pref.mThemeId);
|
||||||
pref.setSelected(selected);
|
pref.setSelected(selected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
final KeyboardTheme keyboardTheme = KeyboardTheme.searchKeyboardThemeById(
|
final KeyboardTheme keyboardTheme = KeyboardTheme.searchKeyboardThemeById(
|
||||||
getKeyboardThemeForTests());
|
getKeyboardThemeForTests(), KeyboardTheme.KEYBOARD_THEMES);
|
||||||
setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId));
|
setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId));
|
||||||
KeyboardLayoutSet.onKeyboardThemeChanged();
|
KeyboardLayoutSet.onKeyboardThemeChanged();
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@ import android.preference.PreferenceManager;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public class KeyboardThemeTests extends AndroidTestCase {
|
public class KeyboardThemeTests extends AndroidTestCase {
|
||||||
private SharedPreferences mPrefs;
|
private SharedPreferences mPrefs;
|
||||||
|
@ -77,7 +79,9 @@ public class KeyboardThemeTests extends AndroidTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertKeyboardTheme(final int sdkVersion, final int expectedThemeId) {
|
private void assertKeyboardTheme(final int sdkVersion, final int expectedThemeId) {
|
||||||
assertEquals(expectedThemeId, KeyboardTheme.getKeyboardTheme(mPrefs, sdkVersion).mThemeId);
|
final KeyboardTheme actualTheme = KeyboardTheme.getKeyboardTheme(
|
||||||
|
mPrefs, sdkVersion, KeyboardTheme.KEYBOARD_THEMES);
|
||||||
|
assertEquals(expectedThemeId, actualTheme.mThemeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -139,8 +143,8 @@ public class KeyboardThemeTests extends AndroidTestCase {
|
||||||
final String oldPrefKey = KeyboardTheme.KLP_KEYBOARD_THEME_KEY;
|
final String oldPrefKey = KeyboardTheme.KLP_KEYBOARD_THEME_KEY;
|
||||||
setKeyboardThemePreference(oldPrefKey, previousThemeId);
|
setKeyboardThemePreference(oldPrefKey, previousThemeId);
|
||||||
|
|
||||||
final KeyboardTheme defaultTheme =
|
final KeyboardTheme defaultTheme = KeyboardTheme.getDefaultKeyboardTheme(
|
||||||
KeyboardTheme.getDefaultKeyboardTheme(mPrefs, sdkVersion);
|
mPrefs, sdkVersion, KeyboardTheme.KEYBOARD_THEMES);
|
||||||
|
|
||||||
assertNotNull(defaultTheme);
|
assertNotNull(defaultTheme);
|
||||||
assertEquals(expectedThemeId, defaultTheme.mThemeId);
|
assertEquals(expectedThemeId, defaultTheme.mThemeId);
|
||||||
|
@ -194,7 +198,8 @@ public class KeyboardThemeTests extends AndroidTestCase {
|
||||||
// Clean up new keyboard theme preference to simulate "upgrade to LXX keyboard".
|
// Clean up new keyboard theme preference to simulate "upgrade to LXX keyboard".
|
||||||
setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL);
|
setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL);
|
||||||
|
|
||||||
final KeyboardTheme theme = KeyboardTheme.getKeyboardTheme(mPrefs, sdkVersion);
|
final KeyboardTheme theme = KeyboardTheme.getKeyboardTheme(
|
||||||
|
mPrefs, sdkVersion, KeyboardTheme.KEYBOARD_THEMES);
|
||||||
|
|
||||||
assertNotNull(theme);
|
assertNotNull(theme);
|
||||||
assertEquals(expectedThemeId, theme.mThemeId);
|
assertEquals(expectedThemeId, theme.mThemeId);
|
||||||
|
@ -341,4 +346,60 @@ public class KeyboardThemeTests extends AndroidTestCase {
|
||||||
assertUpgradePlatformFromTo(
|
assertUpgradePlatformFromTo(
|
||||||
oldSdkVersion, newSdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX_LIGHT);
|
oldSdkVersion, newSdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX_LIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test for missing selected theme.
|
||||||
|
*/
|
||||||
|
private static KeyboardTheme[] LIMITED_THEMES = {
|
||||||
|
KeyboardTheme.searchKeyboardThemeById(THEME_ID_ICS, KeyboardTheme.KEYBOARD_THEMES),
|
||||||
|
KeyboardTheme.searchKeyboardThemeById(THEME_ID_KLP, KeyboardTheme.KEYBOARD_THEMES)
|
||||||
|
};
|
||||||
|
static {
|
||||||
|
Arrays.sort(LIMITED_THEMES);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMissingSelectedThemeIcs() {
|
||||||
|
// Clean up preferences.
|
||||||
|
setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL);
|
||||||
|
setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL);
|
||||||
|
|
||||||
|
final int sdkVersion = VERSION_CODES.ICE_CREAM_SANDWICH;
|
||||||
|
final String oldPrefKey = KeyboardTheme.getPreferenceKey(sdkVersion);
|
||||||
|
setKeyboardThemePreference(oldPrefKey, THEME_ID_LXX_LIGHT);
|
||||||
|
|
||||||
|
final KeyboardTheme actualTheme = KeyboardTheme.getKeyboardTheme(
|
||||||
|
mPrefs, sdkVersion, LIMITED_THEMES);
|
||||||
|
// LXX_LIGHT is missing, fall-back to KLP.
|
||||||
|
assertEquals(THEME_ID_KLP, actualTheme.mThemeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMissingSelectedThemeKlp() {
|
||||||
|
// Clean up preferences.
|
||||||
|
setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL);
|
||||||
|
setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL);
|
||||||
|
|
||||||
|
final int sdkVersion = VERSION_CODES.KITKAT;
|
||||||
|
final String oldPrefKey = KeyboardTheme.getPreferenceKey(sdkVersion);
|
||||||
|
setKeyboardThemePreference(oldPrefKey, THEME_ID_LXX_LIGHT);
|
||||||
|
|
||||||
|
final KeyboardTheme actualTheme = KeyboardTheme.getKeyboardTheme(
|
||||||
|
mPrefs, sdkVersion, LIMITED_THEMES);
|
||||||
|
// LXX_LIGHT is missing, fall-back to KLP.
|
||||||
|
assertEquals(THEME_ID_KLP, actualTheme.mThemeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMissingSelectedThemeLxx() {
|
||||||
|
// Clean up preferences.
|
||||||
|
setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL);
|
||||||
|
setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL);
|
||||||
|
|
||||||
|
final int sdkVersion = VERSION_CODES_LXX;
|
||||||
|
final String oldPrefKey = KeyboardTheme.getPreferenceKey(sdkVersion);
|
||||||
|
setKeyboardThemePreference(oldPrefKey, THEME_ID_LXX_DARK);
|
||||||
|
|
||||||
|
final KeyboardTheme actualTheme = KeyboardTheme.getKeyboardTheme(
|
||||||
|
mPrefs, sdkVersion, LIMITED_THEMES);
|
||||||
|
// LXX_DARK is missing, fall-back to KLP.
|
||||||
|
assertEquals(THEME_ID_KLP, actualTheme.mThemeId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue