Multitude of launcher behaviour changes.

- Merging widgets and shortcuts in widgets pane
- Removing legacy long press menu items (make it go straight to wallpapers)
- Removing old option menu (just making it point to wallpapers)
- Dropping user to workspace after adding an item (animations to be tweaked) or back to AppsCustomize only on failure/cancel

Change-Id: Ia73670ce76f321dc45defb27bb5a828764240ab4
diff --git a/src/com/android/launcher2/AddAdapter.java b/src/com/android/launcher2/AddAdapter.java
index 5b7e92c..c2a424b 100644
--- a/src/com/android/launcher2/AddAdapter.java
+++ b/src/com/android/launcher2/AddAdapter.java
@@ -70,16 +70,8 @@
         // Create default actions
         Resources res = launcher.getResources();
 
-        mItems.add(new ListItem(res, R.string.group_applications,
-                R.drawable.ic_launcher_application, ITEM_APPLICATION));
-
-        mItems.add(new ListItem(res, R.string.group_widgets,
-                R.drawable.ic_launcher_appwidget, ITEM_APPWIDGET));
-        mItems.add(new ListItem(res, R.string.group_shortcuts,
-                R.drawable.ic_launcher_application, ITEM_SHORTCUT));
         mItems.add(new ListItem(res, R.string.group_wallpapers,
                 R.drawable.ic_launcher_wallpaper, ITEM_WALLPAPER));
-
     }
 
     public View getView(int position, View convertView, ViewGroup parent) {
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index cb60034..e9c22ff 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -167,7 +167,6 @@
     private ContentType mContentType;
     private ArrayList<ApplicationInfo> mApps;
     private ArrayList<Object> mWidgets;
-    private ArrayList<Object> mShortcuts;
 
     // Caching
     private Canvas mCanvas;
@@ -180,9 +179,6 @@
     private int mMaxWidgetSpan, mMinWidgetSpan;
     private int mWidgetCountX, mWidgetCountY;
     private int mWidgetWidthGap, mWidgetHeightGap;
-    private int mShortcutCountX, mShortcutCountY;
-    private int mShortcutWidthGap, mShortcutHeightGap;
-    private int mNumWidgetPages, mNumShortcutPages;
     private final int mWidgetPreviewIconPaddedDimension;
     private final float sWidgetPreviewIconPaddingPercentage = 0.25f;
     private PagedViewCellLayout mWidgetSpacingLayout;
@@ -198,7 +194,6 @@
         mContentType = ContentType.Applications;
         mApps = new ArrayList<ApplicationInfo>();
         mWidgets = new ArrayList<Object>();
-        mShortcuts = new ArrayList<Object>();
         mIconCache = ((LauncherApplication) context.getApplicationContext()).getIconCache();
         mHolographicOutlineHelper = new HolographicOutlineHelper();
         mCanvas = new Canvas();
@@ -286,13 +281,6 @@
         mCellCountY = mWidgetSpacingLayout.getCellCountY();
         mWidgetCountX = Math.max(1, (int) Math.round(mCellCountX / 2f));
         mWidgetCountY = Math.max(1, (int) Math.round(mCellCountY / 3f));
-        mShortcutCountX = Math.max(1, (int) Math.round(mCellCountX / 2f));
-        mShortcutCountY = Math.max(1, (int) Math.round(mCellCountY / 2f));
-
-        mNumWidgetPages = (int) Math.ceil(mWidgets.size() /
-                (float) (mWidgetCountX * mWidgetCountY));
-        mNumShortcutPages = (int) Math.ceil(mShortcuts.size() /
-                (float) (mShortcutCountX * mShortcutCountY));
 
         // Force a measure to update recalculate the gaps
         int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST);
