Maro
Maro

Reputation: 1

create custom arabic keyboard for android

I want to create a custom keyboard in Android. I want to use this code from http://code.tutsplus.com/tutorials/create-a-custom-keyboard-on-android--cms-22615, but I'm facing a problem with Arabic ASCII codes because they are in two parts, and XML doesn't support that. I'm using this site to convert: http://www.asciitohex.com/.

For example, the ASCII code for 'ش' is '216 180', but I can't use that in XML.

Upvotes: 0

Views: 1191

Answers (1)

Amirali
Amirali

Reputation: 11

for arabic,persian ,etc (utf-8) character custom keyboards you should use you characeter in java class instead , the algorithm is find the keycode that is defined in xml and use they equal character in arabic with that,

as the tutorial above they code for "ش" character should look something like this:

public void onKey(int primaryCode, int[] keyCodes) {
    InputConnection ic = getCurrentInputConnection();
    playClick(primaryCode);
    switch (primaryCode) {
    case Keyboard.KEYCODE_DELETE:
        ic.deleteSurroundingText(1, 0);
        break;
    case Keyboard.KEYCODE_SHIFT:
        caps = !caps;
        keyboard.setShifted(caps);
        kv.invalidateAllKeys();
        break;
    case Keyboard.KEYCODE_DONE:
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
        break;
    default:
        char code = (char) primaryCode;
        if (Character.isLetter(code) && caps) {
            code = Character.toUpperCase(code);
        }
        if (code == 97) {
            ic.commitText(" ش",1);// your character

        } else {
            ic.commitText(String.valueOf(code), 1);
        }
    }
}

Upvotes: 1

Related Questions