Merge "Add support for popup dark theme" into ub-launcher3-dorval-polish
diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
index 83c1370..d3d23ca 100644
--- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
+++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
@@ -102,12 +102,7 @@
         private SpringAnimation spring;
 
         public ViewHolder(View v) {
-            this(v, null);
-        }
-
-        public ViewHolder(View v, SpringAnimation spring) {
             super(v);
-            this.spring = spring;
         }
     }
 
@@ -290,7 +285,6 @@
 
     @Override
     public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
-        ViewHolder viewHolder;
         switch (viewType) {
             case VIEW_TYPE_ICON:
             case VIEW_TYPE_PREDICTION_ICON:
@@ -304,19 +298,16 @@
 
                 // Ensure the all apps icon height matches the workspace icons
                 icon.getLayoutParams().height = getCellSize().y;
-                viewHolder = new ViewHolder(icon);
-                break;
+                return new ViewHolder(icon);
             case VIEW_TYPE_DISCOVERY_ITEM:
                 AppDiscoveryItemView appDiscoveryItemView = (AppDiscoveryItemView) mLayoutInflater
                         .inflate(R.layout.all_apps_discovery_item, parent, false);
                 appDiscoveryItemView.init(mIconClickListener, mLauncher.getAccessibilityDelegate(),
                         mIconLongClickListener);
-                viewHolder = new ViewHolder(appDiscoveryItemView);
-                break;
+                return new ViewHolder(appDiscoveryItemView);
             case VIEW_TYPE_EMPTY_SEARCH:
-                viewHolder = new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search,
+                return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search,
                         parent, false));
-                break;
             case VIEW_TYPE_SEARCH_MARKET:
                 View searchMarketView = mLayoutInflater.inflate(R.layout.all_apps_search_market,
                         parent, false);
@@ -326,30 +317,21 @@
                         mLauncher.startActivitySafely(v, mMarketSearchIntent, null);
                     }
                 });
-                viewHolder = new ViewHolder(searchMarketView);
-                break;
+                return new ViewHolder(searchMarketView);
             case VIEW_TYPE_SEARCH_DIVIDER:
-                viewHolder = new ViewHolder(mLayoutInflater.inflate(
+                return new ViewHolder(mLayoutInflater.inflate(
                         R.layout.all_apps_search_divider, parent, false));
-                break;
             case VIEW_TYPE_APPS_LOADING_DIVIDER:
                 View loadingDividerView = mLayoutInflater.inflate(
                         R.layout.all_apps_discovery_loading_divider, parent, false);
-                viewHolder = new ViewHolder(loadingDividerView);
-                break;
+                return new ViewHolder(loadingDividerView);
             case VIEW_TYPE_PREDICTION_DIVIDER:
             case VIEW_TYPE_SEARCH_MARKET_DIVIDER:
-                viewHolder = new ViewHolder(mLayoutInflater.inflate(
+                return new ViewHolder(mLayoutInflater.inflate(
                         R.layout.all_apps_divider, parent, false));
-                break;
             default:
                 throw new RuntimeException("Unexpected view type");
         }
-
-        if (FeatureFlags.LAUNCHER3_PHYSICS && isViewType(viewType, VIEW_TYPE_MASK_HAS_SPRINGS)) {
-            viewHolder.spring = mSpringAnimationHandler.createSpringAnimation(viewHolder.itemView);
-        }
-        return viewHolder;
     }
 
     private Point getCellSize() {
@@ -358,8 +340,7 @@
 
     @Override
     public void onBindViewHolder(ViewHolder holder, int position) {
-        int viewType = holder.getItemViewType();
-        switch (viewType) {
+        switch (holder.getItemViewType()) {
             case VIEW_TYPE_ICON:
             case VIEW_TYPE_PREDICTION_ICON:
                 AppInfo info = mApps.getAdapterItems().get(position).appInfo;
@@ -396,16 +377,21 @@
                 // nothing to do
                 break;
         }
-        if (FeatureFlags.LAUNCHER3_PHYSICS && isViewType(viewType, VIEW_TYPE_MASK_HAS_SPRINGS)) {
-            holder.spring = mSpringAnimationHandler.add(holder.itemView, position, mApps,
-                    mAppsPerRow, holder.spring);
-        }
         if (mBindViewCallback != null) {
             mBindViewCallback.onBindView(holder);
         }
     }
 
     @Override
+    public void onViewAttachedToWindow(ViewHolder holder) {
+        int type = holder.getItemViewType();
+        if (FeatureFlags.LAUNCHER3_PHYSICS && isViewType(type, VIEW_TYPE_MASK_HAS_SPRINGS)) {
+            holder.spring = mSpringAnimationHandler.add(holder.itemView,
+                    holder.getAdapterPosition(), mApps, mAppsPerRow, holder.spring);
+        }
+    }
+
+    @Override
     public void onViewDetachedFromWindow(ViewHolder holder) {
         int type = holder.getItemViewType();
         if (FeatureFlags.LAUNCHER3_PHYSICS && isViewType(type, VIEW_TYPE_MASK_HAS_SPRINGS)) {
diff --git a/src/com/android/launcher3/anim/SpringAnimationHandler.java b/src/com/android/launcher3/anim/SpringAnimationHandler.java
index 92acfb8..488657c 100644
--- a/src/com/android/launcher3/anim/SpringAnimationHandler.java
+++ b/src/com/android/launcher3/anim/SpringAnimationHandler.java
@@ -178,7 +178,7 @@
         return mDirection == Y_DIRECTION;
     }
 
-    public SpringAnimation createSpringAnimation(View view) {
+    private SpringAnimation createSpringAnimation(View view) {
         DynamicAnimation.ViewProperty property = isVerticalDirection()
                 ? DynamicAnimation.TRANSLATION_Y
                 : DynamicAnimation.TRANSLATION_X;
diff --git a/src/com/android/launcher3/graphics/LauncherIcons.java b/src/com/android/launcher3/graphics/LauncherIcons.java
index 53521f2..19e57024 100644
--- a/src/com/android/launcher3/graphics/LauncherIcons.java
+++ b/src/com/android/launcher3/graphics/LauncherIcons.java
@@ -266,9 +266,10 @@
 
             sOldBounds.set(icon.getBounds());
             if (Utilities.isAtLeastO() && icon instanceof AdaptiveIconDrawable) {
-                int offset = Math.min(left, top);
+                int offset = Math.max((int)(ShadowGenerator.BLUR_FACTOR * iconBitmapSize),
+                        Math.min(left, top));
                 int size = Math.max(width, height);
-                icon.setBounds(offset, offset, offset + size, offset + size);
+                icon.setBounds(offset, offset, size, size);
             } else {
                 icon.setBounds(left, top, left+width, top+height);
             }
diff --git a/src/com/android/launcher3/graphics/ShadowGenerator.java b/src/com/android/launcher3/graphics/ShadowGenerator.java
index 695015d..37fb4ec 100644
--- a/src/com/android/launcher3/graphics/ShadowGenerator.java
+++ b/src/com/android/launcher3/graphics/ShadowGenerator.java
@@ -37,7 +37,7 @@
 
     // Percent of actual icon size
     private static final float HALF_DISTANCE = 0.5f;
-    private static final float BLUR_FACTOR = 0.5f/48;
+    public static final float BLUR_FACTOR = 0.5f/48;
 
     // Percent of actual icon size
     private static final float KEY_SHADOW_DISTANCE = 1f/48;