OSDN Git Service

Ensure FloatingToolbar is not rendered at negative x, y coordinates.
authorAbodunrinwa Toki <toki@google.com>
Thu, 28 Apr 2016 18:59:57 +0000 (19:59 +0100)
committerAbodunrinwa Toki <toki@google.com>
Thu, 28 Apr 2016 18:59:57 +0000 (19:59 +0100)
Bug: 28343540
Change-Id: I550a1a2389a6f90525498962709f0c82e8e310ab

core/java/com/android/internal/widget/FloatingToolbar.java

index 1848fe8..bc12391 100644 (file)
@@ -592,9 +592,11 @@ public final class FloatingToolbar {
         private void refreshCoordinatesAndOverflowDirection(Rect contentRectOnScreen) {
             refreshViewPort();
 
-            int x = contentRectOnScreen.centerX() - mPopupWindow.getWidth() / 2;
-            // Update x so that the toolbar isn't rendered behind the nav bar in landscape.
-            x = Math.max(0, Math.min(x, mViewPortOnScreen.right - mPopupWindow.getWidth()));
+            // Initialize x ensuring that the toolbar isn't rendered behind the nav bar in
+            // landscape.
+            final int x = Math.min(
+                    contentRectOnScreen.centerX() - mPopupWindow.getWidth() / 2,
+                    mViewPortOnScreen.right - mPopupWindow.getWidth());
 
             final int y;
 
@@ -684,7 +686,8 @@ public final class FloatingToolbar {
             int rootViewTopOnWindow = mTmpCoords[1];
             int windowLeftOnScreen = rootViewLeftOnScreen - rootViewLeftOnWindow;
             int windowTopOnScreen = rootViewTopOnScreen - rootViewTopOnWindow;
-            mCoordsOnWindow.set(x - windowLeftOnScreen, y - windowTopOnScreen);
+            mCoordsOnWindow.set(
+                    Math.max(0, x - windowLeftOnScreen), Math.max(0, y - windowTopOnScreen));
         }
 
         /**