summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@android.com>2010-09-01 13:45:16 -0700
committerBrad Fitzpatrick <bradfitz@android.com>2010-09-01 15:44:57 -0700
commit319226a894f5f0b94ca94e64f976a043e3873a40 (patch)
tree1daf13803b3342e9a5bbcfe53056e61c496a0a77 /src
parentfdf5fd63c6e76fffd28df6d032ee6bac1417edf6 (diff)
downloadandroid_packages_apps_Trebuchet-319226a894f5f0b94ca94e64f976a043e3873a40.tar.gz
android_packages_apps_Trebuchet-319226a894f5f0b94ca94e64f976a043e3873a40.tar.bz2
android_packages_apps_Trebuchet-319226a894f5f0b94ca94e64f976a043e3873a40.zip
Make Launcher.checkForLocaleChange async.
Logging indicated a 1.2 second improvement in Launcher start time during boot (when single-threaded yaffs is very heavily contended). BUG=2947474 Change-Id: Ie72cf02c5eacb27c6d874b6d67a0bb2de7f6b74a
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/Launcher.java63
1 files changed, 43 insertions, 20 deletions
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index a5988bf6c..28a671263 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -46,6 +46,7 @@ import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
@@ -198,8 +199,10 @@ public final class Launcher extends Activity
private LauncherModel mModel;
private IconCache mIconCache;
+ private static LocaleConfiguration sLocaleConfiguration = null;
+
private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
- private static HashMap<Long, FolderInfo> mFolders = new HashMap<Long, FolderInfo>();
+ private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
private ImageView mPreviousView;
private ImageView mNextView;
@@ -260,31 +263,51 @@ public final class Launcher extends Activity
}
private void checkForLocaleChange() {
- final LocaleConfiguration localeConfiguration = new LocaleConfiguration();
- readConfiguration(this, localeConfiguration);
+ if (sLocaleConfiguration == null) {
+ new AsyncTask<Void, Void, LocaleConfiguration>() {
+ @Override
+ protected LocaleConfiguration doInBackground(Void... unused) {
+ LocaleConfiguration localeConfiguration = new LocaleConfiguration();
+ readConfiguration(Launcher.this, localeConfiguration);
+ return localeConfiguration;
+ }
+
+ @Override
+ protected void onPostExecute(LocaleConfiguration result) {
+ sLocaleConfiguration = result;
+ checkForLocaleChange(); // recursive, but now with a locale configuration
+ }
+ }.execute();
+ return;
+ }
final Configuration configuration = getResources().getConfiguration();
- final String previousLocale = localeConfiguration.locale;
+ final String previousLocale = sLocaleConfiguration.locale;
final String locale = configuration.locale.toString();
- final int previousMcc = localeConfiguration.mcc;
+ final int previousMcc = sLocaleConfiguration.mcc;
final int mcc = configuration.mcc;
- final int previousMnc = localeConfiguration.mnc;
+ final int previousMnc = sLocaleConfiguration.mnc;
final int mnc = configuration.mnc;
boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
if (localeChanged) {
- localeConfiguration.locale = locale;
- localeConfiguration.mcc = mcc;
- localeConfiguration.mnc = mnc;
+ sLocaleConfiguration.locale = locale;
+ sLocaleConfiguration.mcc = mcc;
+ sLocaleConfiguration.mnc = mnc;
- writeConfiguration(this, localeConfiguration);
mIconCache.flush();
-
loadHotseats();
+
+ final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
+ new Thread("WriteLocaleConfiguration") {
+ public void run() {
+ writeConfiguration(Launcher.this, localeConfiguration);
+ }
+ }.start();
}
}
@@ -687,7 +710,7 @@ public final class Launcher extends Activity
boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
if (renameFolder) {
long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
- mFolderInfo = mModel.getFolderById(this, mFolders, id);
+ mFolderInfo = mModel.getFolderById(this, sFolders, id);
mRestoring = true;
}
}
@@ -1230,7 +1253,7 @@ public final class Launcher extends Activity
LauncherModel.addItemToDatabase(this, folderInfo,
LauncherSettings.Favorites.CONTAINER_DESKTOP,
mWorkspace.getCurrentScreen(), cellInfo.cellX, cellInfo.cellY, false);
- mFolders.put(folderInfo.id, folderInfo);
+ sFolders.put(folderInfo.id, folderInfo);
// Create the view
FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
@@ -1240,7 +1263,7 @@ public final class Launcher extends Activity
}
void removeFolder(FolderInfo folder) {
- mFolders.remove(folder.id);
+ sFolders.remove(folder.id);
}
private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo) {
@@ -1295,7 +1318,7 @@ public final class Launcher extends Activity
LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
- mFolders.put(info.id, info);
+ sFolders.put(info.id, info);
return info;
}
@@ -1845,7 +1868,7 @@ public final class Launcher extends Activity
final String name = mInput.getText().toString();
if (!TextUtils.isEmpty(name)) {
// Make sure we have the right folder info
- mFolderInfo = mFolders.get(mFolderInfo.id);
+ mFolderInfo = sFolders.get(mFolderInfo.id);
mFolderInfo.title = name;
LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
@@ -2170,8 +2193,8 @@ public final class Launcher extends Activity
* Implementation of the method from LauncherModel.Callbacks.
*/
public void bindFolders(HashMap<Long, FolderInfo> folders) {
- mFolders.clear();
- mFolders.putAll(folders);
+ sFolders.clear();
+ sFolders.putAll(folders);
}
/**
@@ -2224,7 +2247,7 @@ public final class Launcher extends Activity
final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
if (userFolders != null) {
for (long folderId : userFolders) {
- final FolderInfo info = mFolders.get(folderId);
+ final FolderInfo info = sFolders.get(folderId);
if (info != null) {
openFolder(info);
}
@@ -2300,7 +2323,7 @@ public final class Launcher extends Activity
Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
- Log.d(TAG, "mFolders.size=" + mFolders.size());
+ Log.d(TAG, "sFolders.size=" + sFolders.size());
mModel.dumpState();
mAllAppsGrid.dumpState();
Log.d(TAG, "END launcher2 dump state");