OSDN Git Service

Fix RTL bug for actionbar tooltips
authorYigit Boyar <yboyar@google.com>
Fri, 22 Aug 2014 00:48:58 +0000 (17:48 -0700)
committerYigit Boyar <yboyar@google.com>
Fri, 22 Aug 2014 00:48:58 +0000 (17:48 -0700)
Bug: 12570378
Change-Id: I13ba94c8b736a3a80a8d79e95bd18b93a1157303

core/java/com/android/internal/view/menu/ActionMenuItemView.java

index 891baea..7eec392 100644 (file)
@@ -265,13 +265,15 @@ public class ActionMenuItemView extends TextView
         final int width = getWidth();
         final int height = getHeight();
         final int midy = screenPos[1] + height / 2;
-        final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
-
+        int referenceX = screenPos[0] + width / 2;
+        if (v.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR) {
+            final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
+            referenceX = screenWidth - referenceX; // mirror
+        }
         Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT);
         if (midy < displayFrame.height()) {
             // Show along the top; follow action buttons
-            cheatSheet.setGravity(Gravity.TOP | Gravity.END,
-                    screenWidth - screenPos[0] - width / 2, height);
+            cheatSheet.setGravity(Gravity.TOP | Gravity.END, referenceX, height);
         } else {
             // Show along the bottom center
             cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);