android 5.1源代码之自定义app名称 根据包名或者app名称对这个应用给其他语言的或者自定义的应用名称

在android系统中从一个语言环境切换到另一个语言环境的时候,会涉及到更换app名称的事件。比如从中文切换到英文或者其他语言的时候,app的名称从中文切换到英文或者其他语言。先获取app的名称或者包名,然后根据这个包名或者app名给这个应用对应的其他语言的app名称 。废话不多说,直接进入代码,红色的为主要的代码部分

packages/apps/Trebuchet/src/com/android/laucher3/iconCache

private CacheEntry cacheLocked(ComponentName componentName, LauncherActivityInfoCompat info,
            HashMap<Object, CharSequence> labelCache, UserHandleCompat user,
            boolean usePackageIcon, int unreadNum) {
        CacheKey cacheKey = new CacheKey(componentName, user);
        CacheEntry entry = mCache.get(cacheKey);

        boolean isCustomTitle = false;
        String activity = null;
        if (info != null) {
            boolean condition = (mContext.getResources().
                    getBoolean(R.bool.config_launcher_stkAppRename))
                    && info.getComponentName().getPackageName().toString()
                            .equalsIgnoreCase(STK_PACKAGE_NAME);
            activity = info.getComponentName().getClassName().toString();

            if (condition
                    && !TextUtils.isEmpty(((LauncherApplication) mContext)
                            .getStkAppName(activity))) {
                isCustomTitle = true;
            }
        }
        if (entry == null || unreadNum >= 0) {
            entry = new CacheEntry();

            mCache.put(cacheKey, entry);

            if (info != null) {
                ComponentName labelKey = info.getComponentName();
                if (labelCache != null && labelCache.containsKey(labelKey)) {
                    if (isCustomTitle) {
                        entry.title = ((LauncherApplication) mContext)
                                .getStkAppName(activity);
                    } else {
                        entry.title = labelCache.get(labelKey).toString();
                    }
                } else {
                    if (isCustomTitle) {
                        entry.title = ((LauncherApplication) mContext)
                                .getStkAppName(activity);
                    } else {
                        entry.title = info.getLabel().toString();
                    }
                    if (labelCache != null) {
                        labelCache.put(labelKey, entry.title);
                    }
                }

                entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
                entry.icon = Utilities.createIconBitmap(
                        info.getBadgedIcon(mIconDpi), mContext, unreadNum);
            } else {
                entry.title = "";
                Bitmap preloaded = getPreloadedIcon(componentName, user);
                if (preloaded != null) {
                    if (DEBUG) Log.d(TAG, "using preloaded icon for " +
                            componentName.toShortString());
                    entry.icon = preloaded;
                } else {
                    if (usePackageIcon) {
                        CacheEntry packageEntry = getEntryForPackage(
                                componentName.getPackageName(), user);
                        if (packageEntry != null) {
                            if (DEBUG) Log.d(TAG, "using package default icon for " +
                                    componentName.toShortString());
                            entry.icon = packageEntry.icon;
                            entry.title = packageEntry.title;
                        }
                    }
                    if (entry.icon == null) {
                        if (DEBUG) Log.d(TAG, "using default icon for " +
                                componentName.toShortString());
                        entry.icon = getDefaultIcon(user);
                    }
                }
            }
        }
        if(componentName!=null){
    //tergun add
       if(Local.getLocaleLanguage().equals("mn-CN")) {
        if(componentName.getPackageName().equals("com.android.contacts")){
                    entry.title=mContext.getString(R.string.delete_zone_label_workspace);
                  }else if(entry.title.equals("WeChat")){
                       entry.title=mContext.getString(R.string.wechat);
                  }
            }
       //tergun end

        }
        return entry;
    }

 

求评论

能帮你解决问题就打个赏吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值