Android custom keyboard orientation character / qwerty

I am using android softkeyboard sample as a training project. I added a second language and everything works for me so far. However, one of the problems was difficult to solve. When changing device orientation from portrait to landscape, I would like the keyboard layout to be enabled. logics:

 // on orientation or configuration change
if (currentKeyboard==mQwertyKeyboard) {
          // keep as is
            mCurKeyboard = mQwertyKeyboard ;   
 }else if (currentKeyboard == mSymbolsKeyboard) {
          // keep as is
            mCurKeyboard = mSymbolsKeyboard;
}else if (currentKeyboard == mSymbolsShiftedKeyboard) {
          // keep as is
            mCurKeyboard = mSymbolsShiftedKeyboard ; 
 }

      

I tried to implement this in:

@Override
public void onConfigurationChanged(Configuration newConfig) {...}

      

inside Softkeyboard.java, but not completely. Thanks in advance.

+3


source to share


1 answer


I had the same problem - I solved it with onConfigurationChanged(Configuration newConfig)

and a little side coding

If removed, my code will change orientation, but my keyboard will not change. Since I like the parent's repartition function, I created an array containing all the keyboards, and after changing the orientation, I would update the array so that the keyboard array is sized as needed.



@Override
public void onConfigurationChanged(Configuration newConfig) {

    int currentKeyboard = 0;
    boolean isShifted = kv.isShifted();
    for (int i = 0; i < keyboard.length; i++) {
        if(kv.getKeyboard().equals(keyboard[i])){
            currentKeyboard = i;
            break;
        }
    }

    super.onConfigurationChanged(newConfig);

    initializeKeyboardArray();
    setKeyboard(keyboard[currentKeyboard]);
    kv.setShifted(isShifted);

}

private void initializeKeyboardArray(){
    keyboard = new Keyboard[7];
    keyboard[ARABIC] = arabic;
    keyboard[ARABIC_SHIFT] = arabicShift;
    keyboard[ARABIC_SYMBOLS] = arabicSymbols;
    keyboard[ARABIC_SYMBOLS_SHIFT] = arabicSymbolsShift;
    keyboard[QWERTY] = qwerty;
    keyboard[QWERTY_SYMBOLS] = qwertySymbols;
    keyboard[QWERTY_SYMBOLS_SHIFT] = qwertySymbolsShift;
}

      

0


source







All Articles