Merge "Auto generate various shift states alphabet keyboard automatically"

This commit is contained in:
Tadashi G. Takaoka 2012-01-30 20:07:26 -08:00 committed by Android (Google) Code Review
commit 30964843db
28 changed files with 394 additions and 505 deletions

View file

@ -60,16 +60,16 @@
<attr name="keyHintLetterRatio" format="float" /> <attr name="keyHintLetterRatio" format="float" />
<!-- Size of the text for hint label, in the proportion of key height. --> <!-- Size of the text for hint label, in the proportion of key height. -->
<attr name="keyHintLabelRatio" format="float" /> <attr name="keyHintLabelRatio" format="float" />
<!-- Size of the text for upper case letter, in the proportion of key height. --> <!-- Size of the text for shifted letter hint, in the proportion of key height. -->
<attr name="keyUppercaseLetterRatio" format="float" /> <attr name="keyShiftedLetterHintRatio" format="float" />
<!-- Horizontal padding of left/right aligned key label to the edge of the key. --> <!-- Horizontal padding of left/right aligned key label to the edge of the key. -->
<attr name="keyLabelHorizontalPadding" format="dimension" /> <attr name="keyLabelHorizontalPadding" format="dimension" />
<!-- Top and right padding of hint letter to the edge of the key.--> <!-- Top and right padding of hint letter to the edge of the key.-->
<attr name="keyHintLetterPadding" format="dimension" /> <attr name="keyHintLetterPadding" format="dimension" />
<!-- Bottom padding of popup hint letter "..." to the edge of the key.--> <!-- Bottom padding of popup hint letter "..." to the edge of the key.-->
<attr name="keyPopupHintLetterPadding" format="dimension" /> <attr name="keyPopupHintLetterPadding" format="dimension" />
<!-- Top and right padding of upper case letter to the edge of the key.--> <!-- Top and right padding of shifted letter hint to the edge of the key.-->
<attr name="keyUppercaseLetterPadding" format="dimension" /> <attr name="keyShiftedLetterHintPadding" format="dimension" />
<!-- Color to use for the label in a key. --> <!-- Color to use for the label in a key. -->
<attr name="keyTextColor" format="color" /> <attr name="keyTextColor" format="color" />
@ -79,9 +79,9 @@
<attr name="keyHintLetterColor" format="color" /> <attr name="keyHintLetterColor" format="color" />
<!-- Key hint label color --> <!-- Key hint label color -->
<attr name="keyHintLabelColor" format="color" /> <attr name="keyHintLabelColor" format="color" />
<!-- Upper case letter colors --> <!-- Shifted letter hint colors -->
<attr name="keyUppercaseLetterInactivatedColor" format="color" /> <attr name="keyShiftedLetterHintInactivatedColor" format="color" />
<attr name="keyUppercaseLetterActivatedColor" format="color" /> <attr name="keyShiftedLetterHintActivatedColor" format="color" />
<!-- Layout resource for key press feedback.--> <!-- Layout resource for key press feedback.-->
<attr name="keyPreviewLayout" format="reference" /> <attr name="keyPreviewLayout" format="reference" />
@ -240,7 +240,8 @@
<enum name="normal" value="0" /> <enum name="normal" value="0" />
<enum name="functional" value="1" /> <enum name="functional" value="1" />
<enum name="action" value="2" /> <enum name="action" value="2" />
<enum name="sticky" value="3" /> <enum name="stickyOff" value="3" />
<enum name="stickyOn" value="4" />
</attr> </attr>
<!-- The key action flags. --> <!-- The key action flags. -->
<attr name="keyActionFlags" format="integer"> <attr name="keyActionFlags" format="integer">
@ -267,7 +268,7 @@
<flag name="followKeyLetterRatio" value="0x80" /> <flag name="followKeyLetterRatio" value="0x80" />
<flag name="followKeyHintLabelRatio" value="0x100" /> <flag name="followKeyHintLabelRatio" value="0x100" />
<flag name="hasPopupHint" value="0x200" /> <flag name="hasPopupHint" value="0x200" />
<flag name="hasUppercaseLetter" value="0x400" /> <flag name="hasShiftedLetterHint" value="0x400" />
<flag name="hasHintLabel" value="0x800" /> <flag name="hasHintLabel" value="0x800" />
<flag name="withIconLeft" value="0x1000" /> <flag name="withIconLeft" value="0x1000" />
<flag name="withIconRight" value="0x2000" /> <flag name="withIconRight" value="0x2000" />
@ -275,10 +276,9 @@
<!-- If true, character case of code, altCode, moreKeys, keyOutputText, keyLabel, <!-- If true, character case of code, altCode, moreKeys, keyOutputText, keyLabel,
or keyHintLabel will never be subject to change. --> or keyHintLabel will never be subject to change. -->
<flag name="preserveCase" value="0x8000" /> <flag name="preserveCase" value="0x8000" />
<!-- If true, use keyTextInactivatedColor for the label --> <!-- If true, use keyShiftedLetterHintActivatedColor for the shifted letter hint and
<flag name="inactivatedLabel" value="0x10000" /> keyTextInactivatedColor for the primary key top label. -->
<!-- If true, use keyUppercaseLetterInactivatedColor for the uppercase letter --> <flag name="shiftedLetterActivated" value="0x10000" />
<flag name="inactivatedUppercaseLetter" value="0x20000" />
</attr> </attr>
<!-- The icon to display on the key instead of the label. --> <!-- The icon to display on the key instead of the label. -->
<attr name="keyIcon" format="enum"> <attr name="keyIcon" format="enum">
@ -407,7 +407,5 @@
<enum name="number" value="9" /> <enum name="number" value="9" />
</attr> </attr>
<attr name="elementKeyboard" format="reference"/> <attr name="elementKeyboard" format="reference"/>
<attr name="elementAutoGenerate" format="boolean" />
<!-- TODO: Add setShifted and setShiftLocked attribute. -->
</declare-styleable> </declare-styleable>
</resources> </resources>

View file

@ -39,18 +39,18 @@
<item name="keyLabelRatio">@fraction/key_label_ratio</item> <item name="keyLabelRatio">@fraction/key_label_ratio</item>
<item name="keyHintLetterRatio">@fraction/key_hint_letter_ratio</item> <item name="keyHintLetterRatio">@fraction/key_hint_letter_ratio</item>
<item name="keyHintLabelRatio">@fraction/key_hint_label_ratio</item> <item name="keyHintLabelRatio">@fraction/key_hint_label_ratio</item>
<item name="keyUppercaseLetterRatio">@fraction/key_uppercase_letter_ratio</item> <item name="keyShiftedLetterHintRatio">@fraction/key_uppercase_letter_ratio</item>
<item name="keyTextStyle">normal</item> <item name="keyTextStyle">normal</item>
<item name="keyTextColor">#FFFFFFFF</item> <item name="keyTextColor">#FFFFFFFF</item>
<item name="keyTextInactivatedColor">#FFFFFFFF</item> <item name="keyTextInactivatedColor">#FFFFFFFF</item>
<item name="keyHintLetterColor">#80000000</item> <item name="keyHintLetterColor">#80000000</item>
<item name="keyHintLabelColor">#E0E0E4E5</item> <item name="keyHintLabelColor">#E0E0E4E5</item>
<item name="keyUppercaseLetterInactivatedColor">#66E0E4E5</item> <item name="keyShiftedLetterHintInactivatedColor">#66E0E4E5</item>
<item name="keyUppercaseLetterActivatedColor">#CCE0E4E5</item> <item name="keyShiftedLetterHintActivatedColor">#CCE0E4E5</item>
<item name="keyLabelHorizontalPadding">@dimen/key_label_horizontal_padding</item> <item name="keyLabelHorizontalPadding">@dimen/key_label_horizontal_padding</item>
<item name="keyHintLetterPadding">@dimen/key_hint_letter_padding</item> <item name="keyHintLetterPadding">@dimen/key_hint_letter_padding</item>
<item name="keyPopupHintLetterPadding">@dimen/key_popup_hint_letter_padding</item> <item name="keyPopupHintLetterPadding">@dimen/key_popup_hint_letter_padding</item>
<item name="keyUppercaseLetterPadding">@dimen/key_uppercase_letter_padding</item> <item name="keyShiftedLetterHintPadding">@dimen/key_uppercase_letter_padding</item>
<item name="keyPreviewLayout">@layout/key_preview</item> <item name="keyPreviewLayout">@layout/key_preview</item>
<item name="keyPreviewBackground">@drawable/keyboard_key_feedback</item> <item name="keyPreviewBackground">@drawable/keyboard_key_feedback</item>
<item name="keyPreviewLeftBackground">@null</item> <item name="keyPreviewLeftBackground">@null</item>
@ -181,8 +181,8 @@
<item name="keyTextInactivatedColor">#FF808080</item> <item name="keyTextInactivatedColor">#FF808080</item>
<item name="keyHintLetterColor">#80000000</item> <item name="keyHintLetterColor">#80000000</item>
<item name="keyHintLabelColor">#E0000000</item> <item name="keyHintLabelColor">#E0000000</item>
<item name="keyUppercaseLetterInactivatedColor">#66000000</item> <item name="keyShiftedLetterHintInactivatedColor">#66000000</item>
<item name="keyUppercaseLetterActivatedColor">#CC000000</item> <item name="keyShiftedLetterHintActivatedColor">#CC000000</item>
<item name="shadowColor">#FFFFFFFF</item> <item name="shadowColor">#FFFFFFFF</item>
</style> </style>
<style <style
@ -298,8 +298,8 @@
<item name="keyTextInactivatedColor">#66E0E4E5</item> <item name="keyTextInactivatedColor">#66E0E4E5</item>
<item name="keyHintLetterColor">#80000000</item> <item name="keyHintLetterColor">#80000000</item>
<item name="keyHintLabelColor">#A0FFFFFF</item> <item name="keyHintLabelColor">#A0FFFFFF</item>
<item name="keyUppercaseLetterInactivatedColor">#66E0E4E5</item> <item name="keyShiftedLetterHintInactivatedColor">#66E0E4E5</item>
<item name="keyUppercaseLetterActivatedColor">#FFFFFFFF</item> <item name="keyShiftedLetterHintActivatedColor">#FFFFFFFF</item>
<item name="keyPreviewBackground">@drawable/keyboard_key_feedback_ics</item> <item name="keyPreviewBackground">@drawable/keyboard_key_feedback_ics</item>
<item name="keyPreviewLeftBackground">@drawable/keyboard_key_feedback_left_ics</item> <item name="keyPreviewLeftBackground">@drawable/keyboard_key_feedback_left_ics</item>
<item name="keyPreviewRightBackground">@drawable/keyboard_key_feedback_right_ics</item> <item name="keyPreviewRightBackground">@drawable/keyboard_key_feedback_right_ics</item>

View file

@ -33,18 +33,18 @@
> >
<Key <Key
latin:keyLabel="-" latin:keyLabel="-"
latin:keyLabelFlags="hasUppercaseLetter"
latin:keyHintLabel="_" latin:keyHintLabel="_"
latin:moreKeys="_" /> latin:moreKeys="_"
latin:keyStyle="hasShiftedLetterHintStyle" />
</case> </case>
<case <case
latin:imeAction="actionSearch" latin:imeAction="actionSearch"
> >
<Key <Key
latin:keyLabel=":" latin:keyLabel=":"
latin:keyLabelFlags="hasUppercaseLetter"
latin:keyHintLabel="+" latin:keyHintLabel="+"
latin:moreKeys="+" /> latin:moreKeys="+"
latin:keyStyle="hasShiftedLetterHintStyle" />
</case> </case>
<default> <default>
<Key <Key

View file

@ -38,13 +38,51 @@
latin:backgroundType="functional" /> latin:backgroundType="functional" />
</default> </default>
</switch> </switch>
<switch>
<case
latin:keyboardSetElement="alphabetManualShifted|alphabetShiftLockShifted"
>
<key-style
latin:styleName="hasShiftedLetterHintStyle"
latin:keyLabelFlags="hasShiftedLetterHint|shiftedLetterActivated" />
</case>
<default>
<key-style
latin:styleName="hasShiftedLetterHintStyle"
latin:keyLabelFlags="hasShiftedLetterHint" />
</default>
</switch>
<!-- Functional key styles --> <!-- Functional key styles -->
<key-style <switch>
latin:styleName="shiftKeyStyle" <case
latin:code="@integer/key_shift" latin:keyboardSetElement="alphabetManualShifted|alphabetAutomaticShifted"
latin:keyIcon="iconShiftKey" >
latin:keyActionFlags="noKeyPreview" <key-style
latin:backgroundType="sticky" /> latin:styleName="shiftKeyStyle"
latin:code="@integer/key_shift"
latin:keyIcon="iconShiftKeyShifted"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="stickyOff" />
</case>
<case
latin:keyboardSetElement="alphabetShiftLocked|alphabetShiftLockShifted"
>
<key-style
latin:styleName="shiftKeyStyle"
latin:code="@integer/key_shift"
latin:keyIcon="iconShiftKeyShifted"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="stickyOn" />
</case>
<default>
<key-style
latin:styleName="shiftKeyStyle"
latin:code="@integer/key_shift"
latin:keyIcon="iconShiftKey"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="stickyOff" />
</default>
</switch>
<key-style <key-style
latin:styleName="deleteKeyStyle" latin:styleName="deleteKeyStyle"
latin:code="@integer/key_delete" latin:code="@integer/key_delete"
@ -69,7 +107,7 @@
latin:styleName="smileyKeyStyle" latin:styleName="smileyKeyStyle"
latin:keyLabel=":-)" latin:keyLabel=":-)"
latin:keyOutputText=":-) " latin:keyOutputText=":-) "
latin:keyLabelFlags="hasPopupHint" latin:keyLabelFlags="hasPopupHint|preserveCase"
latin:moreKeys="@string/more_keys_for_smiley" latin:moreKeys="@string/more_keys_for_smiley"
latin:maxMoreKeysColumn="5" /> latin:maxMoreKeysColumn="5" />
<key-style <key-style
@ -95,30 +133,34 @@
latin:styleName="toSymbolKeyStyle" latin:styleName="toSymbolKeyStyle"
latin:code="@integer/key_switch_alpha_symbol" latin:code="@integer/key_switch_alpha_symbol"
latin:keyLabel="@string/label_to_symbol_key" latin:keyLabel="@string/label_to_symbol_key"
latin:keyLabelFlags="preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="toAlphaKeyStyle" latin:styleName="toAlphaKeyStyle"
latin:code="@integer/key_switch_alpha_symbol" latin:code="@integer/key_switch_alpha_symbol"
latin:keyLabel="@string/label_to_alpha_key" latin:keyLabel="@string/label_to_alpha_key"
latin:keyLabelFlags="preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="toMoreSymbolKeyStyle" latin:styleName="toMoreSymbolKeyStyle"
latin:code="@integer/key_shift" latin:code="@integer/key_shift"
latin:keyLabel="@string/label_to_more_symbol_for_tablet_key" latin:keyLabel="@string/label_to_more_symbol_for_tablet_key"
latin:keyLabelFlags="preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="backFromMoreSymbolKeyStyle" latin:styleName="backFromMoreSymbolKeyStyle"
latin:code="@integer/key_shift" latin:code="@integer/key_shift"
latin:keyLabel="@string/label_to_symbol_key" latin:keyLabel="@string/label_to_symbol_key"
latin:keyLabelFlags="preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="comKeyStyle" latin:styleName="comKeyStyle"
latin:keyLabel="@string/keylabel_for_popular_domain" latin:keyLabel="@string/keylabel_for_popular_domain"
latin:keyLabelFlags="fontNormal|hasPopupHint" latin:keyLabelFlags="fontNormal|hasPopupHint|preserveCase"
latin:keyOutputText="@string/keylabel_for_popular_domain" latin:keyOutputText="@string/keylabel_for_popular_domain"
latin:moreKeys="@string/more_keys_for_popular_domain" /> latin:moreKeys="@string/more_keys_for_popular_domain" />
</merge> </merge>

View file

@ -33,16 +33,16 @@
> >
<Key <Key
latin:keyLabel="/" latin:keyLabel="/"
latin:keyLabelFlags="hasUppercaseLetter"
latin:keyHintLabel=":" latin:keyHintLabel=":"
latin:moreKeys=":" /> latin:moreKeys=":"
latin:keyStyle="hasShiftedLetterHintStyle" />
</case> </case>
<default> <default>
<Key <Key
latin:keyLabel="@string/keylabel_for_apostrophe" latin:keyLabel="@string/keylabel_for_apostrophe"
latin:keyLabelFlags="hasUppercaseLetter"
latin:keyHintLabel="@string/keyhintlabel_for_apostrophe" latin:keyHintLabel="@string/keyhintlabel_for_apostrophe"
latin:moreKeys="@string/more_keys_for_apostrophe" /> latin:moreKeys="@string/more_keys_for_apostrophe"
latin:keyStyle="hasShiftedLetterHintStyle" />
</default> </default>
</switch> </switch>
<switch> <switch>
@ -55,9 +55,9 @@
<default> <default>
<Key <Key
latin:keyLabel="@string/keylabel_for_dash" latin:keyLabel="@string/keylabel_for_dash"
latin:keyLabelFlags="hasUppercaseLetter"
latin:keyHintLabel="@string/keyhintlabel_for_dash" latin:keyHintLabel="@string/keyhintlabel_for_dash"
latin:moreKeys="@string/more_keys_for_dash" /> latin:moreKeys="@string/more_keys_for_dash"
latin:keyStyle="hasShiftedLetterHintStyle" />
</default> </default>
</switch> </switch>
</merge> </merge>

View file

@ -45,9 +45,9 @@
<default> <default>
<Key <Key
latin:keyLabel="/" latin:keyLabel="/"
latin:keyLabelFlags="hasUppercaseLetter"
latin:keyHintLabel="\@" latin:keyHintLabel="\@"
latin:moreKeys="\@" /> latin:moreKeys="\@"
latin:keyStyle="hasShiftedLetterHintStyle" />
</default> </default>
</switch> </switch>
<Key <Key

View file

@ -21,12 +21,50 @@
<merge <merge
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
> >
<key-style <switch>
latin:styleName="shiftKeyStyle" <case
latin:code="@integer/key_shift" latin:keyboardSetElement="alphabetManualShifted|alphabetShiftLockShifted"
latin:keyIcon="iconShiftKey" >
latin:keyActionFlags="noKeyPreview" <key-style
latin:backgroundType="sticky" /> latin:styleName="hasShiftedLetterHintStyle"
latin:keyLabelFlags="hasShiftedLetterHint|shiftedLetterActivated" />
</case>
<default>
<key-style
latin:styleName="hasShiftedLetterHintStyle"
latin:keyLabelFlags="hasShiftedLetterHint" />
</default>
</switch>
<switch>
<case
latin:keyboardSetElement="alphabetManualShifted|alphabetAutomaticShifted"
>
<key-style
latin:styleName="shiftKeyStyle"
latin:code="@integer/key_shift"
latin:keyIcon="iconShiftKeyShifted"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="stickyOff" />
</case>
<case
latin:keyboardSetElement="alphabetShiftLocked|alphabetShiftLockShifted"
>
<key-style
latin:styleName="shiftKeyStyle"
latin:code="@integer/key_shift"
latin:keyIcon="iconShiftKeyShifted"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="stickyOn" />
</case>
<default>
<key-style
latin:styleName="shiftKeyStyle"
latin:code="@integer/key_shift"
latin:keyIcon="iconShiftKey"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="stickyOff" />
</default>
</switch>
<key-style <key-style
latin:styleName="deleteKeyStyle" latin:styleName="deleteKeyStyle"
latin:code="@integer/key_delete" latin:code="@integer/key_delete"
@ -51,7 +89,7 @@
latin:styleName="smileyKeyStyle" latin:styleName="smileyKeyStyle"
latin:keyLabel=":-)" latin:keyLabel=":-)"
latin:keyOutputText=":-) " latin:keyOutputText=":-) "
latin:keyLabelFlags="hasPopupHint" latin:keyLabelFlags="hasPopupHint|preserveCase"
latin:moreKeys="@string/more_keys_for_smiley" latin:moreKeys="@string/more_keys_for_smiley"
latin:maxMoreKeysColumn="5" /> latin:maxMoreKeysColumn="5" />
<key-style <key-style
@ -71,40 +109,40 @@
latin:styleName="tabKeyStyle" latin:styleName="tabKeyStyle"
latin:code="@integer/key_tab" latin:code="@integer/key_tab"
latin:keyLabel="@string/label_tab_key" latin:keyLabel="@string/label_tab_key"
latin:keyLabelFlags="fontNormal" latin:keyLabelFlags="fontNormal|preserveCase"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="toSymbolKeyStyle" latin:styleName="toSymbolKeyStyle"
latin:code="@integer/key_switch_alpha_symbol" latin:code="@integer/key_switch_alpha_symbol"
latin:keyLabel="@string/label_to_symbol_key" latin:keyLabel="@string/label_to_symbol_key"
latin:keyLabelFlags="fontNormal" latin:keyLabelFlags="fontNormal|preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="toAlphaKeyStyle" latin:styleName="toAlphaKeyStyle"
latin:code="@integer/key_switch_alpha_symbol" latin:code="@integer/key_switch_alpha_symbol"
latin:keyLabel="@string/label_to_alpha_key" latin:keyLabel="@string/label_to_alpha_key"
latin:keyLabelFlags="fontNormal" latin:keyLabelFlags="fontNormal|preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="toMoreSymbolKeyStyle" latin:styleName="toMoreSymbolKeyStyle"
latin:code="@integer/key_shift" latin:code="@integer/key_shift"
latin:keyLabel="@string/label_to_more_symbol_for_tablet_key" latin:keyLabel="@string/label_to_more_symbol_for_tablet_key"
latin:keyLabelFlags="fontNormal" latin:keyLabelFlags="fontNormal|preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="backFromMoreSymbolKeyStyle" latin:styleName="backFromMoreSymbolKeyStyle"
latin:code="@integer/key_shift" latin:code="@integer/key_shift"
latin:keyLabel="@string/label_to_symbol_key" latin:keyLabel="@string/label_to_symbol_key"
latin:keyLabelFlags="fontNormal" latin:keyLabelFlags="fontNormal|preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="comKeyStyle" latin:styleName="comKeyStyle"
latin:keyLabel="@string/keylabel_for_popular_domain" latin:keyLabel="@string/keylabel_for_popular_domain"
latin:keyLabelFlags="fontNormal|hasPopupHint" latin:keyLabelFlags="fontNormal|hasPopupHint|preserveCase"
latin:keyOutputText="@string/keylabel_for_popular_domain" latin:keyOutputText="@string/keylabel_for_popular_domain"
latin:moreKeys="@string/more_keys_for_popular_domain" /> latin:moreKeys="@string/more_keys_for_popular_domain" />
</merge> </merge>

View file

@ -33,16 +33,16 @@
> >
<Key <Key
latin:keyLabel="/" latin:keyLabel="/"
latin:keyLabelFlags="hasUppercaseLetter"
latin:keyHintLabel=":" latin:keyHintLabel=":"
latin:moreKeys=":" /> latin:moreKeys=":"
latin:keyStyle="hasShiftedLetterHintStyle" />
</case> </case>
<default> <default>
<Key <Key
latin:keyLabel="@string/keylabel_for_apostrophe" latin:keyLabel="@string/keylabel_for_apostrophe"
latin:keyLabelFlags="hasUppercaseLetter"
latin:keyHintLabel="@string/keyhintlabel_for_apostrophe" latin:keyHintLabel="@string/keyhintlabel_for_apostrophe"
latin:moreKeys="@string/more_keys_for_apostrophe" /> latin:moreKeys="@string/more_keys_for_apostrophe"
latin:keyStyle="hasShiftedLetterHintStyle" />
</default> </default>
</switch> </switch>
<switch> <switch>
@ -55,9 +55,9 @@
<default> <default>
<Key <Key
latin:keyLabel="@string/keylabel_for_dash" latin:keyLabel="@string/keylabel_for_dash"
latin:keyLabelFlags="hasUppercaseLetter"
latin:keyHintLabel="@string/keyhintlabel_for_dash" latin:keyHintLabel="@string/keyhintlabel_for_dash"
latin:moreKeys="@string/more_keys_for_dash" /> latin:moreKeys="@string/more_keys_for_dash"
latin:keyStyle="hasShiftedLetterHintStyle" />
</default> </default>
</switch> </switch>
</merge> </merge>

View file

@ -57,9 +57,9 @@
> >
<Key <Key
latin:keyLabel=":" latin:keyLabel=":"
latin:keyLabelFlags="hasUppercaseLetter"
latin:keyHintLabel="+" latin:keyHintLabel="+"
latin:moreKeys="+" /> latin:moreKeys="+"
latin:keyStyle="hasShiftedLetterHintStyle" />
</case> </case>
<default> <default>
<Key <Key
@ -76,9 +76,9 @@
<default> <default>
<Key <Key
latin:keyLabel="/" latin:keyLabel="/"
latin:keyLabelFlags="hasUppercaseLetter"
latin:keyHintLabel="\@" latin:keyHintLabel="\@"
latin:moreKeys="\@" /> latin:moreKeys="\@"
latin:keyStyle="hasShiftedLetterHintStyle" />
</default> </default>
</switch> </switch>
</default> </default>

View file

@ -124,7 +124,7 @@
latin:moreKeys="@string/more_keys_for_n" /> latin:moreKeys="@string/more_keys_for_n" />
<Key <Key
latin:keyLabel="\'" latin:keyLabel="\'"
latin:keyLabelFlags="hasUppercaseLetter" latin:keyLabelFlags="hasShiftedLetterHint"
latin:keyHintLabel=":" latin:keyHintLabel=":"
latin:moreKeys=":" /> latin:moreKeys=":" />
<include <include

View file

