summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Haoyu Zhang <haoyuchang@google.com> 2023-08-30 22:44:10 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2023-08-30 22:44:10 +0000
commitd79c9b9adda4883839c6a610b7c1f43e1185cba7 (patch)
tree90b5e0f3d808be4c23525c1fd1867974d7490e41
parent5c179c021a69840dbdbbb3701ba3a924090d9228 (diff)
parent17a0a8f5c03440730647432e1b33f4c17b0a11e3 (diff)
Merge "Avoid unnecessary allocation in HandwritingInitiator" into udc-qpr-dev am: 2f56dc2c9b am: 17a0a8f5c0
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24541343 Change-Id: I7590f3e5cfd07ce385226168533ca801332a1245 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--core/java/android/view/HandwritingInitiator.java38
1 files changed, 22 insertions, 16 deletions
diff --git a/core/java/android/view/HandwritingInitiator.java b/core/java/android/view/HandwritingInitiator.java
index 23afb03569ce..a208d1f1a558 100644
--- a/core/java/android/view/HandwritingInitiator.java
+++ b/core/java/android/view/HandwritingInitiator.java
@@ -81,6 +81,8 @@ public class HandwritingInitiator {
private int mConnectionCount = 0;
private final InputMethodManager mImm;
+ private final Rect mTempRect = new Rect();
+
private final RectF mTempRectF = new RectF();
private final Region mTempRegion = new Region();
@@ -401,8 +403,9 @@ public class HandwritingInitiator {
final View cachedHoverTarget = getCachedHoverTarget();
if (cachedHoverTarget != null) {
- final Rect handwritingArea = getViewHandwritingArea(cachedHoverTarget);
- if (isInHandwritingArea(handwritingArea, hoverX, hoverY, cachedHoverTarget,
+ final Rect handwritingArea = mTempRect;
+ if (getViewHandwritingArea(cachedHoverTarget, handwritingArea)
+ && isInHandwritingArea(handwritingArea, hoverX, hoverY, cachedHoverTarget,
/* isHover */ true)
&& shouldTriggerStylusHandwritingForView(cachedHoverTarget)) {
return cachedHoverTarget;
@@ -445,8 +448,9 @@ public class HandwritingInitiator {
// directly return the connectedView.
final View connectedView = getConnectedView();
if (connectedView != null) {
- Rect handwritingArea = getViewHandwritingArea(connectedView);
- if (isInHandwritingArea(handwritingArea, x, y, connectedView, isHover)
+ Rect handwritingArea = mTempRect;
+ if (getViewHandwritingArea(connectedView, handwritingArea)
+ && isInHandwritingArea(handwritingArea, x, y, connectedView, isHover)
&& shouldTriggerStylusHandwritingForView(connectedView)) {
return connectedView;
}
@@ -528,28 +532,30 @@ public class HandwritingInitiator {
/**
* Return the handwriting area of the given view, represented in the window's coordinate.
* If the view didn't set any handwriting area, it will return the view's boundary.
- * It will return null if the view or its handwriting area is not visible.
*
- * The handwriting area is clipped to its visible part.
+ * <p> The handwriting area is clipped to its visible part.
* Notice that the returned rectangle is the view's original handwriting area without the
- * view's handwriting area extends.
+ * view's handwriting area extends. </p>
+ *
+ * @param view the {@link View} whose handwriting area we want to compute.
+ * @param rect the {@link Rect} to receive the result.
+ *
+ * @return true if the view's handwriting area is still visible, or false if it's clipped and
+ * fully invisible. This method only consider the clip by given view's parents, but not the case
+ * where a view is covered by its sibling view.
*/
- @Nullable
- private static Rect getViewHandwritingArea(@NonNull View view) {
+ private static boolean getViewHandwritingArea(@NonNull View view, @NonNull Rect rect) {
final ViewParent viewParent = view.getParent();
if (viewParent != null && view.isAttachedToWindow() && view.isAggregatedVisible()) {
final Rect localHandwritingArea = view.getHandwritingArea();
- final Rect globalHandwritingArea = new Rect();
if (localHandwritingArea != null) {
- globalHandwritingArea.set(localHandwritingArea);
+ rect.set(localHandwritingArea);
} else {
- globalHandwritingArea.set(0, 0, view.getWidth(), view.getHeight());
- }
- if (viewParent.getChildVisibleRect(view, globalHandwritingArea, null)) {
- return globalHandwritingArea;
+ rect.set(0, 0, view.getWidth(), view.getHeight());
}
+ return viewParent.getChildVisibleRect(view, rect, null);
}
- return null;
+ return false;
}
/**