Reapplying state UI when the insets change

Change-Id: Ief9588400f332b2c5b084a8a11c3102b2c20c4ea
diff --git a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java
index d2057cf..68f6eed 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java
@@ -100,12 +100,12 @@
         float scale = pageRect.height() / childHeight;
         Rect insets = launcher.getDragLayer().getInsets();
 
-        float halfHeight = ws.getHeight() / 2;
+        float halfHeight = ws.getExpectedHeight() / 2;
         float childTop = halfHeight - scale * (halfHeight - ws.getPaddingTop() - insets.top);
         float translationY = pageRect.top - childTop;
 
         // Align the workspace horizontally centered with the task rect
-        float halfWidth = ws.getWidth() / 2;
+        float halfWidth = ws.getExpectedWidth() / 2;
         float childCenter = halfWidth -
                 scale * (halfWidth - ws.getPaddingLeft() - insets.left - childWidth / 2);
         float translationX = pageRect.exactCenterX() - childCenter;
diff --git a/src/com/android/launcher3/LauncherRootView.java b/src/com/android/launcher3/LauncherRootView.java
index 1a1bec6..290c517 100644
--- a/src/com/android/launcher3/LauncherRootView.java
+++ b/src/com/android/launcher3/LauncherRootView.java
@@ -66,6 +66,7 @@
 
         // Update device profile before notifying th children.
         mLauncher.getDeviceProfile().updateInsets(insets);
+        boolean resetState = !insets.equals(mInsets);
         setInsets(insets);
 
         if (mAlignedView != null) {
@@ -77,6 +78,9 @@
                 mAlignedView.setLayoutParams(lp);
             }
         }
+        if (resetState) {
+            mLauncher.getStateManager().reapplyState();
+        }
 
         return true; // I'll take it from here
     }
diff --git a/src/com/android/launcher3/LauncherStateManager.java b/src/com/android/launcher3/LauncherStateManager.java
index bcb6252..8eeeec3 100644
--- a/src/com/android/launcher3/LauncherStateManager.java
+++ b/src/com/android/launcher3/LauncherStateManager.java
@@ -146,6 +146,14 @@
         goToState(state, true, delay, null);
     }
 
+    public void reapplyState() {
+        if (mConfig.mCurrentAnimation == null) {
+            for (StateHandler handler : getStateHandlers()) {
+                handler.setState(mState);
+            }
+        }
+    }
+
     private void goToState(LauncherState state, boolean animated, long delay,
             Runnable onCompleteRunnable) {
         if (mLauncher.isInState(state) && mConfig.mCurrentAnimation == null) {
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 4c30853..ad94a6b 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -563,13 +563,21 @@
         computeScrollHelper();
     }
 
+    public int getExpectedHeight() {
+        return getMeasuredHeight();
+    }
+
     public int getNormalChildHeight() {
-        return  getMeasuredHeight() - getPaddingTop() - getPaddingBottom()
+        return  getExpectedHeight() - getPaddingTop() - getPaddingBottom()
                 - mInsets.top - mInsets.bottom;
     }
 
+    public int getExpectedWidth() {
+        return getMeasuredWidth();
+    }
+
     public int getNormalChildWidth() {
-        return  getMeasuredWidth() - getPaddingLeft() - getPaddingRight()
+        return  getExpectedWidth() - getPaddingLeft() - getPaddingRight()
                 - mInsets.left - mInsets.right;
     }
 
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index de3b09a..c946a44 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -3447,6 +3447,18 @@
     }
 
     @Override
+    public int getExpectedHeight() {
+        return getMeasuredHeight() <= 0
+                ? mLauncher.getDeviceProfile().heightPx : getMeasuredHeight();
+    }
+
+    @Override
+    public int getExpectedWidth() {
+        return getMeasuredWidth() <= 0
+                ? mLauncher.getDeviceProfile().widthPx : getMeasuredWidth();
+    }
+
+    @Override
     protected String getPageIndicatorDescription() {
         return getResources().getString(R.string.all_apps_button_label);
     }