Merge "Specify workspace resource in preload broadcast" into jb-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a2042d0ae9
@@ -379,8 +379,8 @@ public class LauncherModel extends BroadcastReceiver {
|
||||
*/
|
||||
static void moveItemInDatabase(Context context, final ItemInfo item, final long container,
|
||||
final int screen, final int cellX, final int cellY) {
|
||||
String transaction = "DbDebug Modify item (" + item.title + ") in db, id: " + item.id +
|
||||
" (" + item.container + ", " + item.screen + ", " + item.cellX + ", " + item.cellY +
|
||||
String transaction = "DbDebug Modify item (" + item.title + ") in db, id: " + item.id +
|
||||
" (" + item.container + ", " + item.screen + ", " + item.cellX + ", " + item.cellY +
|
||||
") --> " + "(" + container + ", " + screen + ", " + cellX + ", " + cellY + ")";
|
||||
Launcher.sDumpLogs.add(transaction);
|
||||
Log.d(TAG, transaction);
|
||||
@@ -411,8 +411,8 @@ public class LauncherModel extends BroadcastReceiver {
|
||||
*/
|
||||
static void modifyItemInDatabase(Context context, final ItemInfo item, final long container,
|
||||
final int screen, final int cellX, final int cellY, final int spanX, final int spanY) {
|
||||
String transaction = "DbDebug Modify item (" + item.title + ") in db, id: " + item.id +
|
||||
" (" + item.container + ", " + item.screen + ", " + item.cellX + ", " + item.cellY +
|
||||
String transaction = "DbDebug Modify item (" + item.title + ") in db, id: " + item.id +
|
||||
" (" + item.container + ", " + item.screen + ", " + item.cellX + ", " + item.cellY +
|
||||
") --> " + "(" + container + ", " + screen + ", " + cellX + ", " + cellY + ")";
|
||||
Launcher.sDumpLogs.add(transaction);
|
||||
Log.d(TAG, transaction);
|
||||
@@ -1234,7 +1234,7 @@ public class LauncherModel extends BroadcastReceiver {
|
||||
final boolean isSafeMode = manager.isSafeMode();
|
||||
|
||||
// Make sure the default workspace is loaded, if needed
|
||||
mApp.getLauncherProvider().loadDefaultFavoritesIfNecessary();
|
||||
mApp.getLauncherProvider().loadDefaultFavoritesIfNecessary(0);
|
||||
|
||||
synchronized (sBgLock) {
|
||||
sBgWorkspaceItems.clear();
|
||||
|
||||
@@ -203,14 +203,22 @@ public class LauncherProvider extends ContentProvider {
|
||||
return mOpenHelper.generateNewId();
|
||||
}
|
||||
|
||||
synchronized public void loadDefaultFavoritesIfNecessary() {
|
||||
/**
|
||||
* @param workspaceResId that can be 0 to use default or non-zero for specific resource
|
||||
*/
|
||||
synchronized public void loadDefaultFavoritesIfNecessary(int workspaceResId) {
|
||||
String spKey = LauncherApplication.getSharedPreferencesKey();
|
||||
SharedPreferences sp = getContext().getSharedPreferences(spKey, Context.MODE_PRIVATE);
|
||||
if (sp.getBoolean(DB_CREATED_BUT_DEFAULT_WORKSPACE_NOT_LOADED, false)) {
|
||||
// Use default workspace resource if none provided
|
||||
if (workspaceResId == 0) {
|
||||
workspaceResId = R.xml.default_workspace;
|
||||
}
|
||||
|
||||
// Populate favorites table with initial favorites
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.remove(DB_CREATED_BUT_DEFAULT_WORKSPACE_NOT_LOADED);
|
||||
mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(), R.xml.default_workspace);
|
||||
mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(), workspaceResId);
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,31 @@ package com.android.launcher2;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
public class PreloadReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "Launcher.PreloadReceiver";
|
||||
private static final boolean LOGD = false;
|
||||
|
||||
public static final String EXTRA_WORKSPACE_NAME =
|
||||
"com.android.launcher.action.EXTRA_WORKSPACE_NAME";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final LauncherApplication app = (LauncherApplication) context.getApplicationContext();
|
||||
final LauncherProvider provider = app.getLauncherProvider();
|
||||
if (provider != null) {
|
||||
String name = intent.getStringExtra(EXTRA_WORKSPACE_NAME);
|
||||
final int workspaceResId = !TextUtils.isEmpty(name)
|
||||
? context.getResources().getIdentifier(name, "xml", "com.android.launcher") : 0;
|
||||
if (LOGD) {
|
||||
Log.d(TAG, "workspace name: " + name + " id: " + workspaceResId);
|
||||
}
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
provider.loadDefaultFavoritesIfNecessary();
|
||||
provider.loadDefaultFavoritesIfNecessary(workspaceResId);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user