修改系统默认语言

                                           修改默认语言

1. 切换不同UI后的默认语言。(以西班牙语为例:es_ES)
一般要求使用切换UI指令切换UI后,修改默认的语言为西班牙语。(某一UI下切换到其他语言如中文,再使用切换UI指令切换到其他UI后,要恢复到默认语言西班牙语。)
打开文件:SpecialCharSequenceMgr.java,在最后位置加入强制设置语言方法:forceChangeUserLocale(Locale locale),此方法在切换指令的方法中使用时,一定要添加重启方法之前。
文件路径:packages/apps/Dialer/src/com/android/dialer/SpecialCharSequenceMgr.java
代码如下:
static boolean handleUserIdLogoSwitch(Context context, String input) {
        boolean switched = false;
        if ((input.equals("*#*#0000#*#*"))||(input.equals("*#*#2000#*#*")&&(FeatureOption.CUSTOM_PROJECT_A||FeatureOption.CUSTOM_PROJECT_C))) {
            int logo_id = 0;//----------android
            int errCode = ProjectManager.writeLogoId(logo_id);
            DisplayResult(context, errCode);
            switched = true;
    
        } else if ((input.equals("*#*#6695#*#*")&&(FeatureOption.CUSTOM_PROJECT_A))||(input.equals("*#*#3000#*#*")&&(FeatureOption.CUSTOM_PROJECT_B))){
            int logo_id = 1;//----------LK
            int errCode = ProjectManager.writeLogoId(logo_id);
            DisplayResult(context, errCode);
            switched = true;

        }else if (input.equals("*#*#3000#*#*")&&(FeatureOption.CUSTOM_PROJECT_A||FeatureOption.CUSTOM_PROJECT_C)) {
            int logo_id = 2;//----------welcome
            int errCode = ProjectManager.writeLogoId(logo_id);
            DisplayResult(context, errCode);
            switched = true;

        }else if (input.equals("*#*#6679#*#*")&&(FeatureOption.CUSTOM_PROJECT_A||FeatureOption.CUSTOM_PROJECT_C)) {
            int logo_id = 3;----------sony
            int errCode = ProjectManager.writeLogoId(logo_id);
            DisplayResult(context, errCode);
            switched = true; 


        }else if (input.equals("*#*#6677#*#*")&&(FeatureOption.CUSTOM_PROJECT_C)) {
            int logo_id = 10;//------orro
            int errCode = ProjectManager.writeLogoId(logo_id);
            DisplayResult(context, errCode);
            switched = true;
    
        }
       

        if (switched) {
            finshChangeUI(context);// 切换指令后,执行此方法
        /*    try {
                WallpaperManager.getInstance(context).clear();
                Intent intent = new Intent();
                ComponentName componentName = new ComponentName("com.android.builtindata","com.android.builtindata.RebootActivity");
                intent.setComponent(componentName);
                context.startActivity(intent);
            } catch (Exception e) {
                Log.i(TAG, "handleUserIdLogoSwitch e = "+e);
            }
            // doSyncMovies();
            return true;*/        
        }


        return false;
    }
       

    private static boolean finshChangeUI(Context context){
        try {
            forceChangeUserLocaleByProject();
            WallpaperManager.getInstance(context).clear();
            Intent intent = new Intent();
                ComponentName componentName = new ComponentName("com.android.builtindata",     "com.android.builtindata.SwitchRebootActivity");
            intent.setComponent(componentName);
            mContext.startActivity(intent);
            } catch (Exception e) {
                Log.i(TAG, "handleUserIdLogoSwitch e = "+e);
            }
            // doSyncMovies();
            return true;
    }
   

    //不同分支项目不同UI下切换,强制转换
    private static void forceChangeUserLocaleByProject(){
        if( FeatureOption.CUSTOM_PROJECT_C && (ProjectManager.isUi2()|| ProjectManager.isUi10() || ProjectManager.isAndroid())){
            forceChangeUserLocale(new Locale("es", "ES"));//西班牙文
        }else if( FeatureOption.CUSTOM_PROJECT_B ){
            forceChangeUserLocale(new Locale("en", "US"));// 英文
        }else if( FeatureOption.CUSTOM_PROJECT_C && ProjectManager.isUi3() ){
            forceChangeUserLocale(new Locale("en", "US"));// 英文
        }
    }


    //强制转换方法
    private static boolean forceChangeUserLocale(Locale locale){
        boolean ret = false;
        try {
            IActivityManager am = ActivityManagerNative.getDefault();
            Configuration config = am.getConfiguration();
            config.locale = locale;
            config.userSetLocale = true;
            am.updateConfiguration(config);
            ret = true;
        } catch (RemoteException e) {
            ret = false;
        }
        return ret;
    }