@@ -335,19 +323,16 @@
 
     public void onPackagesUpdated() {
         // Get the list of widgets and shortcuts
-        boolean wasEmpty = mWidgets.isEmpty() && mShortcuts.isEmpty();
+        boolean wasEmpty = mWidgets.isEmpty();
         mWidgets.clear();
-        mShortcuts.clear();
         List<AppWidgetProviderInfo> widgets =
             AppWidgetManager.getInstance(mLauncher).getInstalledProviders();
-        Collections.sort(widgets,
-                new LauncherModel.WidgetAndShortcutNameComparator(mPackageManager));
         Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
         List<ResolveInfo> shortcuts = mPackageManager.queryIntentActivities(shortcutsIntent, 0);
-        Collections.sort(shortcuts,
-                new LauncherModel.WidgetAndShortcutNameComparator(mPackageManager));
         mWidgets.addAll(widgets);
-        mShortcuts.addAll(shortcuts);
+        mWidgets.addAll(shortcuts);
+        Collections.sort(mWidgets,
+                new LauncherModel.WidgetAndShortcutNameComparator(mPackageManager));
 
         if (wasEmpty) {
             // The next layout pass will trigger data-ready if both widgets and apps are set, so request
@@ -511,9 +496,6 @@
     public void setCurrentPageToWidgets() {
         invalidatePageData(0);
     }
-    public void setCurrentPageToShortcuts() {
-        invalidatePageData(mNumWidgetPages);
-    }
 
     /*
      * Apps PagedView implementation
@@ -858,45 +840,33 @@
     public void syncWidgetPages() {
         // Ensure that we have the right number of pages
         Context context = getContext();
-        int[] countX = { mWidgetCountX, mShortcutCountX };
-        int[] countY = { mWidgetCountY, mShortcutCountY };
-        int[] numPages = { mNumWidgetPages, mNumShortcutPages };
-        for (int i = 0; i < 2; ++i) {
-            for (int j = 0; j < numPages[i]; ++j) {
-                PagedViewGridLayout layout = new PagedViewGridLayout(context, countX[i], countY[i]);
-                setupPage(layout);
-                addView(layout);
-            }
+        int numPages = (int) Math.ceil(mWidgets.size() /
+                (float) (mWidgetCountX * mWidgetCountY));
+        for (int j = 0; j < numPages; ++j) {
+            PagedViewGridLayout layout = new PagedViewGridLayout(context, mWidgetCountX,
+                    mWidgetCountY);
+            setupPage(layout);
+            addView(layout);
         }
     }
     public void syncWidgetPageItems(int page) {
-        int[] countX = { mWidgetCountX, mShortcutCountX };
-        int[] countY = { mWidgetCountY, mShortcutCountY };
-        int[] widthGap = { mWidgetWidthGap, mWidgetWidthGap };
-        int[] heightGap = { mWidgetHeightGap, mWidgetHeightGap };
-        int[] numItemsPerPage = { mWidgetCountX * mWidgetCountY,
-                mShortcutCountX * mShortcutCountY };
-        Object[] collection = { mWidgets, mShortcuts };
+        int numItemsPerPage = mWidgetCountX * mWidgetCountY;
         int contentWidth = mWidgetSpacingLayout.getContentWidth();
         int contentHeight = mWidgetSpacingLayout.getContentHeight();
-        int numWidgetPages = (int) Math.ceil(mWidgets.size() / (float) numItemsPerPage[0]);
-        int[] offsets = { page * numItemsPerPage[0], (page - numWidgetPages) * numItemsPerPage[1] };
-        int index = (page < numWidgetPages ? 0 : 1);
 
         // Calculate the dimensions of each cell we are giving to each widget
-        ArrayList<Object> list = (ArrayList<Object>) collection[index];
         ArrayList<Object> items = new ArrayList<Object>();
         int cellWidth = ((contentWidth - mPageLayoutPaddingLeft - mPageLayoutPaddingRight
-                - ((countX[index] - 1) * widthGap[index])) / countX[index]);
+                - ((mWidgetCountX - 1) * mWidgetWidthGap)) / mWidgetCountX);
         int cellHeight = ((contentHeight - mPageLayoutPaddingTop - mPageLayoutPaddingBottom
-                - ((countY[index] - 1) * heightGap[index])) / countY[index]);
+                - ((mWidgetCountY - 1) * mWidgetHeightGap)) / mWidgetCountY);
 
-        int offset = offsets[index];
-        for (int i = offset; i < Math.min(offset + numItemsPerPage[index], list.size()); ++i) {
-            items.add(list.get(i));
+        int offset = page * numItemsPerPage;
+        for (int i = offset; i < Math.min(offset + numItemsPerPage, mWidgets.size()); ++i) {
+            items.add(mWidgets.get(i));
         }
 
-        prepareLoadWidgetPreviewsTask(page, items, cellWidth, cellHeight, countX[index]);
+        prepareLoadWidgetPreviewsTask(page, items, cellWidth, cellHeight, mWidgetCountX);
     }
     private void onSyncWidgetPageItems(AsyncTaskPageData data) {
         int page = data.page;
@@ -1149,7 +1119,6 @@
         // TODO: Dump information related to current list of Applications, Widgets, etc.
         ApplicationInfo.dumpApplicationInfoList(LOG_TAG, "mApps", mApps);
         dumpAppWidgetProviderInfoList(LOG_TAG, "mWidgets", mWidgets);
-        dumpAppWidgetProviderInfoList(LOG_TAG, "mShortcuts", mShortcuts);
     }
     private void dumpAppWidgetProviderInfoList(String tag, String label,
             ArrayList<Object> list) {
diff --git a/src/com/android/launcher2/AppsCustomizeTabHost.java b/src/com/android/launcher2/AppsCustomizeTabHost.java
index b6bc5dc..2f5cc40 100644
--- a/src/com/android/launcher2/AppsCustomizeTabHost.java
+++ b/src/com/android/launcher2/AppsCustomizeTabHost.java
@@ -71,12 +71,6 @@
 
         setCurrentTabByTag(WIDGETS_TAB_TAG);
     }
-    void selectShortcutsTab() {
-        setContentTypeImmediate(AppsCustomizePagedView.ContentType.Widgets);
-        mAppsCustomizePane.setCurrentPageToShortcuts();
-
-        setCurrentTabByTag(WIDGETS_TAB_TAG);
-    }
 
     /**
      * Setup the tab host and create all necessary tabs.
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 34cbf1a..a8782ba 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -500,7 +500,7 @@
         }
 
         // Exit spring loaded mode if necessary after cancelling the configuration of a widget
-        exitSpringLoadedDragModeDelayed(delayExitSpringLoadedMode);
+        exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode);
     }
 
     @Override
@@ -1197,36 +1197,7 @@
 
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
-        if (isWorkspaceLocked()) {
-            return false;
-        }
-
         super.onCreateOptionsMenu(menu);
-
-        menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
-                .setIcon(android.R.drawable.ic_menu_add)
-                .setAlphabeticShortcut('A');
-        menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
-                .setIcon(android.R.drawable.ic_menu_manage)
-                .setAlphabeticShortcut('M');
-        menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
-                 .setIcon(android.R.drawable.ic_menu_gallery)
-                 .setAlphabeticShortcut('W');
-        menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
-                .setIcon(android.R.drawable.ic_search_category_default)
-                .setAlphabeticShortcut(SearchManager.MENU_KEY);
-        menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
-                .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
-                .setAlphabeticShortcut('N');
-
-        final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
-        settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
-                Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
-
-        menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
-                .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
-                .setIntent(settings);
-
         return true;
     }
 
@@ -1234,10 +1205,7 @@
     public boolean onPrepareOptionsMenu(Menu menu) {
         super.onPrepareOptionsMenu(menu);
 
-        // TODO-APPS_CUSTOMIZE: Remove this for the phone UI at some point, along with all the menu
-        // related code?
-        if (mAppsCustomizeContent != null && mAppsCustomizeContent.isAnimating()) return false;
-
+        startWallpaper();
         return true;
     }
 
@@ -1348,7 +1316,7 @@
             completeAddAppWidget(appWidgetId, info.container, info.screen);
 
             // Exit spring loaded mode if necessary after adding the widget
-            exitSpringLoadedDragModeDelayed(false);
+            exitSpringLoadedDragModeDelayed(true, false);
         }
     }
 
@@ -1630,16 +1598,6 @@
     }
 
     /**
-     * Event handler for the "gear" button that appears on the home screen, which
-     * enters home screen customization mode.
-     *
-     * @param v The view that was clicked.
-     */
-    public void onClickConfigureButton(View v) {
-        addItems();
-    }
-
-    /**
      * Event handler for the "grid" button that appears on the home screen, which
      * enters all apps mode.
      *
@@ -1824,7 +1782,7 @@
                 // User long pressed on empty space
                 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                         HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
-                addItems();
+                startWallpaper();
             } else {
                 if (!(itemUnderLongClick instanceof Folder)) {
                     // User long pressed on an item
@@ -2238,11 +2196,14 @@
         }
         // Otherwise, we are not in spring loaded mode, so don't do anything.
     }
-    void exitSpringLoadedDragModeDelayed(boolean extendedDelay) {
+    void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay) {
         mWorkspace.postDelayed(new Runnable() {
             @Override
             public void run() {
                 exitSpringLoadedDragMode();
+                if (successfulDrop) {
+                    showWorkspace(true);
+                }
             }
         }, (extendedDelay ?
                 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
@@ -2580,13 +2541,6 @@
 
             AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
             switch (item.actionTag) {
-                case AddAdapter.ITEM_SHORTCUT: {
-                    if (mAppsCustomizeTabHost != null) {
-                        mAppsCustomizeTabHost.selectShortcutsTab();
-                    }
-                    showAllApps(true);
-                    break;
-                }
                 case AddAdapter.ITEM_APPLICATION: {
                     if (mAppsCustomizeTabHost != null) {
                         mAppsCustomizeTabHost.selectAppsTab();
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index c10bd1a..bf60409 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -3026,7 +3026,7 @@
         final Runnable exitSpringLoadedRunnable = new Runnable() {
             @Override
             public void run() {
-                mLauncher.exitSpringLoadedDragModeDelayed(false);
+                mLauncher.exitSpringLoadedDragModeDelayed(true, false);
             }
         };