Adding app widget restore support in Launcher3 for android L

When the app is restored, it displays placeholders for all pending widgets.
These placeholders can be moved and removed similar to a widget (size is fixed
to what defined in backup). Once the system notifies the launcher of the new
widget ids, the place holders are replaced with actual widgets.

issue: 10779035

Change-Id: I68cbe4da01e9ca2978cb4471a7c645d2aa592055
diff --git a/src/com/android/launcher3/LauncherAppWidgetHostView.java b/src/com/android/launcher3/LauncherAppWidgetHostView.java
index f47fd13..7eb0052 100644
--- a/src/com/android/launcher3/LauncherAppWidgetHostView.java
+++ b/src/com/android/launcher3/LauncherAppWidgetHostView.java
@@ -18,6 +18,7 @@
 
 import android.appwidget.AppWidgetHostView;
 import android.content.Context;
+import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
@@ -39,12 +40,28 @@
 
     private float mSlop;
 
+    private boolean mWidgetReady;
+
     public LauncherAppWidgetHostView(Context context) {
+        this(context, true);
+    }
+
+    public LauncherAppWidgetHostView(Context context, boolean widgetReady) {
         super(context);
         mContext = context;
         mLongPressHelper = new CheckLongPressHelper(this);
         mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         mDragLayer = ((Launcher) context).getDragLayer();
+        mWidgetReady = widgetReady;
+    }
+
+    @Override
+    public void updateAppWidgetSize(Bundle newOptions, int minWidth, int minHeight, int maxWidth,
+            int maxHeight) {
+        // If the widget is not yet ready, the app widget size cannot be updated.
+        if (mWidgetReady) {
+            super.updateAppWidgetSize(newOptions, minWidth, minHeight, maxWidth, maxHeight);
+        }
     }
 
     @Override
@@ -53,6 +70,15 @@
     }
 
     @Override
+    protected View getDefaultView() {
+        if (mWidgetReady) {
+            return super.getDefaultView();
+        } else {
+            return mInflater.inflate(R.layout.appwidget_not_ready, this, false);
+        }
+    }
+
+    @Override
     public void updateAppWidget(RemoteViews remoteViews) {
         // Store the orientation in which the widget was inflated
         mPreviousOrientation = mContext.getResources().getConfiguration().orientation;