Merge "Revert "Refactor KeyboardTheme""
This commit is contained in:
commit
4f5ea4dfc2
9 changed files with 34 additions and 269 deletions
|
@ -24,6 +24,9 @@
|
||||||
at input history to suggest a hopefully helpful suggestions for the next word? -->
|
at input history to suggest a hopefully helpful suggestions for the next word? -->
|
||||||
<bool name="config_default_next_word_prediction">true</bool>
|
<bool name="config_default_next_word_prediction">true</bool>
|
||||||
|
|
||||||
|
<!-- This configuration must be aligned with {@link KeyboardTheme#DEFAULT_THEME_ID}. -->
|
||||||
|
<string name="config_default_keyboard_theme_id" translatable="false">2</string>
|
||||||
|
|
||||||
<integer name="config_delay_update_shift_state">100</integer>
|
<integer name="config_delay_update_shift_state">100</integer>
|
||||||
<integer name="config_double_space_period_timeout">1100</integer>
|
<integer name="config_double_space_period_timeout">1100</integer>
|
||||||
|
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
/*
|
|
||||||
**
|
|
||||||
** Copyright 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.
|
|
||||||
*/
|
|
||||||
-->
|
|
||||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
|
||||||
<!-- For keyboard color scheme option dialog. -->
|
|
||||||
<string-array name="keyboard_theme_names" translatable="false">
|
|
||||||
<item>@string/keyboard_color_scheme_white</item>
|
|
||||||
<item>@string/keyboard_color_scheme_blue</item>
|
|
||||||
<!-- TODO: Make this item as translatable string resource. -->
|
|
||||||
<item>Quantum</item>
|
|
||||||
</string-array>
|
|
||||||
<!-- An element must be a keyboard theme id of {@link KeyboardTheme#THEME_ID_*}. -->
|
|
||||||
<string-array name="keyboard_theme_ids" translatable="false">
|
|
||||||
<item>2</item>
|
|
||||||
<item>0</item>
|
|
||||||
<item>3</item>
|
|
||||||
</string-array>
|
|
||||||
</resources>
|
|
|
@ -158,11 +158,12 @@
|
||||||
android:persistent="true"
|
android:persistent="true"
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false" />
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="pref_keyboard_theme"
|
android:key="pref_keyboard_layout_20110916"
|
||||||
android:title="@string/keyboard_color_scheme"
|
android:title="@string/keyboard_color_scheme"
|
||||||
android:persistent="true"
|
android:persistent="true"
|
||||||
android:entryValues="@array/keyboard_theme_ids"
|
android:entryValues="@array/keyboard_theme_ids"
|
||||||
android:entries="@array/keyboard_theme_names" />
|
android:entries="@array/keyboard_theme_names"
|
||||||
|
android:defaultValue="@string/config_default_keyboard_theme_id" />
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
android:fragment="com.android.inputmethod.latin.settings.AdditionalSubtypeSettings"
|
android:fragment="com.android.inputmethod.latin.settings.AdditionalSubtypeSettings"
|
||||||
android:key="custom_input_styles"
|
android:key="custom_input_styles"
|
||||||
|
|
|
@ -64,7 +64,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
* what user actually typed. */
|
* what user actually typed. */
|
||||||
private boolean mIsAutoCorrectionActive;
|
private boolean mIsAutoCorrectionActive;
|
||||||
|
|
||||||
private KeyboardTheme mKeyboardTheme;
|
private KeyboardTheme mKeyboardTheme = KeyboardTheme.getDefaultKeyboardTheme();
|
||||||
private Context mThemeContext;
|
private Context mThemeContext;
|
||||||
|
|
||||||
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
|
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
|
||||||
|
@ -101,7 +101,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
|
|
||||||
private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context,
|
private boolean updateKeyboardThemeAndContextThemeWrapper(final Context context,
|
||||||
final KeyboardTheme keyboardTheme) {
|
final KeyboardTheme keyboardTheme) {
|
||||||
if (mThemeContext == null || !keyboardTheme.equals(mKeyboardTheme)) {
|
if (mThemeContext == null || mKeyboardTheme.mThemeId != keyboardTheme.mThemeId) {
|
||||||
mKeyboardTheme = keyboardTheme;
|
mKeyboardTheme = keyboardTheme;
|
||||||
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
|
mThemeContext = new ContextThemeWrapper(context, keyboardTheme.mStyleId);
|
||||||
KeyboardLayoutSet.clearKeyboardCache();
|
KeyboardLayoutSet.clearKeyboardCache();
|
||||||
|
@ -342,8 +342,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
mKeyboardView.closing();
|
mKeyboardView.closing();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateKeyboardThemeAndContextThemeWrapper(
|
updateKeyboardThemeAndContextThemeWrapper(mLatinIME, mKeyboardTheme);
|
||||||
mLatinIME, KeyboardTheme.getKeyboardTheme(mPrefs));
|
|
||||||
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);
|
||||||
|
|
|
@ -17,86 +17,34 @@
|
||||||
package com.android.inputmethod.keyboard;
|
package com.android.inputmethod.keyboard;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Build.VERSION_CODES;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
|
import com.android.inputmethod.latin.settings.Settings;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
public final class KeyboardTheme {
|
public final class KeyboardTheme {
|
||||||
private static final String TAG = KeyboardTheme.class.getSimpleName();
|
private static final String TAG = KeyboardTheme.class.getSimpleName();
|
||||||
|
|
||||||
static final String KITKAT_KEYBOARD_THEME_KEY = "pref_keyboard_layout_20110916";
|
public static final int THEME_ID_ICS = 0;
|
||||||
static final String KEYBOARD_THEME_KEY = "pref_keyboard_theme_20140509";
|
public static final int THEME_ID_KLP = 2;
|
||||||
|
private static final int DEFAULT_THEME_ID = THEME_ID_KLP;
|
||||||
static final int THEME_ID_ICS = 0;
|
|
||||||
static final int THEME_ID_KLP = 2;
|
|
||||||
static final int THEME_ID_LMP = 3;
|
|
||||||
static final int DEFAULT_THEME_ID = THEME_ID_KLP;
|
|
||||||
|
|
||||||
private static final KeyboardTheme[] KEYBOARD_THEMES = {
|
private static final KeyboardTheme[] KEYBOARD_THEMES = {
|
||||||
new KeyboardTheme(THEME_ID_ICS, R.style.KeyboardTheme_ICS,
|
new KeyboardTheme(THEME_ID_ICS, R.style.KeyboardTheme_ICS),
|
||||||
VERSION_CODES.ICE_CREAM_SANDWICH),
|
new KeyboardTheme(THEME_ID_KLP, R.style.KeyboardTheme_KLP),
|
||||||
new KeyboardTheme(THEME_ID_KLP, R.style.KeyboardTheme_KLP,
|
|
||||||
VERSION_CODES.KITKAT),
|
|
||||||
// TODO: Update to LMP style.
|
|
||||||
new KeyboardTheme(THEME_ID_LMP, R.style.KeyboardTheme_KLP,
|
|
||||||
// TODO: Update this constant once the *next* version becomes available.
|
|
||||||
VERSION_CODES.CUR_DEVELOPMENT),
|
|
||||||
};
|
};
|
||||||
static {
|
|
||||||
// Sort {@link #KEYBOARD_THEME} by descending order of {@link #mMinApiVersion}.
|
|
||||||
Arrays.sort(KEYBOARD_THEMES, new Comparator<KeyboardTheme>() {
|
|
||||||
@Override
|
|
||||||
public int compare(final KeyboardTheme lhs, final KeyboardTheme rhs) {
|
|
||||||
if (lhs.mMinApiVersion > rhs.mMinApiVersion) return -1;
|
|
||||||
if (lhs.mMinApiVersion < rhs.mMinApiVersion) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public final int mThemeId;
|
public final int mThemeId;
|
||||||
public final int mStyleId;
|
public final int mStyleId;
|
||||||
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/style.xml.
|
||||||
private KeyboardTheme(final int themeId, final int styleId, final int minApiVersion) {
|
public KeyboardTheme(final int themeId, final int styleId) {
|
||||||
mThemeId = themeId;
|
mThemeId = themeId;
|
||||||
mStyleId = styleId;
|
mStyleId = styleId;
|
||||||
mMinApiVersion = minApiVersion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static KeyboardTheme searchKeyboardTheme(final int themeId) {
|
||||||
public boolean equals(final Object o) {
|
|
||||||
if (o == this) return true;
|
|
||||||
return (o instanceof KeyboardTheme) && ((KeyboardTheme)o).mThemeId == mThemeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return mThemeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: This method should be removed when {@link LatinImeLogger} is removed.
|
|
||||||
public int getCompatibleThemeIdForLogging() {
|
|
||||||
switch (mThemeId) {
|
|
||||||
case THEME_ID_ICS:
|
|
||||||
return 5;
|
|
||||||
case THEME_ID_KLP:
|
|
||||||
return 9;
|
|
||||||
case THEME_ID_LMP:
|
|
||||||
return 10;
|
|
||||||
default: // Invalid theme
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static KeyboardTheme searchKeyboardThemeById(final int themeId) {
|
|
||||||
// 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 : KEYBOARD_THEMES) {
|
||||||
if (theme.mThemeId == themeId) {
|
if (theme.mThemeId == themeId) {
|
||||||
|
@ -106,57 +54,18 @@ public final class KeyboardTheme {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getSdkVersion() {
|
public static KeyboardTheme getDefaultKeyboardTheme() {
|
||||||
final int sdkVersion = Build.VERSION.SDK_INT;
|
return searchKeyboardTheme(DEFAULT_THEME_ID);
|
||||||
// TODO: Consider to remove this check once the *next* version becomes available.
|
|
||||||
if (sdkVersion == VERSION_CODES.KITKAT && Build.VERSION.CODENAME.startsWith("L")) {
|
|
||||||
return VERSION_CODES.CUR_DEVELOPMENT;
|
|
||||||
}
|
|
||||||
return sdkVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
static KeyboardTheme getDefaultKeyboardTheme(final SharedPreferences prefs,
|
|
||||||
final int sdkVersion) {
|
|
||||||
final String obsoleteIdString = prefs.getString(KITKAT_KEYBOARD_THEME_KEY, null);
|
|
||||||
if (obsoleteIdString != null) {
|
|
||||||
// Remove old preference.
|
|
||||||
prefs.edit().remove(KITKAT_KEYBOARD_THEME_KEY).apply();
|
|
||||||
if (sdkVersion <= VERSION_CODES.KITKAT) {
|
|
||||||
try {
|
|
||||||
final int themeId = Integer.parseInt(obsoleteIdString);
|
|
||||||
final KeyboardTheme theme = searchKeyboardThemeById(themeId);
|
|
||||||
if (theme != null) {
|
|
||||||
return theme;
|
|
||||||
}
|
|
||||||
Log.w(TAG, "Unknown keyboard theme in preference: " + obsoleteIdString);
|
|
||||||
} catch (final NumberFormatException e) {
|
|
||||||
Log.w(TAG, "Illegal keyboard theme in preference: " + obsoleteIdString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: This search algorithm isn't optimal if there are many themes.
|
|
||||||
for (final KeyboardTheme theme : KEYBOARD_THEMES) {
|
|
||||||
if (sdkVersion >= theme.mMinApiVersion) {
|
|
||||||
return theme;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return searchKeyboardThemeById(DEFAULT_THEME_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void saveKeyboardThemeId(final String themeIdString,
|
|
||||||
final SharedPreferences prefs) {
|
|
||||||
prefs.edit().putString(KEYBOARD_THEME_KEY, themeIdString).apply();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs) {
|
public static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs) {
|
||||||
final int sdkVersion = getSdkVersion();
|
final String themeIdString = prefs.getString(Settings.PREF_KEYBOARD_LAYOUT, null);
|
||||||
final String themeIdString = prefs.getString(KEYBOARD_THEME_KEY, null);
|
|
||||||
if (themeIdString == null) {
|
if (themeIdString == null) {
|
||||||
return getDefaultKeyboardTheme(prefs, sdkVersion);
|
return getDefaultKeyboardTheme();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final int themeId = Integer.parseInt(themeIdString);
|
final int themeId = Integer.parseInt(themeIdString);
|
||||||
final KeyboardTheme theme = searchKeyboardThemeById(themeId);
|
final KeyboardTheme theme = searchKeyboardTheme(themeId);
|
||||||
if (theme != null) {
|
if (theme != null) {
|
||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
@ -164,8 +73,9 @@ public final class KeyboardTheme {
|
||||||
} catch (final NumberFormatException e) {
|
} catch (final NumberFormatException e) {
|
||||||
Log.w(TAG, "Illegal keyboard theme in preference: " + themeIdString);
|
Log.w(TAG, "Illegal keyboard theme in preference: " + themeIdString);
|
||||||
}
|
}
|
||||||
// Remove preference.
|
// Reset preference to default value.
|
||||||
prefs.edit().remove(KEYBOARD_THEME_KEY).apply();
|
final String defaultThemeIdString = Integer.toString(DEFAULT_THEME_ID);
|
||||||
return getDefaultKeyboardTheme(prefs, sdkVersion);
|
prefs.edit().putString(Settings.PREF_KEYBOARD_LAYOUT, defaultThemeIdString).apply();
|
||||||
|
return getDefaultKeyboardTheme();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||||
"pref_show_language_switch_key";
|
"pref_show_language_switch_key";
|
||||||
public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST =
|
public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST =
|
||||||
"pref_include_other_imes_in_language_switch_list";
|
"pref_include_other_imes_in_language_switch_list";
|
||||||
public static final String PREF_KEYBOARD_THEME = "pref_keyboard_theme";
|
public static final String PREF_KEYBOARD_LAYOUT = "pref_keyboard_layout_20110916";
|
||||||
public static final String PREF_CUSTOM_INPUT_STYLES = "custom_input_styles";
|
public static final String PREF_CUSTOM_INPUT_STYLES = "custom_input_styles";
|
||||||
// TODO: consolidate key preview dismiss delay with the key preview animation parameters.
|
// TODO: consolidate key preview dismiss delay with the key preview animation parameters.
|
||||||
public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY =
|
public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY =
|
||||||
|
|
|
@ -37,7 +37,6 @@ import android.util.Log;
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import com.android.inputmethod.dictionarypack.DictionarySettingsActivity;
|
import com.android.inputmethod.dictionarypack.DictionarySettingsActivity;
|
||||||
import com.android.inputmethod.keyboard.KeyboardTheme;
|
|
||||||
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
|
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.SubtypeSwitcher;
|
import com.android.inputmethod.latin.SubtypeSwitcher;
|
||||||
|
@ -254,30 +253,10 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
}
|
}
|
||||||
updateListPreferenceSummaryToCurrentValue(Settings.PREF_SHOW_SUGGESTIONS_SETTING);
|
updateListPreferenceSummaryToCurrentValue(Settings.PREF_SHOW_SUGGESTIONS_SETTING);
|
||||||
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
|
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
|
||||||
final ListPreference keyboardThemePref = (ListPreference)findPreference(
|
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEYBOARD_LAYOUT);
|
||||||
Settings.PREF_KEYBOARD_THEME);
|
|
||||||
if (keyboardThemePref != null) {
|
|
||||||
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(prefs);
|
|
||||||
final String value = Integer.toString(keyboardTheme.mThemeId);
|
|
||||||
final CharSequence entries[] = keyboardThemePref.getEntries();
|
|
||||||
final int entryIndex = keyboardThemePref.findIndexOfValue(value);
|
|
||||||
keyboardThemePref.setSummary(entryIndex < 0 ? null : entries[entryIndex]);
|
|
||||||
keyboardThemePref.setValue(value);
|
|
||||||
}
|
|
||||||
updateCustomInputStylesSummary(prefs, res);
|
updateCustomInputStylesSummary(prefs, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
|
||||||
final ListPreference keyboardThemePref = (ListPreference)findPreference(
|
|
||||||
Settings.PREF_KEYBOARD_THEME);
|
|
||||||
if (keyboardThemePref != null) {
|
|
||||||
KeyboardTheme.saveKeyboardThemeId(keyboardThemePref.getValue(), prefs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(
|
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(
|
||||||
|
@ -308,7 +287,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
ensureConsistencyOfAutoCorrectionSettings();
|
ensureConsistencyOfAutoCorrectionSettings();
|
||||||
updateListPreferenceSummaryToCurrentValue(Settings.PREF_SHOW_SUGGESTIONS_SETTING);
|
updateListPreferenceSummaryToCurrentValue(Settings.PREF_SHOW_SUGGESTIONS_SETTING);
|
||||||
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
|
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
|
||||||
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEYBOARD_THEME);
|
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEYBOARD_LAYOUT);
|
||||||
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());
|
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ package com.android.inputmethod.keyboard;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
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 android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
|
@ -41,6 +40,9 @@ import java.util.Locale;
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
public class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
public class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
||||||
|
private static final KeyboardTheme DEFAULT_KEYBOARD_THEME =
|
||||||
|
KeyboardTheme.getDefaultKeyboardTheme();
|
||||||
|
|
||||||
// All input method subtypes of LatinIME.
|
// All input method subtypes of LatinIME.
|
||||||
private final ArrayList<InputMethodSubtype> mAllSubtypesList = CollectionUtils.newArrayList();
|
private final ArrayList<InputMethodSubtype> mAllSubtypesList = CollectionUtils.newArrayList();
|
||||||
private final ArrayList<InputMethodSubtype> mAsciiCapableSubtypesList =
|
private final ArrayList<InputMethodSubtype> mAsciiCapableSubtypesList =
|
||||||
|
@ -56,9 +58,7 @@ public class KeyboardLayoutSetTestsBase extends AndroidTestCase {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
mScreenMetrics = mContext.getResources().getInteger(R.integer.config_screen_metrics);
|
mScreenMetrics = mContext.getResources().getInteger(R.integer.config_screen_metrics);
|
||||||
|
|
||||||
final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(
|
mThemeContext = new ContextThemeWrapper(mContext, DEFAULT_KEYBOARD_THEME.mStyleId);
|
||||||
PreferenceManager.getDefaultSharedPreferences(mContext));
|
|
||||||
mThemeContext = new ContextThemeWrapper(mContext, keyboardTheme.mStyleId);
|
|
||||||
RichInputMethodManager.init(mThemeContext);
|
RichInputMethodManager.init(mThemeContext);
|
||||||
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
|
||||||
|
|
||||||
|
|
|
@ -1,93 +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 com.android.inputmethod.keyboard;
|
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Build.VERSION_CODES;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.test.AndroidTestCase;
|
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
|
||||||
|
|
||||||
@SmallTest
|
|
||||||
public class KeyboardThemeTests extends AndroidTestCase {
|
|
||||||
private SharedPreferences mPrefs;
|
|
||||||
|
|
||||||
private static final int THEME_ID_NULL = -1;
|
|
||||||
private static final int THEME_ID_ICS = KeyboardTheme.THEME_ID_ICS;
|
|
||||||
private static final int THEME_ID_KLP = KeyboardTheme.THEME_ID_KLP;
|
|
||||||
private static final int THEME_ID_LMP = KeyboardTheme.THEME_ID_LMP;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertDefaultKeyboardTheme(final int sdkVersion, final int oldThemeId,
|
|
||||||
final int expectedThemeId) {
|
|
||||||
if (oldThemeId == THEME_ID_NULL) {
|
|
||||||
mPrefs.edit().remove(KeyboardTheme.KITKAT_KEYBOARD_THEME_KEY).apply();
|
|
||||||
} else {
|
|
||||||
final String themeIdString = Integer.toString(oldThemeId);
|
|
||||||
mPrefs.edit().putString(KeyboardTheme.KITKAT_KEYBOARD_THEME_KEY, themeIdString).apply();
|
|
||||||
}
|
|
||||||
final KeyboardTheme defaultTheme =
|
|
||||||
KeyboardTheme.getDefaultKeyboardTheme(mPrefs, sdkVersion);
|
|
||||||
assertNotNull(defaultTheme);
|
|
||||||
assertEquals(expectedThemeId, defaultTheme.mThemeId);
|
|
||||||
assertFalse(mPrefs.contains(KeyboardTheme.KITKAT_KEYBOARD_THEME_KEY));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertDefaultKeyboardThemeICS(final int sdkVersion) {
|
|
||||||
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_NULL, THEME_ID_ICS);
|
|
||||||
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ICS, THEME_ID_ICS);
|
|
||||||
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_KLP, THEME_ID_KLP);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertDefaultKeyboardThemeKLP(final int sdkVersion) {
|
|
||||||
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_NULL, THEME_ID_KLP);
|
|
||||||
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ICS, THEME_ID_ICS);
|
|
||||||
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_KLP, THEME_ID_KLP);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertDefaultKeyboardThemeLMP(final int sdkVersion) {
|
|
||||||
// Forced to switch to LMP theme.
|
|
||||||
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_NULL, THEME_ID_LMP);
|
|
||||||
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_ICS, THEME_ID_LMP);
|
|
||||||
assertDefaultKeyboardTheme(sdkVersion, THEME_ID_KLP, THEME_ID_LMP);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDefaultKeyboardThemeICS() {
|
|
||||||
assertDefaultKeyboardThemeICS(VERSION_CODES.ICE_CREAM_SANDWICH);
|
|
||||||
assertDefaultKeyboardThemeICS(VERSION_CODES.ICE_CREAM_SANDWICH_MR1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDefaultKeyboardThemeJB() {
|
|
||||||
assertDefaultKeyboardThemeICS(VERSION_CODES.JELLY_BEAN);
|
|
||||||
assertDefaultKeyboardThemeICS(VERSION_CODES.JELLY_BEAN_MR1);
|
|
||||||
assertDefaultKeyboardThemeICS(VERSION_CODES.JELLY_BEAN_MR2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDefaultKeyboardThemeKLP() {
|
|
||||||
assertDefaultKeyboardThemeKLP(VERSION_CODES.KITKAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDefaultKeyboardThemeLMP() {
|
|
||||||
// TODO: Update this constant once the *next* version becomes available.
|
|
||||||
assertDefaultKeyboardThemeLMP(VERSION_CODES.CUR_DEVELOPMENT);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue