private static InputMethodInfo getMyImi(Context context, InputMethodManager imm) {
   final List<InputMethodInfo> imis = imm.getInputMethodList();
   for (int i = 0; i < imis.size(); ++i) {
     final InputMethodInfo imi = imis.get(i);
     if (imis.get(i).getPackageName().equals(context.getPackageName())) {
       return imi;
     }
   }
   return null;
 }
Ejemplo n.º 2
0
 public static InputMethodInfo getInputMethodInfoOfThisIme(Context context) {
   if (sInputMethodInfoOfThisIme == null) {
     final InputMethodManager imm = getInputMethodManager(context);
     final String packageName = context.getPackageName();
     for (final InputMethodInfo imi : imm.getInputMethodList()) {
       if (imi.getPackageName().equals(packageName)) return imi;
     }
     throw new RuntimeException("Can not find input method id for " + packageName);
   }
   return sInputMethodInfoOfThisIme;
 }
 @Override
 public void onSaveInputMethodPreference(final InputMethodPreference pref) {
   final boolean hasHardwareKeyboard =
       getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY;
   InputMethodAndSubtypeUtil.saveInputMethodSubtypeList(
       this, getContentResolver(), mImm.getInputMethodList(), hasHardwareKeyboard);
   // Update input method settings and preference list.
   mInputMethodSettingValues.refreshAllInputMethodAndSubtypes();
   for (final InputMethodPreference p : mInputMethodPreferenceList) {
     p.updatePreferenceViews();
   }
 }
