Build 1.0_r1(from source)

android.view
Class FocusFinder

java.lang.Object
  extended by android.view.FocusFinder

public class FocusFinder
extends Object

The algorithm used for finding the next focusable view in a given direction from a view that currently has focus.


Field Summary
(package private)  Rect mBestCandidateRect
           
(package private)  Rect mFocusedRect
           
(package private)  Rect mOtherRect
           
 
Method Summary
(package private)  boolean beamBeats(int direction, Rect source, Rect rect1, Rect rect2)
          One rectangle may be another candidate than another by virtue of being exclusively in the beam of the source rect.
(package private)  boolean beamsOverlap(int direction, Rect rect1, Rect rect2)
          Do the "beams" w.r.t the given direcition's axos of rect1 and rect2 overlap?
 View findNearestTouchable(ViewGroup root, int x, int y, int direction, int[] deltas)
          Find the nearest touchable view to the specified view.
 View findNextFocus(ViewGroup root, View focused, int direction)
          Find the next view to take focus in root's descendants, starting from the view that currently is focused.
 View findNextFocusFromRect(ViewGroup root, Rect focusedRect, int direction)
          Find the next view to take focus in root's descendants, searching from a particular rectangle in root's coordinates.
static FocusFinder getInstance()
          Get the focus finder for this thread.
(package private)  int getWeightedDistanceFor(int majorAxisDistance, int minorAxisDistance)
          Fudge-factor opportunity: how to calculate distance given major and minor axis distances.
(package private)  boolean isBetterCandidate(int direction, Rect source, Rect rect1, Rect rect2)
          Is rect1 a better candidate than rect2 for a focus search in a particular direction from a source rect? This is the core routine that determines the order of focus searching.
(package private)  boolean isCandidate(Rect srcRect, Rect destRect, int direction)
          Is destRect a candidate for the next focus given the direction? This checks whether the dest is at least partially to the direction of (e.g left of) from source.
(package private)  boolean isToDirectionOf(int direction, Rect src, Rect dest)
          e.g for left, is 'to left of'
(package private) static int majorAxisDistance(int direction, Rect source, Rect dest)
           
(package private) static int majorAxisDistanceRaw(int direction, Rect source, Rect dest)
           
(package private) static int majorAxisDistanceToFarEdge(int direction, Rect source, Rect dest)
           
(package private) static int majorAxisDistanceToFarEdgeRaw(int direction, Rect source, Rect dest)
           
(package private) static int minorAxisDistance(int direction, Rect source, Rect dest)
          Find the distance on the minor axis w.r.t the direction to the nearest edge of the destination rectange.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mFocusedRect

Rect mFocusedRect

mOtherRect

Rect mOtherRect

mBestCandidateRect

Rect mBestCandidateRect
Method Detail

getInstance

public static FocusFinder getInstance()
Get the focus finder for this thread.


findNextFocus

public final View findNextFocus(ViewGroup root,
                                View focused,
                                int direction)
Find the next view to take focus in root's descendants, starting from the view that currently is focused.

Parameters:
root - Contains focused
focused - Has focus now.
direction - Direction to look.
Returns:
The next focusable view, or null if none exists.

findNextFocusFromRect

public View findNextFocusFromRect(ViewGroup root,
                                  Rect focusedRect,
                                  int direction)
Find the next view to take focus in root's descendants, searching from a particular rectangle in root's coordinates.

Parameters:
root - Contains focusedRect.
focusedRect - The starting point of the search.
direction - Direction to look.
Returns:
The next focusable view, or null if none exists.

isBetterCandidate

boolean isBetterCandidate(int direction,
                          Rect source,
                          Rect rect1,
                          Rect rect2)
Is rect1 a better candidate than rect2 for a focus search in a particular direction from a source rect? This is the core routine that determines the order of focus searching.

Parameters:
direction - the direction (up, down, left, right)
source - The source we are searching from
rect1 - The candidate rectangle
rect2 - The current best candidate.
Returns:
Whether the candidate is the new best.

beamBeats

boolean beamBeats(int direction,
                  Rect source,
                  Rect rect1,
                  Rect rect2)
One rectangle may be another candidate than another by virtue of being exclusively in the beam of the source rect.

Returns:
Whether rect1 is a better candidate than rect2 by virtue of it being in src's beam

getWeightedDistanceFor

int getWeightedDistanceFor(int majorAxisDistance,
                           int minorAxisDistance)
Fudge-factor opportunity: how to calculate distance given major and minor axis distances. Warning: this fudge factor is finely tuned, be sure to run all focus tests if you dare tweak it.


isCandidate

boolean isCandidate(Rect srcRect,
                    Rect destRect,
                    int direction)
Is destRect a candidate for the next focus given the direction? This checks whether the dest is at least partially to the direction of (e.g left of) from source. Includes an edge case for an empty rect (which is used in some cases when searching from a point on the screen).


beamsOverlap

boolean beamsOverlap(int direction,
                     Rect rect1,
                     Rect rect2)
Do the "beams" w.r.t the given direcition's axos of rect1 and rect2 overlap?

Parameters:
direction - the direction (up, down, left, right)
rect1 - The first rectangle
rect2 - The second rectangle
Returns:
whether the beams overlap

isToDirectionOf

boolean isToDirectionOf(int direction,
                        Rect src,
                        Rect dest)
e.g for left, is 'to left of'


majorAxisDistance

static int majorAxisDistance(int direction,
                             Rect source,
                             Rect dest)
Returns:
The distance from the edge furthest in the given direction of source to the edge nearest in the given direction of dest. If the dest is not in the direction from source, return 0.

majorAxisDistanceRaw

static int majorAxisDistanceRaw(int direction,
                                Rect source,
                                Rect dest)

majorAxisDistanceToFarEdge

static int majorAxisDistanceToFarEdge(int direction,
                                      Rect source,
                                      Rect dest)
Returns:
The distance along the major axis w.r.t the direction from the edge of source to the far edge of dest. If the dest is not in the direction from source, return 1 (to break ties with majorAxisDistance(int, android.graphics.Rect, android.graphics.Rect)).

majorAxisDistanceToFarEdgeRaw

static int majorAxisDistanceToFarEdgeRaw(int direction,
                                         Rect source,
                                         Rect dest)

minorAxisDistance

static int minorAxisDistance(int direction,
                             Rect source,
                             Rect dest)
Find the distance on the minor axis w.r.t the direction to the nearest edge of the destination rectange.

Parameters:
direction - the direction (up, down, left, right)
source - The source rect.
dest - The destination rect.
Returns:
The distance.

findNearestTouchable

public View findNearestTouchable(ViewGroup root,
                                 int x,
                                 int y,
                                 int direction,
                                 int[] deltas)
Find the nearest touchable view to the specified view.

Parameters:
root - The root of the tree in which to search
x - X coordinate from which to start the search
y - Y coordinate from which to start the search
direction - Direction to look
deltas - Offset from the to the edge of the nearest view. Note that this array may already be populated with values.
Returns:
The nearest touchable view, or null if none exists.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature