Take the window insets into account when ABL is dragged

BUG: 23946168
Change-Id: I561d3e9f378c536589fe8847b8f98bbf252f28cf
diff --git a/design/src/android/support/design/widget/AppBarLayout.java b/design/src/android/support/design/widget/AppBarLayout.java
index 262caa0..08cebfc 100644
--- a/design/src/android/support/design/widget/AppBarLayout.java
+++ b/design/src/android/support/design/widget/AppBarLayout.java
@@ -332,7 +332,7 @@
                 break;
             }
         }
-        return mTotalScrollRange = (range - getTopInset());
+        return mTotalScrollRange = Math.max(0, range - getTopInset());
     }
 
     private boolean hasScrollableChildren() {
@@ -406,9 +406,10 @@
 
                 if ((flags & LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED) != 0) {
                     // For a collapsing exit scroll, we to take the collapsed height into account.
-                    // We also return the range straight away since later views can't scroll
+                    // We also break the range straight away since later views can't scroll
                     // beneath us
-                    return mDownScrollRange = (range - ViewCompat.getMinimumHeight(child));
+                    range -= ViewCompat.getMinimumHeight(child) + getTopInset();
+                    break;
                 }
             } else {
                 // As soon as a view doesn't have the scroll flag, we end the range calculation.
@@ -416,7 +417,7 @@
                 break;
             }
         }
-        return mDownScrollRange = range;
+        return mDownScrollRange = Math.max(0, range - getTopInset());
     }
 
     final int getMinimumHeightForVisibleOverlappingContent() {