mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Make KeyboardTheme a stub, remove KeyboardThemeTests
This commit is contained in:
parent
a19ce6122e
commit
6a76537d3b
@ -1,160 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
**
|
||||
** Copyright 2015, The Android Open Source Project
|
||||
**
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
**
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
**
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<style name="KeyboardTheme.LXX_Dark" parent="KeyboardIcons.LXX_Dark">
|
||||
<item name="inputViewStyle">@style/InputView.LXX</item>
|
||||
<item name="keyboardStyle">@style/Keyboard.LXX_Dark</item>
|
||||
<item name="keyboardViewStyle">@style/KeyboardView.LXX_Dark</item>
|
||||
<item name="mainKeyboardViewStyle">@style/MainKeyboardView.LXX_Dark</item>
|
||||
<item name="emojiPalettesViewStyle">@style/EmojiPalettesView.LXX_Dark</item>
|
||||
<item name="moreKeysKeyboardStyle">@style/MoreKeysKeyboard.LXX_Dark</item>
|
||||
<item name="moreKeysKeyboardViewStyle">@style/MoreKeysKeyboardView.LXX_Dark</item>
|
||||
<item name="moreKeysKeyboardViewForActionStyle">@style/MoreKeysKeyboardView.LXX_Dark.Action</item>
|
||||
<item name="suggestionStripViewStyle">@style/SuggestionStripView.LXX_Dark</item>
|
||||
<item name="suggestionWordStyle">@style/SuggestionWord.LXX_Dark</item>
|
||||
</style>
|
||||
<style
|
||||
name="Keyboard.LXX_Dark"
|
||||
parent="Keyboard"
|
||||
>
|
||||
<!-- This should be aligned with KeyboardTheme.THEME_ID_* -->
|
||||
<item name="themeId">LXXDark</item>
|
||||
</style>
|
||||
<style
|
||||
name="KeyboardView.LXX_Dark"
|
||||
parent="KeyboardView.LXX"
|
||||
>
|
||||
<item name="android:background">@drawable/keyboard_background_lxx_dark</item>
|
||||
<item name="keyBackground">@drawable/btn_keyboard_key_lxx_dark</item>
|
||||
<item name="functionalKeyBackground">@drawable/btn_keyboard_key_functional_lxx_dark</item>
|
||||
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_lxx_dark</item>
|
||||
<item name="keyTextColor">@color/key_text_color_lxx_dark</item>
|
||||
<item name="keyTextInactivatedColor">@color/key_functional_text_color_lxx_dark</item>
|
||||
<item name="keyPressedTextColor">@color/key_text_color_lxx_dark</item>
|
||||
<item name="functionalTextColor">@color/key_text_color_lxx_dark</item>
|
||||
<item name="keyHintLetterColor">@color/key_hint_letter_color_lxx_dark</item>
|
||||
<item name="keyHintLabelColor">@color/key_text_inactive_color_lxx_dark</item>
|
||||
<item name="keyShiftedLetterHintInactivatedColor">@color/key_text_inactive_color_lxx_dark</item>
|
||||
<item name="keyShiftedLetterHintActivatedColor">@color/key_text_color_lxx_dark</item>
|
||||
<item name="keyPreviewTextColor">@color/key_text_color_lxx_dark</item>
|
||||
</style>
|
||||
<style
|
||||
name="MainKeyboardView.LXX_Dark"
|
||||
parent="KeyboardView.LXX_Dark"
|
||||
>
|
||||
<item name="moreKeysKeyboardForActionLayout">@layout/more_keys_keyboard_for_action_lxx</item>
|
||||
<item name="keyPreviewBackground">@drawable/keyboard_key_feedback_lxx_dark</item>
|
||||
<item name="keyPreviewHeight">@dimen/config_key_preview_height_lxx</item>
|
||||
<item name="keyPreviewOffset">@dimen/config_key_preview_offset_lxx</item>
|
||||
<item name="keyPreviewShowUpAnimator">@anim/key_preview_show_up_lxx</item>
|
||||
<item name="keyPreviewDismissAnimator">@anim/key_preview_dismiss_lxx</item>
|
||||
<item name="gestureFloatingPreviewTextColor">@color/auto_correct_color_lxx_dark</item>
|
||||
<item name="gestureFloatingPreviewColor">@color/gesture_floating_preview_color_lxx_dark</item>
|
||||
<item name="gestureTrailColor">@color/gesture_trail_color_lxx_dark</item>
|
||||
<item name="slidingKeyInputPreviewColor">@color/sliding_key_input_preview_color_lxx_dark</item>
|
||||
<item name="languageOnSpacebarTextColor">@color/key_text_inactive_color_lxx_dark</item>
|
||||
<!-- A negative value to disable text shadow layer. -->
|
||||
<item name="languageOnSpacebarTextShadowRadius">-1.0</item>
|
||||
</style>
|
||||
<!-- Though {@link org.futo.inputmethod.keyboard.emoji.EmojiPalettesView} doesn't extend
|
||||
{@link org.futo.inputmethod.keyboard.KeyboardView}, some views inside it, for instance
|
||||
delete button, need themed {@link org.futo.inputmethod.keyboard.KeyboardView}
|
||||
attributes. -->
|
||||
<style
|
||||
name="EmojiPalettesView.LXX_Dark"
|
||||
parent="MainKeyboardView.LXX_Dark"
|
||||
>
|
||||
<item name="categoryIndicatorEnabled">false</item>
|
||||
<item name="categoryPageIndicatorColor">@color/highlight_color_lxx_dark</item>
|
||||
<item name="categoryPageIndicatorBackground">@color/emoji_tab_page_indicator_background_lxx_dark</item>
|
||||
<item name="iconEmojiRecentsTab">@drawable/ic_emoji_recents_lxx_dark</item>
|
||||
<item name="iconEmojiCategory1Tab">@drawable/ic_emoji_people_lxx_dark</item>
|
||||
<item name="iconEmojiCategory2Tab">@drawable/ic_emoji_objects_lxx_dark</item>
|
||||
<item name="iconEmojiCategory3Tab">@drawable/ic_emoji_nature_lxx_dark</item>
|
||||
<item name="iconEmojiCategory4Tab">@drawable/ic_emoji_places_lxx_dark</item>
|
||||
<item name="iconEmojiCategory5Tab">@drawable/ic_emoji_symbols_lxx_dark</item>
|
||||
<item name="iconEmojiCategory6Tab">@drawable/ic_emoji_emoticons_lxx_dark</item>
|
||||
<item name="iconEmojiCategory7Tab">@drawable/ic_emoji_flag_lxx_dark</item>
|
||||
<item name="iconEmojiCategory8Tab">@drawable/ic_emoji_people_lxx_dark</item>
|
||||
<item name="iconEmojiCategory9Tab">@drawable/ic_emoji_nature_lxx_dark</item>
|
||||
<item name="iconEmojiCategory10Tab">@drawable/ic_emoji_food_lxx_dark</item>
|
||||
<item name="iconEmojiCategory11Tab">@drawable/ic_emoji_places_lxx_dark</item>
|
||||
<item name="iconEmojiCategory12Tab">@drawable/ic_emoji_activity_lxx_dark</item>
|
||||
<item name="iconEmojiCategory13Tab">@drawable/ic_emoji_objects_lxx_dark</item>
|
||||
<item name="iconEmojiCategory14Tab">@drawable/ic_emoji_symbols_lxx_dark</item>
|
||||
<item name="iconEmojiCategory15Tab">@drawable/ic_emoji_flag_lxx_dark</item>
|
||||
<item name="iconEmojiCategory16Tab">@drawable/ic_emoji_people_lxx_dark</item>
|
||||
</style>
|
||||
<style
|
||||
name="MoreKeysKeyboard.LXX_Dark"
|
||||
parent="Keyboard.LXX_Dark"
|
||||
>
|
||||
<item name="keyboardTopPadding">0%p</item>
|
||||
<item name="keyboardBottomPadding">0%p</item>
|
||||
<item name="horizontalGap">0%p</item>
|
||||
<item name="touchPositionCorrectionData">@null</item>
|
||||
</style>
|
||||
<style
|
||||
name="MoreKeysKeyboardView.LXX_Dark"
|
||||
parent="KeyboardView.LXX_Dark"
|
||||
>
|
||||
<item name="android:background">@drawable/keyboard_popup_panel_background_lxx_dark</item>
|
||||
<item name="keyBackground">@drawable/btn_keyboard_key_popup_lxx_dark</item>
|
||||
<item name="divider">@drawable/more_keys_divider</item>
|
||||
<item name="keyTypeface">normal</item>
|
||||
<item name="verticalCorrection">@dimen/config_more_keys_keyboard_vertical_correction_holo</item>
|
||||
<item name="isMoreKey">true</item>
|
||||
</style>
|
||||
<style
|
||||
name="MoreKeysKeyboardView.LXX_Dark.Action"
|
||||
parent="MoreKeysKeyboardView.LXX_Dark"
|
||||
>
|
||||
<item name="android:background">@android:color/transparent</item>
|
||||
<item name="keyBackground">@drawable/btn_keyboard_key_popup_action_lxx_dark</item>
|
||||
<item name="divider">@null</item>
|
||||
<item name="keyLabelFlags">keepBackgroundAspectRatio</item>
|
||||
<item name="isAction">true</item>
|
||||
</style>
|
||||
<style
|
||||
name="SuggestionStripView.LXX_Dark"
|
||||
parent="KeyboardView.LXX_Dark"
|
||||
>
|
||||
<item name="suggestionsCountInStrip">@integer/config_suggestions_count_in_strip</item>
|
||||
<item name="centerSuggestionPercentile">@fraction/config_center_suggestion_percentile</item>
|
||||
<item name="maxMoreSuggestionsRow">@integer/config_max_more_suggestions_row</item>
|
||||
<item name="minMoreSuggestionsWidth">@fraction/config_min_more_suggestions_width</item>
|
||||
<item name="android:background">@color/gesture_floating_preview_color_lxx_dark</item>
|
||||
<item name="android:src">@drawable/suggestions_strip_divider_lxx_dark</item>
|
||||
<item name="suggestionStripOptions">autoCorrectBold|validTypedWordBold</item>
|
||||
<item name="colorValidTypedWord">@color/typed_word_color_lxx_dark</item>
|
||||
<item name="colorTypedWord">@color/typed_word_color_lxx_dark</item>
|
||||
<item name="colorAutoCorrect">@color/auto_correct_color_lxx_dark</item>
|
||||
<item name="colorSuggested">@color/suggested_word_color_lxx_dark</item>
|
||||
<item name="alphaObsoleted">70%</item>
|
||||
</style>
|
||||
<style
|
||||
name="SuggestionWord.LXX_Dark"
|
||||
parent="SuggestionWord"
|
||||
>
|
||||
<item name="android:background">@drawable/btn_suggestion_lxx_dark</item>
|
||||
<item name="android:textColor">@color/highlight_color_lxx_dark</item>
|
||||
</style>
|
||||
</resources>
|
@ -17,46 +17,21 @@
|
||||
package org.futo.inputmethod.keyboard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.futo.inputmethod.compat.BuildCompatUtils;
|
||||
import org.futo.inputmethod.latin.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
// Actual theming is handled in DynamicThemeProvider/BasicThemeProvider these days.
|
||||
// This class is left as a stub since some code still depends on it.
|
||||
// TODO: Eventually remove this class
|
||||
public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||
private static final String TAG = KeyboardTheme.class.getSimpleName();
|
||||
|
||||
static final String KLP_KEYBOARD_THEME_KEY = "pref_keyboard_layout_20110916";
|
||||
static final String LXX_KEYBOARD_THEME_KEY = "pref_keyboard_theme_20140509";
|
||||
|
||||
// These should be aligned with Keyboard.themeId and Keyboard.Case.keyboardTheme
|
||||
// attributes' values in attrs.xml.
|
||||
public static final int THEME_ID_LXX_LIGHT = 3;
|
||||
public static final int THEME_ID_LXX_DARK = 4;
|
||||
public static final int DEFAULT_THEME_ID = THEME_ID_LXX_LIGHT;
|
||||
|
||||
private static KeyboardTheme[] AVAILABLE_KEYBOARD_THEMES;
|
||||
|
||||
/* package private for testing */
|
||||
static final KeyboardTheme[] KEYBOARD_THEMES = {
|
||||
new KeyboardTheme(THEME_ID_LXX_LIGHT, "LXXLight", R.style.KeyboardTheme_LXX_Light,
|
||||
// Default theme for LXX.
|
||||
Build.VERSION_CODES.LOLLIPOP),
|
||||
new KeyboardTheme(THEME_ID_LXX_DARK, "LXXDark", R.style.KeyboardTheme_LXX_Dark,
|
||||
// This has never been selected as default theme.
|
||||
VERSION_CODES.BASE),
|
||||
Build.VERSION_CODES.LOLLIPOP)
|
||||
};
|
||||
|
||||
static {
|
||||
// Sort {@link #KEYBOARD_THEME} by descending order of {@link #mMinApiVersion}.
|
||||
Arrays.sort(KEYBOARD_THEMES);
|
||||
}
|
||||
|
||||
public final int mThemeId;
|
||||
public final int mStyleId;
|
||||
@ -91,115 +66,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
|
||||
return mThemeId;
|
||||
}
|
||||
|
||||
/* package private for testing */
|
||||
static KeyboardTheme searchKeyboardThemeById(final int themeId,
|
||||
final KeyboardTheme[] availableThemeIds) {
|
||||
// TODO: This search algorithm isn't optimal if there are many themes.
|
||||
for (final KeyboardTheme theme : availableThemeIds) {
|
||||
if (theme.mThemeId == themeId) {
|
||||
return theme;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* package private for testing */
|
||||
static KeyboardTheme getDefaultKeyboardTheme(final SharedPreferences prefs,
|
||||
final int sdkVersion, final KeyboardTheme[] availableThemeArray) {
|
||||
final String klpThemeIdString = prefs.getString(KLP_KEYBOARD_THEME_KEY, null);
|
||||
if (klpThemeIdString != null) {
|
||||
if (sdkVersion <= VERSION_CODES.KITKAT) {
|
||||
try {
|
||||
final int themeId = Integer.parseInt(klpThemeIdString);
|
||||
final KeyboardTheme theme = searchKeyboardThemeById(themeId,
|
||||
availableThemeArray);
|
||||
if (theme != null) {
|
||||
return theme;
|
||||
}
|
||||
Log.w(TAG, "Unknown keyboard theme in KLP preference: " + klpThemeIdString);
|
||||
} catch (final NumberFormatException e) {
|
||||
Log.w(TAG, "Illegal keyboard theme in KLP preference: " + klpThemeIdString, e);
|
||||
}
|
||||
}
|
||||
// Remove old preference.
|
||||
Log.i(TAG, "Remove KLP keyboard theme preference: " + klpThemeIdString);
|
||||
prefs.edit().remove(KLP_KEYBOARD_THEME_KEY).apply();
|
||||
}
|
||||
// TODO: This search algorithm isn't optimal if there are many themes.
|
||||
for (final KeyboardTheme theme : availableThemeArray) {
|
||||
if (sdkVersion >= theme.mMinApiVersion) {
|
||||
return theme;
|
||||
}
|
||||
}
|
||||
return searchKeyboardThemeById(DEFAULT_THEME_ID, availableThemeArray);
|
||||
}
|
||||
|
||||
public static String getKeyboardThemeName(final int themeId) {
|
||||
final KeyboardTheme theme = searchKeyboardThemeById(themeId, KEYBOARD_THEMES);
|
||||
return theme.mThemeName;
|
||||
}
|
||||
|
||||
public static void saveKeyboardThemeId(final int themeId, final SharedPreferences prefs) {
|
||||
saveKeyboardThemeId(themeId, prefs, BuildCompatUtils.EFFECTIVE_SDK_INT);
|
||||
}
|
||||
|
||||
/* package private for testing */
|
||||
static String getPreferenceKey(final int sdkVersion) {
|
||||
if (sdkVersion <= VERSION_CODES.KITKAT) {
|
||||
return KLP_KEYBOARD_THEME_KEY;
|
||||
}
|
||||
return LXX_KEYBOARD_THEME_KEY;
|
||||
}
|
||||
|
||||
/* package private for testing */
|
||||
static void saveKeyboardThemeId(final int themeId, final SharedPreferences prefs,
|
||||
final int sdkVersion) {
|
||||
final String prefKey = getPreferenceKey(sdkVersion);
|
||||
prefs.edit().putString(prefKey, Integer.toString(themeId)).apply();
|
||||
}
|
||||
|
||||
public static KeyboardTheme getKeyboardTheme(final Context context) {
|
||||
return KEYBOARD_THEMES[0];
|
||||
}
|
||||
|
||||
/* package private for testing */
|
||||
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()]);
|
||||
Arrays.sort(AVAILABLE_KEYBOARD_THEMES);
|
||||
}
|
||||
return AVAILABLE_KEYBOARD_THEMES;
|
||||
}
|
||||
|
||||
/* package private for testing */
|
||||
static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs, final int sdkVersion,
|
||||
final KeyboardTheme[] availableThemeArray) {
|
||||
final String lxxThemeIdString = prefs.getString(LXX_KEYBOARD_THEME_KEY, null);
|
||||
if (lxxThemeIdString == null) {
|
||||
return getDefaultKeyboardTheme(prefs, sdkVersion, availableThemeArray);
|
||||
}
|
||||
try {
|
||||
final int themeId = Integer.parseInt(lxxThemeIdString);
|
||||
final KeyboardTheme theme = searchKeyboardThemeById(themeId, availableThemeArray);
|
||||
if (theme != null) {
|
||||
return theme;
|
||||
}
|
||||
Log.w(TAG, "Unknown keyboard theme in LXX preference: " + lxxThemeIdString);
|
||||
} catch (final NumberFormatException e) {
|
||||
Log.w(TAG, "Illegal keyboard theme in LXX preference: " + lxxThemeIdString, e);
|
||||
}
|
||||
// Remove preference that contains unknown or illegal theme id.
|
||||
prefs.edit().remove(LXX_KEYBOARD_THEME_KEY).apply();
|
||||
return getDefaultKeyboardTheme(prefs, sdkVersion, availableThemeArray);
|
||||
}
|
||||
}
|
||||
|
@ -83,8 +83,7 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
||||
res.getStringArray(R.array.predefined_subtypes)));
|
||||
//mRichImm.setAdditionalInputMethodSubtypes(predefinedAdditionalSubtypes);
|
||||
|
||||
final KeyboardTheme keyboardTheme = KeyboardTheme.searchKeyboardThemeById(
|
||||
getKeyboardThemeForTests(), KeyboardTheme.KEYBOARD_THEMES);
|
||||
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context);
|
||||
setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId));
|
||||
KeyboardLayoutSetV2.onKeyboardThemeChanged();
|
||||
|
||||
|
@ -1,421 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.futo.inputmethod.keyboard;
|
||||
|
||||
import static org.futo.inputmethod.keyboard.KeyboardTheme.THEME_ID_LXX_DARK;
|
||||
import static org.futo.inputmethod.keyboard.KeyboardTheme.THEME_ID_LXX_LIGHT;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class KeyboardThemeTests {
|
||||
private SharedPreferences mPrefs;
|
||||
|
||||
private static final int THEME_ID_NULL = -1;
|
||||
private static final int THEME_ID_UNKNOWN = -2;
|
||||
private static final int THEME_ID_ILLEGAL = -3;
|
||||
private static final String ILLEGAL_THEME_ID_STRING = "ThisCausesNumberFormatExecption";
|
||||
|
||||
private Context getContext() {
|
||||
return InstrumentationRegistry.getTargetContext();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper functions.
|
||||
*/
|
||||
|
||||
private static boolean isValidKeyboardThemeId(final int themeId) {
|
||||
switch (themeId) {
|
||||
case THEME_ID_LXX_LIGHT:
|
||||
case THEME_ID_LXX_DARK:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void setKeyboardThemePreference(final String prefKey, final int themeId) {
|
||||
final String themeIdString = Integer.toString(themeId);
|
||||
if (isValidKeyboardThemeId(themeId) || themeId == THEME_ID_UNKNOWN) {
|
||||
// Set valid theme id to preference.
|
||||
mPrefs.edit().putString(prefKey, themeIdString).apply();
|
||||
return;
|
||||
}
|
||||
if (themeId == THEME_ID_NULL) {
|
||||
// Simulate undefined preference.
|
||||
mPrefs.edit().remove(prefKey).apply();
|
||||
return;
|
||||
}
|
||||
// themeId == THEME_ID_ILLEGAL
|
||||
// Simulate illegal format theme id in preference.
|
||||
mPrefs.edit().putString(prefKey, ILLEGAL_THEME_ID_STRING).apply();
|
||||
}
|
||||
|
||||
private void assertKeyboardTheme(final int sdkVersion, final int expectedThemeId) {
|
||||
final KeyboardTheme actualTheme = KeyboardTheme.getKeyboardTheme(
|
||||
mPrefs, sdkVersion, KeyboardTheme.KEYBOARD_THEMES);
|
||||
assertEquals(expectedThemeId, actualTheme.mThemeId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test keyboard theme preference on the same platform version and the same keyboard version.
|
||||
*/
|
||||
|
||||
private void assertKeyboardThemePreference(final int sdkVersion, final int previousThemeId,
|
||||
final int expectedThemeId) {
|
||||
// Clear preferences before testing.
|
||||
setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL);
|
||||
setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL);
|
||||
// Set the preference of the sdkVersion to previousThemeId.
|
||||
final String prefKey = KeyboardTheme.getPreferenceKey(sdkVersion);
|
||||
setKeyboardThemePreference(prefKey, previousThemeId);
|
||||
assertKeyboardTheme(sdkVersion, expectedThemeId);
|
||||
}
|
||||
|
||||
private void assertKeyboardThemePreferenceOnKlp(final int sdkVersion) {
|
||||
final int defaultThemeId = THEME_ID_LXX_LIGHT;
|
||||
assertKeyboardThemePreference(sdkVersion, THEME_ID_NULL, defaultThemeId);
|
||||
assertKeyboardThemePreference(sdkVersion, THEME_ID_LXX_LIGHT, THEME_ID_LXX_LIGHT);
|
||||
assertKeyboardThemePreference(sdkVersion, THEME_ID_LXX_DARK, THEME_ID_LXX_DARK);
|
||||
assertKeyboardThemePreference(sdkVersion, THEME_ID_UNKNOWN, defaultThemeId);
|
||||
assertKeyboardThemePreference(sdkVersion, THEME_ID_ILLEGAL, defaultThemeId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeyboardThemePreferenceOnKlp() {
|
||||
assertKeyboardThemePreferenceOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH);
|
||||
assertKeyboardThemePreferenceOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
|
||||
assertKeyboardThemePreferenceOnKlp(VERSION_CODES.JELLY_BEAN);
|
||||
assertKeyboardThemePreferenceOnKlp(VERSION_CODES.JELLY_BEAN_MR1);
|
||||
assertKeyboardThemePreferenceOnKlp(VERSION_CODES.JELLY_BEAN_MR2);
|
||||
assertKeyboardThemePreferenceOnKlp(VERSION_CODES.KITKAT);
|
||||
}
|
||||
|
||||
private void assertKeyboardThemePreferenceOnLxx(final int sdkVersion) {
|
||||
final int defaultThemeId = THEME_ID_LXX_LIGHT;
|
||||
assertKeyboardThemePreference(sdkVersion, THEME_ID_NULL, defaultThemeId);
|
||||
assertKeyboardThemePreference(sdkVersion, THEME_ID_LXX_LIGHT, THEME_ID_LXX_LIGHT);
|
||||
assertKeyboardThemePreference(sdkVersion, THEME_ID_LXX_DARK, THEME_ID_LXX_DARK);
|
||||
assertKeyboardThemePreference(sdkVersion, THEME_ID_UNKNOWN, defaultThemeId);
|
||||
assertKeyboardThemePreference(sdkVersion, THEME_ID_ILLEGAL, defaultThemeId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeyboardThemePreferenceOnLxx() {
|
||||
assertKeyboardThemePreferenceOnLxx(Build.VERSION_CODES.LOLLIPOP);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test default keyboard theme based on the platform version.
|
||||
*/
|
||||
|
||||
private void assertDefaultKeyboardTheme(final int sdkVersion, final int previousThemeId,
|
||||
final int expectedThemeId) {
|
||||
final String oldPrefKey = KeyboardTheme.KLP_KEYBOARD_THEME_KEY;
|
||||
setKeyboardThemePreference(oldPrefKey, previousThemeId);
|
||||
|
||||
final KeyboardTheme defaultTheme = KeyboardTheme.getDefaultKeyboardTheme(
|
||||
mPrefs, sdkVersion, KeyboardTheme.KEYBOARD_THEMES);
|
||||
|
||||
assertNotNull(defaultTheme);
|
||||
assertEquals(expectedThemeId, defaultTheme.mThemeId);
|
||||
if (sdkVersion <= VERSION_CODES.KITKAT) {
|
||||
// Old preference must be retained if it is valid. Otherwise it must be pruned.
|
||||
assertEquals(isValidKeyboardThemeId(previousThemeId), mPrefs.contains(oldPrefKey));
|
||||
return;
|
||||
}
|
||||
// Old preference must be removed.
|
||||
assertFalse(mPrefs.contains(oldPrefKey));
|
||||
}
|
||||
|
||||
private void assertDefaultKeyboardThemeOnKlp(final int sdkVersion) {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultKeyboardThemeOnKlp() {
|
||||
assertDefaultKeyboardThemeOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH);
|
||||
assertDefaultKeyboardThemeOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
|
||||
assertDefaultKeyboardThemeOnKlp(VERSION_CODES.JELLY_BEAN);
|
||||
assertDefaultKeyboardThemeOnKlp(VERSION_CODES.JELLY_BEAN_MR1);
|
||||
assertDefaultKeyboardThemeOnKlp(VERSION_CODES.JELLY_BEAN_MR2);
|
||||
assertDefaultKeyboardThemeOnKlp(VERSION_CODES.KITKAT);
|
||||
}
|
||||
|
||||
private void assertDefaultKeyboardThemeOnLxx(final int sdkVersion) {
|
||||
// Forced to switch to LXX theme.
|
||||
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_NULL, THEME_ID_LXX_LIGHT);
|
||||
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_UNKNOWN, THEME_ID_LXX_LIGHT);
|
||||
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX_LIGHT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultKeyboardThemeOnLxx() {
|
||||
assertDefaultKeyboardThemeOnLxx(Build.VERSION_CODES.LOLLIPOP);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test keyboard theme preference while upgrading the keyboard that doesn't support LXX theme
|
||||
* to the keyboard that supports LXX theme.
|
||||
*/
|
||||
|
||||
private void assertUpgradeKeyboardToLxxOn(final int sdkVersion, final int previousThemeId,
|
||||
final int expectedThemeId) {
|
||||
setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, previousThemeId);
|
||||
// Clean up new keyboard theme preference to simulate "upgrade to LXX keyboard".
|
||||
setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL);
|
||||
|
||||
final KeyboardTheme theme = KeyboardTheme.getKeyboardTheme(
|
||||
mPrefs, sdkVersion, KeyboardTheme.KEYBOARD_THEMES);
|
||||
|
||||
assertNotNull(theme);
|
||||
assertEquals(expectedThemeId, theme.mThemeId);
|
||||
if (sdkVersion <= VERSION_CODES.KITKAT) {
|
||||
// New preference must not exist.
|
||||
assertFalse(mPrefs.contains(KeyboardTheme.LXX_KEYBOARD_THEME_KEY));
|
||||
// Old preference must be retained if it is valid. Otherwise it must be pruned.
|
||||
assertEquals(isValidKeyboardThemeId(previousThemeId),
|
||||
mPrefs.contains(KeyboardTheme.KLP_KEYBOARD_THEME_KEY));
|
||||
if (isValidKeyboardThemeId(previousThemeId)) {
|
||||
// Old preference must have an expected value.
|
||||
assertEquals(mPrefs.getString(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, null),
|
||||
Integer.toString(expectedThemeId));
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Old preference must be removed.
|
||||
assertFalse(mPrefs.contains(KeyboardTheme.KLP_KEYBOARD_THEME_KEY));
|
||||
// New preference must not exist.
|
||||
assertFalse(mPrefs.contains(KeyboardTheme.LXX_KEYBOARD_THEME_KEY));
|
||||
}
|
||||
|
||||
private void assertUpgradeKeyboardToLxxOnKlp(final int sdkVersion) {
|
||||
}
|
||||
|
||||
// Upgrading keyboard on I,J and K.
|
||||
@Test
|
||||
public void testUpgradeKeyboardToLxxOnKlp() {
|
||||
assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH);
|
||||
assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
|
||||
assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.JELLY_BEAN);
|
||||
assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.JELLY_BEAN_MR1);
|
||||
assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.JELLY_BEAN_MR2);
|
||||
assertUpgradeKeyboardToLxxOnKlp(VERSION_CODES.KITKAT);
|
||||
}
|
||||
|
||||
private void assertUpgradeKeyboardToLxxOnLxx(final int sdkVersion) {
|
||||
// Forced to switch to LXX theme.
|
||||
assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_NULL, THEME_ID_LXX_LIGHT);
|
||||
assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_UNKNOWN, THEME_ID_LXX_LIGHT);
|
||||
assertUpgradeKeyboardToLxxOn(sdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX_LIGHT);
|
||||
}
|
||||
|
||||
// Upgrading keyboard on L.
|
||||
@Test
|
||||
public void testUpgradeKeyboardToLxxOnLxx() {
|
||||
assertUpgradeKeyboardToLxxOnLxx(Build.VERSION_CODES.LOLLIPOP);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test keyboard theme preference while upgrading platform version.
|
||||
*/
|
||||
|
||||
private void assertUpgradePlatformFromTo(final int oldSdkVersion, final int newSdkVersion,
|
||||
final int previousThemeId, final int expectedThemeId) {
|
||||
if (newSdkVersion < oldSdkVersion) {
|
||||
// No need to test.
|
||||
return;
|
||||
}
|
||||
// Clean up preferences.
|
||||
setKeyboardThemePreference(KeyboardTheme.KLP_KEYBOARD_THEME_KEY, THEME_ID_NULL);
|
||||
setKeyboardThemePreference(KeyboardTheme.LXX_KEYBOARD_THEME_KEY, THEME_ID_NULL);
|
||||
|
||||
final String oldPrefKey = KeyboardTheme.getPreferenceKey(oldSdkVersion);
|
||||
setKeyboardThemePreference(oldPrefKey, previousThemeId);
|
||||
|
||||
assertKeyboardTheme(newSdkVersion, expectedThemeId);
|
||||
}
|
||||
|
||||
private void assertUpgradePlatformFromKlpToKlp(final int oldSdkVersion,
|
||||
final int newSdkVersion) {
|
||||
}
|
||||
|
||||
private void assertUpgradePlatformToKlpFrom(final int oldSdkVersion) {
|
||||
assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.ICE_CREAM_SANDWICH);
|
||||
assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
|
||||
assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.JELLY_BEAN);
|
||||
assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.JELLY_BEAN_MR1);
|
||||
assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.JELLY_BEAN_MR2);
|
||||
assertUpgradePlatformFromKlpToKlp(oldSdkVersion, VERSION_CODES.KITKAT);
|
||||
}
|
||||
|
||||
// Update platform from I,J, and K to I,J, and K
|
||||
@Test
|
||||
public void testUpgradePlatformToKlpFromKlp() {
|
||||
assertUpgradePlatformToKlpFrom(VERSION_CODES.ICE_CREAM_SANDWICH);
|
||||
assertUpgradePlatformToKlpFrom(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
|
||||
assertUpgradePlatformToKlpFrom(VERSION_CODES.JELLY_BEAN);
|
||||
assertUpgradePlatformToKlpFrom(VERSION_CODES.JELLY_BEAN_MR1);
|
||||
assertUpgradePlatformToKlpFrom(VERSION_CODES.JELLY_BEAN_MR2);
|
||||
assertUpgradePlatformToKlpFrom(VERSION_CODES.KITKAT);
|
||||
}
|
||||
|
||||
private void assertUpgradePlatformToLxxFrom(final int oldSdkVersion) {
|
||||
// Forced to switch to LXX theme.
|
||||
final int newSdkVersion = Build.VERSION_CODES.LOLLIPOP;
|
||||
assertUpgradePlatformFromTo(
|
||||
oldSdkVersion, newSdkVersion, THEME_ID_NULL, THEME_ID_LXX_LIGHT);
|
||||
assertUpgradePlatformFromTo(
|
||||
oldSdkVersion, newSdkVersion, THEME_ID_UNKNOWN, THEME_ID_LXX_LIGHT);
|
||||
assertUpgradePlatformFromTo(
|
||||
oldSdkVersion, newSdkVersion, THEME_ID_ILLEGAL, THEME_ID_LXX_LIGHT);
|
||||
}
|
||||
|
||||
// Update platform from I,J, and K to L
|
||||
@Test
|
||||
public void testUpgradePlatformToLxx() {
|
||||
assertUpgradePlatformToLxxFrom(VERSION_CODES.ICE_CREAM_SANDWICH);
|
||||
assertUpgradePlatformToLxxFrom(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
|
||||
assertUpgradePlatformToLxxFrom(VERSION_CODES.JELLY_BEAN);
|
||||
assertUpgradePlatformToLxxFrom(VERSION_CODES.JELLY_BEAN_MR1);
|
||||
assertUpgradePlatformToLxxFrom(VERSION_CODES.JELLY_BEAN_MR2);
|
||||
assertUpgradePlatformToLxxFrom(VERSION_CODES.KITKAT);
|
||||
}
|
||||
|
||||
// Update platform from L to L.
|
||||
@Test
|
||||
public void testUpgradePlatformToLxxFromLxx() {
|
||||
final int oldSdkVersion = Build.VERSION_CODES.LOLLIPOP;
|
||||
final int newSdkVersion = Build.VERSION_CODES.LOLLIPOP;
|
||||
assertUpgradePlatformFromTo(
|
||||
oldSdkVersion, newSdkVersion, THEME_ID_NULL, THEME_ID_LXX_LIGHT);
|
||||
assertUpgradePlatformFromTo(
|
||||
oldSdkVersion, newSdkVersion, THEME_ID_LXX_LIGHT, THEME_ID_LXX_LIGHT);
|
||||
assertUpgradePlatformFromTo(
|
||||
oldSdkVersion, newSdkVersion, THEME_ID_LXX_DARK, THEME_ID_LXX_DARK);
|
||||
assertUpgradePlatformFromTo(
|
||||
oldSdkVersion, newSdkVersion, THEME_ID_UNKNOWN, THEME_ID_LXX_LIGHT);
|
||||
assertUpgradePlatformFromTo(
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortedKeyboardTheme() {
|
||||
assertSortedKeyboardThemeArray(KeyboardTheme.KEYBOARD_THEMES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortedAvailableKeyboardTheme() {
|
||||
assertSortedKeyboardThemeArray(KeyboardTheme.getAvailableThemeArray(getContext()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test for missing selected theme.
|
||||
*/
|
||||
private static KeyboardTheme[] LIMITED_THEMES = {
|
||||
};
|
||||
static {
|
||||
Arrays.sort(LIMITED_THEMES);
|
||||
assertSortedKeyboardThemeArray(LIMITED_THEMES);
|
||||
}
|
||||
|
||||
@Test
|
||||
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.
|
||||
}
|
||||
|
||||
@Test
|
||||
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.
|
||||
}
|
||||
|
||||
@Test
|
||||
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 = Build.VERSION_CODES.LOLLIPOP;
|
||||
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.
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user