Interface IFocusDelegate
interface IFocusDelegate
Extends com.amazon.apmf.IStandard
Interface handles APIs for searching Views that can take focus and manages
requesting and clearing focus of a View.
Each function of this delegate provides an additional parameter which holds a pointer
to the default implementation of this delegate. This enables the user to call the base implementation of the
function as per the use-case (similar to calling the parent class function from the overriden function in child class).
Methods
findNextFocusableView()
Searches for the next focusable View in the specified direction. This function searches for the next focusable View in the specified direction from the given View. If no focusable View is found in the specified direction, the function returns nullptr.IView?findNextFocusableView(IView*currentView,FocusDirectiondirection,IFocusDelegate*defaultDelegate)
Parameters
currentView
IView* — Required
IView The current View from which to start the search.
direction
FocusDirection — Required
IView The FocusDirection in which to search for the next focusable View.
defaultDelegate
IFocusDelegate* — Required
IFocusDelegate Pointer to the default implementation of IFocusDelegate.
Returns
IView?
The return value is optional and might be absent.
A pointer to the next focusable View, or nullptr if no focusable View
is found in the specified direction.
addFocusables()
Adds Views that can take focus to the specified list. This function is called to populate a list of Views that can take focus based on the given parameters.voidaddFocusables(IView*requesterView, inoutIView*[]*outFocusables,FocusDirectiondirection,boolonlyTouchFocusableViews,IFocusDelegate*defaultDelegate)
Parameters
requesterView
IView* — Required
IView The View requesting to add focusables.
outFocusables (inout)
IView*[]* — Required
IView[] An array to which focusable Views will be added.
direction
FocusDirection — Required
FocusDirection The direction of the focus operation.
onlyTouchFocusableViews
bool — Required
bool If true, only add Views focusable in touch mode,
if false, add all focusable Views.
defaultDelegate
IFocusDelegate* — Required
IFocusDelegate Pointer to the default implementation of IFocusDelegate.
Note: The outFocusables array will be populated with Views that can take focus
in the specified direction and mode.
clearFocus()
Clears the focus from this view. This method is called when this view wants to give up focus. If focus is cleared, the onFocusChanged listener will be invoked. The framework will try to give focus to the first focusable View from the top of the View hierarchy after focus is cleared. If this view is the first focusable View from the top, then all callbacks related to clearing focus will be invoked, after which the framework will give focus to this view. After clearing focus, no focusable item is immediately focused. The first focusable item in the View hierarchy will become focused and visible only when the user interacts with the D-pad or keyboard.voidclearFocus(IView*view,IFocusDelegate*defaultDelegate)
Parameters
view
IView* — Required
IView The View for which to clear focus.
defaultDelegate
IFocusDelegate* — Required
IFocusDelegate Pointer to the default implementation of IFocusDelegate.
requestFocus()
Call this to try to give focus to a specific View or to one of its descendants and give it a hint about what direction focus is heading. A View will not actually take focus if it is not focusable, or if it is focusable and it is not focusable in touch mode while the device is in touch mode. A View will not take focus if it is not visible. A View will not take focus if one of its parents has getDescendantFocusability() equal to FOCUS_BLOCK_DESCENDANTS. The default implementation of this function will prioritize self view for getting focus, then will callboolrequestFocus(IView*view,FocusDirection?direction,com.amazon.kepler.uitoolkit.graphics.Rect?previouslyFocusedRect,IFocusDelegate*defaultDelegate)
IFocusDelegate::searchChildrenForFocus if the descendant focusability is set to FOCUS_BEFORE_DESCENDANTS, and
vice-versa for FOCUS_AFTER_DESCENDANTS.
See also- IFocusState::setDescendantFocusability.
Parameters
view
IView* — Required
IView The View for which to request focus.
direction
FocusDirection? — Optional
FocusDirection One of FocusDirection enum value.
previouslyFocusedRect
com.amazon.kepler.uitoolkit.graphics.Rect? — Optional
Rect The rectangle (in this View’s coordinate system)
to give a finer-grained hint about where focus is coming from. May be null
if there is no hint.
defaultDelegate
IFocusDelegate* — Required
IFocusDelegate Pointer to the default implementation of IFocusDelegate.
Returns
bool
Whether this View or one of its descendants actually took focus.
requestChildFocus()
Called when a child of this parent wants focus.voidrequestChildFocus(IView*parent,IView*child,IView*focused,IFocusDelegate*defaultDelegate)
Parameters
parent
IView* — Required
IView The parent View that is handling the focus request.
child
IView* — Required
IView The child of this ViewParent that wants focus. This View will
contain the focused View. It is not necessarily the View that actually has focus.
focused
IView* — Required
IView The View that is a descendant of child that actually has focus.
defaultDelegate
IFocusDelegate* — Required
IFocusDelegate Pointer to the default implementation of IFocusDelegate.
clearChildFocus()
Called when a child of this parent is giving up focus. This method will traverse up the view hierarchy and recursively call this function for the parent of this view.voidclearChildFocus(IView*parent,IView*child,IFocusDelegate*defaultDelegate)
Parameters
parent
IView* — Required
IView The parent View that is handling the focus request.
child
IView* — Required
IView The View that is giving up focus.
defaultDelegate
IFocusDelegate* — Required
IFocusDelegate Pointer to the default implementation of IFocusDelegate.
unFocus()
Method to clear focus on requested view. It will recursively traverse down to the leaf view and will set the focus child to null. Once the focussed child has been cleared, it will internally callvoidunFocus(IView*view,IFocusDelegate*defaultDelegate)
onFocusChanged.
Parameters
view
IView* — Required
IView The View that is giving up focus.
defaultDelegate
IFocusDelegate* — Required
IFocusDelegate Pointer to the default implementation of IFocusDelegate.
searchChildrenForFocus()
This function is called from by the default implementation ofboolsearchChildrenForFocus(IView*view,FocusDirectiondirection,com.amazon.kepler.uitoolkit.graphics.Rect?previousFocusArea,IFocusDelegate*defaultDelegate)
IFocusDelegate::requestFocus internally depending on the
value set by IFocusState::setDescendantFocusability.
The default implementation of this function searches through the children of current view to determine which
child should get next focus.
Parameters
view
IView* — Required
IView The parent view for which next child to be focussed is to be determined.
direction
FocusDirection — Required
FocusDirection The direction of focus movement.
previousFocusArea
com.amazon.kepler.uitoolkit.graphics.Rect? — Optional
Rect Represents the area which was previously having focus.
defaultDelegate
IFocusDelegate* — Required
IFocusDelegate Pointer to the default implementation of IFocusDelegate.
Returns
bool
bool True if any child has taken focus, else false.

