private void initInternal(final LatinIME latinIme, final SharedPreferences prefs) {
   mLatinIME = latinIme;
   mResources = latinIme.getResources();
   mPrefs = prefs;
   mSubtypeSwitcher = SubtypeSwitcher.getInstance();
   mState = new KeyboardState(this);
   setContextThemeWrapper(latinIme, getKeyboardTheme(latinIme, prefs));
 }
 private void setKeyboard(final Keyboard keyboard) {
   // Make {@link MainKeyboardView} visible and hide {@link EmojiPalettesView}.
   setMainKeyboardFrame();
   final MainKeyboardView keyboardView = mKeyboardView;
   final Keyboard oldKeyboard = keyboardView.getKeyboard();
   keyboardView.setKeyboard(keyboard);
   mCurrentInputView.setKeyboardGeometry(keyboard.mTopPadding);
   keyboardView.setKeyPreviewPopupEnabled(
       Settings.readKeyPreviewPopupEnabled(mPrefs, mResources),
       Settings.readKeyPreviewPopupDismissDelay(mPrefs, mResources));
   keyboardView.updateAutoCorrectionState(mIsAutoCorrectionActive);
   keyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
   final boolean subtypeChanged =
       (oldKeyboard == null) || !keyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale);
   final boolean needsToDisplayLanguage =
       mSubtypeSwitcher.needsToDisplayLanguage(keyboard.mId.mLocale);
   keyboardView.startDisplayLanguageOnSpacebar(
       subtypeChanged,
       needsToDisplayLanguage,
       RichInputMethodManager.getInstance().hasMultipleEnabledIMEsOrSubtypes(true));
 }
 public void loadKeyboard(final EditorInfo editorInfo, final SettingsValues settingsValues) {
   final KeyboardLayoutSet.Builder builder =
       new KeyboardLayoutSet.Builder(mThemeContext, editorInfo);
   final Resources res = mThemeContext.getResources();
   final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
   final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
   builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
   builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
   builder.setOptions(
       settingsValues.isVoiceKeyEnabled(editorInfo),
       true /* always show a voice key on the main keyboard */,
       settingsValues.isLanguageSwitchKeyEnabled());
   mKeyboardLayoutSet = builder.build();
   try {
     mState.onLoadKeyboard();
   } catch (KeyboardLayoutSetException e) {
     Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause());
     LatinImeLogger.logOnException(e.mKeyboardId.toString(), e.getCause());
     return;
   }
 }
 public void onNetworkStateChanged() {
   if (mKeyboardView != null) {
     mKeyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
   }
 }