android.view.inputmethod.InputMethodManager#getEnabledInputMethodList ( )源码实例Demo

下面列出了android.view.inputmethod.InputMethodManager#getEnabledInputMethodList ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openboard   文件: RichInputMethodManager.java
private boolean switchToNextInputMethodAndSubtype(final IBinder token) {
    final InputMethodManager imm = mImmWrapper.mImm;
    final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();
    final int currentIndex = getImiIndexInList(getInputMethodInfoOfThisIme(), enabledImis);
    if (currentIndex == INDEX_NOT_FOUND) {
        Log.w(TAG, "Can't find current IME in enabled IMEs: IME package="
                + getInputMethodInfoOfThisIme().getPackageName());
        return false;
    }
    final InputMethodInfo nextImi = getNextNonAuxiliaryIme(currentIndex, enabledImis);
    final List<InputMethodSubtype> enabledSubtypes = getEnabledInputMethodSubtypeList(nextImi,
            true /* allowsImplicitlySelectedSubtypes */);
    if (enabledSubtypes.isEmpty()) {
        // The next IME has no subtype.
        imm.setInputMethod(token, nextImi.getId());
        return true;
    }
    final InputMethodSubtype firstSubtype = enabledSubtypes.get(0);
    imm.setInputMethodAndSubtype(token, nextImi.getId(), firstSubtype);
    return true;
}
 
源代码2 项目: openboard   文件: RichInputMethodManager.java
public boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes() {
    final Locale systemLocale = mContext.getResources().getConfiguration().locale;
    final Set<InputMethodSubtype> enabledSubtypesOfEnabledImes = new HashSet<>();
    final InputMethodManager inputMethodManager = getInputMethodManager();
    final List<InputMethodInfo> enabledInputMethodInfoList =
            inputMethodManager.getEnabledInputMethodList();
    for (final InputMethodInfo info : enabledInputMethodInfoList) {
        final List<InputMethodSubtype> enabledSubtypes =
                inputMethodManager.getEnabledInputMethodSubtypeList(
                        info, true /* allowsImplicitlySelectedSubtypes */);
        if (enabledSubtypes.isEmpty()) {
            // An IME with no subtypes is found.
            return false;
        }
        enabledSubtypesOfEnabledImes.addAll(enabledSubtypes);
    }
    for (final InputMethodSubtype subtype : enabledSubtypesOfEnabledImes) {
        if (!subtype.isAuxiliary() && !subtype.getLocale().isEmpty()
                && !systemLocale.equals(SubtypeLocaleUtils.getSubtypeLocale(subtype))) {
            return false;
        }
    }
    return true;
}
 
private boolean switchToNextInputMethodAndSubtype(final IBinder token) {
    final InputMethodManager imm = mImmWrapper.mImm;
    final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();
    final int currentIndex = getImiIndexInList(getInputMethodInfoOfThisIme(), enabledImis);
    if (currentIndex == INDEX_NOT_FOUND) {
        Log.w(TAG, "Can't find current IME in enabled IMEs: IME package="
                + getInputMethodInfoOfThisIme().getPackageName());
        return false;
    }
    final InputMethodInfo nextImi = getNextNonAuxiliaryIme(currentIndex, enabledImis);
    final List<InputMethodSubtype> enabledSubtypes = getEnabledInputMethodSubtypeList(nextImi,
            true /* allowsImplicitlySelectedSubtypes */);
    if (enabledSubtypes.isEmpty()) {
        // The next IME has no subtype.
        imm.setInputMethod(token, nextImi.getId());
        return true;
    }
    final InputMethodSubtype firstSubtype = enabledSubtypes.get(0);
    imm.setInputMethodAndSubtype(token, nextImi.getId(), firstSubtype);
    return true;
}
 
public boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes() {
    final Locale systemLocale = mContext.getResources().getConfiguration().locale;
    final Set<InputMethodSubtype> enabledSubtypesOfEnabledImes = new HashSet<>();
    final InputMethodManager inputMethodManager = getInputMethodManager();
    final List<InputMethodInfo> enabledInputMethodInfoList =
            inputMethodManager.getEnabledInputMethodList();
    for (final InputMethodInfo info : enabledInputMethodInfoList) {
        final List<InputMethodSubtype> enabledSubtypes =
                inputMethodManager.getEnabledInputMethodSubtypeList(
                        info, true /* allowsImplicitlySelectedSubtypes */);
        if (enabledSubtypes.isEmpty()) {
            // An IME with no subtypes is found.
            return false;
        }
        enabledSubtypesOfEnabledImes.addAll(enabledSubtypes);
    }
    for (final InputMethodSubtype subtype : enabledSubtypesOfEnabledImes) {
        if (!subtype.isAuxiliary() && !subtype.getLocale().isEmpty()
                && !systemLocale.equals(SubtypeLocaleUtils.getSubtypeLocale(subtype))) {
            return false;
        }
    }
    return true;
}
 
