am 2a7a5740: am 0af2472a: Add new "keyboardTheme" <case> predicator

* commit '2a7a5740e929503a0aca23f376175a9c118b7a83':
  Add new "keyboardTheme" <case> predicator
main
Tadashi G. Takaoka 2014-09-03 17:55:52 +00:00 committed by Android Git Automerger
commit 6a4e9218ca
9 changed files with 75 additions and 22 deletions

View File

@ -207,7 +207,13 @@
</declare-styleable> </declare-styleable>
<declare-styleable name="Keyboard"> <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 --> <!-- Touch position correction -->
<attr name="touchPositionCorrectionData" format="reference" /> <attr name="touchPositionCorrectionData" format="reference" />
<!-- Keyboard top, bottom, left, right edges paddings, in propotion of keyboard height. --> <!-- Keyboard top, bottom, left, right edges paddings, in propotion of keyboard height. -->
@ -427,6 +433,13 @@
<enum name="emojiCategory5" value="15" /> <enum name="emojiCategory5" value="15" />
<enum name="emojiCategory6" value="16" /> <enum name="emojiCategory6" value="16" />
</attr> </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_* --> <!-- This should be aligned with KeyboardId.MODE_* -->
<attr name="mode" format="enum|string"> <attr name="mode" format="enum|string">
<enum name="text" value="0" /> <enum name="text" value="0" />

View File

@ -33,8 +33,8 @@
name="Keyboard.ICS" name="Keyboard.ICS"
parent="Keyboard" parent="Keyboard"
> >
<!-- This should be aligned with KeyboardSwitcher.KEYBOARD_THEMES[] --> <!-- This should be aligned with KeyboardTheme.THEME_ID_* -->
<item name="themeId">2</item> <item name="themeId">ICS</item>
</style> </style>
<style <style
name="KeyboardView.ICS" name="KeyboardView.ICS"

View File

@ -33,8 +33,8 @@
name="Keyboard.KLP" name="Keyboard.KLP"
parent="Keyboard" parent="Keyboard"
> >
<!-- This should be aligned with KeyboardSwitcher.KEYBOARD_THEMES[] --> <!-- This should be aligned with KeyboardTheme.THEME_ID_* -->
<item name="themeId">0</item> <item name="themeId">KLP</item>
</style> </style>
<style <style
name="KeyboardView.KLP" name="KeyboardView.KLP"

View File

@ -33,8 +33,8 @@
name="Keyboard.LXX_Dark" name="Keyboard.LXX_Dark"
parent="Keyboard" parent="Keyboard"
> >
<!-- This should be aligned with KeyboardSwitcher.KEYBOARD_THEMES[] --> <!-- This should be aligned with KeyboardTheme.THEME_ID_* -->
<item name="themeId">4</item> <item name="themeId">LXXDark</item>
</style> </style>
<style <style
name="KeyboardView.LXX_Dark" name="KeyboardView.LXX_Dark"

View File

@ -33,8 +33,8 @@
name="Keyboard.LXX_Light" name="Keyboard.LXX_Light"
parent="Keyboard" parent="Keyboard"
> >
<!-- This should be aligned with KeyboardSwitcher.KEYBOARD_THEMES[] --> <!-- This should be aligned with KeyboardTheme.THEME_ID_* -->
<item name="themeId">3</item> <item name="themeId">LXXLight</item>
</style> </style>
<style <style
name="KeyboardView.LXX_Light" name="KeyboardView.LXX_Light"

View File

@ -224,12 +224,24 @@
</case> </case>
<case <case
latin:imeAction="actionCustomLabel" latin:imeAction="actionCustomLabel"
latin:keyboardTheme="ICS|KLP"
> >
<key-style <key-style
latin:styleName="enterKeyStyle" latin:styleName="enterKeyStyle"
latin:keySpec="dummy_label|!code/key_enter" latin:keySpec="dummy_label|!code/key_enter"
latin:keyLabelFlags="fromCustomActionLabel" 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" /> latin:parentStyle="defaultEnterKeyStyle" />
</case> </case>
<!-- imeAction is either actionNone or actionUnspecified. --> <!-- imeAction is either actionNone or actionUnspecified. -->

View File

@ -393,12 +393,24 @@
</case> </case>
<case <case
latin:imeAction="actionCustomLabel" latin:imeAction="actionCustomLabel"
latin:keyboardTheme="ICS|KLP"
> >
<key-style <key-style
latin:styleName="enterKeyStyle" latin:styleName="enterKeyStyle"
latin:keySpec="dummy_label|!code/key_enter" latin:keySpec="dummy_label|!code/key_enter"
latin:keyLabelFlags="fromCustomActionLabel" 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" /> latin:parentStyle="defaultEnterKeyStyle" />
</case> </case>
<!-- imeAction is either actionNone or actionUnspecified. --> <!-- imeAction is either actionNone or actionUnspecified. -->

