I have created a Custom Keyboard using the Android Keyboard Class.
I want to have Rows for two modes. One is the normal mode. And one is when the user presses the \"Sym
Ok figured it out myself.
There is no method to simply switch the keyboard modes. What you have to do is create 2 different keyboards and switch between them manually.
Here is what the updated XML looks like. NOTE that Rows that you want in both the keywords should not include the flag android:keyboardMode.
Then create a integer.xml
1
0
Here is the relevant java code. When you create the Keyboard object you pass the keyboard_normal or keyboard_symbol.
normalKeyBoard = new Keyboard(activity, R.id.board, R.integer.keyboard_normal);
symbolKeyBoard = new Keyboard(activity, R.id.board, R.integer.keyboard_symbol);
Now create a class variable to keep track of the mode. Default value is R.integer.keyboard_normal
private int mKeyboardState = R.integer.keyboard_normal;
Now in your onKeyboardActionListner().onKey method put the code to capture the key that switches the modes (assuming that you have created one in your keyboard).
if( primaryCode== Keyboard.KEYCODE_MODE_CHANGE) {
if(mKeyboardView != null) {
if(mKeyboardState == R.integer.keyboard_normal){
//change to symbol keyboard
if(symbolKeyBoard== null){
symbolKeyBoard = new Keyboard(mHostActivity, R.xml.hexkbd, R.integer.keyboard_symbol);
}
mKeyboardView.setKeyboard(symbolKeyBoard);
mKeyboardState = R.integer.keyboard_symbol;
} else {
if(normalKeyBoard== null){
normalKeyBoard = new Keyboard(mHostActivity, R.xml.hexkbd, R.integer.keyboard_normal);
}
mKeyboardView.setKeyboard(normalKeyBoard);
mKeyboardState = R.integer.keyboard_normal;
}
//no shifting
mKeyboardView.setShifted(false);
}
}