2
votes

Ive been banging my head on this for a while now. hopefully someone who understands kivy/and or android better than me will be able to answer my question(kivy allows you to compile python for android and includes some nice UI stuff)

I have created my own kivy vkeyboard layout json file and it works fine in windows with the simulator. but when I install it onto the device it never uses my custom keyboard.

I think it is because I am not putting the .json file in the right place on the device (but really I have no Idea)

my code is below

appname.kv

...
<NumericVKeyboard>:
    layout: "numeric"
    size: (700,70)

<more rules>...

then I am using it in a widget class I created

from kivy.uix.textinput import TextInput
class NumericTextInput(TextInput):
    def on_focus(self, instance, value, *largs):
        win = self.get_root_window()

        if win:
            win.release_all_keyboards()
            win._keyboards = {}

            if value: #User focus; use special keyboard
                win.set_vkeyboard_class(NumericVKeyboard)
                print "NumericVKeyboard:", win._vkeyboard_cls, VKeyboard.layout_path
            else: #User defocus; switch back to standard keyboard
                win.set_vkeyboard_class(VKeyboard)
                print "VKeyboard:", win._vkeyboard_cls, VKeyboard.layout_path

        return TextInput.on_focus(self, instance, value, *largs)

every thing works fine on windows and it correctly uses the NumericVKeyboard. but when I build the apk and put it on a device it just uses the default keyboard instead of my custom keyboard

if it helps this is the message from adb logcat

<snip>
I/python  ( 1261): NumericVKeyboard: <class 'base.NumericVKeyboard'> <kivy.properties.StringProperty object at 0x5d4db1f0>

I/LatinIME(  284): InputType.TYPE_NULL is specified

W/LatinIME(  284): Unexpected input class: inputType=0x00000000 imeOptions=0x00000000
</snip>

please help ... im getting close to deperate enough to write my own "keyboard" widget. but I would really really like to use kivy's vkeyboard

1

1 Answers

2
votes

Well Im not sure why it took me so long to figure out. but the trick was two fold and totally obvious on hindsight ...

I had to add the keyboard_mode=dock to the Config.ini file for kivy.

I had to have my numeric.json layout in my assets directory.

In the end it was not that hard. I just struggled with getting it to work for some reason.