@ -62,12 +62,36 @@
</default> </default>
</switch> </switch>
<!-- Functional key styles --> <!-- Functional key styles -->
<key-style <switch>
latin:styleName="shiftKeyStyle" <case
latin:code="@integer/key_shift" latin:keyboardSetElement="alphabetManualShifted|alphabetAutomaticShifted"
latin:keyIcon="iconShiftKey" >
latin:keyActionFlags="noKeyPreview" <key-style
latin:backgroundType="sticky" /> latin:styleName="shiftKeyStyle"
latin:code="@integer/key_shift"
latin:keyIcon="iconShiftKeyShifted"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="stickyOff" />
</case>
<case
latin:keyboardSetElement="alphabetShiftLocked|alphabetShiftLockShifted"
>
<key-style
latin:styleName="shiftKeyStyle"
latin:code="@integer/key_shift"
latin:keyIcon="iconShiftKeyShifted"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="stickyOn" />
</case>
<default>
<key-style
latin:styleName="shiftKeyStyle"
latin:code="@integer/key_shift"
latin:keyIcon="iconShiftKey"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="stickyOff" />
</default>
</switch>
<key-style <key-style
latin:styleName="deleteKeyStyle" latin:styleName="deleteKeyStyle"
latin:code="@integer/key_delete" latin:code="@integer/key_delete"
@ -84,7 +108,7 @@
latin:styleName="returnKeyStyle" latin:styleName="returnKeyStyle"
latin:keyLabel=":-)" latin:keyLabel=":-)"
latin:keyOutputText=":-) " latin:keyOutputText=":-) "
latin:keyLabelFlags="hasPopupHint" latin:keyLabelFlags="hasPopupHint|preserveCase"
latin:moreKeys="@string/more_keys_for_smiley" latin:moreKeys="@string/more_keys_for_smiley"
latin:maxMoreKeysColumn="5" latin:maxMoreKeysColumn="5"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
@ -96,7 +120,7 @@
latin:styleName="returnKeyStyle" latin:styleName="returnKeyStyle"
latin:code="@integer/key_return" latin:code="@integer/key_return"
latin:keyLabel="@string/label_go_key" latin:keyLabel="@string/label_go_key"
latin:keyLabelFlags="autoXScale" latin:keyLabelFlags="autoXScale|preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action" /> latin:backgroundType="action" />
</case> </case>
@ -107,7 +131,7 @@
latin:styleName="returnKeyStyle" latin:styleName="returnKeyStyle"
latin:code="@integer/key_return" latin:code="@integer/key_return"
latin:keyLabel="@string/label_next_key" latin:keyLabel="@string/label_next_key"
latin:keyLabelFlags="autoXScale" latin:keyLabelFlags="autoXScale|preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action" /> latin:backgroundType="action" />
</case> </case>
@ -118,7 +142,7 @@
latin:styleName="returnKeyStyle" latin:styleName="returnKeyStyle"
latin:code="@integer/key_return" latin:code="@integer/key_return"
latin:keyLabel="@string/label_done_key" latin:keyLabel="@string/label_done_key"
latin:keyLabelFlags="autoXScale" latin:keyLabelFlags="autoXScale|preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action" /> latin:backgroundType="action" />
</case> </case>
@ -129,7 +153,7 @@
latin:styleName="returnKeyStyle" latin:styleName="returnKeyStyle"
latin:code="@integer/key_return" latin:code="@integer/key_return"
latin:keyLabel="@string/label_send_key" latin:keyLabel="@string/label_send_key"
latin:keyLabelFlags="autoXScale" latin:keyLabelFlags="autoXScale|preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="action" /> latin:backgroundType="action" />
</case> </case>
@ -199,7 +223,7 @@
latin:code="@integer/key_switch_alpha_symbol" latin:code="@integer/key_switch_alpha_symbol"
latin:keyIcon="iconShortcutForLabel" latin:keyIcon="iconShortcutForLabel"
latin:keyLabel="@string/label_to_symbol_with_microphone_key" latin:keyLabel="@string/label_to_symbol_with_microphone_key"
latin:keyLabelFlags="withIconRight" latin:keyLabelFlags="withIconRight|preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
</case> </case>
@ -208,6 +232,7 @@
latin:styleName="toSymbolKeyStyle" latin:styleName="toSymbolKeyStyle"
latin:code="@integer/key_switch_alpha_symbol" latin:code="@integer/key_switch_alpha_symbol"
latin:keyLabel="@string/label_to_symbol_key" latin:keyLabel="@string/label_to_symbol_key"
latin:keyLabelFlags="preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
</default> </default>
@ -216,25 +241,28 @@
latin:styleName="toAlphaKeyStyle" latin:styleName="toAlphaKeyStyle"
latin:code="@integer/key_switch_alpha_symbol" latin:code="@integer/key_switch_alpha_symbol"
latin:keyLabel="@string/label_to_alpha_key" latin:keyLabel="@string/label_to_alpha_key"
latin:keyLabelFlags="preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="toMoreSymbolKeyStyle" latin:styleName="toMoreSymbolKeyStyle"
latin:code="@integer/key_shift" latin:code="@integer/key_shift"
latin:keyLabel="@string/label_to_more_symbol_key" latin:keyLabel="@string/label_to_more_symbol_key"
latin:keyLabelFlags="preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="backFromMoreSymbolKeyStyle" latin:styleName="backFromMoreSymbolKeyStyle"
latin:code="@integer/key_shift" latin:code="@integer/key_shift"
latin:keyLabel="@string/label_to_symbol_key" latin:keyLabel="@string/label_to_symbol_key"
latin:keyLabelFlags="preserveCase"
latin:keyActionFlags="noKeyPreview" latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="punctuationKeyStyle" latin:styleName="punctuationKeyStyle"
latin:keyLabel="." latin:keyLabel="."
latin:keyHintLabel="@string/keyhintlabel_for_punctuation" latin:keyHintLabel="@string/keyhintlabel_for_punctuation"
latin:keyLabelFlags="hasPopupHint" latin:keyLabelFlags="hasPopupHint|preserveCase"
latin:moreKeys="@string/more_keys_for_punctuation" latin:moreKeys="@string/more_keys_for_punctuation"
latin:maxMoreKeysColumn="@integer/mini_keyboard_column_for_punctuation" latin:maxMoreKeysColumn="@integer/mini_keyboard_column_for_punctuation"
latin:backgroundType="functional" /> latin:backgroundType="functional" />

View file

@ -23,24 +23,7 @@
latin:keyboardLocale="en_GB,en_US"> latin:keyboardLocale="en_GB,en_US">
<Element <Element
latin:elementName="alphabet" latin:elementName="alphabet"
latin:elementKeyboard="@xml/kbd_qwerty" latin:elementKeyboard="@xml/kbd_qwerty" />
latin:elementAutoGenerate="true" />
<Element
latin:elementName="alphabetManualShifted"
latin:elementKeyboard="@xml/kbd_qwerty"
latin:elementAutoGenerate="true" />
<Element
latin:elementName="alphabetAutomaticShifted"
latin:elementKeyboard="@xml/kbd_qwerty"
latin:elementAutoGenerate="true" />
<Element
latin:elementName="alphabetShiftLocked"
latin:elementKeyboard="@xml/kbd_qwerty"
latin:elementAutoGenerate="true" />
<Element
latin:elementName="alphabetShiftLockShifted"
latin:elementKeyboard="@xml/kbd_qwerty"
latin:elementAutoGenerate="true" />
<Element <Element
latin:elementName="symbols" latin:elementName="symbols"
latin:elementKeyboard="@xml/kbd_symbols" /> latin:elementKeyboard="@xml/kbd_symbols" />

View file

@ -33,14 +33,14 @@
<default> <default>
<Key <Key
latin:keyLabel="," latin:keyLabel=","
latin:keyLabelFlags="hasUppercaseLetter"
latin:keyHintLabel="!" latin:keyHintLabel="!"
latin:moreKeys="!" /> latin:moreKeys="!"
latin:keyStyle="hasShiftedLetterHintStyle" />
<Key <Key
latin:keyLabel="." latin:keyLabel="."
latin:keyLabelFlags="hasUppercaseLetter"
latin:keyHintLabel="\?" latin:keyHintLabel="\?"
latin:moreKeys="\?" /> latin:moreKeys="\?"
latin:keyStyle="hasShiftedLetterHintStyle" />
</default> </default>
</switch> </switch>
</merge> </merge>

View file

