当前位置:   article > 正文

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

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;
    }

 

求评论

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/174051?site
推荐阅读
相关标签
  

闽ICP备14008679号