Changing long-press-on-workspace behaviour to show Applications & Widgets.

- Disabling tap-on-widgets-to-add in favour of long press

Change-Id: Ia82143b74216a968ab11890cba83a01c4ab72a06
diff --git a/res/layout/add_list_item.xml b/res/layout/add_list_item.xml
index 62fc4f4..e937d7b 100644
--- a/res/layout/add_list_item.xml
+++ b/res/layout/add_list_item.xml
@@ -18,7 +18,7 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:minHeight="?android:attr/listPreferredItemHeight"
-    android:textAppearance="?android:attr/textAppearanceLargeInverse"
+    android:textAppearance="?android:attr/textAppearanceLarge"
     android:gravity="center_vertical"
     android:drawablePadding="14dip"
     android:paddingLeft="15dip"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7e8bec0..0b90353 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -74,6 +74,10 @@
     <!--  Tile of the tab for applications that were downloaded from market [CHAR_LIMIT=24] -->
     <string name="all_apps_tab_downloaded">My apps</string>
 
+    <!-- AppsCustomize pane -->
+    <!-- Message to tell the user to long-press on a widget to add it [CHAR_LIMIT=50] -->
+    <string name="long_press_widget_to_add">Long-press to pick up a widget</string>
+
     <!-- All Apps pane -->
     <!-- Message to show when there are no games [CHAR_LIMIT=25] -->
     <string name="all_apps_no_games">No games found.</string>
diff --git a/src/com/android/launcher2/AddAdapter.java b/src/com/android/launcher2/AddAdapter.java
index 6f97d72..d1076b1 100644
--- a/src/com/android/launcher2/AddAdapter.java
+++ b/src/com/android/launcher2/AddAdapter.java
@@ -40,6 +40,7 @@
     
     public static final int ITEM_SHORTCUT = 0;
     public static final int ITEM_APPWIDGET = 1;
+    public static final int ITEM_APPLICATION = 2;
     public static final int ITEM_WALLPAPER = 3;
     
     /**
@@ -69,8 +70,8 @@
         // Create default actions
         Resources res = launcher.getResources();
         
-        mItems.add(new ListItem(res, R.string.group_shortcuts,
-                R.drawable.ic_launcher_shortcut, ITEM_SHORTCUT));
+        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));
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index 4500744..bd70463 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -25,8 +25,10 @@
 
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
+import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
 import android.animation.PropertyValuesHolder;
+import android.animation.ValueAnimator;
 import android.app.WallpaperManager;
 import android.appwidget.AppWidgetManager;
 import android.appwidget.AppWidgetProviderInfo;
@@ -53,10 +55,12 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.animation.AccelerateInterpolator;
 import android.view.animation.DecelerateInterpolator;
 import android.view.animation.LinearInterpolator;
 import android.widget.ImageView;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.android.launcher.R;
 
@@ -341,31 +345,21 @@
                     });
                 }
             } else {
-                // Add the widget to the current workspace screen
-                Workspace w = mLauncher.getWorkspace();
-                int currentWorkspaceScreen = mLauncher.getCurrentWorkspaceScreen();
-                final CellLayout cl = (CellLayout) w.getChildAt(currentWorkspaceScreen);
-                final View dragView = v.findViewById(R.id.widget_preview);
-                final ItemInfo itemInfo = (ItemInfo) v.getTag();
-                animateClickFeedback(v, new Runnable() {
-                    @Override
-                    public void run() {
-                        cl.calculateSpans(itemInfo);
-                        if (cl.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY)) {
-                            if (LauncherApplication.isScreenLarge()) {
-                                animateItemOntoScreen(dragView, cl, itemInfo);
-                            } else {
-                                mLauncher.addExternalItemToScreen(itemInfo, cl);
-                                itemInfo.dropPos = null;
-                            }
+                // Let the user know that they have to long press to add a widget
+                Toast.makeText(getContext(), R.string.long_press_widget_to_add,
+                        Toast.LENGTH_SHORT).show();
 
-                            // Hide the pane so we can see the workspace we dropped on
-                            mLauncher.showWorkspace(true);
-                        } else {
-                            mLauncher.showOutOfSpaceMessage();
-                        }
-                    }
-                });
+                // Create a little animation to show that the widget can move
+                float offsetY = getResources().getDimensionPixelSize(R.dimen.dragViewOffsetY);
+                final ImageView p = (ImageView) v.findViewById(R.id.widget_preview);
+                AnimatorSet bounce = new AnimatorSet();
+                ValueAnimator tyuAnim = ObjectAnimator.ofFloat(p, "translationY", offsetY);
+                tyuAnim.setDuration(125);
+                ValueAnimator tydAnim = ObjectAnimator.ofFloat(p, "translationY", 0f);
+                tydAnim.setDuration(100);
+                bounce.play(tyuAnim).before(tydAnim);
+                bounce.setInterpolator(new AccelerateInterpolator());
+                bounce.start();
             }
         }
     }
diff --git a/src/com/android/launcher2/AppsCustomizeTabHost.java b/src/com/android/launcher2/AppsCustomizeTabHost.java
index e2d21b6..cd8e7ef 100644
--- a/src/com/android/launcher2/AppsCustomizeTabHost.java
+++ b/src/com/android/launcher2/AppsCustomizeTabHost.java
@@ -42,6 +42,13 @@
         mLayoutInflater = LayoutInflater.from(context);
     }
 
+    void selectAppsTab() {
+        setCurrentTabByTag(APPS_TAB_TAG);
+    }
+    void selectWidgetsTab() {
+        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 2a16e99..f8d3411 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -2230,11 +2230,7 @@
                 mWorkspace.setAllowLongPress(false);
                 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                         HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
-                if (LauncherApplication.isScreenLarge()) {
-                    addItems();
-                } else {
-                    startWallpaper();
-                }
+                addItems();
             } else {
                 if (!(itemUnderLongClick instanceof Folder)) {
                     // User long pressed on an item
@@ -2970,9 +2966,8 @@
             // Change the state *after* we've called all the transition code
             mState = State.ALL_APPS;
         } else {
-            View appsCustomizePane = findViewById(R.id.apps_customize_pane);
             cameraZoomOut(State.APPS_CUSTOMIZE, animated, false);
-            appsCustomizePane.requestFocus();
+            mAppsCustomizeTabHost.requestFocus();
 
             // Change the state *after* we've called all the transition code
             mState = State.APPS_CUSTOMIZE;
@@ -3242,12 +3237,11 @@
         Dialog createDialog() {
             mAdapter = new AddAdapter(Launcher.this);
 
-            final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
+            final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this, 
+                    AlertDialog.THEME_HOLO_DARK);
             builder.setTitle(getString(R.string.menu_item_add_item));
             builder.setAdapter(mAdapter, this);
 
-            builder.setInverseBackgroundForced(true);
-
             AlertDialog dialog = builder.create();
             dialog.setOnCancelListener(this);
             dialog.setOnDismissListener(this);
@@ -3262,6 +3256,8 @@
         }
 
         public void onDismiss(DialogInterface dialog) {
+            mWaitingForResult = false;
+            cleanup();
         }
 
         private void cleanup() {
@@ -3279,22 +3275,26 @@
             Resources res = getResources();
             cleanup();
 
-            switch (which) {
+            AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
+            switch (item.actionTag) {
                 case AddAdapter.ITEM_SHORTCUT: {
                     pickShortcut();
                     break;
                 }
-
-                case AddAdapter.ITEM_APPWIDGET: {
-                    int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
-
-                    Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
-                    pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
-                    // start the pick activity
-                    startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
+                case AddAdapter.ITEM_APPLICATION: {
+                    if (mAppsCustomizeTabHost != null) {
+                        mAppsCustomizeTabHost.selectAppsTab();
+                    }
+                    showAllApps(true);
                     break;
                 }
-
+                case AddAdapter.ITEM_APPWIDGET: {
+                    if (mAppsCustomizeTabHost != null) {
+                        mAppsCustomizeTabHost.selectWidgetsTab();
+                    }
+                    showAllApps(true);
+                    break;
+                }
                 case AddAdapter.ITEM_WALLPAPER: {
                     startWallpaper();
                     break;