@ -175,25 +175,6 @@ public class KeyCodeDescriptionMapper {
} }
} }
/**
* Returns the keycode for the specified key given the current keyboard
* state.
*
* @param keyboard The keyboard on which the key resides.
* @param key The key from which to obtain a key code.
* @return the key code for the specified key
*/
private int getCorrectKeyCode(Keyboard keyboard, Key key) {
// If keyboard is in manual temporary upper case state and key has
// manual temporary uppercase letter as key hint letter, alternate
// character code should be sent.
if (keyboard.isManualTemporaryUpperCase() && key.hasUppercaseLetter()
&& !TextUtils.isEmpty(key.mHintLabel)) {
return key.mHintLabel.charAt(0);
}
return key.mCode;
}
/** /**
* Returns a localized character sequence describing what will happen when * Returns a localized character sequence describing what will happen when
* the specified key is pressed based on its key code. * the specified key is pressed based on its key code.
@ -217,7 +198,7 @@ public class KeyCodeDescriptionMapper {
*/ */
private CharSequence getDescriptionForKeyCode(Context context, Keyboard keyboard, Key key, private CharSequence getDescriptionForKeyCode(Context context, Keyboard keyboard, Key key,
boolean shouldObscure) { boolean shouldObscure) {
final int code = getCorrectKeyCode(keyboard, key); final int code = key.mCode;
if (keyboard.isShiftLocked() && mShiftLockedKeyCodeMap.containsKey(code)) { if (keyboard.isShiftLocked() && mShiftLockedKeyCodeMap.containsKey(code)) {
return context.getString(mShiftLockedKeyCodeMap.get(code)); return context.getString(mShiftLockedKeyCodeMap.get(code));

View file

@ -66,14 +66,13 @@ public class Key {
private static final int LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO = 0x80; private static final int LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO = 0x80;
private static final int LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO = 0x100; private static final int LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO = 0x100;
private static final int LABEL_FLAGS_HAS_POPUP_HINT = 0x200; private static final int LABEL_FLAGS_HAS_POPUP_HINT = 0x200;
private static final int LABEL_FLAGS_HAS_UPPERCASE_LETTER = 0x400; private static final int LABEL_FLAGS_HAS_SHIFTED_LETTER_HINT = 0x400;
private static final int LABEL_FLAGS_HAS_HINT_LABEL = 0x800; private static final int LABEL_FLAGS_HAS_HINT_LABEL = 0x800;
private static final int LABEL_FLAGS_WITH_ICON_LEFT = 0x1000; private static final int LABEL_FLAGS_WITH_ICON_LEFT = 0x1000;
private static final int LABEL_FLAGS_WITH_ICON_RIGHT = 0x2000; private static final int LABEL_FLAGS_WITH_ICON_RIGHT = 0x2000;
private static final int LABEL_FLAGS_AUTO_X_SCALE = 0x4000; private static final int LABEL_FLAGS_AUTO_X_SCALE = 0x4000;
private static final int LABEL_FLAGS_PRESERVE_CASE = 0x8000; private static final int LABEL_FLAGS_PRESERVE_CASE = 0x8000;
private static final int LABEL_FLAGS_INACTIVATED_LABEL = 0x10000; private static final int LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED = 0x10000;
private static final int LABEL_FLAGS_INACTIVATED_UPPERCASE_LETTER = 0x20000;
/** Icon to display instead of a label. Icon takes precedence over a label */ /** Icon to display instead of a label. Icon takes precedence over a label */
private final int mIconAttrId; private final int mIconAttrId;
@ -114,7 +113,8 @@ public class Key {
public static final int BACKGROUND_TYPE_NORMAL = 0; public static final int BACKGROUND_TYPE_NORMAL = 0;
public static final int BACKGROUND_TYPE_FUNCTIONAL = 1; public static final int BACKGROUND_TYPE_FUNCTIONAL = 1;
public static final int BACKGROUND_TYPE_ACTION = 2; public static final int BACKGROUND_TYPE_ACTION = 2;
public static final int BACKGROUND_TYPE_STICKY = 3; public static final int BACKGROUND_TYPE_STICKY_OFF = 3;
public static final int BACKGROUND_TYPE_STICKY_ON = 4;
private final int mActionFlags; private final int mActionFlags;
private static final int ACTION_FLAGS_IS_REPEATABLE = 0x01; private static final int ACTION_FLAGS_IS_REPEATABLE = 0x01;
@ -125,8 +125,6 @@ public class Key {
/** The current pressed state of this key */ /** The current pressed state of this key */
private boolean mPressed; private boolean mPressed;
/** If this is a sticky key, is its highlight on? */
private boolean mHighlightOn;
/** Key is enabled and responds on press */ /** Key is enabled and responds on press */
private boolean mEnabled = true; private boolean mEnabled = true;
@ -303,31 +301,46 @@ public class Key {
keyAttr, R.styleable.Keyboard_Key_keyLabel), preserveCase, params.mId); keyAttr, R.styleable.Keyboard_Key_keyLabel), preserveCase, params.mId);
mHintLabel = adjustCaseOfStringForKeyboardId(style.getString( mHintLabel = adjustCaseOfStringForKeyboardId(style.getString(
keyAttr, R.styleable.Keyboard_Key_keyHintLabel), preserveCase, params.mId); keyAttr, R.styleable.Keyboard_Key_keyHintLabel), preserveCase, params.mId);
mOutputText = adjustCaseOfStringForKeyboardId(style.getString( String outputText = adjustCaseOfStringForKeyboardId(style.getString(
keyAttr, R.styleable.Keyboard_Key_keyOutputText), preserveCase, params.mId); keyAttr, R.styleable.Keyboard_Key_keyOutputText), preserveCase, params.mId);
// Choose the first letter of the label as primary code if not final int code = style.getInt(
// specified. keyAttr, R.styleable.Keyboard_Key_code, Keyboard.CODE_UNSPECIFIED);
final int code = adjustCaseOfCodeForKeyboardId(style.getInt( // Choose the first letter of the label as primary code if not specified.
keyAttr, R.styleable.Keyboard_Key_code, Keyboard.CODE_UNSPECIFIED), preserveCase, if (code == Keyboard.CODE_UNSPECIFIED && TextUtils.isEmpty(outputText)
params.mId);
if (code == Keyboard.CODE_UNSPECIFIED && mOutputText == null
&& !TextUtils.isEmpty(mLabel)) { && !TextUtils.isEmpty(mLabel)) {
if (mLabel.length() != 1) { if (mLabel.codePointCount(0, mLabel.length()) == 1) {
Log.w(TAG, "Label is not a single letter: label=" + mLabel); final int activatedCode;
// Use the first letter of the hint label if shiftedLetterActivated flag is
// specified.
if (hasShiftedLetterHint() && isShiftedLetterActivated()
&& !TextUtils.isEmpty(mHintLabel)) {
activatedCode = mHintLabel.codePointAt(0);
} else {
activatedCode = mLabel.codePointAt(0);
}
mCode = getRtlParenthesisCode(activatedCode, params.mIsRtlKeyboard);
} else {
// In some locale and case, the character might be represented by multiple code
// points, such as upper case Eszett of German alphabet.
outputText = mLabel;
mCode = Keyboard.CODE_OUTPUT_TEXT;
} }
final int firstChar = mLabel.charAt(0); } else if (code == Keyboard.CODE_UNSPECIFIED && outputText != null) {
mCode = getRtlParenthesisCode(firstChar, params.mIsRtlKeyboard);
} else if (code == Keyboard.CODE_UNSPECIFIED && mOutputText != null) {
mCode = Keyboard.CODE_OUTPUT_TEXT; mCode = Keyboard.CODE_OUTPUT_TEXT;
} else { } else {
mCode = code; mCode = adjustCaseOfCodeForKeyboardId(code, preserveCase, params.mId);
} }
mOutputText = outputText;
mAltCode = adjustCaseOfCodeForKeyboardId(style.getInt(keyAttr, mAltCode = adjustCaseOfCodeForKeyboardId(style.getInt(keyAttr,
R.styleable.Keyboard_Key_altCode, Keyboard.CODE_UNSPECIFIED), preserveCase, R.styleable.Keyboard_Key_altCode, Keyboard.CODE_UNSPECIFIED), preserveCase,
params.mId); params.mId);
mHashCode = hashCode(this); mHashCode = hashCode(this);
keyAttr.recycle(); keyAttr.recycle();
if (hasShiftedLetterHint() && TextUtils.isEmpty(mHintLabel)) {
Log.w(TAG, "hasShiftedLetterHint specified without keyHintLabel: " + this);
}
} }
private static int adjustCaseOfCodeForKeyboardId(int code, boolean preserveCase, private static int adjustCaseOfCodeForKeyboardId(int code, boolean preserveCase,
@ -335,7 +348,8 @@ public class Key {
if (!Keyboard.isLetterCode(code) || preserveCase) return code; if (!Keyboard.isLetterCode(code) || preserveCase) return code;
final String text = new String(new int[] { code } , 0, 1); final String text = new String(new int[] { code } , 0, 1);
final String casedText = adjustCaseOfStringForKeyboardId(text, preserveCase, id); final String casedText = adjustCaseOfStringForKeyboardId(text, preserveCase, id);
return casedText.codePointAt(0); return casedText.codePointCount(0, casedText.length()) == 1
? casedText.codePointAt(0) : Keyboard.CODE_UNSPECIFIED;
} }
private static String adjustCaseOfStringForKeyboardId(String text, boolean preserveCase, private static String adjustCaseOfStringForKeyboardId(String text, boolean preserveCase,
@ -362,6 +376,7 @@ public class Key {
key.mLabel, key.mLabel,
key.mHintLabel, key.mHintLabel,
key.mIconAttrId, key.mIconAttrId,
key.mBackgroundType,
// Key can be distinguishable without the following members. // Key can be distinguishable without the following members.
// key.mAltCode, // key.mAltCode,
// key.mOutputText, // key.mOutputText,
@ -370,7 +385,6 @@ public class Key {
// key.mIcon, // key.mIcon,
// key.mDisabledIconAttrId, // key.mDisabledIconAttrId,
// key.mPreviewIconAttrId, // key.mPreviewIconAttrId,
// key.mBackgroundType,
// key.mHorizontalGap, // key.mHorizontalGap,
// key.mVerticalGap, // key.mVerticalGap,
// key.mVisualInsetLeft, // key.mVisualInsetLeft,
@ -388,7 +402,9 @@ public class Key {
&& o.mHeight == mHeight && o.mHeight == mHeight
&& o.mCode == mCode && o.mCode == mCode
&& TextUtils.equals(o.mLabel, mLabel) && TextUtils.equals(o.mLabel, mLabel)
&& TextUtils.equals(o.mHintLabel, mHintLabel); && TextUtils.equals(o.mHintLabel, mHintLabel)
&& o.mIconAttrId != mIconAttrId
&& o.mBackgroundType != mBackgroundType;
} }
@Override @Override
@ -401,6 +417,15 @@ public class Key {
return o instanceof Key && equals((Key)o); return o instanceof Key && equals((Key)o);
} }
@Override
public String toString() {
String top = Keyboard.printableCode(mCode);
if (mLabel != null && mLabel.length() != 1) {
top += "/\"" + mLabel + '"';
}
return String.format("%s %d,%d", top, mX, mY);
}
public void markAsLeftEdge(Keyboard.Params params) { public void markAsLeftEdge(Keyboard.Params params) {
mHitBox.left = params.mHorizontalEdgesPadding; mHitBox.left = params.mHorizontalEdgesPadding;
} }
@ -417,10 +442,6 @@ public class Key {
mHitBox.bottom = params.mOccupiedHeight + params.mBottomPadding; mHitBox.bottom = params.mOccupiedHeight + params.mBottomPadding;
} }
public boolean isSticky() {
return mBackgroundType == BACKGROUND_TYPE_STICKY;
}
public boolean isSpacer() { public boolean isSpacer() {
return false; return false;
} }
@ -486,8 +507,8 @@ public class Key {
return (mLabelFlags & LABEL_FLAGS_HAS_POPUP_HINT) != 0; return (mLabelFlags & LABEL_FLAGS_HAS_POPUP_HINT) != 0;
} }
public boolean hasUppercaseLetter() { public boolean hasShiftedLetterHint() {
return (mLabelFlags & LABEL_FLAGS_HAS_UPPERCASE_LETTER) != 0; return (mLabelFlags & LABEL_FLAGS_HAS_SHIFTED_LETTER_HINT) != 0;
} }
public boolean hasHintLabel() { public boolean hasHintLabel() {
@ -506,12 +527,8 @@ public class Key {
return (mLabelFlags & LABEL_FLAGS_AUTO_X_SCALE) != 0; return (mLabelFlags & LABEL_FLAGS_AUTO_X_SCALE) != 0;
} }
public boolean isInactivatedLabel() { public boolean isShiftedLetterActivated() {
return (mLabelFlags & LABEL_FLAGS_INACTIVATED_LABEL) != 0; return (mLabelFlags & LABEL_FLAGS_SHIFTED_LETTER_ACTIVATED) != 0;
}
public boolean isInactivatedUppercaseLetter() {
return (mLabelFlags & LABEL_FLAGS_INACTIVATED_UPPERCASE_LETTER) != 0;
} }
// TODO: Get rid of this method. // TODO: Get rid of this method.
@ -542,10 +559,6 @@ public class Key {
mPressed = false; mPressed = false;
} }
public void setHighlightOn(boolean highlightOn) {
mHighlightOn = highlightOn;
}
public boolean isEnabled() { public boolean isEnabled() {
return mEnabled; return mEnabled;
} }
@ -639,21 +652,17 @@ public class Key {
* @see android.graphics.drawable.StateListDrawable#setState(int[]) * @see android.graphics.drawable.StateListDrawable#setState(int[])
*/ */
public int[] getCurrentDrawableState() { public int[] getCurrentDrawableState() {
final boolean pressed = mPressed;
switch (mBackgroundType) { switch (mBackgroundType) {
case BACKGROUND_TYPE_FUNCTIONAL: case BACKGROUND_TYPE_FUNCTIONAL:
return pressed ? KEY_STATE_FUNCTIONAL_PRESSED : KEY_STATE_FUNCTIONAL_NORMAL; return mPressed ? KEY_STATE_FUNCTIONAL_PRESSED : KEY_STATE_FUNCTIONAL_NORMAL;
case BACKGROUND_TYPE_ACTION: case BACKGROUND_TYPE_ACTION:
return pressed ? KEY_STATE_ACTIVE_PRESSED : KEY_STATE_ACTIVE_NORMAL; return mPressed ? KEY_STATE_ACTIVE_PRESSED : KEY_STATE_ACTIVE_NORMAL;
case BACKGROUND_TYPE_STICKY: case BACKGROUND_TYPE_STICKY_OFF:
if (mHighlightOn) { return mPressed ? KEY_STATE_PRESSED_HIGHLIGHT_OFF : KEY_STATE_NORMAL_HIGHLIGHT_OFF;
return pressed ? KEY_STATE_PRESSED_HIGHLIGHT_ON : KEY_STATE_NORMAL_HIGHLIGHT_ON; case BACKGROUND_TYPE_STICKY_ON:
} else { return mPressed ? KEY_STATE_PRESSED_HIGHLIGHT_ON : KEY_STATE_NORMAL_HIGHLIGHT_ON;
return pressed ? KEY_STATE_PRESSED_HIGHLIGHT_OFF : KEY_STATE_NORMAL_HIGHLIGHT_OFF;
}
default: /* BACKGROUND_TYPE_NORMAL */ default: /* BACKGROUND_TYPE_NORMAL */
return pressed ? KEY_STATE_PRESSED : KEY_STATE_NORMAL; return mPressed ? KEY_STATE_PRESSED : KEY_STATE_NORMAL;
} }
} }

View file

@ -20,7 +20,6 @@ import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.content.res.XmlResourceParser; import android.content.res.XmlResourceParser;
import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
@ -31,7 +30,6 @@ import android.view.InflateException;
import com.android.inputmethod.compat.EditorInfoCompatUtils; import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.keyboard.internal.KeyStyles; import com.android.inputmethod.keyboard.internal.KeyStyles;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.keyboard.internal.KeyboardShiftState;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.XmlParseUtils; import com.android.inputmethod.latin.XmlParseUtils;
@ -130,16 +128,12 @@ public class Keyboard {
/** List of keys and icons in this keyboard */ /** List of keys and icons in this keyboard */
public final Set<Key> mKeys; public final Set<Key> mKeys;
public final Set<Key> mShiftKeys; public final Set<Key> mShiftKeys;
public final Set<Key> mShiftLockKeys;
public final KeyboardIconsSet mIconsSet; public final KeyboardIconsSet mIconsSet;
private final Map<Integer, Key> mKeyCache = new HashMap<Integer, Key>(); private final Map<Integer, Key> mKeyCache = new HashMap<Integer, Key>();
private final ProximityInfo mProximityInfo; private final ProximityInfo mProximityInfo;
// TODO: Remove this variable.
private final KeyboardShiftState mShiftState = new KeyboardShiftState();
public Keyboard(Params params) { public Keyboard(Params params) {
mId = params.mId; mId = params.mId;
mThemeId = params.mThemeId; mThemeId = params.mThemeId;
@ -156,7 +150,6 @@ public class Keyboard {
mKeys = Collections.unmodifiableSet(params.mKeys); mKeys = Collections.unmodifiableSet(params.mKeys);
mShiftKeys = Collections.unmodifiableSet(params.mShiftKeys); mShiftKeys = Collections.unmodifiableSet(params.mShiftKeys);
mShiftLockKeys = Collections.unmodifiableSet(params.mShiftLockKeys);
mIconsSet = params.mIconsSet; mIconsSet = params.mIconsSet;
mProximityInfo = new ProximityInfo( mProximityInfo = new ProximityInfo(
@ -188,70 +181,18 @@ public class Keyboard {
} }
// TODO: Remove this method. // TODO: Remove this method.
boolean hasShiftLockKey() {
return !mShiftLockKeys.isEmpty();
}
// TODO: Remove this method.
void setShiftLocked(boolean newShiftLockState) {
for (final Key key : mShiftLockKeys) {
// To represent "shift locked" state. The highlight is handled by background image that
// might be a StateListDrawable.
key.setHighlightOn(newShiftLockState);
final int attrId = newShiftLockState
? R.styleable.Keyboard_iconShiftKeyShifted
: R.styleable.Keyboard_iconShiftKey;
key.setIcon(mIconsSet.getIconByAttrId(attrId));
}
mShiftState.setShiftLocked(newShiftLockState);
}
// TODO: Move this method to KeyboardId.
public boolean isShiftLocked() { public boolean isShiftLocked() {
return mShiftState.isShiftLocked(); return mId.isAlphabetShiftLockedKeyboard();
}
private void setShiftKeyGraphics(boolean newShiftState) {
if (mShiftState.isShiftLocked()) {
return;
}
for (final Key key : mShiftKeys) {
final int attrId = newShiftState
? R.styleable.Keyboard_iconShiftKeyShifted
: R.styleable.Keyboard_iconShiftKey;
key.setIcon(mIconsSet.getIconByAttrId(attrId));
}
} }
// TODO: Remove this method. // TODO: Remove this method.
void setShifted(boolean newShiftState) {
setShiftKeyGraphics(newShiftState);
mShiftState.setShifted(newShiftState);
}
// TODO: Move this method to KeyboardId.
public boolean isShiftedOrShiftLocked() { public boolean isShiftedOrShiftLocked() {
return mShiftState.isShiftedOrShiftLocked(); return mId.isAlphabetShiftedOrShiftLockedKeyboard();
}
// TODO: Remove this method
void setAutomaticTemporaryUpperCase() {
setShiftKeyGraphics(true);
mShiftState.setAutomaticTemporaryUpperCase();
}
// TODO: Move this method to KeyboardId.
public boolean isManualTemporaryUpperCase() {
return mShiftState.isManualTemporaryUpperCase();
} }
// TODO: Remove this method. // TODO: Remove this method.
public String adjustLabelCase(String label) { public boolean isManualShifted() {
if (mId.isAlphabetKeyboard() && isShiftedOrShiftLocked() && !TextUtils.isEmpty(label) return mId.isAlphabetManualShiftedKeyboard();
&& label.length() < 3 && Character.isLowerCase(label.charAt(0))) {
return label.toUpperCase(mId.mLocale);
}
return label;
} }
public static boolean isLetterCode(int code) { public static boolean isLetterCode(int code) {
@ -291,7 +232,6 @@ public class Keyboard {
public final Set<Key> mKeys = new HashSet<Key>(); public final Set<Key> mKeys = new HashSet<Key>();
public final Set<Key> mShiftKeys = new HashSet<Key>(); public final Set<Key> mShiftKeys = new HashSet<Key>();
public final Set<Key> mShiftLockKeys = new HashSet<Key>();
public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet(); public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet();
public KeyboardSet.KeysCache mKeysCache; public KeyboardSet.KeysCache mKeysCache;
@ -360,7 +300,6 @@ public class Keyboard {
protected void clearKeys() { protected void clearKeys() {
mKeys.clear(); mKeys.clear();
mShiftKeys.clear(); mShiftKeys.clear();
mShiftLockKeys.clear();
clearHistogram(); clearHistogram();
} }
@ -370,9 +309,6 @@ public class Keyboard {
updateHistogram(key); updateHistogram(key);
if (key.mCode == Keyboard.CODE_SHIFT) { if (key.mCode == Keyboard.CODE_SHIFT) {
mShiftKeys.add(key); mShiftKeys.add(key);
if (key.isSticky()) {
mShiftLockKeys.add(key);
}
} }
} }
@ -437,6 +373,8 @@ public class Keyboard {
case CODE_DELETE: return "delete"; case CODE_DELETE: return "delete";
case CODE_SHORTCUT: return "shortcut"; case CODE_SHORTCUT: return "shortcut";
case CODE_UNSPECIFIED: return "unspec"; case CODE_UNSPECIFIED: return "unspec";
case CODE_TAB: return "tab";
case CODE_ENTER: return "enter";
default: default:
if (code <= 0) Log.w(TAG, "Unknown non-positive key code=" + code); if (code <= 0) Log.w(TAG, "Unknown non-positive key code=" + code);
if (code < CODE_SPACE) return String.format("'\\u%02x'", code); if (code < CODE_SPACE) return String.format("'\\u%02x'", code);

View file

@ -124,6 +124,22 @@ public class KeyboardId {
return mElementId < ELEMENT_SYMBOLS; return mElementId < ELEMENT_SYMBOLS;
} }
// This should be aligned with {@link KeyboardShiftState#isShiftLocked}.
public boolean isAlphabetShiftLockedKeyboard() {
return mElementId == ELEMENT_ALPHABET_SHIFT_LOCKED
|| mElementId == ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED;
}
// This should be aligned with {@link KeyboardShiftState#isShiftedOrShiftLocked}.
public boolean isAlphabetShiftedOrShiftLockedKeyboard() {
return isAlphabetKeyboard() && mElementId != ELEMENT_ALPHABET;
}
// This should be aligned with {@link KeyboardShiftState#isManualShifted}.
public boolean isAlphabetManualShiftedKeyboard() {
return mElementId != ELEMENT_ALPHABET_MANUAL_SHIFTED;
}
public boolean isSymbolsKeyboard() { public boolean isSymbolsKeyboard() {
return mElementId == ELEMENT_SYMBOLS || mElementId == ELEMENT_SYMBOLS_SHIFTED; return mElementId == ELEMENT_SYMBOLS || mElementId == ELEMENT_SYMBOLS_SHIFTED;
} }

View file

@ -77,17 +77,6 @@ public class KeyboardSet {
} }
} }
static class KeyboardElement {
final int mElementId;
final int mLayoutId;
final boolean mAutoGenerate;
KeyboardElement(int elementId, int layoutId, boolean autoGenerate) {
mElementId = elementId;
mLayoutId = layoutId;
mAutoGenerate = autoGenerate;
}
}
static class Params { static class Params {
int mMode; int mMode;
int mInputType; int mInputType;
@ -100,8 +89,9 @@ public class KeyboardSet {
Locale mLocale; Locale mLocale;
int mOrientation; int mOrientation;
int mWidth; int mWidth;
final Map<Integer, KeyboardElement> mElementKeyboards = // KeyboardSet element id to keyboard layout XML id map.
new HashMap<Integer, KeyboardElement>(); final Map<Integer, Integer> mKeyboardSetElementIdToXmlIdMap =
new HashMap<Integer, Integer>();
Params() {} Params() {}
} }
@ -117,41 +107,38 @@ public class KeyboardSet {
mParams = params; mParams = params;
} }
// TODO: Remove this method, use {@link #getKeyboard} directly.
public Keyboard getMainKeyboard() { public Keyboard getMainKeyboard() {
return getKeyboard(false, false, false); return getKeyboard(KeyboardId.ELEMENT_ALPHABET);
} }
public Keyboard getSymbolsKeyboard() { public Keyboard getKeyboard(int baseKeyboardSetElementId) {
return getKeyboard(true, false, false); final int keyboardSetElementId;
} switch (mParams.mMode) {
case KeyboardId.MODE_PHONE:
keyboardSetElementId =
(baseKeyboardSetElementId == KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED)
? KeyboardId.ELEMENT_PHONE_SHIFTED : KeyboardId.ELEMENT_PHONE;
break;
case KeyboardId.MODE_NUMBER:
keyboardSetElementId = KeyboardId.ELEMENT_NUMBER;
break;
default:
keyboardSetElementId = baseKeyboardSetElementId;
break;
}
public Keyboard getSymbolsShiftedKeyboard() { Integer keyboardXmlId = mParams.mKeyboardSetElementIdToXmlIdMap.get(keyboardSetElementId);
final Keyboard keyboard = getKeyboard(true, false, true); if (keyboardXmlId == null) {
// TODO: Remove this logic once we introduce initial keyboard shift state attribute. keyboardXmlId = mParams.mKeyboardSetElementIdToXmlIdMap.get(
// Symbol shift keyboard may have a shift key that has a caps lock style indicator (a.k.a. KeyboardId.ELEMENT_ALPHABET);
// sticky shift key). To show or dismiss the indicator, we need to call setShiftLocked() }
// that takes care of the current keyboard having such shift key or not. final KeyboardId id = getKeyboardId(keyboardSetElementId);
keyboard.setShiftLocked(keyboard.hasShiftLockKey()); final Keyboard keyboard = getKeyboard(mContext, keyboardXmlId, id);
return keyboard; return keyboard;
} }
private Keyboard getKeyboard(boolean isSymbols, boolean isShiftLock, boolean isShift) { private Keyboard getKeyboard(Context context, int keyboardXmlId, KeyboardId id) {
final int elementId = KeyboardSet.getElementId(
mParams.mMode, isSymbols, isShiftLock, isShift);
final KeyboardElement keyboardElement = mParams.mElementKeyboards.get(elementId);
// TODO: If keyboardElement.mAutoGenerate is true, the keyboard will be auto generated
// based on keyboardElement.mKayoutId Keyboard XML definition.
final KeyboardId id = KeyboardSet.getKeyboardId(elementId, isSymbols, mParams);
final Keyboard keyboard = getKeyboard(mContext, keyboardElement, id);
return keyboard;
}
public KeyboardId getMainKeyboardId() {
final int elementId = KeyboardSet.getElementId(mParams.mMode, false, false, false);
return KeyboardSet.getKeyboardId(elementId, false, mParams);
}
private Keyboard getKeyboard(Context context, KeyboardElement element, KeyboardId id) {
final Resources res = context.getResources(); final Resources res = context.getResources();
final SoftReference<Keyboard> ref = sKeyboardCache.get(id); final SoftReference<Keyboard> ref = sKeyboardCache.get(id);
Keyboard keyboard = (ref == null) ? null : ref.get(); Keyboard keyboard = (ref == null) ? null : ref.get();
@ -160,10 +147,10 @@ public class KeyboardSet {
try { try {
final Keyboard.Builder<Keyboard.Params> builder = final Keyboard.Builder<Keyboard.Params> builder =
new Keyboard.Builder<Keyboard.Params>(context, new Keyboard.Params()); new Keyboard.Builder<Keyboard.Params>(context, new Keyboard.Params());
if (element.mAutoGenerate) { if (id.isAlphabetKeyboard()) {
builder.setAutoGenerate(mKeysCache); builder.setAutoGenerate(mKeysCache);
} }
builder.load(element.mLayoutId, id); builder.load(keyboardXmlId, id);
builder.setTouchPositionCorrectionEnabled(mParams.mTouchPositionCorrectionEnabled); builder.setTouchPositionCorrectionEnabled(mParams.mTouchPositionCorrectionEnabled);
keyboard = builder.build(); keyboard = builder.build();
} finally { } finally {
@ -179,36 +166,23 @@ public class KeyboardSet {
Log.d(TAG, "keyboard cache size=" + sKeyboardCache.size() + ": HIT id=" + id); Log.d(TAG, "keyboard cache size=" + sKeyboardCache.size() + ": HIT id=" + id);
} }
// TODO: Remove setShiftLocked and setShift calls.
keyboard.setShiftLocked(false);
keyboard.setShifted(false);
return keyboard; return keyboard;
} }
private static int getElementId(int mode, boolean isSymbols, boolean isShiftLock, // TODO: Make this method private.
boolean isShift) { // Note: The keyboard for each locale, shift state, and mode are represented as KeyboardSet
switch (mode) { // element id that is a key in keyboard_set.xml. Also that file specifies which XML layout
case KeyboardId.MODE_PHONE: // should be used for each keyboard. The KeyboardId is an internal key for Keyboard object.
return (isSymbols && isShift) public KeyboardId getKeyboardId(int keyboardSetElementId) {
? KeyboardId.ELEMENT_PHONE_SHIFTED : KeyboardId.ELEMENT_PHONE; final Params params = mParams;
case KeyboardId.MODE_NUMBER: final boolean isSymbols = (keyboardSetElementId == KeyboardId.ELEMENT_SYMBOLS
return KeyboardId.ELEMENT_NUMBER; || keyboardSetElementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED);
default:
if (isSymbols) {
return isShift
? KeyboardId.ELEMENT_SYMBOLS_SHIFTED : KeyboardId.ELEMENT_SYMBOLS;
}
// TODO: Consult isShiftLock and isShift to determine the element.
return KeyboardId.ELEMENT_ALPHABET;
}
}
private static KeyboardId getKeyboardId(int elementId, boolean isSymbols, Params params) {
final boolean hasShortcutKey = params.mVoiceKeyEnabled final boolean hasShortcutKey = params.mVoiceKeyEnabled
&& (isSymbols != params.mVoiceKeyOnMain); && (isSymbols != params.mVoiceKeyOnMain);
return new KeyboardId(elementId, params.mLocale, params.mOrientation, params.mWidth, return new KeyboardId(keyboardSetElementId, params.mLocale, params.mOrientation,
params.mMode, params.mInputType, params.mImeOptions, params.mSettingsKeyEnabled, params.mWidth, params.mMode, params.mInputType, params.mImeOptions,
params.mNoSettingsKey, params.mVoiceKeyEnabled, hasShortcutKey); params.mSettingsKeyEnabled, params.mNoSettingsKey, params.mVoiceKeyEnabled,
hasShortcutKey);
} }
public static class Builder { public static class Builder {
@ -345,10 +319,7 @@ public class KeyboardSet {
R.styleable.KeyboardSet_Element_elementName, 0); R.styleable.KeyboardSet_Element_elementName, 0);
final int elementKeyboard = a.getResourceId( final int elementKeyboard = a.getResourceId(
R.styleable.KeyboardSet_Element_elementKeyboard, 0); R.styleable.KeyboardSet_Element_elementKeyboard, 0);
final boolean elementAutoGenerate = a.getBoolean( mParams.mKeyboardSetElementIdToXmlIdMap.put(elementName, elementKeyboard);
R.styleable.KeyboardSet_Element_elementAutoGenerate, false);
mParams.mElementKeyboards.put(elementName, new KeyboardElement(
elementName, elementKeyboard, elementAutoGenerate));
} finally { } finally {
a.recycle(); a.recycle();
} }

View file

@ -135,24 +135,19 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
settingsValues.isVoiceKeyEnabled(editorInfo), settingsValues.isVoiceKeyEnabled(editorInfo),
settingsValues.isVoiceKeyOnMain()); settingsValues.isVoiceKeyOnMain());
mKeyboardSet = builder.build(); mKeyboardSet = builder.build();
final KeyboardId mainKeyboardId = mKeyboardSet.getMainKeyboardId();
try { try {
mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols)); mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols));
} catch (RuntimeException e) { } catch (RuntimeException e) {
Log.w(TAG, "loading keyboard failed: " + mainKeyboardId, e); Log.w(TAG, "loading keyboard failed: " + mKeyboardSet.getKeyboardId(
LatinImeLogger.logOnException(mainKeyboardId.toString(), e); KeyboardId.ELEMENT_ALPHABET), e);
LatinImeLogger.logOnException(mKeyboardSet.getKeyboardId(
KeyboardId.ELEMENT_ALPHABET).toString(), e);
return; return;
} }
// TODO: Should get rid of this special case handling for Phone Number layouts once we
// have separate layouts with unique KeyboardIds for alphabet and alphabet-shifted
// respectively.
if (mainKeyboardId.isPhoneKeyboard()) {
mState.setSymbolsKeyboard();
}
} }
public void saveKeyboardState() { public void saveKeyboardState() {
if (isKeyboardAvailable()) { if (getKeyboard() != null) {
mState.onSaveKeyboardState(); mState.onSaveKeyboardState();
} }
} }
@ -184,31 +179,23 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
mInputMethodService.mHandler.startDisplayLanguageOnSpacebar(localeChanged); mInputMethodService.mHandler.startDisplayLanguageOnSpacebar(localeChanged);
} }
// TODO: Remove this method.
public boolean isAlphabetMode() { public boolean isAlphabetMode() {
final Keyboard keyboard = getKeyboard(); final Keyboard keyboard = getKeyboard();
return keyboard != null && keyboard.mId.isAlphabetKeyboard(); return keyboard != null && keyboard.mId.isAlphabetKeyboard();
} }
// TODO: Remove this method.
public boolean isInputViewShown() { public boolean isInputViewShown() {
return mCurrentInputView != null && mCurrentInputView.isShown(); return mCurrentInputView != null && mCurrentInputView.isShown();
} }
// TODO: Remove this method.
public boolean isShiftedOrShiftLocked() { public boolean isShiftedOrShiftLocked() {
final Keyboard keyboard = getKeyboard(); final Keyboard keyboard = getKeyboard();
return keyboard != null && keyboard.isShiftedOrShiftLocked(); return keyboard != null && keyboard.isShiftedOrShiftLocked();
} }
public boolean isManualTemporaryUpperCase() {
final Keyboard keyboard = getKeyboard();
return keyboard != null && keyboard.isManualTemporaryUpperCase();
}
public boolean isKeyboardAvailable() {
if (mKeyboardView != null)
return mKeyboardView.getKeyboard() != null;
return false;
}
public Keyboard getKeyboard() { public Keyboard getKeyboard() {
if (mKeyboardView != null) { if (mKeyboardView != null) {
return mKeyboardView.getKeyboard(); return mKeyboardView.getKeyboard();
@ -235,91 +222,46 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
mState.onCancelInput(isSinglePointer()); mState.onCancelInput(isSinglePointer());
} }
// TODO: Remove these constants.
private static final int ALPHABET_UNSHIFTED = 0;
private static final int ALPHABET_MANUAL_SHIFTED = 1;
private static final int ALPHABET_AUTOMATIC_SHIFTED = 2;
private static final int ALPHABET_SHIFT_LOCKED = 3;
private static final int ALPHABET_SHIFT_LOCK_SHIFTED = 4;
// TODO: Remove this method.
private void updateAlphabetKeyboardShiftState(int shiftMode) {
mInputMethodService.mHandler.cancelUpdateShiftState();
Keyboard keyboard = getKeyboard();
if (keyboard == null)
return;
switch (shiftMode) {
case ALPHABET_UNSHIFTED:
keyboard.setShifted(false);
break;
case ALPHABET_MANUAL_SHIFTED:
keyboard.setShifted(true);
break;
case ALPHABET_AUTOMATIC_SHIFTED:
keyboard.setAutomaticTemporaryUpperCase();
break;
case ALPHABET_SHIFT_LOCKED:
keyboard.setShiftLocked(true);
break;
case ALPHABET_SHIFT_LOCK_SHIFTED:
keyboard.setShiftLocked(true);
keyboard.setShifted(true);
break;
}
mKeyboardView.invalidateAllKeys();
if (shiftMode != ALPHABET_SHIFT_LOCKED) {
// To be able to turn off caps lock by "double tap" on shift key, we should ignore
// the second tap of the "double tap" from now for a while because we just have
// already turned off caps lock above.
mKeyboardView.startIgnoringDoubleTap();
}
}
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setAlphabetKeyboard() { public void setAlphabetKeyboard() {
setKeyboard(mKeyboardSet.getMainKeyboard()); setKeyboard(mKeyboardSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET));
updateAlphabetKeyboardShiftState(ALPHABET_UNSHIFTED);
} }
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setAlphabetManualShiftedKeyboard() { public void setAlphabetManualShiftedKeyboard() {
setKeyboard(mKeyboardSet.getMainKeyboard()); setKeyboard(mKeyboardSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED));
updateAlphabetKeyboardShiftState(ALPHABET_MANUAL_SHIFTED);
} }
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setAlphabetAutomaticShiftedKeyboard() { public void setAlphabetAutomaticShiftedKeyboard() {
setKeyboard(mKeyboardSet.getMainKeyboard()); setKeyboard(mKeyboardSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED));
updateAlphabetKeyboardShiftState(ALPHABET_AUTOMATIC_SHIFTED);
} }
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setAlphabetShiftLockedKeyboard() { public void setAlphabetShiftLockedKeyboard() {
setKeyboard(mKeyboardSet.getMainKeyboard()); setKeyboard(mKeyboardSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED));
updateAlphabetKeyboardShiftState(ALPHABET_SHIFT_LOCKED);
} }
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setAlphabetShiftLockShiftedKeyboard() { public void setAlphabetShiftLockShiftedKeyboard() {
setKeyboard(mKeyboardSet.getMainKeyboard()); setKeyboard(mKeyboardSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED));
updateAlphabetKeyboardShiftState(ALPHABET_SHIFT_LOCK_SHIFTED);
} }
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setSymbolsKeyboard() { public void setSymbolsKeyboard() {
setKeyboard(mKeyboardSet.getSymbolsKeyboard()); setKeyboard(mKeyboardSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS));
} }
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setSymbolsShiftedKeyboard() { public void setSymbolsShiftedKeyboard() {
setKeyboard(mKeyboardSet.getSymbolsShiftedKeyboard()); setKeyboard(mKeyboardSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS_SHIFTED));
} }
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.

