关于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
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值