Adding initial support for dropping widgets with custom configuration data.

Change-Id: I4a7ba51783b27e544e9a21882bc7cd582b3b43e0
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 961acfe..71978fa 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -1083,8 +1083,10 @@
         // For now, we don't save the coordinate where we dropped the icon because we're not
         // supporting spring-loaded mini-screens; however, leaving the ability to directly place
         // a widget on the home screen in case we want to add it in the future
-        final int[] touchXY = null;
-        //final int[] touchXY = mAddDropPosition;
+        int[] touchXY = null;
+        if (mAddDropPosition[0] > -1 && mAddDropPosition[1] > -1) {
+            touchXY = mAddDropPosition;
+        }
         boolean findNearestVacantAreaFailed = false;
         boolean foundCellSpan = false;
         if (touchXY != null) {
@@ -1429,7 +1431,7 @@
         mAddDropPosition = null;
     }
 
-    void addAppWidgetFromDrop(ComponentName appWidgetProvider, int screen, int[] position) {
+    void addAppWidgetFromDrop(PendingAddWidgetInfo info, int screen, int[] position) {
         resetAddInfo();
         mAddScreen = screen;
 
@@ -1437,8 +1439,8 @@
         mAddDropPosition = position;
 
         int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
-        AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, appWidgetProvider);
-        addAppWidgetImpl(appWidgetId);
+        AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
+        addAppWidgetImpl(appWidgetId, info);
     }
 
     private void manageApps() {
@@ -1450,10 +1452,10 @@
         int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
         // TODO: Is this log message meaningful?
         if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
-        addAppWidgetImpl(appWidgetId);
+        addAppWidgetImpl(appWidgetId, null);
     }
 
-    void addAppWidgetImpl(int appWidgetId) {
+    void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) {
         AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
 
         if (appWidget.configure != null) {
@@ -1461,6 +1463,10 @@
             Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
             intent.setComponent(appWidget.configure);
             intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
+            if (info != null) {
+                intent.putExtra(InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA,
+                        info.configurationData);
+            }
 
             startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
         } else {