Loading java/res/values/keyboard-themes.xml +2 −2 Original line number Diff line number Diff line Loading @@ -26,10 +26,10 @@ <item>@string/keyboard_theme_holo_blue</item> </string-array> <!-- An element must be a keyboard theme id of {@link KeyboardTheme#THEME_ID_*}. --> <integer-array name="keyboard_theme_ids" translatable="false"> <string-array name="keyboard_theme_ids" translatable="false"> <item>3</item> <item>4</item> <item>2</item> <item>0</item> </integer-array> </string-array> </resources> java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +9 −4 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ package com.android.inputmethod.keyboard; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; import android.preference.PreferenceManager; import android.util.Log; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; Loading Loading @@ -45,6 +47,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { private static final String TAG = KeyboardSwitcher.class.getSimpleName(); private SubtypeSwitcher mSubtypeSwitcher; private SharedPreferences mPrefs; private InputView mCurrentInputView; private View mMainKeyboardFrame; Loading Loading @@ -73,11 +76,13 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { } public static void init(final LatinIME latinIme) { sInstance.initInternal(latinIme); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(latinIme); sInstance.initInternal(latinIme, prefs); } private void initInternal(final LatinIME latinIme) { private void initInternal(final LatinIME latinIme, final SharedPreferences prefs) { mLatinIME = latinIme; mPrefs = prefs; mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mState = new KeyboardState(this); mIsHardwareAcceleratedDrawingEnabled = Loading @@ -86,7 +91,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { public void updateKeyboardTheme() { final boolean themeUpdated = updateKeyboardThemeAndContextThemeWrapper( mLatinIME, KeyboardTheme.getKeyboardTheme(mLatinIME /* context */)); mLatinIME, KeyboardTheme.getKeyboardTheme(mPrefs)); if (themeUpdated && mKeyboardView != null) { mLatinIME.setInputView(onCreateInputView(mIsHardwareAcceleratedDrawingEnabled)); } Loading Loading @@ -343,7 +348,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { } updateKeyboardThemeAndContextThemeWrapper( mLatinIME, KeyboardTheme.getKeyboardTheme(mLatinIME /* context */)); mLatinIME, KeyboardTheme.getKeyboardTheme(mPrefs)); mCurrentInputView = (InputView)LayoutInflater.from(mThemeContext).inflate( R.layout.input_view, null); mMainKeyboardFrame = mCurrentInputView.findViewById(R.id.main_keyboard_frame); Loading java/src/com/android/inputmethod/keyboard/KeyboardTheme.java +20 −47 Original line number Diff line number Diff line Loading @@ -16,17 +16,14 @@ package com.android.inputmethod.keyboard; import android.content.Context; import android.content.SharedPreferences; import android.os.Build.VERSION_CODES; import android.preference.PreferenceManager; import android.util.Log; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.compat.BuildCompatUtils; import com.android.inputmethod.latin.R; import java.util.ArrayList; import java.util.Arrays; public final class KeyboardTheme implements Comparable<KeyboardTheme> { Loading @@ -43,10 +40,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { public static final int THEME_ID_LXX_DARK = 4; public static final int DEFAULT_THEME_ID = THEME_ID_KLP; private static KeyboardTheme[] AVAILABLE_KEYBOARD_THEMES; @UsedForTesting static final KeyboardTheme[] KEYBOARD_THEMES = { private static final KeyboardTheme[] KEYBOARD_THEMES = { new KeyboardTheme(THEME_ID_ICS, "ICS", R.style.KeyboardTheme_ICS, // This has never been selected because we support ICS or later. VERSION_CODES.BASE), Loading Loading @@ -99,10 +93,9 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { } @UsedForTesting static KeyboardTheme searchKeyboardThemeById(final int themeId, final KeyboardTheme[] availableThemeIds) { static KeyboardTheme searchKeyboardThemeById(final int themeId) { // TODO: This search algorithm isn't optimal if there are many themes. for (final KeyboardTheme theme : availableThemeIds) { for (final KeyboardTheme theme : KEYBOARD_THEMES) { if (theme.mThemeId == themeId) { return theme; } Loading @@ -112,14 +105,13 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { @UsedForTesting static KeyboardTheme getDefaultKeyboardTheme(final SharedPreferences prefs, final int sdkVersion, final KeyboardTheme[] availableThemeArray) { final int sdkVersion) { 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); final KeyboardTheme theme = searchKeyboardThemeById(themeId); if (theme != null) { return theme; } Loading @@ -133,21 +125,22 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { 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) { for (final KeyboardTheme theme : KEYBOARD_THEMES) { if (sdkVersion >= theme.mMinApiVersion) { return theme; } } return searchKeyboardThemeById(DEFAULT_THEME_ID, availableThemeArray); return searchKeyboardThemeById(DEFAULT_THEME_ID); } public static String getKeyboardThemeName(final int themeId) { final KeyboardTheme theme = searchKeyboardThemeById(themeId, KEYBOARD_THEMES); final KeyboardTheme theme = searchKeyboardThemeById(themeId); return theme.mThemeName; } public static void saveKeyboardThemeId(final int themeId, final SharedPreferences prefs) { saveKeyboardThemeId(themeId, prefs, BuildCompatUtils.EFFECTIVE_SDK_INT); public static void saveKeyboardThemeId(final String themeIdString, final SharedPreferences prefs) { saveKeyboardThemeId(themeIdString, prefs, BuildCompatUtils.EFFECTIVE_SDK_INT); } @UsedForTesting Loading @@ -159,45 +152,25 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { } @UsedForTesting static void saveKeyboardThemeId(final int themeId, final SharedPreferences prefs, final int sdkVersion) { static void saveKeyboardThemeId(final String themeIdString, 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) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final KeyboardTheme[] availableThemeArray = getAvailableThemeArray(context); return getKeyboardTheme(prefs, BuildCompatUtils.EFFECTIVE_SDK_INT, availableThemeArray); prefs.edit().putString(prefKey, themeIdString).apply(); } 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; public static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs) { return getKeyboardTheme(prefs, BuildCompatUtils.EFFECTIVE_SDK_INT); } @UsedForTesting static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs, final int sdkVersion, final KeyboardTheme[] availableThemeArray) { static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs, final int sdkVersion) { final String lxxThemeIdString = prefs.getString(LXX_KEYBOARD_THEME_KEY, null); if (lxxThemeIdString == null) { return getDefaultKeyboardTheme(prefs, sdkVersion, availableThemeArray); return getDefaultKeyboardTheme(prefs, sdkVersion); } try { final int themeId = Integer.parseInt(lxxThemeIdString); final KeyboardTheme theme = searchKeyboardThemeById(themeId, availableThemeArray); final KeyboardTheme theme = searchKeyboardThemeById(themeId); if (theme != null) { return theme; } Loading @@ -207,6 +180,6 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { } // Remove preference that contains unknown or illegal theme id. prefs.edit().remove(LXX_KEYBOARD_THEME_KEY).apply(); return getDefaultKeyboardTheme(prefs, sdkVersion, availableThemeArray); return getDefaultKeyboardTheme(prefs, sdkVersion); } } java/src/com/android/inputmethod/latin/settings/ThemeSettingsFragment.java +16 −14 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.inputmethod.latin.settings; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; import android.os.Bundle; import android.preference.Preference; Loading @@ -31,12 +32,12 @@ import com.android.inputmethod.latin.settings.RadioButtonPreference.OnRadioButto */ public final class ThemeSettingsFragment extends SubScreenFragment implements OnRadioButtonClickedListener { private int mSelectedThemeId; private String mSelectedThemeId; static class KeyboardThemePreference extends RadioButtonPreference { final int mThemeId; final String mThemeId; KeyboardThemePreference(final Context context, final String name, final int id) { KeyboardThemePreference(final Context context, final String name, final String id) { super(context); setTitle(name); mThemeId = id; Loading @@ -44,13 +45,14 @@ public final class ThemeSettingsFragment extends SubScreenFragment } static void updateKeyboardThemeSummary(final Preference pref) { final Context context = pref.getContext(); final Resources res = context.getResources(); final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context); final Resources res = pref.getContext().getResources(); final SharedPreferences prefs = pref.getSharedPreferences(); final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(prefs); final String keyboardThemeId = String.valueOf(keyboardTheme.mThemeId); final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names); final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids); final String[] keyboardThemeIds = res.getStringArray(R.array.keyboard_theme_ids); for (int index = 0; index < keyboardThemeNames.length; index++) { if (keyboardTheme.mThemeId == keyboardThemeIds[index]) { if (keyboardThemeId.equals(keyboardThemeIds[index])) { pref.setSummary(keyboardThemeNames[index]); return; } Loading @@ -62,18 +64,18 @@ public final class ThemeSettingsFragment extends SubScreenFragment super.onCreate(icicle); addPreferencesFromResource(R.xml.prefs_screen_theme); final PreferenceScreen screen = getPreferenceScreen(); final Context context = getActivity(); final Resources res = getResources(); final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names); final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids); final String[] keyboardThemeIds = res.getStringArray(R.array.keyboard_theme_ids); for (int index = 0; index < keyboardThemeNames.length; index++) { final KeyboardThemePreference pref = new KeyboardThemePreference( context, keyboardThemeNames[index], keyboardThemeIds[index]); getActivity(), keyboardThemeNames[index], keyboardThemeIds[index]); screen.addPreference(pref); pref.setOnRadioButtonClickedListener(this); } final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context); mSelectedThemeId = keyboardTheme.mThemeId; final SharedPreferences prefs = getSharedPreferences(); final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(prefs); mSelectedThemeId = String.valueOf(keyboardTheme.mThemeId); } @Override Loading Loading @@ -104,7 +106,7 @@ public final class ThemeSettingsFragment extends SubScreenFragment final Preference preference = screen.getPreference(index); if (preference instanceof KeyboardThemePreference) { final KeyboardThemePreference pref = (KeyboardThemePreference)preference; final boolean selected = (mSelectedThemeId == pref.mThemeId); final boolean selected = mSelectedThemeId.equals(pref.mThemeId); pref.setSelected(selected); } } Loading tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java +1 −1 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase { protected void setUp() throws Exception { super.setUp(); final KeyboardTheme keyboardTheme = KeyboardTheme.searchKeyboardThemeById( getKeyboardThemeForTests(), KeyboardTheme.KEYBOARD_THEMES); getKeyboardThemeForTests()); setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId)); KeyboardLayoutSet.onKeyboardThemeChanged(); Loading Loading
java/res/values/keyboard-themes.xml +2 −2 Original line number Diff line number Diff line Loading @@ -26,10 +26,10 @@ <item>@string/keyboard_theme_holo_blue</item> </string-array> <!-- An element must be a keyboard theme id of {@link KeyboardTheme#THEME_ID_*}. --> <integer-array name="keyboard_theme_ids" translatable="false"> <string-array name="keyboard_theme_ids" translatable="false"> <item>3</item> <item>4</item> <item>2</item> <item>0</item> </integer-array> </string-array> </resources>
java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +9 −4 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ package com.android.inputmethod.keyboard; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; import android.preference.PreferenceManager; import android.util.Log; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; Loading Loading @@ -45,6 +47,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { private static final String TAG = KeyboardSwitcher.class.getSimpleName(); private SubtypeSwitcher mSubtypeSwitcher; private SharedPreferences mPrefs; private InputView mCurrentInputView; private View mMainKeyboardFrame; Loading Loading @@ -73,11 +76,13 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { } public static void init(final LatinIME latinIme) { sInstance.initInternal(latinIme); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(latinIme); sInstance.initInternal(latinIme, prefs); } private void initInternal(final LatinIME latinIme) { private void initInternal(final LatinIME latinIme, final SharedPreferences prefs) { mLatinIME = latinIme; mPrefs = prefs; mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mState = new KeyboardState(this); mIsHardwareAcceleratedDrawingEnabled = Loading @@ -86,7 +91,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { public void updateKeyboardTheme() { final boolean themeUpdated = updateKeyboardThemeAndContextThemeWrapper( mLatinIME, KeyboardTheme.getKeyboardTheme(mLatinIME /* context */)); mLatinIME, KeyboardTheme.getKeyboardTheme(mPrefs)); if (themeUpdated && mKeyboardView != null) { mLatinIME.setInputView(onCreateInputView(mIsHardwareAcceleratedDrawingEnabled)); } Loading Loading @@ -343,7 +348,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { } updateKeyboardThemeAndContextThemeWrapper( mLatinIME, KeyboardTheme.getKeyboardTheme(mLatinIME /* context */)); mLatinIME, KeyboardTheme.getKeyboardTheme(mPrefs)); mCurrentInputView = (InputView)LayoutInflater.from(mThemeContext).inflate( R.layout.input_view, null); mMainKeyboardFrame = mCurrentInputView.findViewById(R.id.main_keyboard_frame); Loading
java/src/com/android/inputmethod/keyboard/KeyboardTheme.java +20 −47 Original line number Diff line number Diff line Loading @@ -16,17 +16,14 @@ package com.android.inputmethod.keyboard; import android.content.Context; import android.content.SharedPreferences; import android.os.Build.VERSION_CODES; import android.preference.PreferenceManager; import android.util.Log; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.compat.BuildCompatUtils; import com.android.inputmethod.latin.R; import java.util.ArrayList; import java.util.Arrays; public final class KeyboardTheme implements Comparable<KeyboardTheme> { Loading @@ -43,10 +40,7 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { public static final int THEME_ID_LXX_DARK = 4; public static final int DEFAULT_THEME_ID = THEME_ID_KLP; private static KeyboardTheme[] AVAILABLE_KEYBOARD_THEMES; @UsedForTesting static final KeyboardTheme[] KEYBOARD_THEMES = { private static final KeyboardTheme[] KEYBOARD_THEMES = { new KeyboardTheme(THEME_ID_ICS, "ICS", R.style.KeyboardTheme_ICS, // This has never been selected because we support ICS or later. VERSION_CODES.BASE), Loading Loading @@ -99,10 +93,9 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { } @UsedForTesting static KeyboardTheme searchKeyboardThemeById(final int themeId, final KeyboardTheme[] availableThemeIds) { static KeyboardTheme searchKeyboardThemeById(final int themeId) { // TODO: This search algorithm isn't optimal if there are many themes. for (final KeyboardTheme theme : availableThemeIds) { for (final KeyboardTheme theme : KEYBOARD_THEMES) { if (theme.mThemeId == themeId) { return theme; } Loading @@ -112,14 +105,13 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { @UsedForTesting static KeyboardTheme getDefaultKeyboardTheme(final SharedPreferences prefs, final int sdkVersion, final KeyboardTheme[] availableThemeArray) { final int sdkVersion) { 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); final KeyboardTheme theme = searchKeyboardThemeById(themeId); if (theme != null) { return theme; } Loading @@ -133,21 +125,22 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { 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) { for (final KeyboardTheme theme : KEYBOARD_THEMES) { if (sdkVersion >= theme.mMinApiVersion) { return theme; } } return searchKeyboardThemeById(DEFAULT_THEME_ID, availableThemeArray); return searchKeyboardThemeById(DEFAULT_THEME_ID); } public static String getKeyboardThemeName(final int themeId) { final KeyboardTheme theme = searchKeyboardThemeById(themeId, KEYBOARD_THEMES); final KeyboardTheme theme = searchKeyboardThemeById(themeId); return theme.mThemeName; } public static void saveKeyboardThemeId(final int themeId, final SharedPreferences prefs) { saveKeyboardThemeId(themeId, prefs, BuildCompatUtils.EFFECTIVE_SDK_INT); public static void saveKeyboardThemeId(final String themeIdString, final SharedPreferences prefs) { saveKeyboardThemeId(themeIdString, prefs, BuildCompatUtils.EFFECTIVE_SDK_INT); } @UsedForTesting Loading @@ -159,45 +152,25 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { } @UsedForTesting static void saveKeyboardThemeId(final int themeId, final SharedPreferences prefs, final int sdkVersion) { static void saveKeyboardThemeId(final String themeIdString, 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) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final KeyboardTheme[] availableThemeArray = getAvailableThemeArray(context); return getKeyboardTheme(prefs, BuildCompatUtils.EFFECTIVE_SDK_INT, availableThemeArray); prefs.edit().putString(prefKey, themeIdString).apply(); } 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; public static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs) { return getKeyboardTheme(prefs, BuildCompatUtils.EFFECTIVE_SDK_INT); } @UsedForTesting static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs, final int sdkVersion, final KeyboardTheme[] availableThemeArray) { static KeyboardTheme getKeyboardTheme(final SharedPreferences prefs, final int sdkVersion) { final String lxxThemeIdString = prefs.getString(LXX_KEYBOARD_THEME_KEY, null); if (lxxThemeIdString == null) { return getDefaultKeyboardTheme(prefs, sdkVersion, availableThemeArray); return getDefaultKeyboardTheme(prefs, sdkVersion); } try { final int themeId = Integer.parseInt(lxxThemeIdString); final KeyboardTheme theme = searchKeyboardThemeById(themeId, availableThemeArray); final KeyboardTheme theme = searchKeyboardThemeById(themeId); if (theme != null) { return theme; } Loading @@ -207,6 +180,6 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { } // Remove preference that contains unknown or illegal theme id. prefs.edit().remove(LXX_KEYBOARD_THEME_KEY).apply(); return getDefaultKeyboardTheme(prefs, sdkVersion, availableThemeArray); return getDefaultKeyboardTheme(prefs, sdkVersion); } }
java/src/com/android/inputmethod/latin/settings/ThemeSettingsFragment.java +16 −14 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.inputmethod.latin.settings; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; import android.os.Bundle; import android.preference.Preference; Loading @@ -31,12 +32,12 @@ import com.android.inputmethod.latin.settings.RadioButtonPreference.OnRadioButto */ public final class ThemeSettingsFragment extends SubScreenFragment implements OnRadioButtonClickedListener { private int mSelectedThemeId; private String mSelectedThemeId; static class KeyboardThemePreference extends RadioButtonPreference { final int mThemeId; final String mThemeId; KeyboardThemePreference(final Context context, final String name, final int id) { KeyboardThemePreference(final Context context, final String name, final String id) { super(context); setTitle(name); mThemeId = id; Loading @@ -44,13 +45,14 @@ public final class ThemeSettingsFragment extends SubScreenFragment } static void updateKeyboardThemeSummary(final Preference pref) { final Context context = pref.getContext(); final Resources res = context.getResources(); final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context); final Resources res = pref.getContext().getResources(); final SharedPreferences prefs = pref.getSharedPreferences(); final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(prefs); final String keyboardThemeId = String.valueOf(keyboardTheme.mThemeId); final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names); final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids); final String[] keyboardThemeIds = res.getStringArray(R.array.keyboard_theme_ids); for (int index = 0; index < keyboardThemeNames.length; index++) { if (keyboardTheme.mThemeId == keyboardThemeIds[index]) { if (keyboardThemeId.equals(keyboardThemeIds[index])) { pref.setSummary(keyboardThemeNames[index]); return; } Loading @@ -62,18 +64,18 @@ public final class ThemeSettingsFragment extends SubScreenFragment super.onCreate(icicle); addPreferencesFromResource(R.xml.prefs_screen_theme); final PreferenceScreen screen = getPreferenceScreen(); final Context context = getActivity(); final Resources res = getResources(); final String[] keyboardThemeNames = res.getStringArray(R.array.keyboard_theme_names); final int[] keyboardThemeIds = res.getIntArray(R.array.keyboard_theme_ids); final String[] keyboardThemeIds = res.getStringArray(R.array.keyboard_theme_ids); for (int index = 0; index < keyboardThemeNames.length; index++) { final KeyboardThemePreference pref = new KeyboardThemePreference( context, keyboardThemeNames[index], keyboardThemeIds[index]); getActivity(), keyboardThemeNames[index], keyboardThemeIds[index]); screen.addPreference(pref); pref.setOnRadioButtonClickedListener(this); } final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(context); mSelectedThemeId = keyboardTheme.mThemeId; final SharedPreferences prefs = getSharedPreferences(); final KeyboardTheme keyboardTheme = KeyboardTheme.getKeyboardTheme(prefs); mSelectedThemeId = String.valueOf(keyboardTheme.mThemeId); } @Override Loading Loading @@ -104,7 +106,7 @@ public final class ThemeSettingsFragment extends SubScreenFragment final Preference preference = screen.getPreference(index); if (preference instanceof KeyboardThemePreference) { final KeyboardThemePreference pref = (KeyboardThemePreference)preference; final boolean selected = (mSelectedThemeId == pref.mThemeId); final boolean selected = mSelectedThemeId.equals(pref.mThemeId); pref.setSelected(selected); } } Loading
tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java +1 −1 Original line number Diff line number Diff line Loading @@ -51,7 +51,7 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase { protected void setUp() throws Exception { super.setUp(); final KeyboardTheme keyboardTheme = KeyboardTheme.searchKeyboardThemeById( getKeyboardThemeForTests(), KeyboardTheme.KEYBOARD_THEMES); getKeyboardThemeForTests()); setContext(new ContextThemeWrapper(getContext(), keyboardTheme.mStyleId)); KeyboardLayoutSet.onKeyboardThemeChanged(); Loading