android.view.inputmethod.InputMethodSubtype#getLanguageTag ( )源码实例Demo

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

public static Locale getLocaleObject(final InputMethodSubtype subtype) {
    // Locale.forLanguageTag() is available only in Android L and later.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        final String languageTag = subtype.getLanguageTag();
        if (!TextUtils.isEmpty(languageTag)) {
            return Locale.forLanguageTag(languageTag);
        }
    }
    return LocaleUtils.constructLocaleFromString(subtype.getLocale());
}
 
源代码2 项目: cronet   文件: ApiCompatibilityUtils.java
/**
 * @see android.view.inputmethod.InputMethodSubType#getLocate()
 */
@SuppressWarnings("deprecation")
public static String getLocale(InputMethodSubtype inputMethodSubType) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        return inputMethodSubType.getLanguageTag();
    } else {
        return inputMethodSubType.getLocale();
    }
}
 
public static Locale getLocaleObject(final InputMethodSubtype subtype) {
    // Locale.forLanguageTag() is available only in Android L and later.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        final String languageTag = subtype.getLanguageTag();
        if (!TextUtils.isEmpty(languageTag)) {
            return Locale.forLanguageTag(languageTag);
        }
    }
    return LocaleUtils.constructLocaleFromString(subtype.getLocale());
}
 
源代码4 项目: 365browser   文件: ApiCompatibilityUtils.java
/**
 * @see android.view.inputmethod.InputMethodSubType#getLocate()
 */
@SuppressWarnings("deprecation")
public static String getLocale(InputMethodSubtype inputMethodSubType) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        return inputMethodSubType.getLanguageTag();
    } else {
        return inputMethodSubType.getLocale();
    }
}
 
源代码5 项目: Telegram-FOSS   文件: AndroidUtilities.java
public static String[] getCurrentKeyboardLanguage() {
    try {
        InputMethodManager inputManager = (InputMethodManager) ApplicationLoader.applicationContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        InputMethodSubtype inputMethodSubtype = inputManager.getCurrentInputMethodSubtype();
        String locale = null;
        if (inputMethodSubtype != null) {
            if (Build.VERSION.SDK_INT >= 24) {
                locale = inputMethodSubtype.getLanguageTag();
            }
            if (TextUtils.isEmpty(locale)) {
                locale = inputMethodSubtype.getLocale();
            }
        } else {
            inputMethodSubtype = inputManager.getLastInputMethodSubtype();
            if (inputMethodSubtype != null) {
                if (Build.VERSION.SDK_INT >= 24) {
                    locale = inputMethodSubtype.getLanguageTag();
                }
                if (TextUtils.isEmpty(locale)) {
                    locale = inputMethodSubtype.getLocale();
                }
            }
        }
        if (TextUtils.isEmpty(locale)) {
            locale = LocaleController.getSystemLocaleStringIso639();
            String locale2;
            LocaleController.LocaleInfo localeInfo = LocaleController.getInstance().getCurrentLocaleInfo();
            locale2 = localeInfo.getBaseLangCode();
            if (TextUtils.isEmpty(locale2)) {
                locale2 = localeInfo.getLangCode();
            }
            if (locale.contains(locale2) || locale2.contains(locale)) {
                if (!locale.contains("en")) {
                    locale2 = "en";
                } else {
                    locale2 = null;
                }
            }
            if (!TextUtils.isEmpty(locale2)) {
                return new String[]{locale.replace('_', '-'), locale2};
            } else {
                return new String[]{locale.replace('_', '-')};
            }
        } else {
            return new String[]{locale.replace('_', '-')};
        }
    } catch (Exception ignore) {

    }
    return new String[]{"en"};
}
 
源代码6 项目: Telegram   文件: AndroidUtilities.java
public static String[] getCurrentKeyboardLanguage() {
    try {
        InputMethodManager inputManager = (InputMethodManager) ApplicationLoader.applicationContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        InputMethodSubtype inputMethodSubtype = inputManager.getCurrentInputMethodSubtype();
        String locale = null;
        if (inputMethodSubtype != null) {
            if (Build.VERSION.SDK_INT >= 24) {
                locale = inputMethodSubtype.getLanguageTag();
            }
            if (TextUtils.isEmpty(locale)) {
                locale = inputMethodSubtype.getLocale();
            }
        } else {
            inputMethodSubtype = inputManager.getLastInputMethodSubtype();
            if (inputMethodSubtype != null) {
                if (Build.VERSION.SDK_INT >= 24) {
                    locale = inputMethodSubtype.getLanguageTag();
                }
                if (TextUtils.isEmpty(locale)) {
                    locale = inputMethodSubtype.getLocale();
                }
            }
        }
        if (TextUtils.isEmpty(locale)) {
            locale = LocaleController.getSystemLocaleStringIso639();
            String locale2;
            LocaleController.LocaleInfo localeInfo = LocaleController.getInstance().getCurrentLocaleInfo();
            locale2 = localeInfo.getBaseLangCode();
            if (TextUtils.isEmpty(locale2)) {
                locale2 = localeInfo.getLangCode();
            }
            if (locale.contains(locale2) || locale2.contains(locale)) {
                if (!locale.contains("en")) {
                    locale2 = "en";
                } else {
                    locale2 = null;
                }
            }
            if (!TextUtils.isEmpty(locale2)) {
                return new String[]{locale.replace('_', '-'), locale2};
            } else {
                return new String[]{locale.replace('_', '-')};
            }
        } else {
            return new String[]{locale.replace('_', '-')};
        }
    } catch (Exception ignore) {

    }
    return new String[]{"en"};
}