0

I am trying to allow the user to switch between keyboards, such as switching from Qwerty to a smiley keyboard. I am having trouble with understanding the concept of how users are able to switch from Qwerty to emoticons by the use of the shift or on iPhones by the globe button. I'm confused on how to code the actual "switch". I found the below code in the softkeyboard SDK sample and I'm wondering if this is how the switch takes place.

private void handleShift() {
        if (mInputView == null) {
            return;
        }

        Keyboard currentKeyboard = mInputView.getKeyboard();
        if (mQwertyKeyboard == currentKeyboard) {
            // Alphabet keyboard
            checkToggleCapsLock();
            mInputView.setShifted(mCapsLock || !mInputView.isShifted());
        } else if (currentKeyboard == mSymbolsKeyboard) {
            mSymbolsKeyboard.setShifted(true);
            mInputView.setKeyboard(mSymbolsShiftedKeyboard);
            mSymbolsShiftedKeyboard.setShifted(true);
        } else if (currentKeyboard == mSymbolsShiftedKeyboard) {
            mSymbolsShiftedKeyboard.setShifted(false);
            mInputView.setKeyboard(mSymbolsKeyboard);
            mSymbolsKeyboard.setShifted(false);
        }
    }

Again I am trying to initialize a switch that allow the users to press the shift button and switch to emoticons and once selected switch back to qwerty to send...

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Victoria C
  • 37
  • 6
  • could the problem be that you are comparing with `==` instead of `.equals()`? `==` will see if the two represent the same variable in memory, while `equals()` will determine if the two are equivalent. – gobernador Apr 10 '12 at 02:05
  • hmmmm....well Im not sure how this code works..this is from the SDK sample I didnt modify it...I was trying to see where that actual switch takes place for instance when users want to add a smiley they press a smiley or shift keyto choose the smiley and they after they are able to return to the qwerty keyboard – Victoria C Apr 10 '12 at 03:03
  • I am doing something similar HERE!!! http://stackoverflow.com/questions/16768930/implementations-of-emoji-emoticon-view-keyboard-layouts – Etienne Lawlor May 27 '13 at 17:03

1 Answers1

0

The sample soft keyboard is coded to changed from the symbols keyboard to the symbols-shifted keyboard whenever the shift key is pressed. To add your emoticon keyboard layout to the rotation, change the posted code to the following:

private void handleShift() {
    if (mInputView == null) {
        return;
    }

    Keyboard currentKeyboard = mInputView.getKeyboard();
    if (mQwertyKeyboard == currentKeyboard) {
        // Alphabet keyboard
        checkToggleCapsLock();
        mInputView.setShifted(mCapsLock || !mInputView.isShifted());
    } else if (currentKeyboard == mSymbolsKeyboard) {
        mSymbolsKeyboard.setShifted(true);
        mInputView.setKeyboard(mSymbolsShiftedKeyboard);
        mSymbolsShiftedKeyboard.setShifted(true);
    } else if (currentKeyboard == mSymbolsShiftedKeyboard) {
        mSymbolsShiftedKeyboard.setShifted(false);
        mInputView.setKeyboard(mEmoticonKeyboard);
        mSymbolsKeyboard.setShifted(false);
    } else if (currentKeyboard == mEmoticonKeyboard) {
        mInputView.setKeyboard(mSymbolsKeyboard);
    }

}
lrAndroid
  • 2,834
  • 18
  • 27