CubieBoard中文论坛

 找回密码
 立即注册
搜索
热搜: unable
查看: 8361|回复: 1

TvdLauncher切换语言桌面应用程序标题不变,需重启才会变

[复制链接]
发表于 2014-5-9 17:11:20 | 显示全部楼层 |阅读模式
经分析,是源码未添加广播接收处理语言环境,导致更新UI失败
修改如下:
1.修改src/com/softwinner/launcher/LauncherApplication.java
在onCreate()方法里增加监听系统改变语言的动作
  1. --- a/device/softwinner/common/packages/TvdLauncher/src/com/softwinner/launcher/LauncherApplication.java
  2. +++ b/device/softwinner/common/packages/TvdLauncher/src/com/softwinner/launcher/LauncherApplication.java
  3. @@ -50,6 +50,8 @@ public class LauncherApplication extends Application {
  4.          filter = new IntentFilter();
  5.          filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
  6.          filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
  7. //添加注册的监听动作
  8. +               filter.addAction(Intent.ACTION_LOCALE_CHANGED);
  9. +        filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
  10.          registerReceiver(mModel, filter);

  11.          // Register for changes to the favorites
复制代码
2.修改src/com/softwinner/launcher/LauncherModel.java,添加广播处理Launcher的UI
  1. --- a/device/softwinner/common/packages/TvdLauncher/src/com/softwinner/launcher/LauncherModel.java
  2. +++ b/device/softwinner/common/packages/TvdLauncher/src/com/softwinner/launcher/LauncherModel.java
  3. @@ -30,6 +30,7 @@ import android.content.pm.ActivityInfo;
  4. import android.content.pm.PackageManager;
  5. import android.content.pm.ProviderInfo;
  6. import android.content.pm.ResolveInfo;
  7. +import android.content.res.Configuration;
  8. import android.content.res.Resources;
  9. import android.database.Cursor;
  10. import android.graphics.Bitmap;
  11. @@ -96,6 +97,7 @@ public class LauncherModel extends BroadcastReceiver {

  12.      private Bitmap mDefaultIcon;

  13. +protected int mPreviousConfigMcc;
  14.      public interface Callbacks {
  15.          public boolean setLoadOnResume();
  16.          
  17. @@ -125,6 +127,8 @@ public class LauncherModel extends BroadcastReceiver {
  18.                  app.getPackageManager().getDefaultActivityIcon(), app);

  19.          mAllAppsLoadDelay = app.getResources().getInteger(R.integer.config_allAppsBatchLoadDelay);
  20. +               Configuration config = app.getResources().getConfiguration();
  21. +        mPreviousConfigMcc = config.mcc;

  22.          mBatchSize = app.getResources().getInteger(R.integer.config_allAppsBatchSize);
  23.      }
  24. @@ -196,6 +200,22 @@ public class LauncherModel extends BroadcastReceiver {
  25.              enqueuePackageUpdated(new PackageUpdatedTask(
  26.                          PackageUpdatedTask.OP_UNAVAILABLE, packages));

  27. +        }else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
  28. +            // If we have changed locale we need to clear out the labels in all apps/workspace.
  29. +            forceReload();
  30. +          Log.i("zhu","ACTION_LOCALE_CHANGED----------------------------forceReload");
  31. +        } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
  32. +             // Check if configuration change was an mcc/mnc change which would affect app resources
  33. +             // and we would need to clear out the labels in all apps/workspace. Same handling as
  34. +             // above for ACTION_LOCALE_CHANGED
  35. +             Configuration currentConfig = context.getResources().getConfiguration();
  36. +             if (mPreviousConfigMcc != currentConfig.mcc) {
  37. +                   Log.d("zhu", "Reload apps on config change. curr_mcc:"
  38. +                       + currentConfig.mcc + " prevmcc:" + mPreviousConfigMcc);
  39. +                   forceReload();
  40. +             }
  41. +             // Update previousConfig
  42. +             mPreviousConfigMcc = currentConfig.mcc;
  43.          }
  44.      }

  45. @@ -254,6 +274,55 @@ public class LauncherModel extends BroadcastReceiver {
  46.              });
  47.          }      
  48.      }
  49. + private void forceReload() {
  50. +        resetLoadedState(true, true);
  51. +
  52. +        // Do this here because if the launcher activity is running it will be restarted.
  53. +        // If it's not running startLoaderFromBackground will merely tell it that it needs
  54. +        // to reload.
  55. +        startLoaderFromBackground();
  56. +    }
  57. +       public void resetLoadedState(boolean resetAllAppsLoaded, boolean resetWorkspaceLoaded) {
  58. +        synchronized (mLock) {
  59. +            // Stop any existing loaders first, so they don't set mAllAppsLoaded or
  60. +            // mWorkspaceLoaded to true later
  61. +            stopLoaderLocked();
  62. +            if (resetAllAppsLoaded) mAllAppsLoaded = false;
  63. +            if (resetWorkspaceLoaded) mWorkspaceLoaded = false;
  64. +        }
  65. +    }
  66. +       /* configuration changes.  So whenever we trigger the loader from the background
  67. +     * tell the launcher that it needs to re-run the loader when it comes back instead
  68. +     * of doing it now.
  69. +     */
  70. +    public void startLoaderFromBackground() {
  71. +        boolean runLoader = false;
  72. +        if (mCallbacks != null) {
  73. +            Callbacks callbacks = mCallbacks.get();
  74. +            if (callbacks != null) {
  75. +                // Only actually run the loader if they're not paused.
  76. +                if (!callbacks.setLoadOnResume()) {
  77. +                    runLoader = true;
  78. +                }
  79. +            }
  80. +        }
  81. +      Log.i("zhu","runLoader-----------------------"+runLoader);
  82. +        if (runLoader) {
  83. +            //startLoader(false, -1);
  84. +                       startLoader(mApp, false);
  85. +        }
  86. +    }
  87. +       private boolean stopLoaderLocked() {
  88. +        boolean isLaunching = false;
  89. +        LoaderTask oldTask = mLoaderTask;
  90. +        if (oldTask != null) {
  91. +            if (oldTask.isLaunching()) {
  92. +                isLaunching = true;
  93. +            }
  94. +            oldTask.stopLocked();
  95. +        }
  96. +        return isLaunching;
  97. +    }

  98.      /**
  99.       * Adds an item to the DB if it was not created previously, or move it to a new
复制代码
3.修改src/com/softwinner/launcher/Launcher.java,使其一进入应用程序开启异步程序加载当前环境
  1. --- a/device/softwinner/common/packages/TvdLauncher/src/com/softwinner/launcher/Launcher.java
  2. +++ b/device/softwinner/common/packages/TvdLauncher/src/com/softwinner/launcher/Launcher.java
  3. @@ -533,6 +533,7 @@ public final class Launcher extends Activity{
  4.       * Finds all the views we need and configure them properly.
  5.       */
  6.      private void setupViews() {
  7. +               checkForLocaleChange();
  8.          setContentView(R.layout.launcher);
  9.          //mAllAppsGrid = (IAllAppsView)findViewById(R.id.all_apps_view);
  10.          WorkSpace mainLayout = (WorkSpace)findViewById(R.id.mainlayout);
复制代码
已验证Ok,附件是修改过的TvdLauncher源码,有需要的朋友可以下载,谢谢!

TvdLauncher.zip

1.46 MB, 下载次数: 22, 下载积分: 金钱 -1

评分

参与人数 1金钱 +7 收起 理由
lin + 7 很给力!

查看全部评分

回复

使用道具 举报

发表于 2014-5-9 19:22:32 | 显示全部楼层
厉害,学习了!!!!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|粤ICP备13051116号|cubie.cc---深刻的嵌入式技术讨论社区

GMT+8, 2022-10-1 00:55 , Processed in 0.019278 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2012 Comsenz Inc. | Style by Coxxs

返回顶部