From f95ed10d9da55c25013200fb35af63f0dac65cb4 Mon Sep 17 00:00:00 2001 From: Clara Bayarri Date: Wed, 12 Aug 2015 19:46:47 +0100 Subject: Fix Insertion ActionMode not showing on RTL languages When long pressing on an empty Text field with the system language set to RTL, the "paste" popup was not showing up. The Floating Toolbar requires a content rect to determine where the text is and place itself close to it. In the case of an empty field, we create a "fake" content rect by taking the placement of the cursor +1 pixel to the right. In RTL languages, this +1 causes the content rect to be considered off the bounds of the view, as the cursor is aligned to the right, and hence the Floating Toolbar is hidden. After making the rect a 0 width rect, we ran into the issue that it was considered out of bounds due to the calculation ignoring rects that simply touch the edge of the view's bounds. BUG: 22540083 Change-Id: I29c79b701f586970b2611178233eff082b802ec1 --- core/java/com/android/internal/view/FloatingActionMode.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'core/java/com') diff --git a/core/java/com/android/internal/view/FloatingActionMode.java b/core/java/com/android/internal/view/FloatingActionMode.java index 41628d0..9761661 100644 --- a/core/java/com/android/internal/view/FloatingActionMode.java +++ b/core/java/com/android/internal/view/FloatingActionMode.java @@ -194,8 +194,16 @@ public class FloatingActionMode extends ActionMode { mContext.getResources().getDisplayMetrics().widthPixels, mContext.getResources().getDisplayMetrics().heightPixels); - return Rect.intersects(mContentRectOnScreen, mScreenRect) - && Rect.intersects(mContentRectOnScreen, mViewRectOnScreen); + return intersectsClosed(mContentRectOnScreen, mScreenRect) + && intersectsClosed(mContentRectOnScreen, mViewRectOnScreen); + } + + /* + * Same as Rect.intersects, but includes cases where the rectangles touch. + */ + private static boolean intersectsClosed(Rect a, Rect b) { + return a.left <= b.right && b.left <= a.right + && a.top <= b.bottom && b.top <= a.bottom; } @Override -- cgit v1.1