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));
  }
 public void onAutoCompletionStateChanged(boolean isAutoCompletion) {
   if (isAutoCompletion != mIsAutoCompletionActive) {
     SoftKeyboardView keyboardView = getInputView();
     mIsAutoCompletionActive = isAutoCompletion;
     keyboardView.invalidateKey(
         ((SoftKeyboard) keyboardView.getKeyboard())
             .onAutoCompletionStateChanged(isAutoCompletion));
   }
 }
  @SuppressLint("InflateParams")
  private void changeSoftKeyboardView(int newLayout, boolean forceReset) {
    if (mLayoutId != newLayout || mInputView == null || forceReset) {
      if (mInputView != null) {
        mInputView.closing();
      }
      /*if (THEMES.length <= newLayout) {
          newLayout = Integer.valueOf(DEFAULT_LAYOUT_ID);
      }*/

      mThemeResId = KeyboardTheme.getThemeResId(newLayout);
      mThemedContext = new ContextThemeWrapper(mInputMethodService, mThemeResId);

      IMEUtil.GCUtils.getInstance().reset();
      boolean tryGC = true;
      for (int i = 0; i < IMEUtil.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
        try {
          // mInputView = (SoftKeyboardView)
          // mInputMethodService.getLayoutInflater().inflate(THEMES[newLayout], null);
          mInputView =
              (SoftKeyboardView)
                  LayoutInflater.from(mThemedContext).inflate(R.layout.input_view, null);
          tryGC = false;
        } catch (OutOfMemoryError e) {
          tryGC = IMEUtil.GCUtils.getInstance().tryGCOrWait(mLayoutId + "," + newLayout, e);
        } catch (InflateException e) {
          tryGC = IMEUtil.GCUtils.getInstance().tryGCOrWait(mLayoutId + "," + newLayout, e);
        }
      }

      mInputView.setStyle(mThemedContext, mThemeResId, mKeyboardBackgroundColor);
      mInputView.setAutoHideMiniKeyboard(mAutoHideMiniKeyboard);
      mInputView.setOnKeyboardActionListener(mInputMethodService);
      mLayoutId = newLayout;
    }
    mInputMethodService.mHandler.post(
        new Runnable() {
          public void run() {
            if (mInputView != null) {
              mInputMethodService.setInputView(mInputView);
            }
            mInputMethodService.updateInputViewShown();
          }
        });
  }
 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);
   }
 }
 public boolean hasDistinctMultitouch() {
   return mInputView != null && mInputView.hasDistinctMultitouch();
 }
 public void setShiftLocked(boolean shiftLocked) {
   if (mInputView != null) {
     mInputView.setShiftLocked(shiftLocked);
   }
 }