源代码5 项目: 365browser   文件: UiUtils.java
/**
 * Gets the set of locales supported by the current enabled Input Methods.
 * @param context A {@link Context} instance.
 * @return A possibly-empty {@link Set} of locale strings.
 */
public static Set<String> getIMELocales(Context context) {
    LinkedHashSet<String> locales = new LinkedHashSet<String>();
    InputMethodManager imManager =
            (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    List<InputMethodInfo> enabledMethods = imManager.getEnabledInputMethodList();
    for (int i = 0; i < enabledMethods.size(); i++) {
        List<InputMethodSubtype> subtypes =
                imManager.getEnabledInputMethodSubtypeList(enabledMethods.get(i), true);
        if (subtypes == null) continue;
        for (int j = 0; j < subtypes.size(); j++) {
            String locale = ApiCompatibilityUtils.getLocale(subtypes.get(j));
            if (!TextUtils.isEmpty(locale)) locales.add(locale);
        }
    }
    return locales;
}
 
源代码6 项目: Chimee   文件: SettingsActivity.java
private boolean isKeyboardActivated() {
    String packageLocal = getPackageName();
    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    if (inputMethodManager == null) return false;
    List<InputMethodInfo> list = inputMethodManager.getEnabledInputMethodList();

    // check if our keyboard is enabled as input method
    for (InputMethodInfo inputMethod : list) {
        String packageName = inputMethod.getPackageName();
        if (packageName.equals(packageLocal)) {
            return true;
        }
    }

    return false;
}
 
源代码7 项目: Indic-Keyboard   文件: RichInputMethodManager.java
private boolean switchToNextInputMethodAndSubtype(final IBinder token) {
    final InputMethodManager imm = mImmWrapper.mImm;
    final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();
    final int currentIndex = getImiIndexInList(getInputMethodInfoOfThisIme(), enabledImis);
    if (currentIndex == INDEX_NOT_FOUND) {
        Log.w(TAG, "Can't find current IME in enabled IMEs: IME package="
                + getInputMethodInfoOfThisIme().getPackageName());
        return false;
    }
    final InputMethodInfo nextImi = getNextNonAuxiliaryIme(currentIndex, enabledImis);
    final List<InputMethodSubtype> enabledSubtypes = getEnabledInputMethodSubtypeList(nextImi,
            true /* allowsImplicitlySelectedSubtypes */);
    if (enabledSubtypes.isEmpty()) {
        // The next IME has no subtype.
        imm.setInputMethod(token, nextImi.getId());
        return true;
    }
    final InputMethodSubtype firstSubtype = enabledSubtypes.get(0);
    imm.setInputMethodAndSubtype(token, nextImi.getId(), firstSubtype);
    return true;
}
 
源代码8 项目: Indic-Keyboard   文件: RichInputMethodManager.java
public boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes() {
    final Locale systemLocale = mContext.getResources().getConfiguration().locale;
    final Set<InputMethodSubtype> enabledSubtypesOfEnabledImes = new HashSet<>();
    final InputMethodManager inputMethodManager = getInputMethodManager();
    final List<InputMethodInfo> enabledInputMethodInfoList =
            inputMethodManager.getEnabledInputMethodList();
    for (final InputMethodInfo info : enabledInputMethodInfoList) {
        final List<InputMethodSubtype> enabledSubtypes =
                inputMethodManager.getEnabledInputMethodSubtypeList(
                        info, true /* allowsImplicitlySelectedSubtypes */);
        if (enabledSubtypes.isEmpty()) {
            // An IME with no subtypes is found.
            return false;
        }
        enabledSubtypesOfEnabledImes.addAll(enabledSubtypes);
    }
    for (final InputMethodSubtype subtype : enabledSubtypesOfEnabledImes) {
        if (!subtype.isAuxiliary() && !subtype.getLocale().isEmpty()
                && !systemLocale.equals(SubtypeLocaleUtils.getSubtypeLocale(subtype))) {
            return false;
        }
    }
    return true;
}
 
/**
 * Check if the IME specified by the context is enabled.
 * CAVEAT: This may cause a round trip IPC.
 *
 * @param context package context of the IME to be checked.
 * @param imm the {@link InputMethodManager}.
 * @return true if this IME is enabled.
 */
public static boolean isThisImeEnabled(final Context context,
        final InputMethodManager imm) {
    final String packageName = context.getPackageName();
    for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) {
        if (packageName.equals(imi.getPackageName())) {
            return true;
        }
    }
    return false;
}
 
源代码10 项目: BaldPhone   文件: TutorialFragment3.java
public void setupBtn() {

        final InputMethodManager im = (InputMethodManager) getContext().getSystemService(INPUT_METHOD_SERVICE);
        final List<InputMethodInfo> inputMethodInfoList = im.getEnabledInputMethodList();
        boolean turnedOn = false;
        for (InputMethodInfo inputMethodInfo : inputMethodInfoList) {
            if (inputMethodInfo.getId().equals("com.bald.uriah.baldphone/.keyboard.BaldInputMethodService")) {
                turnedOn = true;
                break;
            }
        }
        if (!turnedOn)
            bt_set_keyboard.setOnClickListener((v) -> {
                v.getContext().startActivity(new Intent("android.settings.INPUT_METHOD_SETTINGS"));
            });
        else {
            bt_set_keyboard.setText(R.string.already_setted);
            bt_set_keyboard.setOnClickListener(v -> {
                try {
                    ((InputMethodManager) getContext().getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE)).showInputMethodPicker();
                } catch (Exception e) {
                    Log.e(TAG, e.getMessage());
                    e.printStackTrace();
                    BaldToast.error(getContext());
                }
            });

        }
    }
 
