关于KK版本语言列表[Developer]Accented English问题

Accented English 是一种虚拟mapping出来的语言,source code的resource中并没有实际的values-zz-rZZ与source对应。仅仅会引起Settings中部分UI显示发生变化。这个对使用者而言是没有用的,所以屏蔽也无妨。

在语言设置中控制语言列表的是一个ListFragment => 

packages\apps\Settings\src\com\android\settings\LocalePicker.java

而Settings中的LocalePicker是extend

frameworks\base\core\java\com\android\internal\app\LocalePicker.java重写了isInDeveloperMode()方法

   @Override
    protected boolean isInDeveloperMode() {
        final boolean showDev = getActivity().getSharedPreferences(DevelopmentSettings.PREF_FILE,
                Context.MODE_PRIVATE).getBoolean(
                DevelopmentSettings.PREF_SHOW,
                android.os.Build.TYPE.equals("eng")); 
        return showDev;
    }

在父类中的onActivityCreated()方法中可以看到有setListAdater(adapter);

    @Override
    public void onActivityCreated(final Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        <span style="color:#ff0000;">final ArrayAdapter<LocaleInfo> adapter = constructAdapter(getActivity(),
                isInDeveloperMode());</span>
        setListAdapter(adapter);
    }
    public static ArrayAdapter<LocaleInfo> constructAdapter(Context context,
            final int layoutId, final int fieldId, final boolean isInDeveloperMode) {
        final Resources resources = context.getResources();

        ArrayList<String> localeList = new ArrayList<String>(Arrays.asList(
                Resources.getSystem().getAssets().getLocales()));//获取系统支持的语言
        if (isInDeveloperMode) {
            if (!localeList.contains("zz_ZZ")) {
                localeList.add("zz_ZZ");
            }
        /** - TODO: Enable when zz_ZY Pseudolocale is complete
         *  if (!localeList.contains("zz_ZY")) {
         *      localeList.add("zz_ZY");
         *	}
         */
        }
	....
        ....
        for (int i = 0 ; i < origSize; i++ ) {
            final String s = locales[i];
            final int len = s.length();
            if (len == 5) {
                String language = s.substring(0, 2);
                String country = s.substring(3, 5);
                final Locale l = new Locale(language, country);

                if (finalSize == 0) {
                    if (DEBUG) {
                        Log.v(TAG, "adding initial "+ toTitleCase(l.getDisplayLanguage(l)));
                    }
                    preprocess[finalSize++] =
                            new LocaleInfo(toTitleCase(l.getDisplayLanguage(l)), l);
                } else {
                    if (preprocess[finalSize-1].locale.getLanguage().equals(
                            language) &&
                            !preprocess[finalSize-1].locale.getLanguage().equals("zz")) {//如果语言是一样的话,在显示的时候需要将地区标注上去,如:中文(简体)、中文(繁体)等
                        preprocess[finalSize-1].label = toTitleCase(
                                getDisplayName(preprocess[finalSize-1].locale,
                                        specialLocaleCodes, specialLocaleNames));
                        preprocess[finalSize++] =
                                new LocaleInfo(toTitleCase(
                                        getDisplayName(
                                                l, specialLocaleCodes, specialLocaleNames)), l);
                    } else {
                        String displayName;
                        if (s.equals("zz_ZZ")) {
                          <span style="color:#ff0000;">  displayName = "[Developer] Accented English";</span>
                        } else if (s.equals("zz_ZY")) {
                            displayName = "[Developer] Fake Bi-Directional";
                        } else {
                            displayName = toTitleCase(l.getDisplayLanguage(l));
                        }
                        preprocess[finalSize++] = new LocaleInfo(displayName, l);
                    }
                }
            }
        }
        ....
        };
    }

在方法中当locale为zz_ZZ时,设置displayName为"[Deveploper] Accented English",这个就是显示在Settings语言列表中的Accented English,

在localelist中默认并不包含有zz_ZZ这个选项,只有在isInDeveloperMode为true时才会添加这个选项,即isInDeveploperMode()方法返回为true时才会添加。

