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;
 }
 // Reload enabledSubtypes from the framework.
 private void updateEnabledSubtypes() {
   final String currentMode = getCurrentSubtypeMode();
   boolean foundCurrentSubtypeBecameDisabled = true;
   mAllEnabledSubtypesOfCurrentInputMethod = mImm.getEnabledInputMethodSubtypeList(null, true);
   mEnabledLanguagesOfCurrentInputMethod.clear();
   mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
   for (InputMethodSubtypeCompatWrapper ims : mAllEnabledSubtypesOfCurrentInputMethod) {
     final String locale = getSubtypeLocale(ims);
     final String mode = ims.getMode();
     mLocaleSplitter.setString(locale);
     if (mLocaleSplitter.hasNext()) {
       mEnabledLanguagesOfCurrentInputMethod.add(mLocaleSplitter.next());
     }
     if (locale.equals(mInputLocaleStr) && mode.equals(currentMode)) {
       foundCurrentSubtypeBecameDisabled = false;
     }
     if (KEYBOARD_MODE.equals(ims.getMode())) {
       mEnabledKeyboardSubtypesOfCurrentInputMethod.add(ims);
     }
   }
   mNeedsToDisplayLanguage =
       !(getEnabledKeyboardLocaleCount() <= 1 && mIsSystemLanguageSameAsInputLanguage);
   if (foundCurrentSubtypeBecameDisabled) {
     if (DBG) {
       Log.w(TAG, "Current subtype: " + mInputLocaleStr + ", " + currentMode);
       Log.w(TAG, "Last subtype was disabled. Update to the current one.");
     }
     updateSubtype(mImm.getCurrentInputMethodSubtype());
   }
 }
 public boolean isShortcutImeReady() {
   if (mShortcutInputMethodInfo == null) return false;
   if (mShortcutSubtype == null) return true;
   if (contains(
       mShortcutSubtype.getExtraValue().split(","),
       SUBTYPE_EXTRAVALUE_REQUIRE_NETWORK_CONNECTIVITY)) {
     return mIsNetworkConnected;
   }
   return true;
 }
 public boolean isShortcutImeEnabled() {
   if (mShortcutInputMethodInfo == null) {
     return false;
   }
   if (mShortcutSubtype == null) {
     return true;
   }
   // For compatibility, if the shortcut subtype is dummy, we assume the shortcut IME
   // (built-in voice dummy subtype) is available.
   if (!mShortcutSubtype.hasOriginalObject()) {
     return true;
   }
   final boolean allowsImplicitlySelectedSubtypes = true;
   for (final InputMethodSubtypeCompatWrapper enabledSubtype :
       mImm.getEnabledInputMethodSubtypeList(
           mShortcutInputMethodInfo, allowsImplicitlySelectedSubtypes)) {
     if (enabledSubtype.equals(mShortcutSubtype)) {
       return true;
     }
   }
   return false;
 }
 private void updateShortcutIME() {
   if (DBG) {
     Log.d(
         TAG,
         "Update shortcut IME from : "
             + (mShortcutInputMethodInfo == null ? "<null>" : mShortcutInputMethodInfo.getId())
             + ", "
             + (mShortcutSubtype == null
                 ? "<null>"
                 : (getSubtypeLocale(mShortcutSubtype) + ", " + mShortcutSubtype.getMode())));
   }
   // TODO: Update an icon for shortcut IME
   final Map<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>> shortcuts =
       mImm.getShortcutInputMethodsAndSubtypes();
   mShortcutInputMethodInfo = null;
   mShortcutSubtype = null;
   for (InputMethodInfoCompatWrapper imi : shortcuts.keySet()) {
     List<InputMethodSubtypeCompatWrapper> subtypes = shortcuts.get(imi);
     // TODO: Returns the first found IMI for now. Should handle all shortcuts as
     // appropriate.
     mShortcutInputMethodInfo = imi;
     // TODO: Pick up the first found subtype for now. Should handle all subtypes
     // as appropriate.
     mShortcutSubtype = subtypes.size() > 0 ? subtypes.get(0) : null;
     break;
   }
   if (DBG) {
     Log.d(
         TAG,
         "Update shortcut IME to : "
             + (mShortcutInputMethodInfo == null ? "<null>" : mShortcutInputMethodInfo.getId())
             + ", "
             + (mShortcutSubtype == null
                 ? "<null>"
                 : (getSubtypeLocale(mShortcutSubtype) + ", " + mShortcutSubtype.getMode())));
   }
 }
 public String getCurrentSubtypeMode() {
   return null != mCurrentSubtype ? mCurrentSubtype.getMode() : KEYBOARD_MODE;
 }
 public String getCurrentSubtypeExtraValueOf(String key) {
   // If null, return what an empty ExtraValue would return : null.
   return null != mCurrentSubtype ? mCurrentSubtype.getExtraValueOf(key) : null;
 }
 public boolean currentSubtypeContainsExtraValueKey(String key) {
   // If null, return what an empty ExtraValue would return : false.
   return null != mCurrentSubtype ? mCurrentSubtype.containsExtraValueKey(key) : false;
 }
 public String getCurrentSubtypeExtraValue() {
   // If null, return what an empty ExtraValue would return : the empty string.
   return null != mCurrentSubtype ? mCurrentSubtype.getExtraValue() : "";
 }
Esempio n. 10
0
 public boolean isDummyVoiceMode() {
   return mCurrentSubtype != null
       && mCurrentSubtype.getOriginalObject() == null
       && VOICE_MODE.equals(getCurrentSubtypeMode());
 }
Esempio n. 11
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());
      }
    }
  }
Esempio n. 12
0
 private static String getSubtypeLocale(InputMethodSubtypeCompatWrapper subtype) {
   final String keyboardLocale =
       subtype.getExtraValueOf(LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE);
   return keyboardLocale != null ? keyboardLocale : subtype.getLocale();
 }