安卓删除系统语言代码解析
Posted 我爱一次性
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了安卓删除系统语言代码解析相关的知识,希望对你有一定的参考价值。
本文所在的平台是安卓9
前言:
上一篇已经介绍了安卓主要修改哪些配置文件去修改系统语言。本文就主要讲解一下代码,大家来探究一下。
上一篇:安卓增加或删除系统语言
1.找出添加语言的这个button布局 add_language
1.1在settings源码里搜索关键字 Add a language :
路径:packages/apps/Settings/res/values/strings.xml
1.2根据字符串的id搜索button 搜索 add_a_language
路径:packages/apps/Settings/res/layout/locale_order_list.xml
1.3在根据布局id定位源码 搜索add_a_languge上面的 add_language
最后图的路径:/packages/apps/Settings/localepicker/LocaleListEditor.java
2.寻找LocalePickerWithRegion类
路径:frameworks/base/core/java/com/android/internal/app/LocalePickerWithRegion.java
2.2找方法createLanguagePicker
2.3找方法setListener
private boolean setListener(Context context, LocaleSelectedListener listener,
LocaleStore.LocaleInfo parent, boolean translatedOnly) {
this.mParentLocale = parent;
this.mListener = listener;
this.mTranslatedOnly = translatedOnly;
setRetainInstance(true);
final HashSet<String> langTagsToIgnore = new HashSet<>();
if (!translatedOnly) {
final LocaleList userLocales = LocalePicker.getLocales();
final String[] langTags = userLocales.toLanguageTags().split(",");
Collections.addAll(langTagsToIgnore, langTags);
}
if (parent != null) {
mLocaleList = LocaleStore.getLevelLocales(context,
langTagsToIgnore, parent, translatedOnly);
if (mLocaleList.size() <= 1) {
if (listener != null && (mLocaleList.size() == 1)) {
listener.onLocaleSelected(mLocaleList.iterator().next());
}
return false;
}
} else {
mLocaleList = LocaleStore.getLevelLocales(context, langTagsToIgnore,
null /* no parent */, translatedOnly);
}
return true;
}
2.4搜索LocaleStore.getLevelLocales方法
mLocaleList = LocaleStore.getLevelLocales(context, langTagsToIgnore, null /* no parent */, translatedOnly);
类路径:frameworks/base/core/java/com/android/internal/app/LocaleStore.java
public static Set<LocaleInfo> getLevelLocales(Context context, Set<String> ignorables,
LocaleInfo parent, boolean translatedOnly) {
fillCache(context);
String parentId = parent == null ? null : parent.getId();
HashSet<LocaleInfo> result = new HashSet<>();
Collection<LocaleStore.LocaleInfo> values =
new ArrayList<LocaleStore.LocaleInfo>(sLocaleCache.values());
for (LocaleStore.LocaleInfo li : values) {
int level = getLevel(ignorables, li, translatedOnly);
if (level == 2) {
if (parent != null) { // region selection
if (parentId.equals(li.getParent().toLanguageTag())) {
result.add(li);
}
} else { // language selection
if (li.isSuggestionOfType(LocaleInfo.SUGGESTION_TYPE_SIM)) {
result.add(li);
} else {
result.add(getLocaleInfo(li.getParent()));
}
}
}
}
return result;
}
继续搜索:fillCache(context)
public static void fillCache(Context context) {
if (sFullyInitialized) {
return;
}
Set<String> simCountries = getSimCountries(context);
final boolean isInDeveloperMode = Settings.Global.getInt(context.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
for (String localeId : LocalePicker.getSupportedLocales(context)) {
//看到这个getSupportedLocales
//那就我们继续搜索
if (localeId.isEmpty()) {
throw new IllformedLocaleException("Bad locale entry in locale_config.xml");
}
LocaleInfo li = new LocaleInfo(localeId);
if (LocaleList.isPseudoLocale(li.getLocale())) {
if (isInDeveloperMode) {
li.setTranslated(true);
li.mIsPseudo = true;
li.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_SIM;
} else {
// Do not display pseudolocales unless in development mode.
continue;
}
}
if (simCountries.contains(li.getLocale().getCountry())) {
li.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_SIM;
}
sLocaleCache.put(li.getId(), li);
final Locale parent = li.getParent();
if (parent != null) {
String parentId = parent.toLanguageTag();
if (!sLocaleCache.containsKey(parentId)) {
sLocaleCache.put(parentId, new LocaleInfo(parent));
}
}
}
// TODO: See if we can reuse what LocaleList.matchScore does
final HashSet<String> localizedLocales = new HashSet<>();
for (String localeId : LocalePicker.getSystemAssetLocales()) {
LocaleInfo li = new LocaleInfo(localeId);
final String country = li.getLocale().getCountry();
// All this is to figure out if we should suggest a country
if (!country.isEmpty()) {
LocaleInfo cachedLocale = null;
if (sLocaleCache.containsKey(li.getId())) { // the simple case, e.g. fr-CH
cachedLocale = sLocaleCache.get(li.getId());
} else { // e.g. zh-TW localized, zh-Hant-TW in cache
final String langScriptCtry = li.getLangScriptKey() + "-" + country;
if (sLocaleCache.containsKey(langScriptCtry)) {
cachedLocale = sLocaleCache.get(langScriptCtry);
}
}
if (cachedLocale != null) {
cachedLocale.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_CFG;
}
}
localizedLocales.add(li.getLangScriptKey());
}
for (LocaleInfo li : sLocaleCache.values()) {
li.setTranslated(localizedLocales.contains(li.getLangScriptKey()));
}
addSuggestedLocalesForRegion(Locale.getDefault());
sFullyInitialized = true;
}
看到for (String localeId : LocalePicker.getSupportedLocales(context))
2.5搜索 LocalePicker.getSupportedLocales
类路径:frameworks/base/core/java/com/android/internal/app/LocalePicker.java
啊,终于找到了,R.array.supported_locales,结合上一篇的文章,我们要修改的就是这个数组。
最后,希望可以帮到大家,如果有用的就收藏一下,白嫖的就点个赞。
以上是关于安卓删除系统语言代码解析的主要内容,如果未能解决你的问题,请参考以下文章