Selection using Android IME -


in input method service trying select text before current cursor position. following code snippet

            inputconnection inputconnection = getcurrentinputconnection();             extractedtext extractedtext = inputconnection.getextractedtext(new extractedtextrequest(), 0);             inputconnection.setselection(extractedtext.selectionstart-1,extractedtext.selectionend);              inputmethodmanager inputmethodmanager = (inputmethodmanager) getsystemservice(context.input_method_service);             inputmethodmanager.updateselection(null, extractedtext.selectionstart-1,extractedtext.selectionend, 0, 0); 

this has flaky behaviour, selects, moves cursor 1 step back.

can point out doing wrong?

addition:

since question has remained unanswered time, pose alternate question. looking around alternate ways of selecting text , on hackers-keyboard, pressing shift , arrow key trick, not able replicate process. tried sending d-pad keys down , key-events along meta_shift_on flag.

but not working... again, doing wrong?

i solved problem using shift+arrow keys.

1 --> requesting "inputconnection" each event. have started using 1 instance of inputconnection request on hook "onbindinput" , use all. 2 --> sending meta_shift_on flag along dpad_left/right/whatever not enough, send press down shift event, dpad up-down, , shift event. following pseudo-code:    private void moveselection(int dpad_keycode) {    inputmethodservice.senddownkeyevent(keyevent.keycode_shift_left, 0); inputmethodservice.senddownandupkeyevent(dpad_keycode, 0); inputmethodservice.sendupkeyevent(keyevent.keycode_shift_left, 0); } 

and took.

note: solution more or less hack , still looking better solution allows me switch anchor of selection. if know better, please share.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -