OSDN Git Service

Specify workspace resource in preload broadcast
authorBrian Muramatsu <btmura@google.com>
Tue, 2 Oct 2012 23:55:54 +0000 (16:55 -0700)
committerBrian Muramatsu <btmura@google.com>
Tue, 2 Oct 2012 23:55:54 +0000 (16:55 -0700)
Bug 7203884

Allow specifying the workspace XML layout in the PRELOAD_WORKSPACE
broadcast.

Change-Id: Iec01c6fa2dde4635f624f040b0772ee11fcd88dc

src/com/android/launcher2/LauncherModel.java
src/com/android/launcher2/LauncherProvider.java
src/com/android/launcher2/PreloadReceiver.java

index 86a9a84..e197b35 100644 (file)
@@ -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();
index ccc126a..74cf7a4 100644 (file)
@@ -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();
         }
     }
index 7bec721..08350b6 100644 (file)
@@ -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();
         }