diff options
54 files changed, 795 insertions, 267 deletions
diff --git a/java/res/drawable-hdpi/sym_keyboard_spacebar_lxx_dark.9.png b/java/res/drawable-hdpi/btn_keyboard_spacebar_normal_lxx_dark.9.png Binary files differindex 32311666f..32311666f 100644 --- a/java/res/drawable-hdpi/sym_keyboard_spacebar_lxx_dark.9.png +++ b/java/res/drawable-hdpi/btn_keyboard_spacebar_normal_lxx_dark.9.png diff --git a/java/res/drawable-hdpi/sym_keyboard_spacebar_lxx_light.9.png b/java/res/drawable-hdpi/btn_keyboard_spacebar_normal_lxx_light.9.png Binary files differindex 1256b8b21..1256b8b21 100644 --- a/java/res/drawable-hdpi/sym_keyboard_spacebar_lxx_light.9.png +++ b/java/res/drawable-hdpi/btn_keyboard_spacebar_normal_lxx_light.9.png diff --git a/java/res/drawable-hdpi/btn_keyboard_spacebar_pressed_lxx_dark.9.png b/java/res/drawable-hdpi/btn_keyboard_spacebar_pressed_lxx_dark.9.png Binary files differnew file mode 100644 index 000000000..cd0d884c6 --- /dev/null +++ b/java/res/drawable-hdpi/btn_keyboard_spacebar_pressed_lxx_dark.9.png diff --git a/java/res/drawable-hdpi/btn_keyboard_spacebar_pressed_lxx_light.9.png b/java/res/drawable-hdpi/btn_keyboard_spacebar_pressed_lxx_light.9.png Binary files differnew file mode 100644 index 000000000..c05605fbf --- /dev/null +++ b/java/res/drawable-hdpi/btn_keyboard_spacebar_pressed_lxx_light.9.png diff --git a/java/res/drawable-mdpi/sym_keyboard_spacebar_lxx_dark.9.png b/java/res/drawable-mdpi/btn_keyboard_spacebar_normal_lxx_dark.9.png Binary files differindex b8e56dab4..b8e56dab4 100644 --- a/java/res/drawable-mdpi/sym_keyboard_spacebar_lxx_dark.9.png +++ b/java/res/drawable-mdpi/btn_keyboard_spacebar_normal_lxx_dark.9.png diff --git a/java/res/drawable-mdpi/sym_keyboard_spacebar_lxx_light.9.png b/java/res/drawable-mdpi/btn_keyboard_spacebar_normal_lxx_light.9.png Binary files differindex 281f83062..281f83062 100644 --- a/java/res/drawable-mdpi/sym_keyboard_spacebar_lxx_light.9.png +++ b/java/res/drawable-mdpi/btn_keyboard_spacebar_normal_lxx_light.9.png diff --git a/java/res/drawable-mdpi/btn_keyboard_spacebar_pressed_lxx_dark.9.png b/java/res/drawable-mdpi/btn_keyboard_spacebar_pressed_lxx_dark.9.png Binary files differnew file mode 100644 index 000000000..cb2ca06d3 --- /dev/null +++ b/java/res/drawable-mdpi/btn_keyboard_spacebar_pressed_lxx_dark.9.png diff --git a/java/res/drawable-mdpi/btn_keyboard_spacebar_pressed_lxx_light.9.png b/java/res/drawable-mdpi/btn_keyboard_spacebar_pressed_lxx_light.9.png Binary files differnew file mode 100644 index 000000000..653da974c --- /dev/null +++ b/java/res/drawable-mdpi/btn_keyboard_spacebar_pressed_lxx_light.9.png diff --git a/java/res/drawable-xhdpi/sym_keyboard_spacebar_lxx_dark.9.png b/java/res/drawable-xhdpi/btn_keyboard_spacebar_normal_lxx_dark.9.png Binary files differindex ab032dc17..ab032dc17 100644 --- a/java/res/drawable-xhdpi/sym_keyboard_spacebar_lxx_dark.9.png +++ b/java/res/drawable-xhdpi/btn_keyboard_spacebar_normal_lxx_dark.9.png diff --git a/java/res/drawable-xhdpi/sym_keyboard_spacebar_lxx_light.9.png b/java/res/drawable-xhdpi/btn_keyboard_spacebar_normal_lxx_light.9.png Binary files differindex c1ed863f8..c1ed863f8 100644 --- a/java/res/drawable-xhdpi/sym_keyboard_spacebar_lxx_light.9.png +++ b/java/res/drawable-xhdpi/btn_keyboard_spacebar_normal_lxx_light.9.png diff --git a/java/res/drawable-xhdpi/btn_keyboard_spacebar_pressed_lxx_dark.9.png b/java/res/drawable-xhdpi/btn_keyboard_spacebar_pressed_lxx_dark.9.png Binary files differnew file mode 100644 index 000000000..c3428bede --- /dev/null +++ b/java/res/drawable-xhdpi/btn_keyboard_spacebar_pressed_lxx_dark.9.png diff --git a/java/res/drawable-xhdpi/btn_keyboard_spacebar_pressed_lxx_light.9.png b/java/res/drawable-xhdpi/btn_keyboard_spacebar_pressed_lxx_light.9.png Binary files differnew file mode 100644 index 000000000..f795ee9af --- /dev/null +++ b/java/res/drawable-xhdpi/btn_keyboard_spacebar_pressed_lxx_light.9.png diff --git a/java/res/drawable-xxhdpi/sym_keyboard_spacebar_lxx_dark.9.png b/java/res/drawable-xxhdpi/btn_keyboard_spacebar_normal_lxx_dark.9.png Binary files differindex 0339de37d..0339de37d 100644 --- a/java/res/drawable-xxhdpi/sym_keyboard_spacebar_lxx_dark.9.png +++ b/java/res/drawable-xxhdpi/btn_keyboard_spacebar_normal_lxx_dark.9.png diff --git a/java/res/drawable-xxhdpi/sym_keyboard_spacebar_lxx_light.9.png b/java/res/drawable-xxhdpi/btn_keyboard_spacebar_normal_lxx_light.9.png Binary files differindex b57cfb3d2..b57cfb3d2 100644 --- a/java/res/drawable-xxhdpi/sym_keyboard_spacebar_lxx_light.9.png +++ b/java/res/drawable-xxhdpi/btn_keyboard_spacebar_normal_lxx_light.9.png diff --git a/java/res/drawable-xxhdpi/btn_keyboard_spacebar_pressed_lxx_dark.9.png b/java/res/drawable-xxhdpi/btn_keyboard_spacebar_pressed_lxx_dark.9.png Binary files differnew file mode 100644 index 000000000..8e74c6723 --- /dev/null +++ b/java/res/drawable-xxhdpi/btn_keyboard_spacebar_pressed_lxx_dark.9.png diff --git a/java/res/drawable-xxhdpi/btn_keyboard_spacebar_pressed_lxx_light.9.png b/java/res/drawable-xxhdpi/btn_keyboard_spacebar_pressed_lxx_light.9.png Binary files differnew file mode 100644 index 000000000..1ca1ae3e9 --- /dev/null +++ b/java/res/drawable-xxhdpi/btn_keyboard_spacebar_pressed_lxx_light.9.png diff --git a/java/res/drawable/btn_keyboard_key_lxx_dark.xml b/java/res/drawable/btn_keyboard_key_lxx_dark.xml index c82c13829..bb1789ae3 100644 --- a/java/res/drawable/btn_keyboard_key_lxx_dark.xml +++ b/java/res/drawable/btn_keyboard_key_lxx_dark.xml @@ -15,11 +15,6 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <!-- Custom label action keys. --> - <item android:state_active="true" android:state_checked="true" android:state_pressed="true" - android:drawable="@color/key_background_pressed_lxx_dark" /> - <item android:state_active="true" android:state_checked="true" - android:drawable="@color/key_background_lxx_dark" /> <!-- Action keys. --> <item android:state_active="true" android:state_pressed="true" android:drawable="@drawable/btn_keyboard_key_active_pressed_lxx_dark" /> diff --git a/java/res/drawable/btn_keyboard_key_lxx_light.xml b/java/res/drawable/btn_keyboard_key_lxx_light.xml index f237fbea9..60fe02dd2 100644 --- a/java/res/drawable/btn_keyboard_key_lxx_light.xml +++ b/java/res/drawable/btn_keyboard_key_lxx_light.xml @@ -15,11 +15,6 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <!-- Custom label action keys. --> - <item android:state_active="true" android:state_checked="true" android:state_pressed="true" - android:drawable="@color/key_background_pressed_lxx_light" /> - <item android:state_active="true" android:state_checked="true" - android:drawable="@color/key_background_lxx_light" /> <!-- Action keys. --> <item android:state_active="true" android:state_pressed="true" android:drawable="@drawable/btn_keyboard_key_active_pressed_lxx_light" /> diff --git a/java/res/drawable/btn_keyboard_spacebar_lxx_dark.xml b/java/res/drawable/btn_keyboard_spacebar_lxx_dark.xml index 5c595d9ed..e930e40e4 100644 --- a/java/res/drawable/btn_keyboard_spacebar_lxx_dark.xml +++ b/java/res/drawable/btn_keyboard_spacebar_lxx_dark.xml @@ -16,6 +16,6 @@ <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" - android:drawable="@color/key_background_pressed_lxx_dark" /> - <item android:drawable="@color/key_background_lxx_dark" /> + android:drawable="@drawable/btn_keyboard_spacebar_pressed_lxx_dark" /> + <item android:drawable="@drawable/btn_keyboard_spacebar_normal_lxx_dark" /> </selector> diff --git a/java/res/drawable/btn_keyboard_spacebar_lxx_light.xml b/java/res/drawable/btn_keyboard_spacebar_lxx_light.xml index acd19fda4..2b059938d 100644 --- a/java/res/drawable/btn_keyboard_spacebar_lxx_light.xml +++ b/java/res/drawable/btn_keyboard_spacebar_lxx_light.xml @@ -16,6 +16,6 @@ <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" - android:drawable="@color/key_background_pressed_lxx_light" /> - <item android:drawable="@color/key_background_lxx_light" /> + android:drawable="@drawable/btn_keyboard_spacebar_pressed_lxx_light" /> + <item android:drawable="@drawable/btn_keyboard_spacebar_normal_lxx_light" /> </selector> diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index c756f8c34..57e73767c 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. --> @@ -278,7 +284,7 @@ <enum name="stickyOff" value="3" /> <enum name="stickyOn" value="4" /> <enum name="action" value="5" /> - <enum name="customAction" value="6" /> + <enum name="spacebar" value="6" /> </attr> <!-- The key action flags. --> <attr name="keyActionFlags" format="integer"> @@ -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/keyboard-icons-lxx-dark.xml b/java/res/values/keyboard-icons-lxx-dark.xml index 305df02cd..2e2fd0abb 100644 --- a/java/res/values/keyboard-icons-lxx-dark.xml +++ b/java/res/values/keyboard-icons-lxx-dark.xml @@ -24,7 +24,7 @@ <item name="iconShiftKey">@drawable/sym_keyboard_shift_lxx_dark</item> <item name="iconDeleteKey">@drawable/sym_keyboard_delete_lxx_dark</item> <item name="iconSettingsKey">@drawable/sym_keyboard_settings_lxx_dark</item> - <item name="iconSpaceKey">@drawable/sym_keyboard_spacebar_lxx_dark</item> + <item name="iconSpaceKey">@null</item> <item name="iconEnterKey">@drawable/sym_keyboard_return_lxx_dark</item> <item name="iconGoKey">@drawable/sym_keyboard_go_lxx_dark</item> <item name="iconSearchKey">@drawable/sym_keyboard_search_lxx_dark</item> diff --git a/java/res/values/keyboard-icons-lxx-light.xml b/java/res/values/keyboard-icons-lxx-light.xml index 866dc682f..099a706fe 100644 --- a/java/res/values/keyboard-icons-lxx-light.xml +++ b/java/res/values/keyboard-icons-lxx-light.xml @@ -24,7 +24,7 @@ <item name="iconShiftKey">@drawable/sym_keyboard_shift_lxx_light</item> <item name="iconDeleteKey">@drawable/sym_keyboard_delete_lxx_light</item> <item name="iconSettingsKey">@drawable/sym_keyboard_settings_lxx_light</item> - <item name="iconSpaceKey">@drawable/sym_keyboard_spacebar_lxx_light</item> + <item name="iconSpaceKey">@null</item> <item name="iconEnterKey">@drawable/sym_keyboard_return_lxx_light</item> <item name="iconGoKey">@drawable/sym_keyboard_go_lxx_light</item> <item name="iconSearchKey">@drawable/sym_keyboard_search_lxx_light</item> diff --git a/java/res/values/themes-ics.xml b/java/res/values/themes-ics.xml index 051489e11..a9c7294a0 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 a853ed9dd..da5e27fa1 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 2aaee1360..c49436c49 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 e7a6f5894..6f0fb7131 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_common.xml b/java/res/xml-sw600dp/key_styles_common.xml index c750a9319..006cda370 100644 --- a/java/res/xml-sw600dp/key_styles_common.xml +++ b/java/res/xml-sw600dp/key_styles_common.xml @@ -86,6 +86,7 @@ <key-style latin:styleName="spaceKeyStyle" latin:keySpec="!icon/space_key|!code/key_space" + latin:backgroundType="spacebar" latin:keyActionFlags="noKeyPreview|enableLongPress" /> <!-- U+200C: ZERO WIDTH NON-JOINER U+200D: ZERO WIDTH JOINER --> diff --git a/java/res/xml-sw600dp/key_styles_enter.xml b/java/res/xml-sw600dp/key_styles_enter.xml index c20523b2a..0227d811b 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-sw600dp/rows_number_normal.xml b/java/res/xml-sw600dp/rows_number_normal.xml index 757e77933..7a4700d5a 100644 --- a/java/res/xml-sw600dp/rows_number_normal.xml +++ b/java/res/xml-sw600dp/rows_number_normal.xml @@ -141,9 +141,8 @@ </Row> <Row> <Key - latin:keyStyle="spaceKeyStyle" - latin:keyWidth="30%p" - latin:backgroundType="functional" /> + latin:keyStyle="tabletNumSpaceKeyStyle" + latin:keyWidth="30%p" /> <Key latin:keyStyle="numStarKeyStyle" latin:keyXPos="31%p" /> diff --git a/java/res/xml-sw600dp/rows_phone.xml b/java/res/xml-sw600dp/rows_phone.xml index 9022bc532..612397a90 100644 --- a/java/res/xml-sw600dp/rows_phone.xml +++ b/java/res/xml-sw600dp/rows_phone.xml @@ -107,9 +107,8 @@ </Row> <Row> <Key - latin:keyStyle="spaceKeyStyle" - latin:keyWidth="30%p" - latin:backgroundType="functional" /> + latin:keyStyle="tabletNumSpaceKeyStyle" + latin:keyWidth="30%p" /> <Key latin:keyStyle="numStarKeyStyle" latin:keyXPos="31%p" /> diff --git a/java/res/xml/key_space_symbols.xml b/java/res/xml/key_space_symbols.xml index 0ce522889..047de9f24 100644 --- a/java/res/xml/key_space_symbols.xml +++ b/java/res/xml/key_space_symbols.xml @@ -22,7 +22,6 @@ xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" > <Key - latin:backgroundType="normal" latin:keyStyle="spaceKeyStyle" latin:keyWidth="30%p" /> </merge> diff --git a/java/res/xml/key_styles_common.xml b/java/res/xml/key_styles_common.xml index 167e6f88d..43ee26b07 100644 --- a/java/res/xml/key_styles_common.xml +++ b/java/res/xml/key_styles_common.xml @@ -91,6 +91,7 @@ <key-style latin:styleName="spaceKeyStyle" latin:keySpec="!icon/space_key|!code/key_space" + latin:backgroundType="spacebar" latin:keyActionFlags="noKeyPreview|enableLongPress" /> <!-- U+200C: ZERO WIDTH NON-JOINER U+200D: ZERO WIDTH JOINER --> diff --git a/java/res/xml/key_styles_enter.xml b/java/res/xml/key_styles_enter.xml index 55dab78c3..7aea1ceff 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/res/xml/key_styles_number.xml b/java/res/xml/key_styles_number.xml index 14b202874..97ae6c6c3 100644 --- a/java/res/xml/key_styles_number.xml +++ b/java/res/xml/key_styles_number.xml @@ -123,4 +123,24 @@ latin:keyLabelFlags="alignIconToBottom" latin:keyActionFlags="enableLongPress" latin:parentStyle="numKeyBaseStyle" /> + <!-- TODO: Consolidate these space key styles with numSpaceKeyStyle above by introducing <case> + predicator that checks device form-factor. --> + <switch> + <case latin:keyboardTheme="ICS|KLP"> + <key-style + latin:styleName="tabletNumSpaceKeyStyle" + latin:keySpec="!icon/space_key|!code/key_space" + latin:backgroundType="functional" + latin:keyActionFlags="enableLongPress" + latin:parentStyle="numKeyBaseStyle" /> + </case> + <case latin:keyboardTheme="LXXLight|LXXDark"> + <key-style + latin:styleName="tabletNumSpaceKeyStyle" + latin:keySpec="!icon/space_key|!code/key_space" + latin:backgroundType="spacebar" + latin:keyActionFlags="enableLongPress" + latin:parentStyle="numKeyBaseStyle" /> + </case> + </switch> </merge> diff --git a/java/res/xml/prefs_screen_debug.xml b/java/res/xml/prefs_screen_debug.xml index e0f3501fd..c47740268 100644 --- a/java/res/xml/prefs_screen_debug.xml +++ b/java/res/xml/prefs_screen_debug.xml @@ -58,32 +58,32 @@ android:defaultValue="false" android:persistent="true" /> <com.android.inputmethod.latin.settings.SeekBarDialogPreference - android:dependency="pref_customize_key_preview_animation" + android:dependency="pref_has_custom_key_preview_animation_params" android:key="pref_key_preview_show_up_start_x_scale" android:title="@string/prefs_key_popup_show_up_start_x_scale_settings" latin:maxValue="100" /> <!-- percent --> <com.android.inputmethod.latin.settings.SeekBarDialogPreference - android:dependency="pref_customize_key_preview_animation" + android:dependency="pref_has_custom_key_preview_animation_params" android:key="pref_key_preview_show_up_start_y_scale" android:title="@string/prefs_key_popup_show_up_start_y_scale_settings" latin:maxValue="100" /> <!-- percent --> <com.android.inputmethod.latin.settings.SeekBarDialogPreference - android:dependency="pref_customize_key_preview_animation" + android:dependency="pref_has_custom_key_preview_animation_params" android:key="pref_key_preview_dismiss_end_x_scale" android:title="@string/prefs_key_popup_dismiss_end_x_scale_settings" latin:maxValue="100" /> <!-- percent --> <com.android.inputmethod.latin.settings.SeekBarDialogPreference - android:dependency="pref_customize_key_preview_animation" + android:dependency="pref_has_custom_key_preview_animation_params" android:key="pref_key_preview_dismiss_end_y_scale" android:title="@string/prefs_key_popup_dismiss_end_y_scale_settings" latin:maxValue="100" /> <!-- percent --> <com.android.inputmethod.latin.settings.SeekBarDialogPreference - android:dependency="pref_customize_key_preview_animation" + android:dependency="pref_has_custom_key_preview_animation_params" android:key="pref_key_preview_show_up_duration" android:title="@string/prefs_key_popup_show_up_duration_settings" latin:maxValue="100" /> <!-- milliseconds --> <com.android.inputmethod.latin.settings.SeekBarDialogPreference - android:dependency="pref_customize_key_preview_animation" + android:dependency="pref_has_custom_key_preview_animation_params" android:key="pref_key_preview_dismiss_duration" android:title="@string/prefs_key_popup_dismiss_duration_settings" latin:maxValue="100" /> <!-- milliseconds --> diff --git a/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java b/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java index 24eaec85c..3a86ccbda 100644 --- a/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/CursorAnchorInfoCompatWrapper.java @@ -23,34 +23,16 @@ import com.android.inputmethod.annotations.UsedForTesting; @UsedForTesting public final class CursorAnchorInfoCompatWrapper { - public static final int CHARACTER_RECT_TYPE_MASK = 0x0f; /** - * Type for {@link #CHARACTER_RECT_TYPE_MASK}: the editor did not specify any type of this - * character. Editor authors should not use this flag. + * The insertion marker or character bounds have at least one visible region. */ - public static final int CHARACTER_RECT_TYPE_UNSPECIFIED = 0; + public static final int FLAG_HAS_VISIBLE_REGION = 0x01; /** - * Type for {@link #CHARACTER_RECT_TYPE_MASK}: the character is entirely visible. + * The insertion marker or character bounds have at least one invisible (clipped) region. */ - public static final int CHARACTER_RECT_TYPE_FULLY_VISIBLE = 1; - - /** - * Type for {@link #CHARACTER_RECT_TYPE_MASK}: some area of the character is invisible. - */ - public static final int CHARACTER_RECT_TYPE_PARTIALLY_VISIBLE = 2; - - /** - * Type for {@link #CHARACTER_RECT_TYPE_MASK}: the character is entirely invisible. - */ - public static final int CHARACTER_RECT_TYPE_INVISIBLE = 3; - - /** - * Type for {@link #CHARACTER_RECT_TYPE_MASK}: the editor gave up to calculate the rectangle - * for this character. Input method authors should ignore the returned rectangle. - */ - public static final int CHARACTER_RECT_TYPE_NOT_FEASIBLE = 4; + public static final int FLAG_HAS_INVISIBLE_REGION = 0x02; // Note that CursorAnchorInfo has been introduced in API level XX (Build.VERSION_CODE.LXX). private static final CompatUtils.ClassWrapper sCursorAnchorInfoClass; @@ -63,7 +45,7 @@ public final class CursorAnchorInfoCompatWrapper { private static final CompatUtils.ToFloatMethodWrapper sGetInsertionMarkerHorizontalMethod; private static final CompatUtils.ToFloatMethodWrapper sGetInsertionMarkerTopMethod; private static final CompatUtils.ToObjectMethodWrapper<Matrix> sGetMatrixMethod; - private static final CompatUtils.ToBooleanMethodWrapper sIsInsertionMarkerClippedMethod; + private static final CompatUtils.ToIntMethodWrapper sGetInsertionMarkerFlagsMethod; private static int COMPOSING_TEXT_START_DEFAULT = -1; static { @@ -72,7 +54,7 @@ public final class CursorAnchorInfoCompatWrapper { sGetCharacterRectMethod = sCursorAnchorInfoClass.getMethod( "getCharacterRect", (RectF)null, int.class); sGetCharacterRectFlagsMethod = sCursorAnchorInfoClass.getPrimitiveMethod( - "getCharacterRectFlags", CHARACTER_RECT_TYPE_UNSPECIFIED, int.class); + "getCharacterRectFlags", 0, int.class); sGetComposingTextMethod = sCursorAnchorInfoClass.getMethod( "getComposingText", (CharSequence)null); sGetComposingTextStartMethod = sCursorAnchorInfoClass.getPrimitiveMethod( @@ -86,8 +68,8 @@ public final class CursorAnchorInfoCompatWrapper { sGetInsertionMarkerTopMethod = sCursorAnchorInfoClass.getPrimitiveMethod( "getInsertionMarkerTop", 0.0f); sGetMatrixMethod = sCursorAnchorInfoClass.getMethod("getMatrix", (Matrix)null); - sIsInsertionMarkerClippedMethod = sCursorAnchorInfoClass.getPrimitiveMethod( - "isInsertionMarkerClipped", false); + sGetInsertionMarkerFlagsMethod = sCursorAnchorInfoClass.getPrimitiveMethod( + "getInsertionMarkerFlags", 0); } @UsedForTesting @@ -154,7 +136,7 @@ public final class CursorAnchorInfoCompatWrapper { return sGetInsertionMarkerTopMethod.invoke(mInstance); } - public boolean isInsertionMarkerClipped() { - return sIsInsertionMarkerClippedMethod.invoke(mInstance); + public int getInsertionMarkerFlags() { + return sGetInsertionMarkerFlagsMethod.invoke(mInstance); } } diff --git a/java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java b/java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java index 862ec8a58..a5c71b22f 100644 --- a/java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/InputConnectionCompatUtils.java @@ -21,30 +21,29 @@ import android.view.inputmethod.InputMethodManager; public final class InputConnectionCompatUtils { private static final CompatUtils.ClassWrapper sInputConnectionType; - private static final CompatUtils.ToBooleanMethodWrapper sRequestUpdateCursorAnchorInfoMethod; + private static final CompatUtils.ToBooleanMethodWrapper sRequestCursorUpdatesMethod; static { sInputConnectionType = new CompatUtils.ClassWrapper(InputConnection.class); - sRequestUpdateCursorAnchorInfoMethod = sInputConnectionType.getPrimitiveMethod( - "requestUpdateCursorAnchorInfo", false, int.class); + sRequestCursorUpdatesMethod = sInputConnectionType.getPrimitiveMethod( + "requestCursorUpdates", false, int.class); } - public static boolean isRequestUpdateCursorAnchorInfoAvailable() { - return sRequestUpdateCursorAnchorInfoMethod != null; + public static boolean isRequestCursorUpdatesAvailable() { + return sRequestCursorUpdatesMethod != null; } /** - * Local copies of some constants in CursorAnchorInfoRequest until the SDK becomes publicly - * available. + * Local copies of some constants in InputConnection until the SDK becomes publicly available. */ - private static int REQUEST_UPDATE_CURSOR_UPDATE_IMMEDIATE = 1 << 0; - private static int REQUEST_UPDATE_CURSOR_UPDATE_MONITOR = 1 << 1; + private static int CURSOR_UPDATE_IMMEDIATE = 1 << 0; + private static int CURSOR_UPDATE_MONITOR = 1 << 1; - private static boolean requestUpdateCursorAnchorInfoImpl(final InputConnection inputConnection, + private static boolean requestCursorUpdatesImpl(final InputConnection inputConnection, final int cursorUpdateMode) { - if (!isRequestUpdateCursorAnchorInfoAvailable()) { + if (!isRequestCursorUpdatesAvailable()) { return false; } - return sRequestUpdateCursorAnchorInfoMethod.invoke(inputConnection, cursorUpdateMode); + return sRequestCursorUpdatesMethod.invoke(inputConnection, cursorUpdateMode); } /** @@ -56,11 +55,10 @@ public final class InputConnectionCompatUtils { * as soon as possible to notify the current cursor/anchor position to the input method. * @return {@code false} if the request is not handled. Otherwise returns {@code true}. */ - public static boolean requestUpdateCursorAnchorInfo(final InputConnection inputConnection, + public static boolean requestCursorUpdates(final InputConnection inputConnection, final boolean enableMonitor, final boolean requestImmediateCallback) { - final int cursorUpdateMode = (enableMonitor ? REQUEST_UPDATE_CURSOR_UPDATE_MONITOR : 0) - | (requestImmediateCallback ? REQUEST_UPDATE_CURSOR_UPDATE_IMMEDIATE : 0); - return requestUpdateCursorAnchorInfoImpl(inputConnection, cursorUpdateMode); + final int cursorUpdateMode = (enableMonitor ? CURSOR_UPDATE_MONITOR : 0) + | (requestImmediateCallback ? CURSOR_UPDATE_IMMEDIATE : 0); + return requestCursorUpdatesImpl(inputConnection, cursorUpdateMode); } - } diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 05334c7f4..efa527e15 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -139,7 +139,7 @@ public class Key implements Comparable<Key> { public static final int BACKGROUND_TYPE_STICKY_OFF = 3; public static final int BACKGROUND_TYPE_STICKY_ON = 4; public static final int BACKGROUND_TYPE_ACTION = 5; - public static final int BACKGROUND_TYPE_CUSTOM_ACTION = 6; + public static final int BACKGROUND_TYPE_SPACEBAR = 6; private final int mActionFlags; private static final int ACTION_FLAGS_IS_REPEATABLE = 0x01; @@ -506,7 +506,7 @@ public class Key implements Comparable<Key> { case BACKGROUND_TYPE_STICKY_OFF: return "stickyOff"; case BACKGROUND_TYPE_STICKY_ON: return "stickyOn"; case BACKGROUND_TYPE_ACTION: return "action"; - case BACKGROUND_TYPE_CUSTOM_ACTION: return "customAction"; + case BACKGROUND_TYPE_SPACEBAR: return "spacebar"; default: return null; } } @@ -889,8 +889,8 @@ public class Key implements Comparable<Key> { new KeyBackgroundState(android.R.attr.state_checkable, android.R.attr.state_checked), // 5: BACKGROUND_TYPE_ACTION new KeyBackgroundState(android.R.attr.state_active), - // 6: BACKGROUND_TYPE_CUSTOM_ACTION - new KeyBackgroundState(android.R.attr.state_active, android.R.attr.state_checked) + // 6: BACKGROUND_TYPE_SPACEBAR + new KeyBackgroundState(), }; } @@ -904,7 +904,7 @@ public class Key implements Comparable<Key> { final Drawable background; if (mBackgroundType == BACKGROUND_TYPE_FUNCTIONAL) { background = functionalKeyBackground; - } else if (getCode() == Constants.CODE_SPACE) { + } else if (mBackgroundType == BACKGROUND_TYPE_SPACEBAR) { background = spacebarBackground; } else { background = keyBackground; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java b/java/src/com/android/inputmethod/keyboard/KeyboardTheme.java index 0cd606d19..7161d3f26 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/TextDecorator.java b/java/src/com/android/inputmethod/keyboard/TextDecorator.java index 178516134..9192853ca 100644 --- a/java/src/com/android/inputmethod/keyboard/TextDecorator.java +++ b/java/src/com/android/inputmethod/keyboard/TextDecorator.java @@ -276,10 +276,10 @@ public class TextDecorator { final int lastCharRectIndex = composingTextStart + composingText.length() - 1; final RectF lastCharRect = info.getCharacterRect(lastCharRectIndex); final int lastCharRectFlag = info.getCharacterRectFlags(lastCharRectIndex); - final int lastCharRectType = - lastCharRectFlag & CursorAnchorInfoCompatWrapper.CHARACTER_RECT_TYPE_MASK; - if (lastCharRect == null || matrix == null || lastCharRectType != - CursorAnchorInfoCompatWrapper.CHARACTER_RECT_TYPE_FULLY_VISIBLE) { + final boolean hasInvisibleRegionInLastCharRect = + (lastCharRectFlag & CursorAnchorInfoCompatWrapper.FLAG_HAS_INVISIBLE_REGION) + != 0; + if (lastCharRect == null || matrix == null || hasInvisibleRegionInLastCharRect) { mUiOperator.hideUi(); return; } @@ -336,7 +336,8 @@ public class TextDecorator { } // In MODE_ADD_TO_DICTIONARY, we cannot retrieve the character position at all because // of the lack of composing text. We will use the insertion marker position instead. - if (info.isInsertionMarkerClipped()) { + if ((info.getInsertionMarkerFlags() & + CursorAnchorInfoCompatWrapper.FLAG_HAS_INVISIBLE_REGION) != 0) { mUiOperator.hideUi(); return; } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java index 8bff27574..fa4192790 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"), diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java index f1c7f4340..6b6384c48 100644 --- a/java/src/com/android/inputmethod/latin/RichInputConnection.java +++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java @@ -922,13 +922,13 @@ public final class RichInputConnection { * prevents the application from fulfilling the request. (TODO: Improve the API when it turns * out that we actually need more detailed error codes) */ - public boolean requestUpdateCursorAnchorInfo(final boolean enableMonitor, + public boolean requestCursorUpdates(final boolean enableMonitor, final boolean requestImmediateCallback) { mIC = mParent.getCurrentInputConnection(); final boolean scheduled; if (null != mIC) { - scheduled = InputConnectionCompatUtils.requestUpdateCursorAnchorInfo(mIC, - enableMonitor, requestImmediateCallback); + scheduled = InputConnectionCompatUtils.requestCursorUpdates(mIC, enableMonitor, + requestImmediateCallback); } else { scheduled = false; } diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 4b5edb076..233a22512 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -167,7 +167,7 @@ public final class InputLogic { if (ProductionFlags.ENABLE_CURSOR_ANCHOR_INFO_CALLBACK) { // AcceptTypedWord feature relies on CursorAnchorInfo. if (settingsValues.mShouldShowUiToAcceptTypedWord) { - mConnection.requestUpdateCursorAnchorInfo(true /* enableMonitor */, + mConnection.requestCursorUpdates(true /* enableMonitor */, true /* requestImmediateCallback */); } } diff --git a/native/jni/NativeFileList.mk b/native/jni/NativeFileList.mk index 4f77388fd..68d2bbd83 100644 --- a/native/jni/NativeFileList.mk +++ b/native/jni/NativeFileList.mk @@ -125,6 +125,7 @@ LATIN_IME_CORE_TEST_FILES := \ suggest/core/dictionary/bloom_filter_test.cpp \ suggest/core/layout/geometry_utils_test.cpp \ suggest/core/layout/normal_distribution_2d_test.cpp \ + suggest/policyimpl/dictionary/header/header_read_write_utils_test.cpp \ suggest/policyimpl/dictionary/structure/v4/content/language_model_dict_content_test.cpp \ suggest/policyimpl/dictionary/structure/v4/content/probability_entry_test.cpp \ suggest/policyimpl/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp \ diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp b/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp index a8f8f284b..d2c3d2fe0 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp @@ -142,7 +142,8 @@ typedef DictionaryHeaderStructurePolicy::AttributeMap AttributeMap; } /* static */ void HeaderReadWriteUtils::setCodePointVectorAttribute( - AttributeMap *const headerAttributes, const char *const key, const std::vector<int> value) { + AttributeMap *const headerAttributes, const char *const key, + const std::vector<int> &value) { AttributeMap::key_type keyVector; insertCharactersIntoVector(key, &keyVector); (*headerAttributes)[keyVector] = value; diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h b/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h index 9b90488fc..1ab2eec69 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h +++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h @@ -64,7 +64,7 @@ class HeaderReadWriteUtils { */ static void setCodePointVectorAttribute( DictionaryHeaderStructurePolicy::AttributeMap *const headerAttributes, - const char *const key, const std::vector<int> value); + const char *const key, const std::vector<int> &value); static void setBoolAttribute( DictionaryHeaderStructurePolicy::AttributeMap *const headerAttributes, diff --git a/native/jni/tests/suggest/policyimpl/dictionary/header/header_read_write_utils_test.cpp b/native/jni/tests/suggest/policyimpl/dictionary/header/header_read_write_utils_test.cpp new file mode 100644 index 000000000..da6a2af27 --- /dev/null +++ b/native/jni/tests/suggest/policyimpl/dictionary/header/header_read_write_utils_test.cpp @@ -0,0 +1,78 @@ +/* + * 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. + */ + +#include "suggest/policyimpl/dictionary/header/header_read_write_utils.h" + +#include <gtest/gtest.h> + +#include <cstring> +#include <vector> + +#include "suggest/core/policy/dictionary_header_structure_policy.h" + +namespace latinime { +namespace { + +TEST(HeaderReadWriteUtilsTest, TestInsertCharactersIntoVector) { + DictionaryHeaderStructurePolicy::AttributeMap::key_type vector; + + HeaderReadWriteUtils::insertCharactersIntoVector("", &vector); + EXPECT_TRUE(vector.empty()); + + static const char *str = "abc-xyz!?"; + HeaderReadWriteUtils::insertCharactersIntoVector(str, &vector); + EXPECT_EQ(strlen(str) , vector.size()); + for (size_t i = 0; i < vector.size(); ++i) { + EXPECT_EQ(str[i], vector[i]); + } +} + +TEST(HeaderReadWriteUtilsTest, TestAttributeMapForInt) { + DictionaryHeaderStructurePolicy::AttributeMap attributeMap; + + // Returns default value if not exists. + EXPECT_EQ(-1, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "", -1)); + EXPECT_EQ(100, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abc", 100)); + + HeaderReadWriteUtils::setIntAttribute(&attributeMap, "abc", 10); + EXPECT_EQ(10, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abc", 100)); + HeaderReadWriteUtils::setIntAttribute(&attributeMap, "abc", 20); + EXPECT_EQ(20, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abc", 100)); + HeaderReadWriteUtils::setIntAttribute(&attributeMap, "abcd", 30); + EXPECT_EQ(30, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abcd", 100)); + EXPECT_EQ(20, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abc", 100)); +} + +TEST(HeaderReadWriteUtilsTest, TestAttributeMapCodeForPoints) { + DictionaryHeaderStructurePolicy::AttributeMap attributeMap; + + // Returns empty vector if not exists. + EXPECT_TRUE(HeaderReadWriteUtils::readCodePointVectorAttributeValue(&attributeMap, "").empty()); + EXPECT_TRUE(HeaderReadWriteUtils::readCodePointVectorAttributeValue( + &attributeMap, "abc").empty()); + + HeaderReadWriteUtils::setCodePointVectorAttribute(&attributeMap, "abc", {}); + EXPECT_TRUE(HeaderReadWriteUtils::readCodePointVectorAttributeValue( + &attributeMap, "abc").empty()); + + const std::vector<int> codePoints = { 0x0, 0x20, 0x1F, 0x100000 }; + HeaderReadWriteUtils::setCodePointVectorAttribute(&attributeMap, "abc", codePoints); + EXPECT_EQ(codePoints, HeaderReadWriteUtils::readCodePointVectorAttributeValue( + &attributeMap, "abc")); +} + +} // namespace +} // namespace latinime diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelBase.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelBase.java new file mode 100644 index 000000000..a25d6d6e7 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelBase.java @@ -0,0 +1,156 @@ +/* + * 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.res.Resources; +import android.text.InputType; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.latin.Constants; +import com.android.inputmethod.latin.utils.RunInLocale; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +import java.util.Locale; + +abstract class KeyboardLayoutSetActionLabelBase extends KeyboardLayoutSetTestsBase { + public void testActionUnspecified() { + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "unspecifiled " + + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, + KeyboardIconsSet.NAME_ENTER_KEY); + } + } + + public void testActionNone() { + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_NONE, + KeyboardIconsSet.NAME_ENTER_KEY); + } + } + + public void testActionSearch() { + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_SEARCH, + KeyboardIconsSet.NAME_SEARCH_KEY); + } + } + + public abstract void testActionGo(); + public abstract void testActionSend(); + public abstract void testActionNext(); + public abstract void testActionDone(); + public abstract void testActionPrevious(); + + public void testActionCustom() { + for (final InputMethodSubtype subtype : getAllSubtypesList()) { + final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); + final CharSequence customLabel = "customLabel"; + final EditorInfo editorInfo = new EditorInfo(); + editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED; + editorInfo.actionLabel = customLabel; + doTestActionKeyLabel(tag, subtype, editorInfo, customLabel); + } + } + + private static void doTestActionKey(final String tag, final KeyboardLayoutSet layoutSet, + final int elementId, final CharSequence label, final int iconId) { + final Keyboard keyboard = layoutSet.getKeyboard(elementId); + final Key enterKey = keyboard.getKey(Constants.CODE_ENTER); + assertNotNull(tag + " enter key on " + keyboard.mId, enterKey); + assertEquals(tag + " enter label " + enterKey, label, enterKey.getLabel()); + assertEquals(tag + " enter icon " + enterKey, iconId, enterKey.getIconId()); + } + + protected void doTestActionKeyLabelResId(final String tag, final InputMethodSubtype subtype, + final int actionId, final int labelResId) { + final Locale labelLocale = subtype.getLocale().equals(SubtypeLocaleUtils.NO_LANGUAGE) + ? null : SubtypeLocaleUtils.getSubtypeLocale(subtype); + doTestActionKeyLabelResIdInLocale(tag, subtype, actionId, labelLocale, labelResId); + } + + protected void doTestActionKeyLabelResIdInLocale(final String tag, + final InputMethodSubtype subtype, final int actionId, final Locale labelLocale, + final int labelResId) { + final EditorInfo editorInfo = new EditorInfo(); + editorInfo.imeOptions = actionId; + final RunInLocale<String> job = new RunInLocale<String>() { + @Override + protected String job(final Resources res) { + return res.getString(labelResId); + } + }; + final String label = job.runInLocale(getContext().getResources(), labelLocale); + doTestActionKeyLabel(tag, subtype, editorInfo, label); + } + + protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype, + final EditorInfo editorInfo, final CharSequence label) { + // Test text layouts. + editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; + final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); + doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, + label, KeyboardIconsSet.ICON_UNDEFINED); + doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, + label, KeyboardIconsSet.ICON_UNDEFINED); + doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, + label, KeyboardIconsSet.ICON_UNDEFINED); + // Test phone number layouts. + doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, + label, KeyboardIconsSet.ICON_UNDEFINED); + doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, + label, KeyboardIconsSet.ICON_UNDEFINED); + // Test normal number layout. + doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, + label, KeyboardIconsSet.ICON_UNDEFINED); + // Test number password layouts. + editorInfo.inputType = + InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; + final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); + doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, + label, KeyboardIconsSet.ICON_UNDEFINED); + } + + protected void doTestActionKeyIcon(final String tag, final InputMethodSubtype subtype, + final int actionId, final String iconName) { + final int iconId = KeyboardIconsSet.getIconId(iconName); + final EditorInfo editorInfo = new EditorInfo(); + editorInfo.imeOptions = actionId; + // Test text layouts. + editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; + final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); + doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, null /* label */, iconId); + doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, null /* label */, iconId); + doTestActionKey( + tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, null /* label */, iconId); + // Test phone number layouts. + doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, null /* label */, iconId); + doTestActionKey( + tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, null /* label */, iconId); + // Test normal number layout. + doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); + // Test number password layout. + editorInfo.inputType = + InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; + final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); + doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelKlpTests.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelKlpTests.java index 9e795dbc2..322a344ff 100644 --- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelKlpTests.java +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelKlpTests.java @@ -30,61 +30,27 @@ import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import java.util.Locale; @MediumTest -public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActionLabelLxxTests { +public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActionLabelBase { @Override protected int getKeyboardThemeForTests() { return KeyboardTheme.THEME_ID_KLP; } - protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype, - final int actionId, final int labelResId) { - final Locale labelLocale = subtype.getLocale().equals(SubtypeLocaleUtils.NO_LANGUAGE) - ? null : SubtypeLocaleUtils.getSubtypeLocale(subtype); - doTestActionKeyLabel(tag, subtype, actionId, labelLocale, labelResId); - } - - protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype, - final int actionId, final Locale labelLocale, final int labelResId) { - final EditorInfo editorInfo = new EditorInfo(); - editorInfo.imeOptions = actionId; - final RunInLocale<String> job = new RunInLocale<String>() { - @Override - protected String job(final Resources res) { - return res.getString(labelResId); - } - }; - final String label = job.runInLocale(getContext().getResources(), labelLocale); - doTestActionKeyLabel(tag, subtype, editorInfo, label); - } - - @Override - public void testActionUnspecified() { - super.testActionUnspecified(); - } - - @Override - public void testActionNone() { - super.testActionNone(); - } - @Override public void testActionGo() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_GO, R.string.label_go_key); + doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_GO, + R.string.label_go_key); } } @Override - public void testActionSearch() { - super.testActionSearch(); - } - - @Override public void testActionSend() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_SEND, R.string.label_send_key); + doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_SEND, + R.string.label_send_key); } } @@ -92,7 +58,8 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio public void testActionNext() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_NEXT, R.string.label_next_key); + doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_NEXT, + R.string.label_next_key); } } @@ -100,7 +67,8 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio public void testActionDone() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyLabel(tag, subtype, EditorInfo.IME_ACTION_DONE, R.string.label_done_key); + doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_DONE, + R.string.label_done_key); } } @@ -108,16 +76,11 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio public void testActionPrevious() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyLabel( - tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, R.string.label_previous_key); + doTestActionKeyLabelResId(tag, subtype, EditorInfo.IME_ACTION_PREVIOUS, + R.string.label_previous_key); } } - @Override - public void testActionCustom() { - super.testActionCustom(); - } - // Working variable to simulate system locale changing. private Locale mSystemLocale = Locale.getDefault(); @@ -137,17 +100,17 @@ public class KeyboardLayoutSetActionLabelKlpTests extends KeyboardLayoutSetActio EditorInfo.IME_ACTION_UNSPECIFIED, KeyboardIconsSet.NAME_ENTER_KEY); doTestActionKeyIcon(tag + " none", subtype, EditorInfo.IME_ACTION_NONE, KeyboardIconsSet.NAME_ENTER_KEY); - doTestActionKeyLabel(tag + " go", subtype, + doTestActionKeyLabelResIdInLocale(tag + " go", subtype, EditorInfo.IME_ACTION_GO, labelLocale, R.string.label_go_key); doTestActionKeyIcon(tag + " search", subtype, EditorInfo.IME_ACTION_SEARCH, KeyboardIconsSet.NAME_SEARCH_KEY); - doTestActionKeyLabel(tag + " send", subtype, + doTestActionKeyLabelResIdInLocale(tag + " send", subtype, EditorInfo.IME_ACTION_SEND, labelLocale, R.string.label_send_key); - doTestActionKeyLabel(tag + " next", subtype, + doTestActionKeyLabelResIdInLocale(tag + " next", subtype, EditorInfo.IME_ACTION_NEXT, labelLocale, R.string.label_next_key); - doTestActionKeyLabel(tag + " done", subtype, + doTestActionKeyLabelResIdInLocale(tag + " done", subtype, EditorInfo.IME_ACTION_DONE, labelLocale, R.string.label_done_key); - doTestActionKeyLabel(tag + " previous", subtype, + doTestActionKeyLabelResIdInLocale(tag + " previous", subtype, EditorInfo.IME_ACTION_PREVIOUS, labelLocale, R.string.label_previous_key); return null; } diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelLxxTests.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelLxxTests.java index 25da50929..028b3e400 100644 --- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelLxxTests.java +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetActionLabelLxxTests.java @@ -17,99 +17,20 @@ package com.android.inputmethod.keyboard; import android.test.suitebuilder.annotation.MediumTest; -import android.text.InputType; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; -import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; @MediumTest -public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTestsBase { +public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetActionLabelBase { @Override protected int getKeyboardThemeForTests() { - return KeyboardTheme.THEME_ID_LXX_DARK; - } - - private static void doTestActionKey(final String tag, final KeyboardLayoutSet layoutSet, - final int elementId, final CharSequence label, final int iconId) { - final Keyboard keyboard = layoutSet.getKeyboard(elementId); - final Key enterKey = keyboard.getKey(Constants.CODE_ENTER); - assertNotNull(tag + " enter key on " + keyboard.mId, enterKey); - assertEquals(tag + " enter label " + enterKey, label, enterKey.getLabel()); - assertEquals(tag + " enter icon " + enterKey, iconId, enterKey.getIconId()); - } - - protected void doTestActionKeyLabel(final String tag, final InputMethodSubtype subtype, - final EditorInfo editorInfo, final CharSequence label) { - // Test text layouts. - editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; - final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, - label, KeyboardIconsSet.ICON_UNDEFINED); - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, - label, KeyboardIconsSet.ICON_UNDEFINED); - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, - label, KeyboardIconsSet.ICON_UNDEFINED); - // Test phone number layouts. - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, - label, KeyboardIconsSet.ICON_UNDEFINED); - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, - label, KeyboardIconsSet.ICON_UNDEFINED); - // Test normal number layout. - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, - label, KeyboardIconsSet.ICON_UNDEFINED); - // Test number password layouts. - editorInfo.inputType = - InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; - final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); - doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, - label, KeyboardIconsSet.ICON_UNDEFINED); - } - - protected void doTestActionKeyIcon(final String tag, final InputMethodSubtype subtype, - final int actionId, final String iconName) { - final int iconId = KeyboardIconsSet.getIconId(iconName); - final EditorInfo editorInfo = new EditorInfo(); - editorInfo.imeOptions = actionId; - // Test text layouts. - editorInfo.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_NORMAL; - final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_ALPHABET, null /* label */, iconId); - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS, null /* label */, iconId); - doTestActionKey( - tag, layoutSet, KeyboardId.ELEMENT_SYMBOLS_SHIFTED, null /* label */, iconId); - // Test phone number layouts. - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_PHONE, null /* label */, iconId); - doTestActionKey( - tag, layoutSet, KeyboardId.ELEMENT_PHONE_SYMBOLS, null /* label */, iconId); - // Test normal number layout. - doTestActionKey(tag, layoutSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); - // Test number password layout. - editorInfo.inputType = - InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; - final KeyboardLayoutSet passwordSet = createKeyboardLayoutSet(subtype, editorInfo); - doTestActionKey(tag, passwordSet, KeyboardId.ELEMENT_NUMBER, null /* label */, iconId); - } - - public void testActionUnspecified() { - for (final InputMethodSubtype subtype : getAllSubtypesList()) { - final String tag = "unspecifiled " - + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_UNSPECIFIED, - KeyboardIconsSet.NAME_ENTER_KEY); - } - } - - public void testActionNone() { - for (final InputMethodSubtype subtype : getAllSubtypesList()) { - final String tag = "none " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_NONE, - KeyboardIconsSet.NAME_ENTER_KEY); - } + return KeyboardTheme.THEME_ID_LXX_LIGHT; } + @Override public void testActionGo() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "go " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); @@ -118,14 +39,7 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests } } - public void testActionSearch() { - for (final InputMethodSubtype subtype : getAllSubtypesList()) { - final String tag = "search " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - doTestActionKeyIcon(tag, subtype, EditorInfo.IME_ACTION_SEARCH, - KeyboardIconsSet.NAME_SEARCH_KEY); - } - } - + @Override public void testActionSend() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "send " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); @@ -134,6 +48,7 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests } } + @Override public void testActionNext() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "next " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); @@ -142,6 +57,7 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests } } + @Override public void testActionDone() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "done " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); @@ -150,6 +66,7 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests } } + @Override public void testActionPrevious() { for (final InputMethodSubtype subtype : getAllSubtypesList()) { final String tag = "previous " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); @@ -157,15 +74,4 @@ public class KeyboardLayoutSetActionLabelLxxTests extends KeyboardLayoutSetTests KeyboardIconsSet.NAME_PREVIOUS_KEY); } } - - public void testActionCustom() { - for (final InputMethodSubtype subtype : getAllSubtypesList()) { - final String tag = "custom " + SubtypeLocaleUtils.getSubtypeNameForLogging(subtype); - final CharSequence customLabel = "customLabel"; - final EditorInfo editorInfo = new EditorInfo(); - editorInfo.imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED; - editorInfo.actionLabel = customLabel; - doTestActionKeyLabel(tag, subtype, editorInfo, customLabel); - } - } } diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysBase.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysBase.java new file mode 100644 index 000000000..1fce362b5 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysBase.java @@ -0,0 +1,324 @@ +/* + * 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.text.InputType; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; + +import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.keyboard.internal.MoreKeySpec; +import com.android.inputmethod.latin.Constants; +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.RichInputMethodManager; +import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; + +import java.util.Arrays; +import java.util.Locale; + +abstract class KeyboardLayoutSetNavigateMoreKeysBase extends KeyboardLayoutSetTestsBase { + private ExpectedMoreKey mExpectedNavigateNextMoreKey; + private ExpectedMoreKey mExpectedNavigatePreviousMoreKey; + private ExpectedMoreKey mExpectedEmojiMoreKey; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mExpectedNavigateNextMoreKey = new ExpectedMoreKey(R.string.label_next_key); + mExpectedNavigatePreviousMoreKey = new ExpectedMoreKey(R.string.label_previous_key); + mExpectedEmojiMoreKey = new ExpectedMoreKey(KeyboardIconsSet.NAME_EMOJI_ACTION_KEY); + } + + /** + * This class represents an expected more key. + */ + protected static class ExpectedMoreKey { + public static final int NO_LABEL = 0; + public static final ExpectedMoreKey[] EMPTY_MORE_KEYS = new ExpectedMoreKey[0]; + + public final int mLabelResId; + public final int mIconId; + + public ExpectedMoreKey(final String iconName) { + mLabelResId = NO_LABEL; + mIconId = KeyboardIconsSet.getIconId(iconName); + } + + public ExpectedMoreKey(final int labelResId) { + mLabelResId = labelResId; + mIconId = KeyboardIconsSet.ICON_UNDEFINED; + } + } + + private void doTestMoreKeysOf(final int code, final InputMethodSubtype subtype, + final int elementId, final int inputType, final int imeOptions, + final ExpectedMoreKey ... expectedMoreKeys) { + final EditorInfo editorInfo = new EditorInfo(); + editorInfo.inputType = inputType; + editorInfo.imeOptions = imeOptions; + final KeyboardLayoutSet layoutSet = createKeyboardLayoutSet(subtype, editorInfo); + final Keyboard keyboard = layoutSet.getKeyboard(elementId); + + final Key actualKey = keyboard.getKey(code); + final MoreKeySpec[] actualMoreKeys = actualKey.getMoreKeys(); + final String tag = actualKey.toString() + " moreKeys=" + Arrays.toString(actualMoreKeys); + if (expectedMoreKeys.length == 0) { + assertEquals(tag, null, actualMoreKeys); + return; + } + if (expectedMoreKeys.length == 1) { + assertEquals(tag + " fixedOrder", false, actualKey.isMoreKeysFixedOrder()); + assertEquals(tag + " fixedColumn", false, actualKey.isMoreKeysFixedColumn()); + } else { + assertEquals(tag + " fixedOrder", true, actualKey.isMoreKeysFixedOrder()); + assertEquals(tag + " fixedColumn", true, actualKey.isMoreKeysFixedColumn()); + // TODO: Can't handle multiple rows of more keys. + assertEquals(tag + " column", + expectedMoreKeys.length, actualKey.getMoreKeysColumnNumber()); + } + assertEquals(tag, expectedMoreKeys.length, actualMoreKeys.length); + for (int index = 0; index < actualMoreKeys.length; index++) { + final int expectedLabelResId = expectedMoreKeys[index].mLabelResId; + if (expectedLabelResId == ExpectedMoreKey.NO_LABEL) { + assertEquals(tag + " label " + index, null, actualMoreKeys[index].mLabel); + } else { + final CharSequence expectedLabel = getContext().getText(expectedLabelResId); + assertEquals(tag + " label " + index, expectedLabel, actualMoreKeys[index].mLabel); + } + final int expectedIconId = expectedMoreKeys[index].mIconId; + assertEquals(tag + " icon " + index, expectedIconId, actualMoreKeys[index].mIconId); + } + } + + private void doTestNavigationMoreKeysOf(final int code, final InputMethodSubtype subtype, + final int elementId, final int inputType) { + // No navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_NULL, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // With next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_NEXT, + mExpectedNavigateNextMoreKey); + // With previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedNavigatePreviousMoreKey); + // With next and previous naviagte flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_NEXT | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedNavigatePreviousMoreKey, mExpectedNavigateNextMoreKey); + // Action next. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action next with next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action next with previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedNavigatePreviousMoreKey); + // Action next with next and previous navigate flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT + | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedNavigatePreviousMoreKey); + // Action previous. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action previous with next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_NEXT, + mExpectedNavigateNextMoreKey); + // Action previous with previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action previous with next and previous navigate flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_NEXT + | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedNavigateNextMoreKey); + } + + private void doTestNavigationWithEmojiMoreKeysOf(final int code, + final InputMethodSubtype subtype, final int elementId, final int inputType) { + // No navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_NULL, + mExpectedEmojiMoreKey); + // With next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_NEXT, + mExpectedEmojiMoreKey, mExpectedNavigateNextMoreKey); + // With previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedEmojiMoreKey, mExpectedNavigatePreviousMoreKey); + // With next and previous naviagte flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_NEXT | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedEmojiMoreKey, mExpectedNavigatePreviousMoreKey, + mExpectedNavigateNextMoreKey); + // Action next. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT, + mExpectedEmojiMoreKey); + // Action next with next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT, + mExpectedEmojiMoreKey); + // Action next with previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedEmojiMoreKey, mExpectedNavigatePreviousMoreKey); + // Action next with next and previous navigate flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT + | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedEmojiMoreKey, mExpectedNavigatePreviousMoreKey); + // Action previous. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS, + mExpectedEmojiMoreKey); + // Action previous with next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_NEXT, + mExpectedEmojiMoreKey, mExpectedNavigateNextMoreKey); + // Action previous with previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedEmojiMoreKey); + // Action previous with next and previous navigate flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_NEXT + | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + mExpectedEmojiMoreKey, mExpectedNavigateNextMoreKey); + } + + private void doTestNoNavigationMoreKeysOf(final int code, final InputMethodSubtype subtype, + final int elementId, final int inputType) { + // No navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_NULL, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // With next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_NEXT, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // With previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // With next and previous naviagte flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_FLAG_NAVIGATE_NEXT | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action next. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action next with next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action next with previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action next with next and previous navigate flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT + | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action previous. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action previous with next navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_NEXT, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action previous with previous navigate flag. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + // Action previous with next and previous navigate flags. + doTestMoreKeysOf(code, subtype, elementId, inputType, + EditorInfo.IME_ACTION_PREVIOUS | EditorInfo.IME_FLAG_NAVIGATE_NEXT + | EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS, + ExpectedMoreKey.EMPTY_MORE_KEYS); + } + + public void testMoreKeysOfEnterKey() { + final RichInputMethodManager richImm = RichInputMethodManager.getInstance(); + final InputMethodSubtype subtype = richImm.findSubtypeByLocaleAndKeyboardLayoutSet( + Locale.US.toString(), SubtypeLocaleUtils.QWERTY); + + // Password field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_ALPHABET, + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); + // Email field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_ALPHABET, + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); + // Url field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_ALPHABET, + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); + // Phone number field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_PHONE, + InputType.TYPE_CLASS_PHONE); + // Number field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_NUMBER, + InputType.TYPE_CLASS_NUMBER); + // Date-time field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_NUMBER, + InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_NORMAL); + // Date field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_NUMBER, + InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_DATE); + // Time field. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, KeyboardId.ELEMENT_NUMBER, + InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_TIME); + // Text field. + if (isPhone()) { + // The enter key has an Emoji key as one of more keys. + doTestNavigationWithEmojiMoreKeysOf(Constants.CODE_ENTER, subtype, + KeyboardId.ELEMENT_ALPHABET, + InputType.TYPE_CLASS_TEXT); + } else { + // Tablet has a dedicated Emoji key, so the Enter key has no Emoji more key. + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, + KeyboardId.ELEMENT_ALPHABET, + InputType.TYPE_CLASS_TEXT); + } + // Short message field. + if (isPhone()) { + // Enter key is switched to Emoji key on a short message field. + // Emoji key has no navigation more keys. + doTestNoNavigationMoreKeysOf(Constants.CODE_EMOJI, subtype, + KeyboardId.ELEMENT_ALPHABET, + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE); + } else { + doTestNavigationMoreKeysOf(Constants.CODE_ENTER, subtype, + KeyboardId.ELEMENT_ALPHABET, + InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE); + } + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysKlpTests.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysKlpTests.java new file mode 100644 index 000000000..286c69d33 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysKlpTests.java @@ -0,0 +1,28 @@ +/* + * 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.test.suitebuilder.annotation.SmallTest; + +@SmallTest +public class KeyboardLayoutSetNavigateMoreKeysKlpTests + extends KeyboardLayoutSetNavigateMoreKeysBase { + @Override + protected int getKeyboardThemeForTests() { + return KeyboardTheme.THEME_ID_KLP; + } +} diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysLxxTests.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysLxxTests.java new file mode 100644 index 000000000..02593cb49 --- /dev/null +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetNavigateMoreKeysLxxTests.java @@ -0,0 +1,28 @@ +/* + * 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.test.suitebuilder.annotation.SmallTest; + +@SmallTest +public class KeyboardLayoutSetNavigateMoreKeysLxxTests + extends KeyboardLayoutSetNavigateMoreKeysBase { + @Override + protected int getKeyboardThemeForTests() { + return KeyboardTheme.THEME_ID_LXX_LIGHT; + } +} |