Example usage for android.view View getFocusedRect

List of usage examples for android.view View getFocusedRect

Introduction

In this page you can find the example usage for android.view View getFocusedRect.

Prototype

public void getFocusedRect(Rect r) 

Source Link

Document

When a view has focus and the user navigates away from it, the next view is searched for starting from the rectangle filled in by this method.

Usage

From source file:Main.java

public static boolean isMotionFocusOnView(View view, MotionEvent event) {
    Rect focusBound = new Rect();
    view.getFocusedRect(focusBound);
    return focusBound.contains((int) event.getX(), (int) event.getY());
}

From source file:org.bangbang.support.v4.widget.HListView.java

/**
     * To avoid horizontal focus searches changing the selected item, we
     * manually focus search within the selected item (as applicable), and
     * prevent focus from jumping to something within another item.
     * @param direction one of {View.FOCUS_LEFT, View.FOCUS_RIGHT}
     * @return Whether this consumes the key event.
     */// www .  j  av a 2  s .  c om
    private boolean handleHorizontalFocusWithinListItem(int direction) {
        if (direction != View.FOCUS_UP && direction != View.FOCUS_DOWN) {
            throw new IllegalArgumentException("direction must be one of" + " {View.FOCUS_UP, View.FOCUS_DOWN}");
        }

        final int numChildren = getChildCount();
        if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) {
            final View selectedView = getSelectedView();
            if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) {

                final View currentFocus = selectedView.findFocus();
                final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView,
                        currentFocus, direction);
                if (nextFocus != null) {
                    // do the math to get interesting rect in next focus' coordinates
                    currentFocus.getFocusedRect(mTempRect);
                    offsetDescendantRectToMyCoords(currentFocus, mTempRect);
                    offsetRectIntoDescendantCoords(nextFocus, mTempRect);
                    if (nextFocus.requestFocus(direction, mTempRect)) {
                        return true;
                    }
                }
                // we are blocking the key from being handled (by returning true)
                // if the global result is going to be some other view within this
                // list.  this is to acheive the overall goal of having
                // horizontal d-pad navigation remain in the current item.
                final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(),
                        currentFocus, direction);
                if (globalNextFocus != null) {
                    return isViewAncestorOf(globalNextFocus, this);
                }
            }
        }
        return false;
    }

From source file:com.zhongsou.souyue.ui.HListView.java

/**
 * To avoid horizontal focus searches changing the selected item, we manually focus search within the selected item (as
 * applicable), and prevent focus from jumping to something within another item.
 *
 * @param direction one of {View.FOCUS_LEFT, View.FOCUS_RIGHT}
 * @return Whether this consumes the key event.
 *//*from ww w.j a  va2s  . c  o  m*/
private boolean handleHorizontalFocusWithinListItem(int direction) {
    // TODO: implement this
    if (direction != View.FOCUS_LEFT && direction != View.FOCUS_RIGHT) {
        throw new IllegalArgumentException("direction must be one of" + " {View.FOCUS_LEFT, View.FOCUS_RIGHT}");
    }

    final int numChildren = getChildCount();
    if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) {
        final View selectedView = getSelectedView();
        if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) {

            final View currentFocus = selectedView.findFocus();
            final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView,
                    currentFocus, direction);
            if (nextFocus != null) {
                // do the math to get interesting rect in next focus' coordinates
                currentFocus.getFocusedRect(mTempRect);
                offsetDescendantRectToMyCoords(currentFocus, mTempRect);
                offsetRectIntoDescendantCoords(nextFocus, mTempRect);
                if (nextFocus.requestFocus(direction, mTempRect)) {
                    return true;
                }
            }
            // we are blocking the key from being handled (by returning true)
            // if the global result is going to be some other view within this
            // list. this is to acheive the overall goal of having
            // horizontal d-pad navigation remain in the current item.
            final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(),
                    currentFocus, direction);
            if (globalNextFocus != null) {
                return isViewAncestorOf(globalNextFocus, this);
            }
        }
    }
    return false;
}

From source file:com.appunite.list.HorizontalListView.java

/**
 * To avoid horizontal focus searches changing the selected item, we
 * manually focus search within the selected item (as applicable), and
 * prevent focus from jumping to something within another item.
 * @param direction one of {View.FOCUS_LEFT, View.FOCUS_RIGHT}
 * @return Whether this consumes the key event.
 *//*w  w w.jav  a2 s . c om*/
