Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android IME which accept unicode

While writing an Input method editor for android, what will i have to do to make it map accept some unicode character as input other than changing android:keyLabel (for example to make me map Malayalam character as input :0D00 - 0DFF)

  <Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
        android:horizontalGap="0px"
        android:keyHeight="@dimen/key_height"
        android:keyWidth="10%p"
        android:verticalGap="0px" >

        <Row>
            <Key
                android:codes="45"
                android:keyEdgeFlags="left"
                android:keyLabel="q"
                android:popupCharacters="@string/hello"
                android:popupKeyboard="@xml/qwerty"/>
            <Key
                android:codes="51"
                android:keyLabel="w" />
            <Key
                android:codes="33"
                android:keyLabel="e" />
            <Key
                android:codes="46"
                android:keyLabel="r" />
            <Key
                android:codes="48"
                android:keyLabel="t" />
            <Key
                android:codes="53"
                android:keyLabel="y" />
            <Key
                android:codes="49"
                android:keyLabel="u" />
            <Key
                android:codes="37"
                android:keyLabel="i" />
            <Key
                android:codes="43"
                android:keyLabel="o" />
            <Key
                android:codes="44"
                android:keyEdgeFlags="right"
                android:keyLabel="p" />
        </Row>
        <Row>
            <Key
                android:codes="29"
                android:horizontalGap="5%p"
                android:keyEdgeFlags="left"
                android:keyLabel="a" />
            <Key
                android:codes="47"
                android:keyLabel="s" />
            <Key
                android:codes="32"
                android:keyLabel="d" />
            <Key
                android:codes="34"
                android:keyLabel="f" />
            <Key
                android:codes="35"
                android:keyLabel="g" />
            <Key
                android:codes="36"
                android:keyLabel="h" />

            <Key
                android:codes="38"
                android:keyLabel="J" />
            <Key
                android:codes="49"
                android:keyLabel="K" />

            <Key
                android:codes="40"
                android:keyEdgeFlags="right"
                android:keyLabel="l" />
        </Row>
        <Row>
            <Key
                android:codes="60"            
                android:keyEdgeFlags="left"
                android:keyIcon="@drawable/sym_keyboard_shift"
                android:iconPreview="@drawable/sym_keyboard_shift"
                android:isModifier="true"
                android:isSticky="true"
                android:keyWidth="15%p"
                android:keyLabel="shift" />
            <Key
                android:codes="54"
                android:keyLabel="z" />
            <Key
                android:codes="52"
                android:keyLabel="x" />
            <Key
                android:codes="31"
                android:keyLabel="c" />
            <Key
                android:codes="50"
                android:keyLabel="v" />
            <Key
                android:codes="30"
                android:keyLabel="b" />
            <Key
                android:codes="42"
                android:keyLabel="n" />
            <Key
                android:codes="41"
                android:keyLabel="m" />
            <Key
                android:codes="67"
                android:isRepeatable="true"
                android:keyEdgeFlags="right"
                android:keyIcon="@drawable/sym_keyboard_delete"
                android:keyWidth="15%p" />
        </Row>
        <Row android:rowEdgeFlags="bottom" >
            <Key
                android:codes="-3"
                android:keyEdgeFlags="left"
                android:keyIcon="@drawable/sym_keyboard_done"
                android:keyWidth="20%p" />
            <Key
                android:codes="-2"
                android:keyLabel="123"
                android:keyWidth="15%p" />
            <Key
                android:codes="62"
                android:isRepeatable="true"
                android:keyIcon="@drawable/sym_keyboard_space"
                android:keyWidth="30%p" />
            <Key
                android:codes="46,55"
                android:keyLabel=". ,"
                android:keyWidth="15%p" />
            <Key
                android:codes="10"
                android:keyEdgeFlags="right"
                android:keyIcon="@drawable/sym_keyboard_return"
                android:keyWidth="20%p" />
        </Row>

    </Keyboard>
like image 688
Akhilan Avatar asked Nov 03 '22 05:11

Akhilan


1 Answers

I know this is an old question, but I haven't found the answer when I needed it so I will provide one here for others who may look for it.

According to the documentation: the Keyboard.Key's (android.inputmethodservice.Keyboard.Key) android:codes xml attribute is:

The unicode value or comma-separated values that this key outputs.

May be a string value, using '\;' to escape characters such as '\n' or '\uxxxx' for a unicode character; May be an integer value, such as "100".

I couldn't figure out how to make it work with using '\;' but you can either:

  • (1) use the decimal unicode value, which you can look up, for example here: http://unicodelookup.com/#%090xD05/1 e.g. 3333 for U+0D05

or

  • (2) instead of escaping with '\;' specify the 0x prefix e.g. 0x0D05

Examples for the character അ Malayalam Letter A U+0D05:

(1)

<Key android:codes="3333" android:keyLabel="\u0D05"/>

(2)

<Key android:codes="0x0D05" android:keyLabel="\u0D05"/>
like image 78
kalnar Avatar answered Nov 11 '22 10:11

kalnar