2. 修改默认语言。(以西班牙语为例:es_ES)
(1) 打开文件:full_gxq6580_weg_l.mk,把PRODUCT_LOCALES中的es_ES放在最前面的位置即可。
若项目有分支项目,则需在分出来的分支中进行更改这个文件。(若分支中没有该文件,则需在分支中添加后修改)。
文件路径:/device/gxq/gxq6580_weg_l/ full_gxq6580_weg_l.mk
代码如下:
PRODUCT_LOCALES := es_ES en_US zh_CN zh_TW pt_BR ru_RU fr_FR de_DE tr_TR vi_VN ms_MY in_ID th_TH it_IT ar_EG hi_IN bn_IN ur_PK fa_IR pt_PT nl_NL el_GR hu_HU tl_PH ro_RO cs_CZ ko_KR km_KH iw_IL my_MM pl_PL es_US bg_BG hr_HR lv_LV lt_LT sk_SK uk_UA de_AT da_DK fi_FI nb_NO sv_SE en_GB hy_AM zh_HK et_EE ja_JP kk_KZ sr_RS sl_SI ca_ES


(2) 同理,打开同目录文件:ProjectConfig.mk,把MTK_PRODUCT_LOCALES中的es_ES放在最前面的位置即可。
若项目有分支项目,则需在分出来的分支中进行更改这个文件。(若分支中没有该文件,则需在分支中添加后修改)。
文件路径:/device/gxq/gxq6580_weg_l/ ProjectConfig.mk
代码如下:
MTK_PRODUCT_LOCALES = es_ES en_US zh_CN zh_TW pt_BR ru_RU fr_FR de_DE tr_TR vi_VN ms_MY in_ID th_TH it_IT ar_EG hi_IN bn_IN ur_PK fa_IR pt_PT nl_NL el_GR hu_HU tl_PH ro_RO cs_CZ ko_KR km_KH iw_IL pl_PL es_US bg_BG hr_HR lv_LV lt_LT sk_SK uk_UA de_AT da_DK fi_FI nb_NO sv_SE en_GB hy_AM et_EE ja_JP kk_KZ sr_RS sl_SI ca_ES my_ZG



