@SuppressWarnings("deprecation") // InputMethodSubtype.getLocale() deprecated in API 24
  private void recordKeyboardLocaleUma() {
    InputMethodManager imm =
        (InputMethodManager) mAppContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    List<InputMethodInfo> ims = imm.getEnabledInputMethodList();
    ArrayList<String> uniqueLanguages = new ArrayList<>();
    for (InputMethodInfo method : ims) {
      List<InputMethodSubtype> submethods = imm.getEnabledInputMethodSubtypeList(method, true);
      for (InputMethodSubtype submethod : submethods) {
        if (submethod.getMode().equals("keyboard")) {
          String language = submethod.getLocale().split("_")[0];
          if (!uniqueLanguages.contains(language)) {
            uniqueLanguages.add(language);
          }
        }
      }
    }
    RecordHistogram.recordCountHistogram("InputMethod.ActiveCount", uniqueLanguages.size());

    InputMethodSubtype currentSubtype = imm.getCurrentInputMethodSubtype();
    Locale systemLocale = Locale.getDefault();
    if (currentSubtype != null && currentSubtype.getLocale() != null && systemLocale != null) {
      String keyboardLanguage = currentSubtype.getLocale().split("_")[0];
      boolean match = systemLocale.getLanguage().equalsIgnoreCase(keyboardLanguage);
      RecordHistogram.recordBooleanHistogram("InputMethod.MatchesSystemLanguage", match);
    }
  }
