weimingtom / nekonme

Automatically exported from code.google.com/p/nekonme
0 stars 0 forks source link

Non-ASCII character input (from soft keyboard) in Android #279

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create minimal NME app:

package ;
import nme.text.TextFormat;
import nme.text.TextField;
import nme.text.TextFieldType;
import nme.display.Sprite;

class TestMain extends Sprite {
    public function new() {
        super();
        var _tf = new TextField( );
        _tf.height = 100;
        _tf.border = true;
        _tf.selectable = true;
        _tf.type = TextFieldType.INPUT;
        _tf.defaultTextFormat = new TextFormat("_sans", 14);
        _tf.text = "Test";

        addChild(_tf);
    }
}

2. Compile and run app on android device.

3. Click on textField and try enter non-ASCII characters from standard system 
software keyboard. 
For example, I tried to enter cyrillic characters (Russian layout).

What is the expected output? What do you see instead?
When I enter English characters, textField changing. But, when I enter Russian 
characters has no effect. 

What version of the product are you using? On what operating system?
NME versions: 3.4.3, 3.4.4beta. 
NME running on linux ubuntu 12.10.
Android version: 2.3.7 cyanogenmod 7-20121028
Android Device: LG Optimus One P500

Please provide any additional information below.
Solution was discussed here: 
http://www.haxenme.org/community/forums/general-discussion/patch-for-non-ascii-c
haracter-input-from-soft-keyboard-in-androi/
Patch from user @rocks works correct with Russsian layout.
Adding emulation onKeyChange and onKeyChange based on onKeyMultiple handler in 
MainView.java fix this problem:

    @Override
    public boolean onKeyMultiple(final int inKeyCode, int repeatCount, KeyEvent event) {
        String s = event.getCharacters();
        if (s == null || s.length() == 0) return super.onKeyMultiple(inKeyCode, repeatCount, event);
        final char[] cc = s.toCharArray();
        int cnt = 0;
        for (int i = cc.length; --i >= 0; cnt += cc[i] != 0 ? 1 : 0);
        if (cnt == 0) return super.onKeyMultiple(inKeyCode, repeatCount, event);
        final MainView me = this;
        queueEvent(new Runnable() {
            // This method will be called on the rendering thread:
            public void run() {
                for (int i = 0, n = cc.length; i < n; i++) {
                    int keyCode;
                    if ((keyCode = cc[i]) != 0) {
                        // Simulate key down and up...
                        me.HandleResult(NME.onKeyChange(keyCode, true));
                        me.HandleResult(NME.onKeyChange(keyCode, false));
                    }
                }
            }
        });
        return true;
    }

Original issue reported on code.google.com by Nitro.bin on 5 Dec 2012 at 3:30

GoogleCodeExporter commented 8 years ago
Linux and flash target has not this problem. 
I attached minimal NME app sources to this comment.

Original comment by Nitro.bin on 5 Dec 2012 at 3:35

Attachments: