Initial Changes for Dynamic Grid

Change-Id: I9e6f1e5167791cf8dc140778dfa447f86424e9bf
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index ab2bc67..c29e74f 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -51,6 +51,7 @@
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Color;
+import android.graphics.Point;
 import android.graphics.PorterDuff;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
@@ -199,7 +200,6 @@
     private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
     private State mState = State.WORKSPACE;
     private AnimatorSet mStateAnimation;
-    private AnimatorSet mDividerAnimator;
 
     static final int APPWIDGET_HOST_ID = 1024;
     private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
@@ -221,7 +221,6 @@
     private LayoutInflater mInflater;
 
     private Workspace mWorkspace;
-    private View mQsbDivider;
     private View mLauncherView;
     private DragLayer mDragLayer;
     private DragController mDragController;
@@ -372,9 +371,23 @@
 
         super.onCreate(savedInstanceState);
 
-        // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
         LauncherAppState.setApplicationContext(getApplicationContext());
         LauncherAppState app = LauncherAppState.getInstance();
+
+        // Determine the dynamic grid properties
+        Point smallestSize = new Point();
+        Point largestSize = new Point();
+        Point realSize = new Point();
+        Display display = getWindowManager().getDefaultDisplay();
+        display.getCurrentSizeRange(smallestSize, largestSize);
+        display.getRealSize(realSize);
+        // Lazy-initialize the dynamic grid
+        DeviceProfile grid = app.initDynamicGrid(this,
+                Math.min(smallestSize.x, smallestSize.y),
+                Math.min(largestSize.x, largestSize.y),
+                realSize.x, realSize.y);
+
+        // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
         mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
                 Context.MODE_PRIVATE);
         mModel = app.setLauncher(this);
@@ -400,6 +413,7 @@
 
         checkForLocaleChange();
         setContentView(R.layout.launcher);
+        grid.layout(this);
         setupViews();
         showFirstRunWorkspaceCling();
 
@@ -1061,7 +1075,6 @@
         mLauncherView = findViewById(R.id.launcher);
         mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
         mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
-        mQsbDivider = findViewById(R.id.qsb_divider);
 
         mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
         mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
@@ -2014,6 +2027,9 @@
             FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
         mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
                 isWorkspaceLocked());
+        // Force measure the new folder icon
+        CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
+        parent.getShortcutsAndWidgets().measureChild(newFolder);
         return newFolder;
     }
 
@@ -2784,11 +2800,6 @@
                     dispatchOnLauncherTransitionEnd(fromView, animated, false);
                     dispatchOnLauncherTransitionEnd(toView, animated, false);
 
-                    if (mWorkspace != null
-                            && !springLoaded
-                            && !LauncherAppState.getInstance().isScreenLarge()) {
-                        hideDockDivider();
-                    }
                     if (!animationCancelled) {
                         updateWallpaperVisibility(false);
                     }
@@ -2855,8 +2866,6 @@
             toView.bringToFront();
 
             if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
-                hideDockDivider();
-
                 // Hide the search bar
                 if (mSearchDropTargetBar != null) {
                     mSearchDropTargetBar.hideSearchBar(false);
@@ -3008,9 +3017,6 @@
                 mSearchDropTargetBar.showSearchBar(wasInSpringLoadedMode);
             }
 
-            // We only need to animate in the dock divider if we're going from spring loaded mode
-            showDockDivider(animated && wasInSpringLoadedMode);
-
             // Set focus to the AppsCustomize button
             if (mAllAppsButton != null) {
                 mAllAppsButton.requestFocus();
@@ -3056,7 +3062,6 @@
     void enterSpringLoadedDragMode() {
         if (isAllAppsVisible()) {
             hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
-            hideDockDivider();
             mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
         }
     }
@@ -3093,33 +3098,6 @@
         // Otherwise, we are not in spring loaded mode, so don't do anything.
     }
 
-    void hideDockDivider() {
-        if (mQsbDivider != null) {
-            mQsbDivider.setVisibility(View.INVISIBLE);
-        }
-    }
-
-    void showDockDivider(boolean animated) {
-        if (mQsbDivider != null) {
-            mQsbDivider.setVisibility(View.VISIBLE);
-            if (mDividerAnimator != null) {
-                mDividerAnimator.cancel();
-                mQsbDivider.setAlpha(1f);
-                mDividerAnimator = null;
-            }
-            if (animated) {
-                mDividerAnimator = LauncherAnimUtils.createAnimatorSet();
-                mDividerAnimator.playTogether(LauncherAnimUtils.ofFloat(mQsbDivider, "alpha", 1f));
-                int duration = 0;
-                if (mSearchDropTargetBar != null) {
-                    duration = mSearchDropTargetBar.getTransitionInDuration();
-                }
-                mDividerAnimator.setDuration(duration);
-                mDividerAnimator.start();
-            }
-        }
-    }
-
     void lockAllApps() {
         // TODO
     }