Example #1
0
        // enforce thread local access
        /// <summary>
        /// Find the next view to take focus in root's descendants, starting from the view
        /// that currently is focused.
        /// </summary>
        /// <remarks>
        /// Find the next view to take focus in root's descendants, starting from the view
        /// that currently is focused.
        /// </remarks>
        /// <param name="root">Contains focused</param>
        /// <param name="focused">Has focus now.</param>
        /// <param name="direction">Direction to look.</param>
        /// <returns>The next focusable view, or null if none exists.</returns>
        public android.view.View findNextFocus(android.view.ViewGroup root, android.view.View
                                               focused, int direction)
        {
            if (focused != null)
            {
                // check for user specified next focus
                android.view.View userSetNextFocus = focused.findUserSetNextFocus(root, direction
                                                                                  );
                if (userSetNextFocus != null && userSetNextFocus.isFocusable() && (!userSetNextFocus
                                                                                   .isInTouchMode() || userSetNextFocus.isFocusableInTouchMode()))
                {
                    return(userSetNextFocus);
                }
                // fill in interesting rect from focused
                focused.getFocusedRect(mFocusedRect);
                root.offsetDescendantRectToMyCoords(focused, mFocusedRect);
            }
            else
            {
                switch (direction)
                {
                case android.view.View.FOCUS_RIGHT:
                case android.view.View.FOCUS_DOWN:
                case android.view.View.FOCUS_FORWARD:
                {
                    // make up a rect at top left or bottom right of root
                    int rootTop  = root.getScrollY();
                    int rootLeft = root.getScrollX();
                    mFocusedRect.set(rootLeft, rootTop, rootLeft, rootTop);
                    break;
                }

                case android.view.View.FOCUS_LEFT:
                case android.view.View.FOCUS_UP:
                case android.view.View.FOCUS_BACKWARD:
                {
                    int rootBottom = root.getScrollY() + root.getHeight();
                    int rootRight  = root.getScrollX() + root.getWidth();
                    mFocusedRect.set(rootRight, rootBottom, rootRight, rootBottom);
                    break;
                }
                }
            }
            return(findNextFocus(root, focused, mFocusedRect, direction));
        }