Example usage for android.view.inputmethod InputMethodSubtype getMode

List of usage examples for android.view.inputmethod InputMethodSubtype getMode

Introduction

In this page you can find the example usage for android.view.inputmethod InputMethodSubtype getMode.

Prototype

public String getMode() 

Source Link

Usage

From source file:com.adguard.android.commons.RawResources.java

/**
 * Gets input languages/*  w ww.j  a  v a 2  s  .c  om*/
 *
 * @param context Application context
 * @return List of input languages
 */
private static List<String> getInputLanguages(Context context) {
    List<String> languages = new ArrayList<>();

    try {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        List<InputMethodInfo> ims = imm.getEnabledInputMethodList();

        for (InputMethodInfo method : ims) {
            List<InputMethodSubtype> subMethods = imm.getEnabledInputMethodSubtypeList(method, true);
            for (InputMethodSubtype subMethod : subMethods) {
                if ("keyboard".equals(subMethod.getMode())) {
                    String currentLocale = subMethod.getLocale();
                    String language = cleanUpLanguageCode(new Locale(currentLocale).getLanguage());
                    if (!languages.contains(language)) {
                        languages.add(language);
                    }
                }
            }
        }
    } catch (Exception ex) {
        LOG.warn("Cannot get user input languages\r\n", ex);
    }

    return languages;
}