下面列出了android.view.inputmethod.InputMethodSubtype#getLocale ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Nonnull
public static String getKeyboardLayoutSetName(final InputMethodSubtype subtype) {
String keyboardLayoutSet = subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET);
if (keyboardLayoutSet == null) {
// This subtype doesn't have a keyboardLayoutSet extra value, so lookup its keyboard
// layout set in sLocaleAndExtraValueToKeyboardLayoutSetMap to keep it compatible with
// pre-JellyBean.
final String key = subtype.getLocale() + ":" + subtype.getExtraValue();
keyboardLayoutSet = sLocaleAndExtraValueToKeyboardLayoutSetMap.get(key);
}
// TODO: Remove this null check when InputMethodManager.getCurrentInputMethodSubtype is
// fixed.
if (keyboardLayoutSet == null) {
android.util.Log.w(TAG, "KeyboardLayoutSet not found, use QWERTY: " +
"locale=" + subtype.getLocale() + " extraValue=" + subtype.getExtraValue());
return QWERTY;
}
return keyboardLayoutSet;
}
/**
* Use the right subtype based on language selected.
*
* @return mCurKeyboard
*/
private LatinKeyboard getSelectedSubtype() {
final InputMethodSubtype subtype = mInputMethodManager.getCurrentInputMethodSubtype();
String s = subtype.getLocale();
switch (s) {
case "ps_AF":
mActiveKeyboard = "ps_AF";
mCurKeyboard = mPashtoKeyboard;
break;
case "ps_latin_AF":
mActiveKeyboard = "ps_latin_AF";
mCurKeyboard = mPashtoLatinKeyboard;
break;
case "fa_AF":
mActiveKeyboard = "fa_AF";
mCurKeyboard = mFarsiKeyboard;
break;
default:
mActiveKeyboard = "en_US";
mCurKeyboard = mQwertyKeyboard;
}
return mCurKeyboard;
}
@Nonnull
public static String getKeyboardLayoutSetName(final InputMethodSubtype subtype) {
String keyboardLayoutSet = subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET);
if (keyboardLayoutSet == null) {
// This subtype doesn't have a keyboardLayoutSet extra value, so lookup its keyboard
// layout set in sLocaleAndExtraValueToKeyboardLayoutSetMap to keep it compatible with
// pre-JellyBean.
final String key = subtype.getLocale() + ":" + subtype.getExtraValue();
keyboardLayoutSet = sLocaleAndExtraValueToKeyboardLayoutSetMap.get(key);
}
// TODO: Remove this null check when InputMethodManager.getCurrentInputMethodSubtype is
// fixed.
if (keyboardLayoutSet == null) {
android.util.Log.w(TAG, "KeyboardLayoutSet not found, use QWERTY: " +
"locale=" + subtype.getLocale() + " extraValue=" + subtype.getExtraValue());
return QWERTY;
}
return keyboardLayoutSet;
}
@Nonnull
public static String getKeyboardLayoutSetName(final InputMethodSubtype subtype) {
String keyboardLayoutSet = subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET);
if (keyboardLayoutSet == null) {
// This subtype doesn't have a keyboardLayoutSet extra value, so lookup its keyboard
// layout set in sLocaleAndExtraValueToKeyboardLayoutSetMap to keep it compatible with
// pre-JellyBean.
final String key = subtype.getLocale() + ":" + subtype.getExtraValue();
keyboardLayoutSet = sLocaleAndExtraValueToKeyboardLayoutSetMap.get(key);
}
// TODO: Remove this null check when InputMethodManager.getCurrentInputMethodSubtype is
// fixed.
if (keyboardLayoutSet == null) {
Log.w(TAG, "KeyboardLayoutSet not found, use QWERTY: " +
"locale=" + subtype.getLocale() + " extraValue=" + subtype.getExtraValue());
return QWERTY;
}
return keyboardLayoutSet;
}
/**
* @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();
}
}
/**
* Called when the subtype was changed.
* @param newSubtype the subtype which is being changed to.
*/
protected void onCurrentInputMethodSubtypeChanged(InputMethodSubtype newSubtype) {
if (DEBUG) {
int nameResId = newSubtype.getNameResId();
String mode = newSubtype.getMode();
String output = "changeInputMethodSubtype:"
+ (nameResId == 0 ? "<none>" : getString(nameResId)) + ","
+ mode + ","
+ newSubtype.getLocale() + "," + newSubtype.getExtraValue();
Log.v(TAG, "--- " + output);
}
}
public static String getPrefSubtype(final InputMethodSubtype subtype) {
final String localeString = subtype.getLocale();
final String keyboardLayoutSetName = SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype);
final String layoutExtraValue = KEYBOARD_LAYOUT_SET + "=" + keyboardLayoutSetName;
final String extraValue = StringUtils.removeFromCommaSplittableTextIfExists(
layoutExtraValue, StringUtils.removeFromCommaSplittableTextIfExists(
IS_ADDITIONAL_SUBTYPE, subtype.getExtraValue()));
final String basePrefSubtype = localeString + LOCALE_AND_LAYOUT_SEPARATOR
+ keyboardLayoutSetName;
return extraValue.isEmpty() ? basePrefSubtype
: basePrefSubtype + LOCALE_AND_LAYOUT_SEPARATOR + extraValue;
}
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);
}
}
public static String getPrefSubtype(final InputMethodSubtype subtype) {
final String localeString = subtype.getLocale();
final String keyboardLayoutSetName = SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype);
final String layoutExtraValue = KEYBOARD_LAYOUT_SET + "=" + keyboardLayoutSetName;
final String extraValue = StringUtils.removeFromCommaSplittableTextIfExists(
layoutExtraValue, StringUtils.removeFromCommaSplittableTextIfExists(
IS_ADDITIONAL_SUBTYPE, subtype.getExtraValue()));
final String basePrefSubtype = localeString + LOCALE_AND_LAYOUT_SEPARATOR
+ keyboardLayoutSetName;
return extraValue.isEmpty() ? basePrefSubtype
: basePrefSubtype + LOCALE_AND_LAYOUT_SEPARATOR + extraValue;
}
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);
}
}
protected static Locale getLabelLocale(final InputMethodSubtype subtype) {
final String localeString = subtype.getLocale();
if (localeString.equals(SubtypeLocaleUtils.NO_LANGUAGE)) {
return null;
}
return LocaleUtils.constructLocaleFromString(localeString);
}
/**
* @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 SubtypeLocaleItem(final InputMethodSubtype subtype) {
mLocaleString = subtype.getLocale();
mDisplayName = SubtypeLocaleUtils.getSubtypeLocaleDisplayNameInSystemLocale(
mLocaleString);
}
private InputMethodSubtype findDuplicatedSubtype(final InputMethodSubtype subtype) {
final String localeString = subtype.getLocale();
final String keyboardLayoutSetName = SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype);
return mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
localeString, keyboardLayoutSetName);
}
public SubtypeLocaleItem(final InputMethodSubtype subtype) {
mLocaleString = subtype.getLocale();
mDisplayName = SubtypeLocaleUtils.getSubtypeLocaleDisplayNameInSystemLocale(
mLocaleString);
}
private InputMethodSubtype findDuplicatedSubtype(final InputMethodSubtype subtype) {
final String localeString = subtype.getLocale();
final String keyboardLayoutSetName = SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype);
return mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
localeString, keyboardLayoutSetName);
}
@Nonnull
public static Locale getSubtypeLocale(@Nonnull final InputMethodSubtype subtype) {
final String localeString = subtype.getLocale();
return LocaleUtils.constructLocaleFromString(localeString);
}
public SubtypeLocaleItem(final InputMethodSubtype subtype) {
mLocaleString = subtype.getLocale();
mDisplayName = SubtypeLocaleUtils.getSubtypeLocaleDisplayNameInSystemLocale(
mLocaleString);
}
public static Locale getSubtypeLocale(final InputMethodSubtype subtype) {
final String localeString = subtype.getLocale();
return LocaleUtils.constructLocaleFromString(localeString);
}
public SubtypeLocaleItem(final InputMethodSubtype subtype) {
mLocaleString = subtype.getLocale();
mDisplayName = SubtypeLocaleUtils.getSubtypeLocaleDisplayNameInSystemLocale(
mLocaleString);
}