diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index c756f8c346a122b04b2d717dc8f8d7c7c82998be..254ef8c0d5805a1a8b1d042f70eb6c8813bc3f8f 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -207,7 +207,13 @@ </declare-styleable> <declare-styleable name="Keyboard"> - <attr name="themeId" format="integer" /> + <attr name="themeId" format="enum"> + <!-- This should be aligned with KeyboardTheme.THEME_ID_*. --> + <enum name="ICS" value="0" /> + <enum name="KLP" value="2" /> + <enum name="LXXLight" value="3" /> + <enum name="LXXDark" value="4" /> + </attr> <!-- Touch position correction --> <attr name="touchPositionCorrectionData" format="reference" /> <!-- Keyboard top, bottom, left, right edges paddings, in propotion of keyboard height. --> @@ -427,6 +433,13 @@ <enum name="emojiCategory5" value="15" /> <enum name="emojiCategory6" value="16" /> </attr> + <!-- This should be aligned with Keyboard.themeId and KeyboardTheme.THEME_ID_* --> + <attr name="keyboardTheme" format="enum|string"> + <enum name="ICS" value="0" /> + <enum name="KLP" value="2" /> + <enum name="LXXLight" value="3" /> + <enum name="LXXDark" value="4" /> + </attr> <!-- This should be aligned with KeyboardId.MODE_* --> <attr name="mode" format="enum|string"> <enum name="text" value="0" /> diff --git a/java/res/values/themes-ics.xml b/java/res/values/themes-ics.xml index 051489e11f298e97cb3411d5b378fc593ff5579d..a9c7294a080390216d7ffdf721e5c13c2113ba90 100644 --- a/java/res/values/themes-ics.xml +++ b/java/res/values/themes-ics.xml @@ -33,8 +33,8 @@ name="Keyboard.ICS" parent="Keyboard" > - <!-- This should be aligned with KeyboardSwitcher.KEYBOARD_THEMES[] --> - <item name="themeId">2</item> + <!-- This should be aligned with KeyboardTheme.THEME_ID_* --> + <item name="themeId">ICS</item> </style> <style name="KeyboardView.ICS" diff --git a/java/res/values/themes-klp.xml b/java/res/values/themes-klp.xml index a853ed9ddf8d85466e077b10e248681cebfb7837..da5e27fa1016cdddc4be1b877bf701bcea92c434 100644 --- a/java/res/values/themes-klp.xml +++ b/java/res/values/themes-klp.xml @@ -33,8 +33,8 @@ name="Keyboard.KLP" parent="Keyboard" > - <!-- This should be aligned with KeyboardSwitcher.KEYBOARD_THEMES[] --> - <item name="themeId">0</item> + <!-- This should be aligned with KeyboardTheme.THEME_ID_* --> + <item name="themeId">KLP</item> </style> <style name="KeyboardView.KLP" diff --git a/java/res/values/themes-lxx-dark.xml b/java/res/values/themes-lxx-dark.xml index 2aaee13601f68412cd28d2499908ada77b689dfe..c49436c4959aa5280e0bc1af9642e338d0c845a3 100644 --- a/java/res/values/themes-lxx-dark.xml +++ b/java/res/values/themes-lxx-dark.xml @@ -33,8 +33,8 @@ name="Keyboard.LXX_Dark" parent="Keyboard" > - <!-- This should be aligned with KeyboardSwitcher.KEYBOARD_THEMES[] --> - <item name="themeId">4</item> + <!-- This should be aligned with KeyboardTheme.THEME_ID_* --> + <item name="themeId">LXXDark</item> </style> <style name="KeyboardView.LXX_Dark" diff --git a/java/res/values/themes-lxx-light.xml b/java/res/values/themes-lxx-light.xml index e7a6f58943dcd9a424ca3407d42e443d820cda5e..6f0fb71310c2b4ceffc93e81046f63e076cb5a33 100644 --- a/java/res/values/themes-lxx-light.xml +++ b/java/res/values/themes-lxx-light.xml @@ -33,8 +33,8 @@ name="Keyboard.LXX_Light" parent="Keyboard" > - <!-- This should be aligned with KeyboardSwitcher.KEYBOARD_THEMES[] --> - <item name="themeId">3</item> + <!-- This should be aligned with KeyboardTheme.THEME_ID_* --> + <item name="themeId">LXXLight</item> </style> <style name="KeyboardView.LXX_Light" diff --git a/java/res/xml-sw600dp/key_styles_enter.xml b/java/res/xml-sw600dp/key_styles_enter.xml index c20523b2a07769360fb41a590147ed84f798af26..0227d811b42c5cc958c256d6e8960af170c22642 100644 --- a/java/res/xml-sw600dp/key_styles_enter.xml +++ b/java/res/xml-sw600dp/key_styles_enter.xml @@ -224,12 +224,24 @@ </case> <case latin:imeAction="actionCustomLabel" + latin:keyboardTheme="ICS|KLP" > <key-style latin:styleName="enterKeyStyle" latin:keySpec="dummy_label|!code/key_enter" latin:keyLabelFlags="fromCustomActionLabel" - latin:backgroundType="customAction" + latin:backgroundType="action" + latin:parentStyle="defaultEnterKeyStyle" /> + </case> + <case + latin:imeAction="actionCustomLabel" + latin:keyboardTheme="LXXLight|LXXDark" + > + <key-style + latin:styleName="enterKeyStyle" + latin:keySpec="dummy_label|!code/key_enter" + latin:keyLabelFlags="fromCustomActionLabel" + latin:backgroundType="functional" latin:parentStyle="defaultEnterKeyStyle" /> </case> <!-- imeAction is either actionNone or actionUnspecified. --> diff --git a/java/res/xml/key_styles_enter.xml b/java/res/xml/key_styles_enter.xml index 55dab78c3b8928d60e6a811f14988c7d4af45e63..7aea1ceff623568fee2ba00e566fd41d944ec9fb 100644 --- a/java/res/xml/key_styles_enter.xml +++ b/java/res/xml/key_styles_enter.xml @@ -393,12 +393,24 @@ </case> <case latin:imeAction="actionCustomLabel" + latin:keyboardTheme="ICS|KLP" > <key-style latin:styleName="enterKeyStyle" latin:keySpec="dummy_label|!code/key_enter" latin:keyLabelFlags="fromCustomActionLabel" - latin:backgroundType="customAction" + latin:backgroundType="action" + latin:parentStyle="defaultEnterKeyStyle" /> + </case> + <case + latin:imeAction="actionCustomLabel" + latin:keyboardTheme="LXXLight|LXXDark" + > + <key-style + latin:styleName="enterKeyStyle" + latin:keySpec="dummy_label|!code/key_enter" + latin:keyLabelFlags="fromCustomActionLabel" + latin:backgroundType="functional" latin:parentStyle="defaultEnterKeyStyle" /> </case> <!-- imeAction is either actionNone or actionUnspecified. --> diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java b/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java index 0cd606d19d1a1b806af6b48bb74b0067831ef39e..7161d3f265119d2dc1df445e4f133066536f4a0a 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java @@ -32,6 +32,8 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { 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_ICS = 0; public static final int THEME_ID_KLP = 2; public static final int THEME_ID_LXX_LIGHT = 3; @@ -39,16 +41,16 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { public static final int DEFAULT_THEME_ID = THEME_ID_KLP; private static final KeyboardTheme[] KEYBOARD_THEMES = { - new KeyboardTheme(THEME_ID_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. VERSION_CODES.BASE), - new KeyboardTheme(THEME_ID_KLP, R.style.KeyboardTheme_KLP, + new KeyboardTheme(THEME_ID_KLP, "KLP", R.style.KeyboardTheme_KLP, // Default theme for ICS, JB, and KLP. VERSION_CODES.ICE_CREAM_SANDWICH), - new KeyboardTheme(THEME_ID_LXX_LIGHT, R.style.KeyboardTheme_LXX_Light, + new KeyboardTheme(THEME_ID_LXX_LIGHT, "LXXLight", R.style.KeyboardTheme_LXX_Light, // Default theme for LXX. BuildCompatUtils.VERSION_CODES_LXX), - new KeyboardTheme(THEME_ID_LXX_DARK, R.style.KeyboardTheme_LXX_Dark, + new KeyboardTheme(THEME_ID_LXX_DARK, "LXXDark", R.style.KeyboardTheme_LXX_Dark, VERSION_CODES.BASE), }; @@ -59,12 +61,15 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { public final int mThemeId; public final int mStyleId; + public final String mThemeName; private final int mMinApiVersion; // Note: The themeId should be aligned with "themeId" attribute of Keyboard style // in values/themes-<style>.xml. - private KeyboardTheme(final int themeId, final int styleId, final int minApiVersion) { + private KeyboardTheme(final int themeId, final String themeName, final int styleId, + final int minApiVersion) { mThemeId = themeId; + mThemeName = themeName; mStyleId = styleId; mMinApiVersion = minApiVersion; } @@ -128,6 +133,11 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> { return searchKeyboardThemeById(DEFAULT_THEME_ID); } + public static String getKeyboardThemeName(final int themeId) { + final KeyboardTheme theme = searchKeyboardThemeById(themeId); + return theme.mThemeName; + } + public static void saveKeyboardThemeId(final String themeIdString, final SharedPreferences prefs) { saveKeyboardThemeId(themeIdString, prefs, BuildCompatUtils.EFFECTIVE_SDK_INT); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java index 8bff27574cc70ae9af76c48039680d01b05b79a5..fa41927901719f2079e7b9a49cbac6f68072df26 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java @@ -31,6 +31,7 @@ import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardId; +import com.android.inputmethod.keyboard.KeyboardTheme; import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.utils.ResourceUtils; @@ -643,6 +644,9 @@ public class KeyboardBuilder<KP extends KeyboardParams> { final boolean keyboardLayoutSetElementMatched = matchTypedValue(caseAttr, R.styleable.Keyboard_Case_keyboardLayoutSetElement, id.mElementId, KeyboardId.elementIdToName(id.mElementId)); + final boolean keyboardThemeMacthed = matchTypedValue(caseAttr, + R.styleable.Keyboard_Case_keyboardTheme, mParams.mThemeId, + KeyboardTheme.getKeyboardThemeName(mParams.mThemeId)); final boolean modeMatched = matchTypedValue(caseAttr, R.styleable.Keyboard_Case_mode, id.mMode, KeyboardId.modeName(id.mMode)); final boolean navigateNextMatched = matchBoolean(caseAttr, @@ -671,19 +675,21 @@ public class KeyboardBuilder<KP extends KeyboardParams> { final boolean countryCodeMatched = matchString(caseAttr, R.styleable.Keyboard_Case_countryCode, id.mLocale.getCountry()); final boolean selected = keyboardLayoutSetMatched && keyboardLayoutSetElementMatched - && modeMatched && navigateNextMatched && navigatePreviousMatched - && passwordInputMatched && clobberSettingsKeyMatched && hasShortcutKeyMatched - && languageSwitchKeyEnabledMatched && isMultiLineMatched && imeActionMatched - && isIconDefinedMatched && localeCodeMatched && languageCodeMatched - && countryCodeMatched; + && keyboardThemeMacthed && modeMatched && navigateNextMatched + && navigatePreviousMatched && passwordInputMatched && clobberSettingsKeyMatched + && hasShortcutKeyMatched && languageSwitchKeyEnabledMatched + && isMultiLineMatched && imeActionMatched && isIconDefinedMatched + && localeCodeMatched && languageCodeMatched && countryCodeMatched; if (DEBUG) { - startTag("<%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s>%s", TAG_CASE, + startTag("<%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s>%s", TAG_CASE, textAttr(caseAttr.getString( R.styleable.Keyboard_Case_keyboardLayoutSet), "keyboardLayoutSet"), textAttr(caseAttr.getString( R.styleable.Keyboard_Case_keyboardLayoutSetElement), "keyboardLayoutSetElement"), + textAttr(caseAttr.getString( + R.styleable.Keyboard_Case_keyboardTheme), "keyboardTheme"), textAttr(caseAttr.getString(R.styleable.Keyboard_Case_mode), "mode"), textAttr(caseAttr.getString(R.styleable.Keyboard_Case_imeAction), "imeAction"),