Merge "Fixing issue with folder inflation" into ub-launcher3-burnaby
diff --git a/src/com/android/launcher3/AppsContainerView.java b/src/com/android/launcher3/AppsContainerView.java
index 7c1aee2..8709101 100644
--- a/src/com/android/launcher3/AppsContainerView.java
+++ b/src/com/android/launcher3/AppsContainerView.java
@@ -396,6 +396,7 @@
                 inset, 0, inset, 0);
         mContentView.setBackground(background);
         mAppsRecyclerView.updateBackgroundPadding(background);
+        mAdapter.updateBackgroundPadding(background);
         getRevealView().setBackground(background.getConstantState().newDrawable());
     }
 
@@ -658,12 +659,14 @@
                 // We workaround the fact that the recycler view needs the touches for the scroll
                 // and we want to intercept it for clicks in the prediction bar by handling clicks
                 // and long clicks in the prediction bar ourselves.
-                mPredictionIconTouchDownPos.set(x, y);
-                mPredictionIconUnderTouch = findPredictedAppAtCoordinate(x, y);
-                if (mPredictionIconUnderTouch != null) {
-                    mPredictionIconCheckForLongPress =
-                            new CheckLongPressHelper(mPredictionIconUnderTouch, this);
-                    mPredictionIconCheckForLongPress.postCheckForLongPress();
+                if (mPredictionBarView != null && mPredictionBarView.getVisibility() == View.VISIBLE) {
+                    mPredictionIconTouchDownPos.set(x, y);
+                    mPredictionIconUnderTouch = findPredictedAppAtCoordinate(x, y);
+                    if (mPredictionIconUnderTouch != null) {
+                        mPredictionIconCheckForLongPress =
+                                new CheckLongPressHelper(mPredictionIconUnderTouch, this);
+                        mPredictionIconCheckForLongPress.postCheckForLongPress();
+                    }
                 }
 
                 if (!mFixedBounds.isEmpty()) {
@@ -730,6 +733,9 @@
         Utilities.mapCoordInSelfToDescendent(mPredictionBarView, this, coord);
         for (int i = 0; i < mPredictionBarView.getChildCount(); i++) {
             View child = mPredictionBarView.getChildAt(i);
+            if (child.getVisibility() != View.VISIBLE) {
+                continue;
+            }
             child.getHitRect(hitRect);
             if (hitRect.contains(coord[0], coord[1])) {
                 return child;
diff --git a/src/com/android/launcher3/AppsGridAdapter.java b/src/com/android/launcher3/AppsGridAdapter.java
index dfbfa01..d5a411e 100644
--- a/src/com/android/launcher3/AppsGridAdapter.java
+++ b/src/com/android/launcher3/AppsGridAdapter.java
@@ -6,6 +6,7 @@
 import android.graphics.Paint;
 import android.graphics.PointF;
 import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
 import android.os.Handler;
 import android.support.v7.widget.GridLayoutManager;
 import android.support.v7.widget.RecyclerView;
@@ -112,9 +113,9 @@
 
                 if (shouldDrawItemDivider(holder, items) && !hasDrawnPredictedAppsDivider) {
                     // Draw the divider under the predicted apps
-                    parent.getBackground().getPadding(mTmpBounds);
                     int top = child.getTop() + child.getHeight();
-                    c.drawLine(mTmpBounds.left, top, parent.getWidth() - mTmpBounds.right, top,
+                    c.drawLine(mBackgroundPadding.left, top,
+                            parent.getWidth() - mBackgroundPadding.right, top,
                             mPredictedAppsDividerPaint);
                     hasDrawnPredictedAppsDivider = true;
 
@@ -265,6 +266,7 @@
     private View.OnTouchListener mTouchListener;
     private View.OnClickListener mIconClickListener;
     private View.OnLongClickListener mIconLongClickListener;
+    @Thunk final Rect mBackgroundPadding = new Rect();
     @Thunk int mPredictionBarHeight;
     @Thunk int mAppsPerRow;
     @Thunk boolean mIsRtl;
@@ -341,6 +343,14 @@
     }
 
     /**
+     * Notifies the adapter of the background padding so that it can draw things correctly in the
+     * item decorator.
+     */
+    public void updateBackgroundPadding(Drawable background) {
+        background.getPadding(mBackgroundPadding);
+    }
+
+    /**
      * Returns the grid layout manager.
      */
     public GridLayoutManager getLayoutManager() {