3. 恢复出厂设置后的默认语言。(以西班牙语为例:es_ES)
(1)打开文件:AndroidRuntime.cpp,在readLocale()方法中修改代码:其中value的值是logoId的值,
若需要某一分支下的一套或几套UI默认西班牙语,则只需要改变value的值。
文件路径:/frameworks/base/core/jni/AndroidRuntime.cpp
代码如下:
static void readLocale(char* language, char* region)
{    
    ALOGD("readLocale==============================");
    char propLang[PROPERTY_VALUE_MAX], propRegn[PROPERTY_VALUE_MAX];

    property_get("persist.sys.language", propLang, "");
    property_get("persist.sys.country", propRegn, "");
    if (*propLang == 0 && *propRegn == 0) {
        ALOGD("readLocale>>>>>>>>>>>>>>>");
        /// M: SIM Locale feature @{
        char propSIMLang[PROPERTY_VALUE_MAX];
        char propSIMRegn[PROPERTY_VALUE_MAX];


        property_get("persist.sys.simlanguage", propSIMLang, "");
        property_get("persist.sys.simcountry", propSIMRegn, "");
        /// @}

        if (*propSIMLang != 0 && *propSIMRegn != 0) {
            /// M: SIM Locale feature:
            /// If simlanguage is set, we will use this as the device default locale
            /// Otherwise, use the en as the default locale @{
            strcpy(propLang, propSIMLang);
            strcpy(propRegn, propSIMRegn);
            /// @}
            ALOGD("readLocale>>>>>>>>>++++++++++++++++++>>>>>>");
        } else {
            char *logoFlagFile = "/proc/env_logo_id";
            int fd = open(logoFlagFile, O_RDONLY);
            int logoNum = 0;
            char buf[20]={0};
            int value = -1; //默认为-1
            ALOGD("readLocale fd = %d ", fd);
            if(fd >= 0){
                int count = read(fd, buf, sizeof(buf));
                if(count <= 0){
                    value = 0;
                }
                close(fd);
                ALOGD("readLocale count = %d ", count);
                
                /*默认UI下(没切UI没恢复出厂设置)buf的值为NULL,value = atoi(buf)的值为0,所以加此判断来区分logoId=0;*/
                if (strcmp(buf, "NULL") == 0){
                    value = -1;    //-------默认UI下value的赋值为-1;
                }else{
                    value = atoi(buf); //-------切UI后value的值为buf读到的值;
                }
                
            }

            ALOGD("readLocale value = %d ", value);

#if defined(CUSTOM_PROJECT_B)//-----分支项目B


            /*logId为0,2,10的UI恢复出厂设置后为西班牙语,vlaue=-1是默认没切UI没恢复出厂设置时的值*/
            if(value==10 || value==0 || value==2  || value==-1){
                strcpy(propLang, "es");
                strcpy(propRegn, "ES");
                ALOGD("readLocale_iiiiiffffffff propLang=%s propRegn=%s\n", propLang, propRegn);/// M: show debug log
                
            }else{ //--------logId为其他时恢复出厂设置后为英语
                strcpy(propLang, "en");
                strcpy(propRegn, "US");
                ALOGD("readLocale_elseeeeeeeeee propLang=%s propRegn=%s\n", propLang, propRegn);/// M: show debug log
            }
#elif defined(CUSTOM_PROJECT_C)//-----分支项目C    
    
            /*logId为0,2,10的UI恢复出厂设置后为西班牙语,vlaue=-1是默认没切UI没恢复出厂设置时的值*/
            if(value==10 || value==0 || value==2  || value==-1){
                strcpy(propLang, "es");
                strcpy(propRegn, "ES");
                ALOGD("readLocale_iiiiiffffffff propLang=%s propRegn=%s\n", propLang, propRegn);/// M: show debug log
                
            }else{ //--------logId为其他时恢复出厂设置后为英语
                strcpy(propLang, "en");
                strcpy(propRegn, "US");
                ALOGD("readLocale_elseeeeeeeeee propLang=%s propRegn=%s\n", propLang, propRegn);/// M: show debug log
            }
#else
            property_get("ro.product.locale.language", propLang, "en");
            property_get("ro.product.locale.region", propRegn, "US");
#endif
        }
    }
    strncat(language, propLang, 3);
    strncat(region, propRegn, 3);
    ALOGD("readLocale1111 propLang=%s propRegn=%s\n", propLang, propRegn);
    ALOGD("readLocale1111 language=%s region=%s\n", language, region);     /// M: show debug log
}



(2)如有分支项目,则需要在同目录下的Android.mk文件中添加分支项目宏开关。
Android.mk路径:/frameworks/base/core/jni/Android.mk
代码如下:
ifeq ($(CUSTOM_PROJECT_A),yes)
    LOCAL_CFLAGS += -DCUSTOM_PROJECT_A
endif

ifeq ($(CUSTOM_PROJECT_B),yes)
    LOCAL_CFLAGS += -DCUSTOM_PROJECT_B
endif

ifeq ($(CUSTOM_PROJECT_C),yes)
    LOCAL_CFLAGS += -DCUSTOM_PROJECT_C
endif


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值