源代码11 项目: TVRemoteIME   文件: Environment.java
public static boolean isEnableIME(Context context){
    try {
        InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
        List<InputMethodInfo> inputs = imm.getEnabledInputMethodList();
        boolean flag = false;
        for(InputMethodInfo input : inputs){
            if(input.getPackageName().equals(IMEService.class.getPackage().getName())){
                return true;
            }
        }
    }catch (Exception ignored){ }
    return false;
}
 
/**
 * Check if the IME specified by the context is enabled.
 * CAVEAT: This may cause a round trip IPC.
 *
 * @param context package context of the IME to be checked.
 * @param imm the {@link InputMethodManager}.
 * @return true if this IME is enabled.
 */
public static boolean isThisImeEnabled(final Context context,
        final InputMethodManager imm) {
    final String packageName = context.getPackageName();
    for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) {
        if (packageName.equals(imi.getPackageName())) {
            return true;
        }
    }
    return false;
}
 
源代码13 项目: prevent   文件: PackageUtils.java
private static void initInputMethods(Context context) {
    InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    List<InputMethodInfo> inputMethods = inputMethodManager.getEnabledInputMethodList();
    final int count = inputMethods == null ? 0 : inputMethods.size();
    for (int i = 0; i < count; ++i) {
        inputMethodPackages.add(inputMethods.get(i).getPackageName());
    }
}
 
源代码14 项目: delion   文件: DeferredStartupHandler.java
private void recordKeyboardLocaleUma() {
    InputMethodManager imm =
            (InputMethodManager) mAppContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    List<InputMethodInfo> ims = imm.getEnabledInputMethodList();
    ArrayList<String> uniqueLanguages = new ArrayList<String>();
    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);
    }
}
 
源代码15 项目: AndroidChromium   文件: DeferredStartupHandler.java
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);
    }
}
 
源代码16 项目: Zom-Android-XMPP   文件: MainActivity.java
private void checkCustomFont ()
{

    if (Preferences.isLanguageTibetan())
    {
        CustomTypefaceManager.loadFromAssets(this,true);

    }
    else
    {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        List<InputMethodInfo> mInputMethodProperties = imm.getEnabledInputMethodList();

        final int N = mInputMethodProperties.size();
        boolean loadTibetan = false;
        for (int i = 0; i < N; i++) {

            InputMethodInfo imi = mInputMethodProperties.get(i);

            //imi contains the information about the keyboard you are using
            if (imi.getPackageName().equals("org.ironrabbit.bhoboard")) {
                //                    CustomTypefaceManager.loadFromKeyboard(this);
                loadTibetan = true;

                break;
            }

        }

        CustomTypefaceManager.loadFromAssets(this, loadTibetan);
    }

}
 
源代码17 项目: Zom-Android-XMPP   文件: LockScreenActivity.java
private void checkCustomFont ()
{

    if (Preferences.getLanguage() != null
            && Preferences.getLanguage().equalsIgnoreCase("bo"))
    {
        CustomTypefaceManager.loadFromAssets(this,true);

    }
    else
    {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        List<InputMethodInfo> mInputMethodProperties = imm.getEnabledInputMethodList();

        final int N = mInputMethodProperties.size();
        boolean loadTibetan = false;

        for (int i = 0; i < N; i++) {

            InputMethodInfo imi = mInputMethodProperties.get(i);

            //imi contains the information about the keyboard you are using
            if (imi.getPackageName().equals("org.ironrabbit.bhoboard")) {
                //                    CustomTypefaceManager.loadFromKeyboard(this);
                loadTibetan = true;
                break;
            }

        }

        CustomTypefaceManager.loadFromAssets(this,loadTibetan);

    }

}
 
源代码18 项目: 365browser   文件: ProcessInitializationHandler.java
@SuppressWarnings("deprecation") // InputMethodSubtype.getLocale() deprecated in API 24
private void recordKeyboardLocaleUma(Context context) {
    InputMethodManager imm =
            (InputMethodManager) context.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);
    }
}
 
/**
 * Check if the IME specified by the context is enabled.
 * CAVEAT: This may cause a round trip IPC.
 *
 * @param context package context of the IME to be checked.
 * @param imm the {@link InputMethodManager}.
 * @return true if this IME is enabled.
 */
public static boolean isThisImeEnabled(final Context context,
        final InputMethodManager imm) {
    final String packageName = context.getPackageName();
    for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) {
        if (packageName.equals(imi.getPackageName())) {
            return true;
        }
    }
    return false;
}