Merge changes Id26e9dcf,I4e323bd7 into jb-ub-gel-agar

* changes:
  Memory debugging overlay for L3.
  Move LauncherApplication's state and code to LauncherAppState.
diff --git a/res/layout/workspace_custom_content.xml b/res/layout/workspace_custom_content.xml
new file mode 100644
index 0000000..6497685
--- /dev/null
+++ b/res/layout/workspace_custom_content.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<com.android.launcher3.CellLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:launcher="http://schemas.android.com/apk/res-auto/com.android.launcher3"
+
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:paddingStart="0dp"
+    android:paddingEnd="0dp"
+    android:paddingTop="0dp"
+    android:paddingBottom="0dp"
+    android:hapticFeedbackEnabled="false"
+
+    launcher:cellWidth="@dimen/workspace_cell_width"
+    launcher:cellHeight="@dimen/workspace_cell_height"
+    launcher:widthGap="@dimen/workspace_width_gap"
+    launcher:heightGap="@dimen/workspace_height_gap"
+    launcher:maxGap="@dimen/workspace_max_gap" />
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 70fa7eb..3adfb95 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -814,6 +814,29 @@
         mDragController.resetLastGestureUpTime();
     }
 
+    protected void onFinishBindingItems() {
+    }
+
+    // Add a fullscreen unpadded view to the workspace to the left all other screens.
+    public void addCustomContentToLeft(View customContent) {
+        CellLayout customScreen = (CellLayout)
+                getLayoutInflater().inflate(R.layout.workspace_custom_content, null);
+
+        int spanX = customScreen.getCountX();
+        int spanY = customScreen.getCountY();
+
+        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, spanX, spanY);
+        lp.canReorder  = false;
+
+        customScreen.addViewToCellLayout(customContent, 0, 0, lp, true);
+
+        mWorkspace.addView(customScreen, 0);
+
+        // Ensure that the current page and default page are maintained.
+        mWorkspace.incrementDefaultScreen();
+        mWorkspace.setCurrentPage(mWorkspace.getCurrentPage() + 1);
+    }
+
     @Override
     public Object onRetainNonConfigurationInstance() {
         // Flag the loader to stop early before switching
@@ -2045,7 +2068,9 @@
     public boolean onTouch(View v, MotionEvent event) {
         // this is an intercepted event being forwarded from mWorkspace;
         // clicking anywhere on the workspace causes the customization drawer to slide down
-        showWorkspace(true);
+        if (event.getAction() == MotionEvent.ACTION_DOWN) {
+            showWorkspace(true);
+        }
         return false;
     }
 
@@ -2896,10 +2921,10 @@
         getWindow().getDecorView()
                 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
 
-        onWorkspaceShown();
+        onWorkspaceShown(animated);
     }
 
-    public void onWorkspaceShown() {
+    public void onWorkspaceShown(boolean animated) {
     }
 
     void showAllApps(boolean animated) {
@@ -3615,6 +3640,12 @@
             mWorkspace.stripDuplicateApps();
             mIntentsOnWorkspaceFromUpgradePath = mWorkspace.stripDuplicateApps();
         }
+        mWorkspace.post(new Runnable() {
+            @Override
+            public void run() {
+                onFinishBindingItems();
+            }
+        });
     }
 
     private boolean canRunNewAppsAnimation() {
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 8716a33..abf8bbd 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -89,6 +89,8 @@
     protected boolean mFirstLayout = true;
 
     protected int mCurrentPage;
+    protected int mChildCountOnLastMeasure;
+
     protected int mNextPage = INVALID_PAGE;
     protected int mMaxScrollX;
     protected Scroller mScroller;
@@ -347,7 +349,7 @@
             return;
         }
 
-
+        mForceScreenScrolled = true;
         mCurrentPage = Math.max(0, Math.min(currentPage, getPageCount() - 1));
         updateCurrentPageScroll();
         updateScrollingIndicator();
@@ -564,6 +566,11 @@
         // ensure that the cache is filled with good values.
         invalidateCachedOffsets();
 
+        if (mChildCountOnLastMeasure != getChildCount()) {
+            setCurrentPage(mCurrentPage);
+        }
+        mChildCountOnLastMeasure = getChildCount();
+
         if (childCount > 0) {
             if (DEBUG) Log.d(TAG, "getRelativeChildOffset(): " + getMeasuredWidth() + ", "
                     + getChildWidth(0));
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index a44ee92..fd32442 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -398,6 +398,12 @@
         UninstallShortcutReceiver.disableAndFlushUninstallQueue(getContext());
     }
 
+    // Just a hack so that if a custom content screen is added to the left, we adjust the
+    // default screen accordingly so that it stays the same.
+    void incrementDefaultScreen() {
+        mDefaultPage++;
+    }
+
     /**
      * Initializes various states for this workspace.
      */