View File

@ -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 KLP_KEYBOARD_THEME_KEY = "pref_keyboard_layout_20110916";
static final String LXX_KEYBOARD_THEME_KEY = "pref_keyboard_theme_20140509"; 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_ICS = 0;
public static final int THEME_ID_KLP = 2; public static final int THEME_ID_KLP = 2;
public static final int THEME_ID_LXX_LIGHT = 3; 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; public 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, "ICS", R.style.KeyboardTheme_ICS,
// This has never been selected because we support ICS or later. // This has never been selected because we support ICS or later.
VERSION_CODES.BASE), 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. // Default theme for ICS, JB, and KLP.
VERSION_CODES.ICE_CREAM_SANDWICH), 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. // Default theme for LXX.
BuildCompatUtils.VERSION_CODES_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), VERSION_CODES.BASE),
}; };
@ -59,12 +61,15 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
public final int mThemeId; public final int mThemeId;
public final int mStyleId; public final int mStyleId;
public final String mThemeName;
private final int mMinApiVersion; private 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/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; mThemeId = themeId;
mThemeName = themeName;
mStyleId = styleId; mStyleId = styleId;
mMinApiVersion = minApiVersion; mMinApiVersion = minApiVersion;
} }
@ -128,6 +133,11 @@ public final class KeyboardTheme implements Comparable<KeyboardTheme> {
return searchKeyboardThemeById(DEFAULT_THEME_ID); 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, public static void saveKeyboardThemeId(final String themeIdString,
final SharedPreferences prefs) { final SharedPreferences prefs) {
saveKeyboardThemeId(themeIdString, prefs, BuildCompatUtils.EFFECTIVE_SDK_INT); saveKeyboardThemeId(themeIdString, prefs, BuildCompatUtils.EFFECTIVE_SDK_INT);

View File

@ -31,6 +31,7 @@ import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.KeyboardTheme;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.utils.ResourceUtils; import com.android.inputmethod.latin.utils.ResourceUtils;
@ -643,6 +644,9 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
final boolean keyboardLayoutSetElementMatched = matchTypedValue(caseAttr, final boolean keyboardLayoutSetElementMatched = matchTypedValue(caseAttr,
R.styleable.Keyboard_Case_keyboardLayoutSetElement, id.mElementId, R.styleable.Keyboard_Case_keyboardLayoutSetElement, id.mElementId,
KeyboardId.elementIdToName(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, final boolean modeMatched = matchTypedValue(caseAttr,
R.styleable.Keyboard_Case_mode, id.mMode, KeyboardId.modeName(id.mMode)); R.styleable.Keyboard_Case_mode, id.mMode, KeyboardId.modeName(id.mMode));
final boolean navigateNextMatched = matchBoolean(caseAttr, final boolean navigateNextMatched = matchBoolean(caseAttr,
@ -671,19 +675,21 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
final boolean countryCodeMatched = matchString(caseAttr, final boolean countryCodeMatched = matchString(caseAttr,
R.styleable.Keyboard_Case_countryCode, id.mLocale.getCountry()); R.styleable.Keyboard_Case_countryCode, id.mLocale.getCountry());
final boolean selected = keyboardLayoutSetMatched && keyboardLayoutSetElementMatched final boolean selected = keyboardLayoutSetMatched && keyboardLayoutSetElementMatched
&& modeMatched && navigateNextMatched && navigatePreviousMatched && keyboardThemeMacthed && modeMatched && navigateNextMatched
&& passwordInputMatched && clobberSettingsKeyMatched && hasShortcutKeyMatched && navigatePreviousMatched && passwordInputMatched && clobberSettingsKeyMatched
&& languageSwitchKeyEnabledMatched && isMultiLineMatched && imeActionMatched && hasShortcutKeyMatched && languageSwitchKeyEnabledMatched
&& isIconDefinedMatched && localeCodeMatched && languageCodeMatched && isMultiLineMatched && imeActionMatched && isIconDefinedMatched
&& countryCodeMatched; && localeCodeMatched && languageCodeMatched && countryCodeMatched;
if (DEBUG) { 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( textAttr(caseAttr.getString(
R.styleable.Keyboard_Case_keyboardLayoutSet), "keyboardLayoutSet"), R.styleable.Keyboard_Case_keyboardLayoutSet), "keyboardLayoutSet"),
textAttr(caseAttr.getString( textAttr(caseAttr.getString(
R.styleable.Keyboard_Case_keyboardLayoutSetElement), R.styleable.Keyboard_Case_keyboardLayoutSetElement),
"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_mode), "mode"),
textAttr(caseAttr.getString(R.styleable.Keyboard_Case_imeAction), textAttr(caseAttr.getString(R.styleable.Keyboard_Case_imeAction),
"imeAction"), "imeAction"),