Ejemplo n.º 4
0
 public String getCurrentInputMethodName() {
   String lastInputMethodId =
       Settings.Secure.getString(
           mActivity.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
   Log.d("tag", "<<<<<<<lastInputMethodId<<<<<<<<<<<<" + lastInputMethodId);
   InputMethodManager mImm =
       (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
   List<InputMethodInfo> mInputMethodProperties = mImm.getInputMethodList();
   for (int i = 0; i < mInputMethodProperties.size(); i++) {
     if (lastInputMethodId.equals(mInputMethodProperties.get(i).getId())) {
       mCurrentInputMethod =
           mInputMethodProperties.get(i).loadLabel(mActivity.getPackageManager()).toString();
       break;
     }
   }
   return mCurrentInputMethod;
 }
  @Override
  public void onReceive(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intentAction)) {
      Log.i(TAG, "Package has been replaced: " + context.getPackageName());
      // Need to restore additional subtypes because system always clears additional
      // subtypes when the package is replaced.
      RichInputMethodManager.init(context);
      final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
      final InputMethodSubtype[] additionalSubtypes = richImm.getAdditionalSubtypes(context);
      richImm.setAdditionalInputMethodSubtypes(additionalSubtypes);
      LauncherIconVisibilityManager.updateSetupWizardIconVisibility(context);
    } else if (Intent.ACTION_BOOT_COMPLETED.equals(intentAction)) {
      Log.i(TAG, "Boot has been completed");
      LauncherIconVisibilityManager.updateSetupWizardIconVisibility(context);
    } else if (IntentCompatUtils.is_ACTION_USER_INITIALIZE(intentAction)) {
      Log.i(TAG, "User initialize");
      LauncherIconVisibilityManager.updateSetupWizardIconVisibility(context);
    } else if (Intent.ACTION_LOCALE_CHANGED.equals(intentAction)) {
      Log.i(TAG, "System locale changed");
      KeyboardLayoutSet.onSystemLocaleChanged();
    }

    // The process that hosts this broadcast receiver is invoked and remains alive even after
    // 1) the package has been re-installed, 2) the device has just booted,
    // 3) a new user has been created.
    // There is no good reason to keep the process alive if this IME isn't a current IME.
    final InputMethodManager imm =
        (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    // Called to check whether this IME has been triggered by the current user or not
    final boolean isInputMethodManagerValidForUserOfThisProcess =
        !imm.getInputMethodList().isEmpty();
    final boolean isCurrentImeOfCurrentUser =
        isInputMethodManagerValidForUserOfThisProcess
            && UncachedInputMethodManagerUtils.isThisImeCurrent(context, imm);
    if (!isCurrentImeOfCurrentUser) {
      final int myPid = Process.myPid();
      Log.i(TAG, "Killing my process: pid=" + myPid);
      Process.killProcess(myPid);
    }
  }
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    addPreferencesFromResource(R.xml.language_settings);

    try {
      mDefaultInputMethodSelectorVisibility =
          Integer.valueOf(getString(R.string.input_method_selector_visibility_default_value));
    } catch (NumberFormatException e) {
    }

    if (getActivity().getAssets().getLocales().length == 1) {
      // No "Select language" pref if there's only one system locale available.
      getPreferenceScreen().removePreference(findPreference(KEY_PHONE_LANGUAGE));
    } else {
      mLanguagePref = findPreference(KEY_PHONE_LANGUAGE);
    }
    if (SHOW_INPUT_METHOD_SWITCHER_SETTINGS) {
      mShowInputMethodSelectorPref = (ListPreference) findPreference(KEY_INPUT_METHOD_SELECTOR);
      mShowInputMethodSelectorPref.setOnPreferenceChangeListener(this);
      // TODO: Update current input method name on summary
      updateInputMethodSelectorSummary(loadInputMethodSelectorVisibility());
    }

    new VoiceInputOutputSettings(this).onCreate();

    // Get references to dynamically constructed categories.
    mHardKeyboardCategory = (PreferenceCategory) findPreference("hard_keyboard");
    mKeyboardSettingsCategory = (PreferenceCategory) findPreference("keyboard_settings_category");
    mGameControllerCategory =
        (PreferenceCategory) findPreference("game_controller_settings_category");

    // Filter out irrelevant features if invoked from IME settings button.
    mIsOnlyImeSettings =
        Settings.ACTION_INPUT_METHOD_SETTINGS.equals(getActivity().getIntent().getAction());
    getActivity().getIntent().setAction(null);
    if (mIsOnlyImeSettings) {
      getPreferenceScreen().removeAll();
      getPreferenceScreen().addPreference(mHardKeyboardCategory);
      if (SHOW_INPUT_METHOD_SWITCHER_SETTINGS) {
        getPreferenceScreen().addPreference(mShowInputMethodSelectorPref);
      }
      getPreferenceScreen().addPreference(mKeyboardSettingsCategory);
    }

    // Build IME preference category.
    mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    mImis = mImm.getInputMethodList();

    mKeyboardSettingsCategory.removeAll();
    if (!mIsOnlyImeSettings) {
      final PreferenceScreen currentIme = new PreferenceScreen(getActivity(), null);
      currentIme.setKey(KEY_CURRENT_INPUT_METHOD);
      currentIme.setTitle(getResources().getString(R.string.current_input_method));
      mKeyboardSettingsCategory.addPreference(currentIme);
    }

    mInputMethodPreferenceList.clear();
    final int N = (mImis == null ? 0 : mImis.size());
    for (int i = 0; i < N; ++i) {
      final InputMethodInfo imi = mImis.get(i);
      final InputMethodPreference pref = getInputMethodPreference(imi, N);
      mInputMethodPreferenceList.add(pref);
    }

    if (!mInputMethodPreferenceList.isEmpty()) {
      Collections.sort(mInputMethodPreferenceList);
      for (int i = 0; i < N; ++i) {
        mKeyboardSettingsCategory.addPreference(mInputMethodPreferenceList.get(i));
      }
    }

    // Build hard keyboard and game controller preference categories.
    mIm = (InputManager) getActivity().getSystemService(Context.INPUT_SERVICE);
    updateInputDevices();

    // Enable or disable mStatusBarImeSwitcher based on boolean value: config_show_cmIMESwitcher
    final Preference keyImeSwitcherPref = findPreference(KEY_IME_SWITCHER);
    if (keyImeSwitcherPref != null) {
      if (!getResources().getBoolean(com.android.internal.R.bool.config_show_cmIMESwitcher)) {
        getPreferenceScreen().removePreference(keyImeSwitcherPref);
      } else {
        mStatusBarImeSwitcher = (CheckBoxPreference) keyImeSwitcherPref;
      }
    }

    // Spell Checker
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setClass(getActivity(), SpellCheckersSettingsActivity.class);
    final SpellCheckersPreference scp =
        ((SpellCheckersPreference) findPreference("spellcheckers_settings"));
    if (scp != null) {
      scp.setFragmentIntent(this, intent);
    }

    mVolumeKeyCursorControl = (ListPreference) findPreference(VOLUME_KEY_CURSOR_CONTROL);
    if (mVolumeKeyCursorControl != null) {
      mVolumeKeyCursorControl.setOnPreferenceChangeListener(this);
      mVolumeKeyCursorControl.setValue(
          Integer.toString(
              Settings.System.getInt(
                  getActivity().getContentResolver(),
                  Settings.System.VOLUME_KEY_CURSOR_CONTROL,
                  0)));
      mVolumeKeyCursorControl.setSummary(mVolumeKeyCursorControl.getEntry());
    }

    mHandler = new Handler();
    mSettingsObserver = new SettingsObserver(mHandler, getActivity());
  }