Add new "keyboardTheme" <case> predicator

Bug: 17318036
Change-Id: Ief386c84969d8646fb5cfe2050a2f59a7db16c88
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index c756f8c..254ef8c 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 051489e..a9c7294 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 a853ed9..da5e27f 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 2aaee13..c49436c 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 e7a6f58..6f0fb71 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 c20523b..0227d81 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 55dab78..7aea1ce 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 0cd606d..7161d3f 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java
@@ -32,6 +32,8 @@
     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 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 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 @@
         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 8bff275..fa41927 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.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 @@
             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 @@
             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"),