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));
  }
  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;
  }
Exemplo n.º 3
0
  private void switchToTargetIME(
      final String imiId, final InputMethodSubtypeCompatWrapper subtype) {
    final IBinder token = mService.getWindow().getWindow().getAttributes().token;
    if (token == null) {
      return;
    }
    new AsyncTask<Void, Void, Void>() {
      @Override
      protected Void doInBackground(Void... params) {
        mImm.setInputMethodAndSubtype(token, imiId, subtype);
        return null;
      }

      @Override
      protected void onPostExecute(Void result) {
        // Calls in this method need to be done in the same thread as the thread which
        // called switchToShortcutIME().

        // Notify an event that the current subtype was changed. This event will be
        // handled if "onCurrentInputMethodSubtypeChanged" can't be implemented
        // when the API level is 10 or previous.
        mService.notifyOnCurrentInputMethodSubtypeChanged(subtype);
      }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
  }
 public AudioAndHapticFeedbackManager(
     final LatinIME latinIme, final SettingsValues settingsValues) {
   mSettingsValues = settingsValues;
   mVibratorUtils = VibratorUtils.getInstance(latinIme);
   mAudioManager = (AudioManager) latinIme.getSystemService(Context.AUDIO_SERVICE);
   mSoundOn = reevaluateIfSoundIsOn();
 }
 private void updateAutoHideMiniKeyboardState(SharedPreferences prefs) {
   Resources resources = mInputMethodService.getResources();
   mAutoHideMiniKeyboard =
       prefs.getBoolean(
           IMESettings.PREF_AUTO_HIDE_MINIKEYBOARD,
           resources.getBoolean(R.bool.default_auto_hide_minikeyboard));
 }
Exemplo n.º 6
0
 private Drawable getSubtypeIcon(
     InputMethodInfoCompatWrapper imi, InputMethodSubtypeCompatWrapper subtype) {
   final PackageManager pm = mService.getPackageManager();
   if (imi != null) {
     final String imiPackageName = imi.getPackageName();
     if (DBG) {
       Log.d(
           TAG,
           "Update icons of IME: "
               + imiPackageName
               + ","
               + getSubtypeLocale(subtype)
               + ","
               + subtype.getMode());
     }
     if (subtype != null) {
       return pm.getDrawable(
           imiPackageName, subtype.getIconResId(), imi.getServiceInfo().applicationInfo);
     } else if (imi.getSubtypeCount() > 0 && imi.getSubtypeAt(0) != null) {
       return pm.getDrawable(
           imiPackageName,
           imi.getSubtypeAt(0).getIconResId(),
           imi.getServiceInfo().applicationInfo);
     } else {
       try {
         return pm.getApplicationInfo(imiPackageName, 0).loadIcon(pm);
       } catch (PackageManager.NameNotFoundException e) {
         Log.w(TAG, "IME can't be found: " + imiPackageName);
       }
     }
   }
   return null;
 }
 private void updateLanguageKeyState(SharedPreferences prefs) {
   Resources resources = mInputMethodService.getResources();
   mLanguageSwitchMode =
       Integer.valueOf(
           prefs.getString(
               IMESettings.PREF_LANGUAGE_KEY,
               resources.getString(R.string.default_language_key_mode)));
 }
 private void updateExtendedRowState(SharedPreferences prefs) {
   Resources resources = mInputMethodService.getResources();
   mShowExtendedRow =
       Integer.valueOf(
           prefs.getString(
               IMESettings.PREF_EXTENDED_ROW,
               resources.getString(R.string.enabled_extened_row_default_value)));
 }
Exemplo n.º 9
0
  private void initialize(LatinIME service) {
    mService = service;
    mResources = service.getResources();
    mImm = InputMethodManagerCompatWrapper.getInstance();
    mConnectivityManager =
        (ConnectivityManager) service.getSystemService(Context.CONNECTIVITY_SERVICE);
    mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
    mEnabledLanguagesOfCurrentInputMethod.clear();
    mSystemLocale = null;
    mInputLocale = null;
    mInputLocaleStr = null;
    mCurrentSubtype = null;
    mAllEnabledSubtypesOfCurrentInputMethod = null;
    mVoiceInputWrapper = null;

    final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
    mIsNetworkConnected = (info != null && info.isConnected());
  }
  public void makeKeyboards(boolean forceCreate) {
    mSymbolsId = makeSymbolsId(getKeyboardSymbolRowsResId());
    mSymbolsShiftedId = makeSymbolsId(getKeyboardSymbolShiftRowsResId());

    if (forceCreate) mKeyboards.clear();
    // Configuration change is coming after the keyboard gets recreated. So don't rely on that.
    // If keyboards have already been made, check if we have a screen width change and
    // create the keyboard layouts again at the correct orientation
    int displayWidth = mInputMethodService.getMaxWidth();
    if (displayWidth == mLastDisplayWidth) return;
    mLastDisplayWidth = displayWidth;
    if (!forceCreate) mKeyboards.clear();
  }
 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 isShowExtendedRow() {
   if (mInputMethodService == null) {
     return false;
   }
   int orientation = mInputMethodService.getOrientation();
   switch (mShowExtendedRow) {
     case EXTENDED_ROW_SHOW_PORTRAIT:
       return (orientation != Configuration.ORIENTATION_LANDSCAPE);
     case EXTENDED_ROW_HIDE:
       return false;
     case EXTENDED_ROW_SHOW:
     default:
       return true;
   }
 }
  /** Pair will be added to the userbigram database. */
  public int addBigrams(String word1, String word2) {
    // remove caps
    if (mIme != null && mIme.getCurrentWord().isAutoCapitalized()) {
      word2 = Character.toLowerCase(word2.charAt(0)) + word2.substring(1);
    }

    int freq = super.addBigram(word1, word2, FREQUENCY_FOR_TYPED);
    if (freq > FREQUENCY_MAX) freq = FREQUENCY_MAX;
    synchronized (mPendingWritesLock) {
      if (freq == FREQUENCY_FOR_TYPED || mPendingWrites.isEmpty()) {
        mPendingWrites.add(new Bigram(word1, word2, freq));
      } else {
        Bigram bi = new Bigram(word1, word2, freq);
        mPendingWrites.remove(bi);
        mPendingWrites.add(bi);
      }
    }

    return freq;
  }
Exemplo n.º 14
0
  // Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
  public void updateSubtype(InputMethodSubtypeCompatWrapper newSubtype) {
    final String newLocale;
    final String newMode;
    final String oldMode = getCurrentSubtypeMode();
    if (newSubtype == null) {
      // Normally, newSubtype shouldn't be null. But just in case newSubtype was null,
      // fallback to the default locale.
      Log.w(TAG, "Couldn't get the current subtype.");
      newLocale = "en_US";
      newMode = KEYBOARD_MODE;
    } else {
      newLocale = getSubtypeLocale(newSubtype);
      newMode = newSubtype.getMode();
    }
    if (DBG) {
      Log.w(
          TAG,
          "Update subtype to:"
              + newLocale
              + ","
              + newMode
              + ", from: "
              + mInputLocaleStr
              + ", "
              + oldMode);
    }
    boolean languageChanged = false;
    if (!newLocale.equals(mInputLocaleStr)) {
      if (mInputLocaleStr != null) {
        languageChanged = true;
      }
      updateInputLocale(newLocale);
    }
    boolean modeChanged = false;
    if (!newMode.equals(oldMode)) {
      if (oldMode != null) {
        modeChanged = true;
      }
    }
    mCurrentSubtype = newSubtype;

    // If the old mode is voice input, we need to reset or cancel its status.
    // We cancel its status when we change mode, while we reset otherwise.
    if (isKeyboardMode()) {
      if (modeChanged) {
        if (VOICE_MODE.equals(oldMode) && mVoiceInputWrapper != null) {
          mVoiceInputWrapper.cancel();
        }
      }
      if (modeChanged || languageChanged) {
        updateShortcutIME();
        mService.onRefreshKeyboard();
      }
    } else if (isVoiceMode() && mVoiceInputWrapper != null) {
      if (VOICE_MODE.equals(oldMode)) {
        mVoiceInputWrapper.reset();
      }
      // If needsToShowWarningDialog is true, voice input need to show warning before
      // show recognition view.
      if (languageChanged || modeChanged || VoiceProxy.getInstance().needsToShowWarningDialog()) {
        triggerVoiceIME();
      }
    } else {
      if (VOICE_MODE.equals(oldMode) && mVoiceInputWrapper != null) {
        // We need to reset the voice input to release the resources and to reset its status
        // as it is not the current input mode.
        mVoiceInputWrapper.reset();
      }
      final String packageName = mService.getPackageName();
      int version = -1;
      try {
        version = mService.getPackageManager().getPackageInfo(packageName, 0).versionCode;
      } catch (NameNotFoundException e) {
      }
      Log.w(
          TAG,
          "Unknown subtype mode: "
              + newMode
              + ","
              + version
              + ", "
              + packageName
              + ", "
              + mVoiceInputWrapper
              + ". IME is already changed to other IME.");
      if (newSubtype != null) {
        Log.w(TAG, "Subtype mode:" + newSubtype.getMode());
        Log.w(TAG, "Subtype locale:" + newSubtype.getLocale());
        Log.w(TAG, "Subtype extra value:" + newSubtype.getExtraValue());
        Log.w(TAG, "Subtype is auxiliary:" + newSubtype.isAuxiliary());
      }
    }
  }
 private void updateKeyboardBackgroundColor(SharedPreferences prefs) {
   Resources resources = mInputMethodService.getResources();
   mKeyboardBackgroundColor =
       prefs.getInt(
           IMESettings.PREF_KEYBOARD_BACKGROUND_COLOR, resources.getColor(R.color.transparent));
 }
Exemplo n.º 16
0
 private void triggerVoiceIME() {
   if (!mService.isInputViewShown()) return;
   VoiceProxy.getInstance()
       .startListening(false, KeyboardSwitcher.getInstance().getKeyboardView().getWindowToken());
 }
 @Override
 public void onChange(float val) {
   LatinIME ime = LatinIME.sInstance;
   if (ime != null) ime.vibrate((int) val);
 }
 // SMM {
 private void updateSettingsKeyState(SharedPreferences prefs) {
   Resources resources = mInputMethodService.getResources();
   mHasSettingsKey =
       prefs.getBoolean(
           IMESettings.PREF_SETTINGS_KEY, resources.getBoolean(R.bool.default_show_settings_key));
 }