From 68255cbabe1cb7fbfc0706a8a2e1b1927eae1b55 Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Fri, 5 Oct 2012 15:02:00 +0200 Subject: Add support for custom manta cling - Load a custom cling if custom workspace layout is specified - Also persist any custom workspace layout Bug: 6992663 --- res/layout/custom_workspace_cling.xml | 30 +++++++++++++++++++++++++ res/values/dimens.xml | 3 +++ res/values/strings.xml | 2 ++ src/com/android/launcher2/Launcher.java | 12 ++++++++++ src/com/android/launcher2/LauncherProvider.java | 11 +++++++-- 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 res/layout/custom_workspace_cling.xml diff --git a/res/layout/custom_workspace_cling.xml b/res/layout/custom_workspace_cling.xml new file mode 100644 index 000000000..5bdc58719 --- /dev/null +++ b/res/layout/custom_workspace_cling.xml @@ -0,0 +1,30 @@ + + + + + + diff --git a/res/values/dimens.xml b/res/values/dimens.xml index d497c2dae..628884fc3 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -22,6 +22,9 @@ 0dp 0dp 48dp + + + To make a new folder on your Home screen, stack one app on top of another. OK + + Error: custom workspace layout passed in but custom cling was not overwritten diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index 3fdf5c3ce..fedf32460 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -3733,6 +3733,18 @@ public final class Launcher extends Activity if (isClingsEnabled() && !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false) && !skipCustomClingIfNoAccounts() ) { + // If we're not using the default workspace layout, replace workspace cling + // with a custom workspace cling (usually specified in an overlay) + if (mSharedPrefs.getInt(LauncherProvider.DEFAULT_WORKSPACE_RESOURCE_ID, 0) != 0) { + // Use a custom cling + View cling = findViewById(R.id.workspace_cling); + ViewGroup clingParent = (ViewGroup) cling.getParent(); + int clingIndex = clingParent.indexOfChild(cling); + clingParent.removeViewAt(clingIndex); + View customCling = mInflater.inflate(R.layout.custom_workspace_cling, clingParent, false); + clingParent.addView(customCling, clingIndex); + customCling.setId(R.id.workspace_cling); + } initCling(R.id.workspace_cling, null, false, 0); } else { removeCling(R.id.workspace_cling); diff --git a/src/com/android/launcher2/LauncherProvider.java b/src/com/android/launcher2/LauncherProvider.java index 74cf7a43f..8097ac99e 100644 --- a/src/com/android/launcher2/LauncherProvider.java +++ b/src/com/android/launcher2/LauncherProvider.java @@ -74,6 +74,8 @@ public class LauncherProvider extends ContentProvider { static final String PARAMETER_NOTIFY = "notify"; static final String DB_CREATED_BUT_DEFAULT_WORKSPACE_NOT_LOADED = "DB_CREATED_BUT_DEFAULT_WORKSPACE_NOT_LOADED"; + static final String DEFAULT_WORKSPACE_RESOURCE_ID = + "DEFAULT_WORKSPACE_RESOURCE_ID"; private static final String ACTION_APPWIDGET_DEFAULT_WORKSPACE_CONFIGURE = "com.android.launcher.action.APPWIDGET_DEFAULT_WORKSPACE_CONFIGURE"; @@ -206,18 +208,23 @@ public class LauncherProvider extends ContentProvider { /** * @param workspaceResId that can be 0 to use default or non-zero for specific resource */ - synchronized public void loadDefaultFavoritesIfNecessary(int workspaceResId) { + synchronized public void loadDefaultFavoritesIfNecessary(int origWorkspaceResId) { String spKey = LauncherApplication.getSharedPreferencesKey(); SharedPreferences sp = getContext().getSharedPreferences(spKey, Context.MODE_PRIVATE); if (sp.getBoolean(DB_CREATED_BUT_DEFAULT_WORKSPACE_NOT_LOADED, false)) { + int workspaceResId = origWorkspaceResId; + // Use default workspace resource if none provided if (workspaceResId == 0) { - workspaceResId = R.xml.default_workspace; + workspaceResId = sp.getInt(DEFAULT_WORKSPACE_RESOURCE_ID, R.xml.default_workspace); } // Populate favorites table with initial favorites SharedPreferences.Editor editor = sp.edit(); editor.remove(DB_CREATED_BUT_DEFAULT_WORKSPACE_NOT_LOADED); + if (origWorkspaceResId != 0) { + editor.putInt(DEFAULT_WORKSPACE_RESOURCE_ID, origWorkspaceResId); + } mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(), workspaceResId); editor.commit(); } -- cgit v1.2.3