Skip to content

Commit defdb1e

Browse files
Tobias Duboisjredestig
authored andcommitted
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
1 parent 0748a56 commit defdb1e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23033,6 +23033,7 @@ package android.view {
2303323033
method public void getDrawingRect(android.graphics.Rect);
2303423034
method public long getDrawingTime();
2303523035
method public boolean getFilterTouchesWhenObscured();
23036+
method public void getFocusRect(android.graphics.Rect);
2303623037
method public java.util.ArrayList<android.view.View> getFocusables(int);
2303723038
method public void getFocusedRect(android.graphics.Rect);
2303823039
method public boolean getGlobalVisibleRect(android.graphics.Rect, android.graphics.Point);

core/java/android/view/FocusFinder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ private View findNextFocus(ViewGroup root, View focused, Rect focusedRect, int d
181181
// only interested in other non-root views
182182
if (focusable == focused || focusable == root) continue;
183183

184-
// get visible bounds of other view in same coordinate system
185-
focusable.getDrawingRect(mOtherRect);
184+
// get focus bounds of other view in same coordinate system
185+
focusable.getFocusRect(mOtherRect);
186186
root.offsetDescendantRectToMyCoords(focusable, mOtherRect);
187187

188188
if (isBetterCandidate(direction, focusedRect, mOtherRect, mBestCandidateRect)) {

core/java/android/view/View.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7129,6 +7129,18 @@ private void updateMatrix() {
71297129
}
71307130

71317131
/**
7132+
* When searching for a view to focus this rectangle is used when considering if this view is
7133+
* a good candidate for receiving focus.
7134+
*
7135+
* By default, the rectangle is the {@link #getDrawingRect}) of the view.
7136+
*
7137+
* @param r The rectangle to fill in, in this view's coordinates.
7138+
*/
7139+
public void getFocusRect(Rect r) {
7140+
getDrawingRect(r);
7141+
}
7142+
7143+
/**
71327144
* Utility method to retrieve the inverse of the current mMatrix property.
71337145
* We cache the matrix to avoid recalculating it when transform properties
71347146
* have not changed.

0 commit comments

Comments
 (0)