private boolean handleHorizontalFocusWithinListItem(int direction) {
    if (direction != View.FOCUS_UP && direction != View.FOCUS_DOWN) {
        throw new IllegalArgumentException("direction must be one of" + " {View.FOCUS_UP, View.FOCUS_DOWN}");
    }

    final int numChildren = getChildCount();
    if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) {
        final View selectedView = getSelectedView();
        if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) {

            final View currentFocus = selectedView.findFocus();
            final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView,
                    currentFocus, direction);
            if (nextFocus != null) {
                // do the math to get interesting rect in next focus' coordinates
                currentFocus.getFocusedRect(mTempRect);
                offsetDescendantRectToMyCoords(currentFocus, mTempRect);
                offsetRectIntoDescendantCoords(nextFocus, mTempRect);
                if (nextFocus.requestFocus(direction, mTempRect)) {
                    return true;
                }
            }
            // we are blocking the key from being handled (by returning true)
            // if the global result is going to be some other view within this
            // list.  this is to acheive the overall goal of having
            // horizontal d-pad navigation remain in the current item.
            final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(),
                    currentFocus, direction);
            if (globalNextFocus != null) {
                return isViewAncestorOf(globalNextFocus, this);
            }
        }
    }
    return false;
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

/**
 * To avoid horizontal focus searches changing the selected item, we manually focus search within the selected item (as
 * applicable), and prevent focus from jumping to something within another item.
 * //ww  w  . j av  a 2  s .c  o m
 * @param direction
 *           one of {View.FOCUS_LEFT, View.FOCUS_RIGHT}
 * @return Whether this consumes the key event.
 */
private boolean handleHorizontalFocusWithinListItem(int direction) {
    // TODO: implement this
    if (direction != View.FOCUS_UP && direction != View.FOCUS_DOWN) {
        throw new IllegalArgumentException("direction must be one of" + " {View.FOCUS_UP, View.FOCUS_DOWN}");
    }

    final int numChildren = getChildCount();
    if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) {
        final View selectedView = getSelectedView();
        if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) {

            final View currentFocus = selectedView.findFocus();
            final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView,
                    currentFocus, direction);
            if (nextFocus != null) {
                // do the math to get interesting rect in next focus' coordinates
                currentFocus.getFocusedRect(mTempRect);
                offsetDescendantRectToMyCoords(currentFocus, mTempRect);
                offsetRectIntoDescendantCoords(nextFocus, mTempRect);
                if (nextFocus.requestFocus(direction, mTempRect)) {
                    return true;
                }
            }
            // we are blocking the key from being handled (by returning true)
            // if the global result is going to be some other view within this
            // list. this is to acheive the overall goal of having
            // horizontal d-pad navigation remain in the current item.
            final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(),
                    currentFocus, direction);
            if (globalNextFocus != null) {
                return isViewAncestorOf(globalNextFocus, this);
            }
        }
    }
    return false;
}

From source file:com.appunite.list.ListView.java

/**
 * To avoid horizontal focus searches changing the selected item, we
 * manually focus search within the selected item (as applicable), and
 * prevent focus from jumping to something within another item.
 * @param direction one of {View.FOCUS_LEFT, View.FOCUS_RIGHT}
 * @return Whether this consumes the key event.
 *///ww w .  j  av a2 s  .c  o m
private boolean handleHorizontalFocusWithinListItem(int direction) {
    if (direction != View.FOCUS_LEFT && direction != View.FOCUS_RIGHT) {
        throw new IllegalArgumentException("direction must be one of" + " {View.FOCUS_LEFT, View.FOCUS_RIGHT}");
    }

    final int numChildren = getChildCount();
    if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) {
        final View selectedView = getSelectedView();
        if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) {

            final View currentFocus = selectedView.findFocus();
            final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView,
                    currentFocus, direction);
            if (nextFocus != null) {
                // do the math to get interesting rect in next focus' coordinates
                currentFocus.getFocusedRect(mTempRect);
                offsetDescendantRectToMyCoords(currentFocus, mTempRect);
                offsetRectIntoDescendantCoords(nextFocus, mTempRect);
                if (nextFocus.requestFocus(direction, mTempRect)) {
                    return true;
                }
            }
            // we are blocking the key from being handled (by returning true)
            // if the global result is going to be some other view within this
            // list.  this is to acheive the overall goal of having
            // horizontal d-pad navigation remain in the current item.
            final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(),
                    currentFocus, direction);
            if (globalNextFocus != null) {
                return isViewAncestorOf(globalNextFocus, this);
            }
        }
    }
    return false;
}

