Finally I solved it with a trick.
Inserted a custom keycode from 900 to 908 into the row which contains my accented characters.
<Row android:keyHeight="16%">
<Key android:codes="900" android:keyLabel="?" android:keyEdgeFlags="left"/>
<Key android:codes="901" android:keyLabel="?"/>
<Key android:codes="902" android:keyLabel="ü"/>
<Key android:codes="903" android:keyLabel="?"/>
<Key android:codes="904" android:keyLabel="ó"/>
<Key android:codes="905" android:keyLabel="ú"/>
<Key android:codes="906" android:keyLabel="á"/>
<Key android:codes="907" android:keyLabel="é"/>
<Key android:codes="908" android:keyLabel="í" android:keyEdgeFlags="right"/>
</Row>
Where i set my KeyboardView's Action Listener i am passing the target EditText as an object to my OnKeyboardActionListener.
This way in my onKey method of my OnKeyboardActionListener i can check if the primaryCode is greater than 900 or equals to it, so then i just simply set the text of the EditText and insert my accented character to the cursor position:
@Override
public void onKey(int primaryCode, int[] keyCodes) {
if(primaryCode >= 900) {
String character = null;
switch(keyCode) {
case 900:
character = "?";
break;
case 901:
character = "?";
break;
case 902:
character = "ü";
break;
case 903:
character = "?";
break;
case 904:
character = "ó";
break;
case 905:
character = "ú";
break;
case 906:
character = "á";
break;
case 907:
character = "é";
break;
case 908:
character = "í";
break;
default:
return;
}
int start = mTargetView.getSelectionStart();
int end = mTargetView.getSelectionEnd();
mTargetView.getText().replace(Math.min(start, end), Math.max(start, end), character, 0, character.length());
} else {
long eventTime = System.currentTimeMillis();
KeyEvent event = new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN, primaryCode, 0, 0, 0, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);
mTargetActivity.dispatchKeyEvent(event);
}
}
Where mTargetView is my EditText. With this trick i could insert accented unicode characters and basically everything into an EditText with the standard keyboard xml mapping.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…