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;
  }
  private void setKeyboardMode(int mode, int imeOptions, boolean isSymbols) {
    if (mInputView == null) return;
    mMode = mode;
    mImeOptions = imeOptions;
    mIsSymbols = isSymbols;

    mInputView.setTextSizeScale(mInputMethodService.getKeyTextSizeScale());
    mInputView.setPreviewEnabled(mInputMethodService.getPopupOn());
    KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols);
    SoftKeyboard keyboard = null;
    keyboard = getKeyboard(id);

    mCurrentId = id;
    mInputView.setKeyboard(keyboard);
    keyboard.setShifted(false);
    keyboard.setShiftLocked(keyboard.isShiftLocked());
    keyboard.setImeOptions(mInputMethodService.getResources(), mMode, imeOptions);
    keyboard.setColorOfSymbolIcons(
        mIsAutoCompletionActive,
        mInputView.getLanguagebarTextColor(),
        mInputView.getLanguagebarShadowColor());
    // Update the settings key state because number of enabled IMEs could have been changed
    updateSettingsKeyState(PreferenceManager.getDefaultSharedPreferences(mInputMethodService));
    updateLanguageKeyState(PreferenceManager.getDefaultSharedPreferences(mInputMethodService));
  }