Moving the setContentView at the end of onCreate

In multi-window mode, when the activity is resized, the window might
exist even before onCreate, which could call onAttachToWindow while
they are being inflated. Many Views in Launcher assume
onAttachToWindow to be called after onCreate has completed.

Bug: 32745705
Change-Id: Id6ee68826c4f3cc579880540812fd8ed834f8267
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 0540249..0a5d44e 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -392,7 +392,7 @@
         // LauncherModel load.
         mPaused = false;
 
-        setContentView(R.layout.launcher);
+        mLauncherView = getLayoutInflater().inflate(R.layout.launcher, null);
 
         setupViews();
         mDeviceProfile.layout(this, false /* notifyListeners */);
@@ -444,12 +444,18 @@
         // we want the screen to auto-rotate based on the current orientation
         setOrientation();
 
+        setContentView(mLauncherView);
         if (mLauncherCallbacks != null) {
             mLauncherCallbacks.onCreate(savedInstanceState);
         }
     }
 
     @Override
+    public View findViewById(int id) {
+        return mLauncherView.findViewById(id);
+    }
+
+    @Override
     public void onExtractedColorsChanged() {
         loadExtractedColorsAndColorItems();
     }
@@ -1268,7 +1274,6 @@
      * Finds all the views we need and configure them properly.
      */
     private void setupViews() {
-        mLauncherView = findViewById(R.id.launcher);
         mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
         mFocusHandler = mDragLayer.getFocusIndicatorHelper();
         mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);