|
经分析,是源码未添加广播接收处理语言环境,导致更新UI失败
修改如下:
1.修改src/com/softwinner/launcher/LauncherApplication.java
在onCreate()方法里增加监听系统改变语言的动作- --- a/device/softwinner/common/packages/TvdLauncher/src/com/softwinner/launcher/LauncherApplication.java
- +++ b/device/softwinner/common/packages/TvdLauncher/src/com/softwinner/launcher/LauncherApplication.java
- @@ -50,6 +50,8 @@ public class LauncherApplication extends Application {
- filter = new IntentFilter();
- filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
- filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
- //添加注册的监听动作
- + filter.addAction(Intent.ACTION_LOCALE_CHANGED);
- + filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
- registerReceiver(mModel, filter);
-
- // Register for changes to the favorites
复制代码 2.修改src/com/softwinner/launcher/LauncherModel.java,添加广播处理Launcher的UI- --- a/device/softwinner/common/packages/TvdLauncher/src/com/softwinner/launcher/LauncherModel.java
- +++ b/device/softwinner/common/packages/TvdLauncher/src/com/softwinner/launcher/LauncherModel.java
- @@ -30,6 +30,7 @@ import android.content.pm.ActivityInfo;
- import android.content.pm.PackageManager;
- import android.content.pm.ProviderInfo;
- import android.content.pm.ResolveInfo;
- +import android.content.res.Configuration;
- import android.content.res.Resources;
- import android.database.Cursor;
- import android.graphics.Bitmap;
- @@ -96,6 +97,7 @@ public class LauncherModel extends BroadcastReceiver {
-
- private Bitmap mDefaultIcon;
-
- +protected int mPreviousConfigMcc;
- public interface Callbacks {
- public boolean setLoadOnResume();
-
- @@ -125,6 +127,8 @@ public class LauncherModel extends BroadcastReceiver {
- app.getPackageManager().getDefaultActivityIcon(), app);
-
- mAllAppsLoadDelay = app.getResources().getInteger(R.integer.config_allAppsBatchLoadDelay);
- + Configuration config = app.getResources().getConfiguration();
- + mPreviousConfigMcc = config.mcc;
-
- mBatchSize = app.getResources().getInteger(R.integer.config_allAppsBatchSize);
- }
- @@ -196,6 +200,22 @@ public class LauncherModel extends BroadcastReceiver {
- enqueuePackageUpdated(new PackageUpdatedTask(
- PackageUpdatedTask.OP_UNAVAILABLE, packages));
-
- + }else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
- + // If we have changed locale we need to clear out the labels in all apps/workspace.
- + forceReload();
- + Log.i("zhu","ACTION_LOCALE_CHANGED----------------------------forceReload");
- + } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
- + // Check if configuration change was an mcc/mnc change which would affect app resources
- + // and we would need to clear out the labels in all apps/workspace. Same handling as
- + // above for ACTION_LOCALE_CHANGED
- + Configuration currentConfig = context.getResources().getConfiguration();
- + if (mPreviousConfigMcc != currentConfig.mcc) {
- + Log.d("zhu", "Reload apps on config change. curr_mcc:"
- + + currentConfig.mcc + " prevmcc:" + mPreviousConfigMcc);
- + forceReload();
- + }
- + // Update previousConfig
- + mPreviousConfigMcc = currentConfig.mcc;
- }
- }
-
- @@ -254,6 +274,55 @@ public class LauncherModel extends BroadcastReceiver {
- });
- }
- }
- + private void forceReload() {
- + resetLoadedState(true, true);
- +
- + // Do this here because if the launcher activity is running it will be restarted.
- + // If it's not running startLoaderFromBackground will merely tell it that it needs
- + // to reload.
- + startLoaderFromBackground();
- + }
- + public void resetLoadedState(boolean resetAllAppsLoaded, boolean resetWorkspaceLoaded) {
- + synchronized (mLock) {
- + // Stop any existing loaders first, so they don't set mAllAppsLoaded or
- + // mWorkspaceLoaded to true later
- + stopLoaderLocked();
- + if (resetAllAppsLoaded) mAllAppsLoaded = false;
- + if (resetWorkspaceLoaded) mWorkspaceLoaded = false;
- + }
- + }
- + /* configuration changes. So whenever we trigger the loader from the background
- + * tell the launcher that it needs to re-run the loader when it comes back instead
- + * of doing it now.
- + */
- + public void startLoaderFromBackground() {
- + boolean runLoader = false;
- + if (mCallbacks != null) {
- + Callbacks callbacks = mCallbacks.get();
- + if (callbacks != null) {
- + // Only actually run the loader if they're not paused.
- + if (!callbacks.setLoadOnResume()) {
- + runLoader = true;
- + }
- + }
- + }
- + Log.i("zhu","runLoader-----------------------"+runLoader);
- + if (runLoader) {
- + //startLoader(false, -1);
- + startLoader(mApp, false);
- + }
- + }
- + private boolean stopLoaderLocked() {
- + boolean isLaunching = false;
- + LoaderTask oldTask = mLoaderTask;
- + if (oldTask != null) {
- + if (oldTask.isLaunching()) {
- + isLaunching = true;
- + }
- + oldTask.stopLocked();
- + }
- + return isLaunching;
- + }
-
- /**
- * 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,使其一进入应用程序开启异步程序加载当前环境- --- a/device/softwinner/common/packages/TvdLauncher/src/com/softwinner/launcher/Launcher.java
- +++ b/device/softwinner/common/packages/TvdLauncher/src/com/softwinner/launcher/Launcher.java
- @@ -533,6 +533,7 @@ public final class Launcher extends Activity{
- * Finds all the views we need and configure them properly.
- */
- private void setupViews() {
- + checkForLocaleChange();
- setContentView(R.layout.launcher);
- //mAllAppsGrid = (IAllAppsView)findViewById(R.id.all_apps_view);
- WorkSpace mainLayout = (WorkSpace)findViewById(R.id.mainlayout);
复制代码 已验证Ok,附件是修改过的TvdLauncher源码,有需要的朋友可以下载,谢谢!
|
评分
-
查看全部评分
|