Esempio n. 2
0
  private boolean isKeyboardEnabled() {
    InputMethodManager inputMethodManager =
        (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    List<InputMethodInfo> inputMethodList = inputMethodManager.getEnabledInputMethodList();
    ComponentName ctrlV = new ComponentName(this, CtrlVKeyboard.class);
    boolean ctrlVIsEnabled = false;
    int i = 0;

    while (!ctrlVIsEnabled && i < inputMethodList.size()) {
      if (inputMethodList.get(i).getComponent().equals(ctrlV)) {
        ctrlVIsEnabled = true;
      }
      i++;
    }

    return ctrlVIsEnabled;
  }
Esempio n. 3
0
 /**
  * Test if user use a custom keyboard
  *
  * @return
  */
 public boolean isUsingCustomInputMethod() {
   InputMethodManager imm =
       (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
   List<InputMethodInfo> mInputMethodProperties = imm.getEnabledInputMethodList();
   final int N = mInputMethodProperties.size();
   for (int i = 0; i < N; i++) {
     InputMethodInfo imi = mInputMethodProperties.get(i);
     if (imi.getId()
         .equals(
             Settings.Secure.getString(
                 getContext().getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) {
       if ((imi.getServiceInfo().applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
         return true;
       }
     }
   }
   return false;
 }
Esempio n. 4
0
 private TreeMap<InputMethodInfo, List<InputMethodSubtype>> getEnabledInputMethodAndSubtypeList() {
   String newEnabledIMIs =
       Settings.Secure.getString(
           mContext.getContentResolver(), Settings.Secure.ENABLED_INPUT_METHODS);
   String currentSystemLocaleString = mContext.getResources().getConfiguration().locale.toString();
   if (!TextUtils.equals(mEnabledInputMethodAndSubtypesCacheStr, newEnabledIMIs)
       || !TextUtils.equals(mLastSystemLocaleString, currentSystemLocaleString)
       || mPackageChanged) {
     mEnabledInputMethodAndSubtypesCache.clear();
     final List<InputMethodInfo> imis = mImm.getEnabledInputMethodList();
     for (InputMethodInfo imi : imis) {
       mEnabledInputMethodAndSubtypesCache.put(
           imi, mImm.getEnabledInputMethodSubtypeList(imi, true));
     }
     mEnabledInputMethodAndSubtypesCacheStr = newEnabledIMIs;
     mPackageChanged = false;
     mLastSystemLocaleString = currentSystemLocaleString;
   }
   return mEnabledInputMethodAndSubtypesCache;
 }
  /**
   * Method adapted from com.android.inputmethod.latin.Utils
   *
   * @param imm The input method manager
   * @param shouldIncludeAuxiliarySubtypes
   * @return true if we have multiple IMEs to choose from
   */
  private boolean hasMultipleEnabledIMEsOrSubtypes(
      InputMethodManager imm, final boolean shouldIncludeAuxiliarySubtypes) {
    final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();

    // Number of the filtered IMEs
    int filteredImisCount = 0;

    for (InputMethodInfo imi : enabledImis) {
      // We can return true immediately after we find two or more filtered IMEs.
      if (filteredImisCount > 1) return true;
      final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(imi, true);
      // IMEs that have no subtypes should be counted.
      if (subtypes.isEmpty()) {
        ++filteredImisCount;
        continue;
      }

      int auxCount = 0;
      for (InputMethodSubtype subtype : subtypes) {
        if (subtype.isAuxiliary()) {
          ++auxCount;
        }
      }
      final int nonAuxCount = subtypes.size() - auxCount;

      // IMEs that have one or more non-auxiliary subtypes should be counted.
      // If shouldIncludeAuxiliarySubtypes is true, IMEs that have two or more auxiliary
      // subtypes should be counted as well.
      if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) {
        ++filteredImisCount;
        continue;
      }
    }

    return filteredImisCount > 1
        // imm.getEnabledInputMethodSubtypeList(null, false) will return the current IME's enabled
        // input method subtype (The current IME should be LatinIME.)
        || imm.getEnabledInputMethodSubtypeList(null, false).size() > 1;
  }
Esempio n. 6
0
 public static boolean hasMultipleEnabledIMEsOrSubtypes(
     Context context, final boolean shouldIncludeAuxiliarySubtypes) {
   final InputMethodManager imm = getInputMethodManager(context);
   final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();
   return hasMultipleEnabledSubtypes(context, shouldIncludeAuxiliarySubtypes, enabledImis);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.pref);

    Preference inputmethod = findPreference(getString(R.string.prefs_next_inputmethod_key));
    if (inputmethod == null) return;

    if (!(inputmethod instanceof ListPreference)) return;

    ListPreference list = (ListPreference) inputmethod;

    InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    PackageManager pm = getPackageManager();
    List<InputMethodInfo> info = im.getEnabledInputMethodList();
    String[] entries = new String[info.size()];
    String[] entriesValue = new String[info.size()];
    int index = 1;
    for (int count = 0; count < info.size(); count++) {
      String label = info.get(count).loadLabel(pm).toString();
      String id = info.get(count).getId();

      if (id.indexOf("com.diycircuits.cangjie") == -1) {
        entries[index] = label;
        entriesValue[index] = id;
        index++;
      }
    }
    entries[0] = getString(R.string.no_next_inputmethod);
    entriesValue[0] = "";
    list.setEntries(entries);
    list.setEntryValues(entriesValue);

    Preference vibrator_on = findPreference("vibrate_on");
    Preference vibrator_settings = findPreference("pref_vibration_duration_settings");
    Preference sound_on = findPreference("sound_on");
    Preference sound_settings = findPreference("pref_keypress_sound_volume");
    final SharedPreferences sp = getPreferenceManager().getSharedPreferences();

    if (getSystemService(Context.VIBRATOR_SERVICE) == null) {
      vibrator_on.setEnabled(false);
      vibrator_settings.setEnabled(false);
    } else {
      vibrator_settings.setEnabled(
          vibrator_on.getSharedPreferences().getBoolean("vibrate_on", false));
      vibrator_settings.setSummary(
          Integer.toString(sp.getInt("pref_vibration_duration_settings", 5)) + "ms");
    }
    sound_settings.setEnabled(sound_on.getSharedPreferences().getBoolean("sound_on", false));
    sound_settings.setSummary(Integer.toString(sp.getInt("pref_keypress_sound_volume", 50)));

    vibrator_on.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue != null && newValue instanceof Boolean) {
              Preference vibrator_on = findPreference("vibrate_on");
              Preference vibrator_settings = findPreference("pref_vibration_duration_settings");
              vibrator_settings.setEnabled(((Boolean) newValue).booleanValue());
              vibrator_settings.setSummary(
                  Integer.toString(sp.getInt("pref_vibration_duration_settings", 5)) + "ms");
            }
            return true;
          }
        });

    vibrator_settings.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference arg0) {
            showKeypressVibrationDurationSettingsDialog();
            return true;
          }
        });

    sound_on.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (newValue != null && newValue instanceof Boolean) {
              Preference sound_on = findPreference("sound_on");
              Preference sound_settings = findPreference("pref_keypress_sound_volume");
              sound_settings.setEnabled(((Boolean) newValue).booleanValue());
              sound_settings.setSummary(
                  Integer.toString(sp.getInt("pref_keypress_sound_volume", 50)));
            }
            return true;
          }
        });

    sound_settings.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference arg0) {
            showKeypressSoundVolumeSettingDialog();
            return true;
          }
        });
  }