From source file:com.appunite.list.AbsHorizontalListView.java

@Override
public void getFocusedRect(Rect r) {
    View view = getSelectedView();
    if (view != null && view.getParent() == this) {
        // the focused rectangle of the selected view offset into the
        // coordinate space of this view.
        view.getFocusedRect(r);
        offsetDescendantRectToMyCoords(view, r);
    } else {/*from ww  w  .  jav a 2 s  .co m*/
        // otherwise, just the norm
        super.getFocusedRect(r);
    }
}

From source file:com.aliasapps.seq.scroller.TwoWayView.java

@Override
public void getFocusedRect(Rect r) {
    View view = getSelectedView();

    if (view != null && view.getParent() == this) {
        // The focused rectangle of the selected view offset into the
        // coordinate space of this view.
        view.getFocusedRect(r);
        offsetDescendantRectToMyCoords(view, r);
    } else {/*from   w ww.j  ava2s  .c  o m*/
        super.getFocusedRect(r);
    }
}

From source file:com.aliasapps.seq.scroller.TwoWayView.java

/**
 * To avoid horizontal/vertical focus searches changing the selected item,
 * we manually focus search within the selected item (as applicable), and
 * prevent focus from jumping to something within another item.
 *
 * @param direction either {@link View#FOCUS_UP} or {@link View#FOCUS_DOWN} or
 *        {@link View#FOCUS_LEFT} or {@link View#FOCUS_RIGHT} depending on the
 *        current view orientation.//from w  w w  . j  a va  2s  . c  o m
 *
 * @return Whether this consumes the key event.
 */
private boolean handleFocusWithinItem(int direction) {
    forceValidInnerFocusDirection(direction);

    final int numChildren = getChildCount();

    if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) {
        final View selectedView = getSelectedView();

        if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) {

            final View currentFocus = selectedView.findFocus();
            final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView,
                    currentFocus, direction);

            if (nextFocus != null) {
                // Do the math to get interesting rect in next focus' coordinates
                currentFocus.getFocusedRect(mTempRect);
                offsetDescendantRectToMyCoords(currentFocus, mTempRect);
                offsetRectIntoDescendantCoords(nextFocus, mTempRect);

                if (nextFocus.requestFocus(direction, mTempRect)) {
                    return true;
                }
            }

            // We are blocking the key from being handled (by returning true)
            // if the global result is going to be some other view within this
            // list. This is to achieve the overall goal of having horizontal/vertical
            // d-pad navigation remain in the current item depending on the current
            // orientation in this view.
            final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(),
                    currentFocus, direction);

            if (globalNextFocus != null) {
                return isViewAncestorOf(globalNextFocus, this);
            }
        }
    }

    return false;
}

From source file:com.artifex.mupdf.view.ThumbnailViews.java

/**
 * To avoid horizontal/vertical focus searches changing the selected item,
 * we manually focus search within the selected item (as applicable), and
 * prevent focus from jumping to something within another item.
 * //from ww w .  j  a v  a 2  s .c  o  m
 * @param direction
 *            either {@link View#FOCUS_UP} or {@link View#FOCUS_DOWN} or
 *            {@link View#FOCUS_LEFT} or {@link View#FOCUS_RIGHT} depending
 *            on the current view orientation.
 * 
 * @return Whether this consumes the key event.
 */
private boolean handleFocusWithinItem(int direction) {
    forceValidInnerFocusDirection(direction);

    final int numChildren = getChildCount();

    if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) {
        final View selectedView = getSelectedView();

        if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) {

            final View currentFocus = selectedView.findFocus();
            final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView,
                    currentFocus, direction);

            if (nextFocus != null) {
                // Do the math to get interesting rect in next focus'
                // coordinates
                currentFocus.getFocusedRect(mTempRect);
                offsetDescendantRectToMyCoords(currentFocus, mTempRect);
                offsetRectIntoDescendantCoords(nextFocus, mTempRect);

                if (nextFocus.requestFocus(direction, mTempRect)) {
                    return true;
                }
            }

            // We are blocking the key from being handled (by returning
            // true)
            // if the global result is going to be some other view within
            // this
            // list. This is to achieve the overall goal of having
            // horizontal/vertical
            // d-pad navigation remain in the current item depending on the
            // current
            // orientation in this view.
            final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(),
                    currentFocus, direction);

            if (globalNextFocus != null) {
                return isViewAncestorOf(globalNextFocus, this);
            }
        }
    }

    return false;
}