From 5524b4957fc7c1c858037327429411efdb8fe7d6 Mon Sep 17 00:00:00 2001 From: Brian Muramatsu Date: Tue, 2 Oct 2012 16:55:54 -0700 Subject: Specify workspace resource in preload broadcast Bug 7203884 Allow specifying the workspace XML layout in the PRELOAD_WORKSPACE broadcast. Change-Id: Iec01c6fa2dde4635f624f040b0772ee11fcd88dc --- src/com/android/launcher2/LauncherModel.java | 10 +++++----- src/com/android/launcher2/LauncherProvider.java | 12 ++++++++++-- src/com/android/launcher2/PreloadReceiver.java | 17 ++++++++++++++++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java index 86a9a84f4..e197b3501 100644 --- a/src/com/android/launcher2/LauncherModel.java +++ b/src/com/android/launcher2/LauncherModel.java @@ -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(); diff --git a/src/com/android/launcher2/LauncherProvider.java b/src/com/android/launcher2/LauncherProvider.java index ccc126a11..74cf7a43f 100644 --- a/src/com/android/launcher2/LauncherProvider.java +++ b/src/com/android/launcher2/LauncherProvider.java @@ -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(); } } diff --git a/src/com/android/launcher2/PreloadReceiver.java b/src/com/android/launcher2/PreloadReceiver.java index 7bec72117..08350b6ff 100644 --- a/src/com/android/launcher2/PreloadReceiver.java +++ b/src/com/android/launcher2/PreloadReceiver.java @@ -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(); } -- cgit v1.2.3