private SoftKeyboard getKeyboard(KeyboardId id) {
    SoftReference<SoftKeyboard> ref = mKeyboards.get(id);
    SoftKeyboard keyboard = (ref == null) ? null : ref.get();
    if (keyboard == null) {
      Resources orig = mInputMethodService.getResources();
      Configuration conf = orig.getConfiguration();
      Locale saveLocale = conf.locale;
      conf.locale = mInputLocale;
      orig.updateConfiguration(conf, null);
      if (mThemedContext != null) {
        keyboard = new SoftKeyboard(mThemedContext, id.mXml, id.mKeyboardMode, mThemeResId);
      } else {
        keyboard = new SoftKeyboard(mInputMethodService, id.mXml, id.mKeyboardMode);
      }
      keyboard.setLanguageSwitcher(
          mLanguageSwitcher,
          mIsAutoCompletionActive,
          mInputView.getLanguagebarTextColor(),
          mInputView.getLanguagebarShadowColor(),
          mLanguageSwitchMode);

      if (id.mEnableShiftLock) {
        keyboard.enableShiftLock();
      }
      mKeyboards.put(id, new SoftReference<SoftKeyboard>(keyboard));

      conf.locale = saveLocale;
      orig.updateConfiguration(conf, null);
    }
    return keyboard;
  }
 public void toggleShift() {
   if (isAlphabetMode()) return;
   if (mCurrentId.equals(mSymbolsId) || !mCurrentId.equals(mSymbolsShiftedId)) {
     SoftKeyboard symbolsShiftedKeyboard = getKeyboard(mSymbolsShiftedId);
     mCurrentId = mSymbolsShiftedId;
     mInputView.setKeyboard(symbolsShiftedKeyboard);
     // Symbol shifted keyboard has an ALT key that has a caps lock style indicator. To
     // enable the indicator, we need to call enableShiftLock() and setShiftLocked(true).
     // Thus we can keep the ALT key's Key.on value true while LatinKey.onRelease() is
     // called.
     symbolsShiftedKeyboard.enableShiftLock();
     symbolsShiftedKeyboard.setShiftLocked(true);
     symbolsShiftedKeyboard.setImeOptions(mInputMethodService.getResources(), mMode, mImeOptions);
   } else {
     SoftKeyboard symbolsKeyboard = getKeyboard(mSymbolsId);
     mCurrentId = mSymbolsId;
     mInputView.setKeyboard(symbolsKeyboard);
     // Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the
     // indicator, we need to call enableShiftLock() and setShiftLocked(false).
     symbolsKeyboard.enableShiftLock();
     symbolsKeyboard.setShifted(false);
     symbolsKeyboard.setImeOptions(mInputMethodService.getResources(), mMode, mImeOptions);
   }
 }