From defdb1e49172fe7c9737347489dbb77361af955a Mon Sep 17 00:00:00 2001 From: Tobias Dubois Date: Wed, 15 Dec 2010 11:35:30 +0100 Subject: [PATCH] Add the possibility to modify the View focus rect This change makes it possible for a view to supply a different rectangle than the drawing rect to be used by the FocusFinder when finding a new view to give focus to. This is useful if e.g. the total view area is larger than the interactive area of the view. The default implementation of getFocusRect() will return getDrawingRect(). The existing behaviour is only changed if getFocusRect() is overridden by a subclass of android.view.View Change-Id: I52dd95c6fa296b744e354217051dcec1bb3c8e92 --- api/current.txt | 1 + core/java/android/view/FocusFinder.java | 4 ++-- core/java/android/view/View.java | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/api/current.txt b/api/current.txt index d270ae040dc23..b71a24c7805cb 100644 --- a/api/current.txt +++ b/api/current.txt @@ -23033,6 +23033,7 @@ package android.view { method public void getDrawingRect(android.graphics.Rect); method public long getDrawingTime(); method public boolean getFilterTouchesWhenObscured(); + method public void getFocusRect(android.graphics.Rect); method public java.util.ArrayList getFocusables(int); method public void getFocusedRect(android.graphics.Rect); method public boolean getGlobalVisibleRect(android.graphics.Rect, android.graphics.Point); diff --git a/core/java/android/view/FocusFinder.java b/core/java/android/view/FocusFinder.java index d9bf918e66049..a0017255c8461 100644 --- a/core/java/android/view/FocusFinder.java +++ b/core/java/android/view/FocusFinder.java @@ -181,8 +181,8 @@ public class FocusFinder { // only interested in other non-root views if (focusable == focused || focusable == root) continue; - // get visible bounds of other view in same coordinate system - focusable.getDrawingRect(mOtherRect); + // get focus bounds of other view in same coordinate system + focusable.getFocusRect(mOtherRect); root.offsetDescendantRectToMyCoords(focusable, mOtherRect); if (isBetterCandidate(direction, focusedRect, mOtherRect, mBestCandidateRect)) { diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 54bb056ab0350..7d756c27fadc0 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -7129,6 +7129,18 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal } /** + * When searching for a view to focus this rectangle is used when considering if this view is + * a good candidate for receiving focus. + * + * By default, the rectangle is the {@link #getDrawingRect}) of the view. + * + * @param r The rectangle to fill in, in this view's coordinates. + */ + public void getFocusRect(Rect r) { + getDrawingRect(r); + } + + /** * Utility method to retrieve the inverse of the current mMatrix property. * We cache the matrix to avoid recalculating it when transform properties * have not changed.