View file

@ -53,12 +53,12 @@ import java.util.HashMap;
* @attr ref R.styleable#KeyboardView_keyLargeLetterRatio * @attr ref R.styleable#KeyboardView_keyLargeLetterRatio
* @attr ref R.styleable#KeyboardView_keyLabelRatio * @attr ref R.styleable#KeyboardView_keyLabelRatio
* @attr ref R.styleable#KeyboardView_keyHintLetterRatio * @attr ref R.styleable#KeyboardView_keyHintLetterRatio
* @attr ref R.styleable#KeyboardView_keyUppercaseLetterRatio * @attr ref R.styleable#KeyboardView_keyShiftedLetterHintRatio
* @attr ref R.styleable#KeyboardView_keyHintLabelRatio * @attr ref R.styleable#KeyboardView_keyHintLabelRatio
* @attr ref R.styleable#KeyboardView_keyLabelHorizontalPadding * @attr ref R.styleable#KeyboardView_keyLabelHorizontalPadding
* @attr ref R.styleable#KeyboardView_keyHintLetterPadding * @attr ref R.styleable#KeyboardView_keyHintLetterPadding
* @attr ref R.styleable#KeyboardView_keyPopupHintLetterPadding * @attr ref R.styleable#KeyboardView_keyPopupHintLetterPadding
* @attr ref R.styleable#KeyboardView_keyUppercaseLetterPadding * @attr ref R.styleable#KeyboardView_keyShiftedLetterHintPadding
* @attr ref R.styleable#KeyboardView_keyTextStyle * @attr ref R.styleable#KeyboardView_keyTextStyle
* @attr ref R.styleable#KeyboardView_keyPreviewLayout * @attr ref R.styleable#KeyboardView_keyPreviewLayout
* @attr ref R.styleable#KeyboardView_keyPreviewTextRatio * @attr ref R.styleable#KeyboardView_keyPreviewTextRatio
@ -68,8 +68,8 @@ import java.util.HashMap;
* @attr ref R.styleable#KeyboardView_keyTextColorDisabled * @attr ref R.styleable#KeyboardView_keyTextColorDisabled
* @attr ref R.styleable#KeyboardView_keyHintLetterColor * @attr ref R.styleable#KeyboardView_keyHintLetterColor
* @attr ref R.styleable#KeyboardView_keyHintLabelColor * @attr ref R.styleable#KeyboardView_keyHintLabelColor
* @attr ref R.styleable#KeyboardView_keyUppercaseLetterInactivatedColor * @attr ref R.styleable#KeyboardView_keyShiftedLetterHintInactivatedColor
* @attr ref R.styleable#KeyboardView_keyUppercaseLetterActivatedColor * @attr ref R.styleable#KeyboardView_keyShiftedLetterHintActivatedColor
* @attr ref R.styleable#KeyboardView_shadowColor * @attr ref R.styleable#KeyboardView_shadowColor
* @attr ref R.styleable#KeyboardView_shadowRadius * @attr ref R.styleable#KeyboardView_shadowRadius
*/ */
@ -175,20 +175,20 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
public final float mKeyLabelHorizontalPadding; public final float mKeyLabelHorizontalPadding;
public final float mKeyHintLetterPadding; public final float mKeyHintLetterPadding;
public final float mKeyPopupHintLetterPadding; public final float mKeyPopupHintLetterPadding;
public final float mKeyUppercaseLetterPadding; public final float mKeyShiftedLetterHintPadding;
public final int mShadowColor; public final int mShadowColor;
public final float mShadowRadius; public final float mShadowRadius;
public final Drawable mKeyBackground; public final Drawable mKeyBackground;
public final int mKeyHintLetterColor; public final int mKeyHintLetterColor;
public final int mKeyHintLabelColor; public final int mKeyHintLabelColor;
public final int mKeyUppercaseLetterInactivatedColor; public final int mKeyShiftedLetterHintInactivatedColor;
public final int mKeyUppercaseLetterActivatedColor; public final int mKeyShiftedLetterHintActivatedColor;
private final float mKeyLetterRatio; private final float mKeyLetterRatio;
private final float mKeyLargeLetterRatio; private final float mKeyLargeLetterRatio;
private final float mKeyLabelRatio; private final float mKeyLabelRatio;
private final float mKeyHintLetterRatio; private final float mKeyHintLetterRatio;
private final float mKeyUppercaseLetterRatio; private final float mKeyShiftedLetterHintRatio;
private final float mKeyHintLabelRatio; private final float mKeyHintLabelRatio;
private static final float UNDEFINED_RATIO = -1.0f; private static final float UNDEFINED_RATIO = -1.0f;
@ -197,7 +197,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
public int mKeyLargeLetterSize; public int mKeyLargeLetterSize;
public int mKeyLabelSize; public int mKeyLabelSize;
public int mKeyHintLetterSize; public int mKeyHintLetterSize;
public int mKeyUppercaseLetterSize; public int mKeyShiftedLetterHintSize;
public int mKeyHintLabelSize; public int mKeyHintLabelSize;
public KeyDrawParams(TypedArray a) { public KeyDrawParams(TypedArray a) {
@ -216,8 +216,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
mKeyLargeLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLargeLetterRatio); mKeyLargeLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLargeLetterRatio);
mKeyHintLetterRatio = getRatio(a, R.styleable.KeyboardView_keyHintLetterRatio); mKeyHintLetterRatio = getRatio(a, R.styleable.KeyboardView_keyHintLetterRatio);
mKeyUppercaseLetterRatio = getRatio(a, mKeyShiftedLetterHintRatio = getRatio(a,
R.styleable.KeyboardView_keyUppercaseLetterRatio); R.styleable.KeyboardView_keyShiftedLetterHintRatio);
mKeyHintLabelRatio = getRatio(a, R.styleable.KeyboardView_keyHintLabelRatio); mKeyHintLabelRatio = getRatio(a, R.styleable.KeyboardView_keyHintLabelRatio);
mKeyLabelHorizontalPadding = a.getDimension( mKeyLabelHorizontalPadding = a.getDimension(
R.styleable.KeyboardView_keyLabelHorizontalPadding, 0); R.styleable.KeyboardView_keyLabelHorizontalPadding, 0);
@ -225,17 +225,17 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
R.styleable.KeyboardView_keyHintLetterPadding, 0); R.styleable.KeyboardView_keyHintLetterPadding, 0);
mKeyPopupHintLetterPadding = a.getDimension( mKeyPopupHintLetterPadding = a.getDimension(
R.styleable.KeyboardView_keyPopupHintLetterPadding, 0); R.styleable.KeyboardView_keyPopupHintLetterPadding, 0);
mKeyUppercaseLetterPadding = a.getDimension( mKeyShiftedLetterHintPadding = a.getDimension(
R.styleable.KeyboardView_keyUppercaseLetterPadding, 0); R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0);
mKeyTextColor = a.getColor(R.styleable.KeyboardView_keyTextColor, 0xFF000000); mKeyTextColor = a.getColor(R.styleable.KeyboardView_keyTextColor, 0xFF000000);
mKeyTextInactivatedColor = a.getColor( mKeyTextInactivatedColor = a.getColor(
R.styleable.KeyboardView_keyTextInactivatedColor, 0xFF000000); R.styleable.KeyboardView_keyTextInactivatedColor, 0xFF000000);
mKeyHintLetterColor = a.getColor(R.styleable.KeyboardView_keyHintLetterColor, 0); mKeyHintLetterColor = a.getColor(R.styleable.KeyboardView_keyHintLetterColor, 0);
mKeyHintLabelColor = a.getColor(R.styleable.KeyboardView_keyHintLabelColor, 0); mKeyHintLabelColor = a.getColor(R.styleable.KeyboardView_keyHintLabelColor, 0);
mKeyUppercaseLetterInactivatedColor = a.getColor( mKeyShiftedLetterHintInactivatedColor = a.getColor(
R.styleable.KeyboardView_keyUppercaseLetterInactivatedColor, 0); R.styleable.KeyboardView_keyShiftedLetterHintInactivatedColor, 0);
mKeyUppercaseLetterActivatedColor = a.getColor( mKeyShiftedLetterHintActivatedColor = a.getColor(
R.styleable.KeyboardView_keyUppercaseLetterActivatedColor, 0); R.styleable.KeyboardView_keyShiftedLetterHintActivatedColor, 0);
mKeyTextStyle = Typeface.defaultFromStyle( mKeyTextStyle = Typeface.defaultFromStyle(
a.getInt(R.styleable.KeyboardView_keyTextStyle, Typeface.NORMAL)); a.getInt(R.styleable.KeyboardView_keyTextStyle, Typeface.NORMAL));
mShadowColor = a.getColor(R.styleable.KeyboardView_shadowColor, 0); mShadowColor = a.getColor(R.styleable.KeyboardView_shadowColor, 0);
@ -251,7 +251,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio); mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio);
mKeyLargeLetterSize = (int)(keyHeight * mKeyLargeLetterRatio); mKeyLargeLetterSize = (int)(keyHeight * mKeyLargeLetterRatio);
mKeyHintLetterSize = (int)(keyHeight * mKeyHintLetterRatio); mKeyHintLetterSize = (int)(keyHeight * mKeyHintLetterRatio);
mKeyUppercaseLetterSize = (int)(keyHeight * mKeyUppercaseLetterRatio); mKeyShiftedLetterHintSize = (int)(keyHeight * mKeyShiftedLetterHintRatio);
mKeyHintLabelSize = (int)(keyHeight * mKeyHintLabelRatio); mKeyHintLabelSize = (int)(keyHeight * mKeyHintLabelRatio);
} }
} }
@ -527,8 +527,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
final Drawable icon = key.getIcon(mKeyboard.mIconsSet); final Drawable icon = key.getIcon(mKeyboard.mIconsSet);
float positionX = centerX; float positionX = centerX;
if (key.mLabel != null) { if (key.mLabel != null) {
// Switch the character to uppercase if shift is pressed final String label = key.mLabel;
final String label = mKeyboard.adjustLabelCase(key.mLabel);
// For characters, use large font. For labels like "Done", use smaller font. // For characters, use large font. For labels like "Done", use smaller font.
paint.setTypeface(key.selectTypeface(params.mKeyTextStyle)); paint.setTypeface(key.selectTypeface(params.mKeyTextStyle));
final int labelSize = key.selectTextSize(params.mKeyLetterSize, final int labelSize = key.selectTextSize(params.mKeyLetterSize,
@ -571,14 +570,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
Math.min(1.0f, (keyWidth * MAX_LABEL_RATIO) / getLabelWidth(label, paint))); Math.min(1.0f, (keyWidth * MAX_LABEL_RATIO) / getLabelWidth(label, paint)));
} }
// TODO: Remove this first if-clause. paint.setColor(key.isShiftedLetterActivated()
if (key.hasUppercaseLetter() && mKeyboard.isManualTemporaryUpperCase()) { ? params.mKeyTextInactivatedColor : params.mKeyTextColor);
paint.setColor(params.mKeyTextInactivatedColor);
} else if (key.isInactivatedLabel()) {
paint.setColor(params.mKeyTextInactivatedColor);
} else {
paint.setColor(params.mKeyTextColor);
}
if (key.isEnabled()) { if (key.isEnabled()) {
// Set a drop shadow for the text // Set a drop shadow for the text
paint.setShadowLayer(params.mShadowRadius, 0, 0, params.mShadowColor); paint.setShadowLayer(params.mShadowRadius, 0, 0, params.mShadowColor);
@ -620,16 +613,11 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
hintColor = params.mKeyHintLabelColor; hintColor = params.mKeyHintLabelColor;
hintSize = params.mKeyHintLabelSize; hintSize = params.mKeyHintLabelSize;
paint.setTypeface(Typeface.DEFAULT); paint.setTypeface(Typeface.DEFAULT);
} else if (key.hasUppercaseLetter()) { } else if (key.hasShiftedLetterHint()) {
// TODO: Remove this first if-clause. hintColor = key.isShiftedLetterActivated()
if (mKeyboard.isManualTemporaryUpperCase()) { ? params.mKeyShiftedLetterHintActivatedColor
hintColor = params.mKeyUppercaseLetterActivatedColor; : params.mKeyShiftedLetterHintInactivatedColor;
} else if (!key.isInactivatedUppercaseLetter()) { hintSize = params.mKeyShiftedLetterHintSize;
hintColor = params.mKeyUppercaseLetterActivatedColor;
} else {
hintColor = params.mKeyUppercaseLetterInactivatedColor;
}
hintSize = params.mKeyUppercaseLetterSize;
} else { // key.hasHintLetter() } else { // key.hasHintLetter()
hintColor = params.mKeyHintLetterColor; hintColor = params.mKeyHintLetterColor;
hintSize = params.mKeyHintLetterSize; hintSize = params.mKeyHintLetterSize;
@ -644,9 +632,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
hintX = positionX + getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) * 2; hintX = positionX + getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) * 2;
hintY = centerY + getCharHeight(KEY_LABEL_REFERENCE_CHAR, paint) / 2; hintY = centerY + getCharHeight(KEY_LABEL_REFERENCE_CHAR, paint) / 2;
paint.setTextAlign(Align.LEFT); paint.setTextAlign(Align.LEFT);
} else if (key.hasUppercaseLetter()) { } else if (key.hasShiftedLetterHint()) {
// The hint label is placed at top-right corner of the key. Used mainly on tablet. // The hint label is placed at top-right corner of the key. Used mainly on tablet.
hintX = keyWidth - params.mKeyUppercaseLetterPadding hintX = keyWidth - params.mKeyShiftedLetterHintPadding
- getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) / 2; - getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) / 2;
hintY = -paint.ascent(); hintY = -paint.ascent();
paint.setTextAlign(Align.CENTER); paint.setTextAlign(Align.CENTER);
@ -870,7 +858,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, params.mPreviewTextSize); previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, params.mPreviewTextSize);
previewText.setTypeface(params.mKeyTextStyle); previewText.setTypeface(params.mKeyTextStyle);
} }
previewText.setText(mKeyboard.adjustLabelCase(key.mLabel)); previewText.setText(key.mLabel);
} else { } else {
final Drawable previewIcon = mKeyboard.mIconsSet.getIconByAttrId( final Drawable previewIcon = mKeyboard.mIconsSet.getIconByAttrId(
key.mPreviewIconAttrId); key.mPreviewIconAttrId);

View file

@ -548,7 +548,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
mMoreKeysPanelPointerTrackerId = tracker.mPointerId; mMoreKeysPanelPointerTrackerId = tracker.mPointerId;
final Keyboard keyboard = getKeyboard(); final Keyboard keyboard = getKeyboard();
moreKeysPanel.setShifted(keyboard.isShiftedOrShiftLocked());
final int pointX = (mConfigShowMiniKeyboardAtTouchedPoint) ? tracker.getLastX() final int pointX = (mConfigShowMiniKeyboardAtTouchedPoint) ? tracker.getLastX()
: parentKey.mX + parentKey.mWidth / 2; : parentKey.mX + parentKey.mWidth / 2;
final int pointY = parentKey.mY - keyboard.mVerticalGap; final int pointY = parentKey.mY - keyboard.mVerticalGap;

View file

@ -130,13 +130,6 @@ public class MiniKeyboardView extends KeyboardView implements MoreKeysPanel {
super.setKeyPreviewPopupEnabled(false, 0); super.setKeyPreviewPopupEnabled(false, 0);
} }
@Override
public void setShifted(boolean shifted) {
final Keyboard keyboard = getKeyboard();
keyboard.setShifted(shifted);
invalidateAllKeys();
}
@Override @Override
public void showMoreKeysPanel(View parentView, Controller controller, int pointX, int pointY, public void showMoreKeysPanel(View parentView, Controller controller, int pointX, int pointY,
PopupWindow window, KeyboardActionListener listener) { PopupWindow window, KeyboardActionListener listener) {

View file

@ -24,9 +24,6 @@ public interface MoreKeysPanel extends PointerTracker.KeyEventHandler {
public boolean dismissMoreKeysPanel(); public boolean dismissMoreKeysPanel();
} }
// TODO: Remove this method.
public void setShifted(boolean shifted);
/** /**
* Show more keys panel. * Show more keys panel.
* *

View file

@ -705,7 +705,7 @@ public class PointerTracker {
if (sParams.mLongPressSpaceKeyTimeout > 0) { if (sParams.mLongPressSpaceKeyTimeout > 0) {
mTimerProxy.startLongPressTimer(sParams.mLongPressSpaceKeyTimeout, this); mTimerProxy.startLongPressTimer(sParams.mLongPressSpaceKeyTimeout, this);
} }
} else if (key.hasUppercaseLetter() && mKeyboard.isManualTemporaryUpperCase()) { } else if (key.hasShiftedLetterHint() && mKeyboard.isManualShifted()) {
// We need not start long press timer on the key which has manual temporary upper case // We need not start long press timer on the key which has manual temporary upper case
// code defined and the keyboard is in manual temporary upper case mode. // code defined and the keyboard is in manual temporary upper case mode.
return; return;
@ -727,13 +727,6 @@ public class PointerTracker {
final int[] codes = mKeyDetector.newCodeArray(); final int[] codes = mKeyDetector.newCodeArray();
mKeyDetector.getKeyAndNearbyCodes(x, y, codes); mKeyDetector.getKeyAndNearbyCodes(x, y, codes);
// If keyboard is in manual temporary upper case state and key has manual temporary
// uppercase letter as key hint letter, alternate character code should be sent.
if (mKeyboard.isManualTemporaryUpperCase() && key.hasUppercaseLetter()) {
code = key.mHintLabel.charAt(0);
codes[0] = code;
}
// Swap the first and second values in the codes array if the primary code is not the // Swap the first and second values in the codes array if the primary code is not the
// first value but the second value in the array. This happens when key debouncing is // first value but the second value in the array. This happens when key debouncing is
// in effect. // in effect.

View file

@ -18,27 +18,27 @@ package com.android.inputmethod.keyboard.internal;
import android.util.Log; import android.util.Log;
public class KeyboardShiftState { public class AlphabetShiftState {
private static final String TAG = KeyboardShiftState.class.getSimpleName(); private static final String TAG = AlphabetShiftState.class.getSimpleName();
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private static final int NORMAL = 0; private static final int UNSHIFTED = 0;
private static final int MANUAL_SHIFTED = 1; private static final int MANUAL_SHIFTED = 1;
private static final int MANUAL_SHIFTED_FROM_AUTO = 2; private static final int MANUAL_SHIFTED_FROM_AUTO = 2;
private static final int AUTO_SHIFTED = 3; private static final int AUTOMATIC_SHIFTED = 3;
private static final int SHIFT_LOCKED = 4; private static final int SHIFT_LOCKED = 4;
private static final int SHIFT_LOCK_SHIFTED = 5; private static final int SHIFT_LOCK_SHIFTED = 5;
private int mState = NORMAL; private int mState = UNSHIFTED;
public void setShifted(boolean newShiftState) { public void setShifted(boolean newShiftState) {
final int oldState = mState; final int oldState = mState;
if (newShiftState) { if (newShiftState) {
switch (oldState) { switch (oldState) {
case NORMAL: case UNSHIFTED:
mState = MANUAL_SHIFTED; mState = MANUAL_SHIFTED;
break; break;
case AUTO_SHIFTED: case AUTOMATIC_SHIFTED:
mState = MANUAL_SHIFTED_FROM_AUTO; mState = MANUAL_SHIFTED_FROM_AUTO;
break; break;
case SHIFT_LOCKED: case SHIFT_LOCKED:
@ -49,8 +49,8 @@ public class KeyboardShiftState {
switch (oldState) { switch (oldState) {
case MANUAL_SHIFTED: case MANUAL_SHIFTED:
case MANUAL_SHIFTED_FROM_AUTO: case MANUAL_SHIFTED_FROM_AUTO:
case AUTO_SHIFTED: case AUTOMATIC_SHIFTED:
mState = NORMAL; mState = UNSHIFTED;
break; break;
case SHIFT_LOCK_SHIFTED: case SHIFT_LOCK_SHIFTED:
mState = SHIFT_LOCKED; mState = SHIFT_LOCKED;
@ -65,30 +65,30 @@ public class KeyboardShiftState {
final int oldState = mState; final int oldState = mState;
if (newShiftLockState) { if (newShiftLockState) {
switch (oldState) { switch (oldState) {
case NORMAL: case UNSHIFTED:
case MANUAL_SHIFTED: case MANUAL_SHIFTED:
case MANUAL_SHIFTED_FROM_AUTO: case MANUAL_SHIFTED_FROM_AUTO:
case AUTO_SHIFTED: case AUTOMATIC_SHIFTED:
mState = SHIFT_LOCKED; mState = SHIFT_LOCKED;
break; break;
} }
} else { } else {
mState = NORMAL; mState = UNSHIFTED;
} }
if (DEBUG) if (DEBUG)
Log.d(TAG, "setShiftLocked(" + newShiftLockState + "): " + toString(oldState) Log.d(TAG, "setShiftLocked(" + newShiftLockState + "): " + toString(oldState)
+ " > " + this); + " > " + this);
} }
public void setAutomaticTemporaryUpperCase() { public void setAutomaticShifted() {
final int oldState = mState; final int oldState = mState;
mState = AUTO_SHIFTED; mState = AUTOMATIC_SHIFTED;
if (DEBUG) if (DEBUG)
Log.d(TAG, "setAutomaticTemporaryUpperCase: " + toString(oldState) + " > " + this); Log.d(TAG, "setAutomaticShifted: " + toString(oldState) + " > " + this);
} }
public boolean isShiftedOrShiftLocked() { public boolean isShiftedOrShiftLocked() {
return mState != NORMAL; return mState != UNSHIFTED;
} }
public boolean isShiftLocked() { public boolean isShiftLocked() {
@ -99,16 +99,16 @@ public class KeyboardShiftState {
return mState == SHIFT_LOCK_SHIFTED; return mState == SHIFT_LOCK_SHIFTED;
} }
public boolean isAutomaticTemporaryUpperCase() { public boolean isAutomaticShifted() {
return mState == AUTO_SHIFTED; return mState == AUTOMATIC_SHIFTED;
} }
public boolean isManualTemporaryUpperCase() { public boolean isManualShifted() {
return mState == MANUAL_SHIFTED || mState == MANUAL_SHIFTED_FROM_AUTO return mState == MANUAL_SHIFTED || mState == MANUAL_SHIFTED_FROM_AUTO
|| mState == SHIFT_LOCK_SHIFTED; || mState == SHIFT_LOCK_SHIFTED;
} }
public boolean isManualTemporaryUpperCaseFromAuto() { public boolean isManualShiftedFromAutomaticShifted() {
return mState == MANUAL_SHIFTED_FROM_AUTO; return mState == MANUAL_SHIFTED_FROM_AUTO;
} }
@ -119,13 +119,13 @@ public class KeyboardShiftState {
private static String toString(int state) { private static String toString(int state) {
switch (state) { switch (state) {
case NORMAL: return "NORMAL"; case UNSHIFTED: return "UNSHIFTED";
case MANUAL_SHIFTED: return "MANUAL_SHIFTED"; case MANUAL_SHIFTED: return "MANUAL_SHIFTED";
case MANUAL_SHIFTED_FROM_AUTO: return "MANUAL_SHIFTED_FROM_AUTO"; case MANUAL_SHIFTED_FROM_AUTO: return "MANUAL_SHIFTED_FROM_AUTO";
case AUTO_SHIFTED: return "AUTO_SHIFTED"; case AUTOMATIC_SHIFTED: return "AUTOMATIC_SHIFTED";
case SHIFT_LOCKED: return "SHIFT_LOCKED"; case SHIFT_LOCKED: return "SHIFT_LOCKED";
case SHIFT_LOCK_SHIFTED: return "SHIFT_LOCK_SHIFTED"; case SHIFT_LOCK_SHIFTED: return "SHIFT_LOCK_SHIFTED";
default: return "UKNOWN"; default: return "UNKNOWN";
} }
} }
} }

View file

@ -70,7 +70,7 @@ public class KeyboardState {
private String mLayoutSwitchBackSymbols; private String mLayoutSwitchBackSymbols;
private boolean mIsAlphabetMode; private boolean mIsAlphabetMode;
private KeyboardShiftState mAlphabetShiftState = new KeyboardShiftState(); private AlphabetShiftState mAlphabetShiftState = new AlphabetShiftState();
private boolean mIsSymbolShifted; private boolean mIsSymbolShifted;
private boolean mPrevMainKeyboardWasShiftLocked; private boolean mPrevMainKeyboardWasShiftLocked;
private boolean mPrevSymbolsKeyboardWasShifted; private boolean mPrevSymbolsKeyboardWasShifted;
@ -167,16 +167,16 @@ public class KeyboardState {
} }
if (!mIsAlphabetMode) return; if (!mIsAlphabetMode) return;
final int prevShiftMode; final int prevShiftMode;
if (mAlphabetShiftState.isAutomaticTemporaryUpperCase()) { if (mAlphabetShiftState.isAutomaticShifted()) {
prevShiftMode = AUTOMATIC_SHIFT; prevShiftMode = AUTOMATIC_SHIFT;
} else if (mAlphabetShiftState.isManualTemporaryUpperCase()) { } else if (mAlphabetShiftState.isManualShifted()) {
prevShiftMode = MANUAL_SHIFT; prevShiftMode = MANUAL_SHIFT;
} else { } else {
prevShiftMode = UNSHIFT; prevShiftMode = UNSHIFT;
} }
switch (shiftMode) { switch (shiftMode) {
case AUTOMATIC_SHIFT: case AUTOMATIC_SHIFT:
mAlphabetShiftState.setAutomaticTemporaryUpperCase(); mAlphabetShiftState.setAutomaticShifted();
if (shiftMode != prevShiftMode) { if (shiftMode != prevShiftMode) {
mSwitchActions.setAlphabetAutomaticShiftedKeyboard(); mSwitchActions.setAlphabetAutomaticShiftedKeyboard();
} }
@ -353,7 +353,7 @@ public class KeyboardState {
// caps lock state and mark as if shift key pressed while normal state. // caps lock state and mark as if shift key pressed while normal state.
setShifted(SHIFT_LOCK_SHIFTED); setShifted(SHIFT_LOCK_SHIFTED);
mShiftKeyState.onPress(); mShiftKeyState.onPress();
} else if (mAlphabetShiftState.isAutomaticTemporaryUpperCase()) { } else if (mAlphabetShiftState.isAutomaticShifted()) {
// Shift key is pressed while automatic temporary upper case, we have to move to // Shift key is pressed while automatic temporary upper case, we have to move to
// manual temporary upper case. // manual temporary upper case.
setShifted(MANUAL_SHIFT); setShifted(MANUAL_SHIFT);
@ -400,7 +400,7 @@ public class KeyboardState {
&& mShiftKeyState.isPressingOnShifted() && !withSliding) { && mShiftKeyState.isPressingOnShifted() && !withSliding) {
// Shift has been pressed without chording while shifted state. // Shift has been pressed without chording while shifted state.
setShifted(UNSHIFT); setShifted(UNSHIFT);
} else if (mAlphabetShiftState.isManualTemporaryUpperCaseFromAuto() } else if (mAlphabetShiftState.isManualShiftedFromAutomaticShifted()
&& mShiftKeyState.isPressing() && !withSliding) { && mShiftKeyState.isPressing() && !withSliding) {
// Shift has been pressed without chording while manual temporary upper case // Shift has been pressed without chording while manual temporary upper case
// transited from automatic temporary upper case. // transited from automatic temporary upper case.

View file

@ -1470,13 +1470,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (ic == null) if (ic == null)
return; return;
// True if keyboard is in either chording shift or manual temporary upper case mode. final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
final boolean isManualTemporaryUpperCase = mKeyboardSwitcher.isManualTemporaryUpperCase(); // True if keyboard is in either shift chording or manual shifted state.
if (EditorInfoCompatUtils.hasFlagNavigateNext(imeOptions) final boolean isManualShifted = (keyboard != null && keyboard.isManualShifted());
&& !isManualTemporaryUpperCase) { if (EditorInfoCompatUtils.hasFlagNavigateNext(imeOptions) && !isManualShifted) {
EditorInfoCompatUtils.performEditorActionNext(ic); EditorInfoCompatUtils.performEditorActionNext(ic);
} else if (EditorInfoCompatUtils.hasFlagNavigatePrevious(imeOptions) } else if (EditorInfoCompatUtils.hasFlagNavigatePrevious(imeOptions) && isManualShifted) {
&& isManualTemporaryUpperCase) {
EditorInfoCompatUtils.performEditorActionPrevious(ic); EditorInfoCompatUtils.performEditorActionPrevious(ic);
} }
} }
@ -1518,27 +1517,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mComposingStateManager.onFinishComposingText(); mComposingStateManager.onFinishComposingText();
} }
} }
final KeyboardSwitcher switcher = mKeyboardSwitcher;
if (switcher.isShiftedOrShiftLocked()) {
if (keyCodes == null || keyCodes[0] < Character.MIN_CODE_POINT
|| keyCodes[0] > Character.MAX_CODE_POINT) {
return;
}
code = keyCodes[0];
if (switcher.isAlphabetMode() && Character.isLowerCase(code)) {
// In some locales, such as Turkish, Character.toUpperCase() may return a wrong
// character because it doesn't take care of locale.
final String upperCaseString = new String(new int[] {code}, 0, 1)
.toUpperCase(mSubtypeSwitcher.getInputLocale());
if (upperCaseString.codePointCount(0, upperCaseString.length()) == 1) {
code = upperCaseString.codePointAt(0);
} else {
// Some keys, such as [eszett], have upper case as multi-characters.
onTextInput(upperCaseString);
return;
}
}
}
if (isComposingWord) { if (isComposingWord) {
mWordComposer.add(code, keyCodes, x, y); mWordComposer.add(code, keyCodes, x, y);
if (ic != null) { if (ic != null) {

View file

@ -140,11 +140,6 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel {
super.setKeyPreviewPopupEnabled(false, 0); super.setKeyPreviewPopupEnabled(false, 0);
} }
@Override
public void setShifted(boolean shifted) {
// Nothing to do with.
}
@Override @Override
public void showMoreKeysPanel(View parentView, Controller controller, int pointX, int pointY, public void showMoreKeysPanel(View parentView, Controller controller, int pointX, int pointY,
PopupWindow window, KeyboardActionListener listener) { PopupWindow window, KeyboardActionListener listener) {