Fixes issue where menu was offset incorrectly when it should be centered in the screen.

PiperOrigin-RevId: 271399786
Change-Id: I92015d17ae78351936b9b5e487d6d0c53700fbe1
diff --git a/src/main/java/com/google/android/libraries/feed/sharedstream/contextmenumanager/ContextMenuManagerImpl.java b/src/main/java/com/google/android/libraries/feed/sharedstream/contextmenumanager/ContextMenuManagerImpl.java
index 1cd945f..20f2e32 100644
--- a/src/main/java/com/google/android/libraries/feed/sharedstream/contextmenumanager/ContextMenuManagerImpl.java
+++ b/src/main/java/com/google/android/libraries/feed/sharedstream/contextmenumanager/ContextMenuManagerImpl.java
@@ -175,7 +175,17 @@
     } else {
       // The menu will fit neither above, nor below the content. Center it in the middle of the
       // screen.
-      return -(menuHeight + anchorViewYInWindow - windowHeight / 2);
+
+      // First, get an offset so that the top of the menu will be at the top of the screen.
+      int offset = -(anchorViewHeight + anchorViewYInWindow);
+
+      // Then, shift so that the middle of the menu is at the top of the screen.
+      offset -= menuHeight / 2;
+
+      // Then, shift so that the center of the menu is at the center of the screen.
+      offset += windowHeight / 2;
+
+      return offset;
     }
   }