现在需要去掉zz_ZZ这个选项的话,需要使isInDeveploperMode()返回为false,在父类中默认是返回false,而在Settings中LocalPicker.java有对这个方法的重写

  @Override
    protected boolean isInDeveloperMode() {
        final boolean showDev = getActivity().getSharedPreferences(DevelopmentSettings.PREF_FILE,
                Context.MODE_PRIVATE).getBoolean(
                DevelopmentSettings.PREF_SHOW,
                android.os.Build.TYPE.equals("eng")); 
        return showDev;
    }

showDev的返回值由DevelopmentSettings.PREF_SHOW的值来决定,如果不是在开发者模式下的话,默认的值就是false。但是连续点击版本号7下的话,可以进入开发者模式,那么此时showDev的值就变成true。这就是在User版(ro.build.tpye=user)默认是不会看到Accented English.

按上述分析,要屏蔽Accented English就很简单了,可以修改isInDeveloperMoed()强制性返回false,或者constructAdapter中去掉localeList.add("zz_ZZ");都可以。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码是一个用于编码转换的示例,它展示了如何使用Python来实现将Unicode数据编码为XML和HTML实体的功能。 让我们逐句解释一下代码: ```python import codecs from htmlentitydefs import codepoint2name ``` 首先,导入了codecs库和codepoint2name模块,后者包含了HTML实体的名称和对应的Unicode码点。 ```python def encode_for_xml(unicode_data, encoding='ascii'): return unicode_data.encode(encoding, 'xmlcharrefreplace') ``` 这是一个名为encode_for_xml的函数,它接受一个Unicode字符串和一个可选的编码参数。它使用给定的编码对Unicode数据进行编码,并将无法编码的字符替换为XML字符引用。 ```python def html_replace(exc): if isinstance(exc, (UnicodeEncodeError, UnicodeTranslateError)): s = [u'&%s;' % codepoint2name[ord(c)] for c in exc.object[exc.start:exc.end]] return ''.join(s), exc.end else: raise TypeError("can't handle %s" % exc.__name__) codecs.register_error('html_replace', html_replace) ``` 这是一个名为html_replace的函数,它是一个错误处理函数。当遇到无法编码的字符时,将调用此函数来处理。它将无法编码的字符替换为对应的HTML实体。 ```python def encode_for_html(unicode_data, encoding='ascii'): return unicode_data.encode(encoding, 'html_replace') ``` 这是另一个编码函数,名为encode_for_html。它与encode_for_xml函数类似,但是使用html_replace函数来处理无法编码的字符。 ```python if __name__ == '__main__': unicode_data = u'\N{LATIN SMALL LETTER A WITH DIAERESIS}' print encode_for_xml(unicode_data, encoding='ascii') data = u''' <html> <head> <title>Encoding Test</title> </head> <body> <p>accented characters: <ur> <li>\xe0 (a + grave) <li>\xe7 (c + cedilla) <li>\xe9 (a + acute) </ul> <p>symbols: <ul> <li>\xa3 (British pound) <li>\u20ac (Euro) <li>\u221e (infinity) </ul> </body></html> ''' print encode_for_xml(data) print encode_for_html(data) ``` 在这个if __name__ == '__main__'的块中,我们定义了一些测试数据并调用了encode_for_xml和encode_for_html函数来进行编码转换。输出将会显示Unicode数据的编码结果。 至于html_replace(exc)函数的参数例子,你可以将其添加到代码中并进行测试。例如: ```python def html_replace(exc): if isinstance(exc, (UnicodeEncodeError, UnicodeTranslateError)): s = [u'&%s;' % codepoint2name[ord(c)] for c in exc.object[exc.start:exc.end]] return ''.join(s), exc.end elif isinstance(exc, UnicodeDecodeError): # 示例参数例子 return u'&%s;' % codepoint2name[ord(exc.object[exc.start])], exc.end else: raise TypeError("can't handle %s" % exc.__name__) ``` 这样,当遇到Unicode解码错误时,将替换为对应的HTML实体。你可以在测试数据中添加一些无法解码的字符来进行测试。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值