Example usage for android.view View requestFocus

List of usage examples for android.view View requestFocus

Introduction

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

Prototype

public boolean requestFocus(int direction, Rect previouslyFocusedRect) 

Source Link

Document

Call this to try to give focus to a specific view or to one of its descendants and give it hints about the direction and a specific rectangle that the focus is coming from.

Usage

From source file:com.aincc.libtest.activity.flip.FlipViewGroup.java

/**
 * We only want the current page that is being shown to be focusable.
 *///from www .  ja  v a 2 s  .c  o m
@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
    int index;
    int increment;
    int end;
    int count = getChildCount();
    if ((direction & FOCUS_FORWARD) != 0) {
        index = 0;
        increment = 1;
        end = count;
    } else {
        index = count - 1;
        increment = -1;
        end = -1;
    }
    for (int i = index; i != end; i += increment) {
        View child = getChildAt(i);
        if (child.getVisibility() == VISIBLE) {
            ItemInfo ii = infoForChild(child);
            if (ii != null && ii.position == currentItem) {
                if (child.requestFocus(direction, previouslyFocusedRect)) {
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java

@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {

    if (mItemCount < 1)
        return false;

    if (isEnabled()) {
        int focusableScreen;
        if (mNextScreen != INVALID_SCREEN) {
            focusableScreen = mNextScreen;
        } else {// w w  w  . jav a2 s  .c  o  m
            focusableScreen = mCurrentScreen;
        }

        if (focusableScreen != INVALID_SCREEN) {
            View child = getChildAt(focusableScreen);
            if (null != child)
                child.requestFocus(direction, previouslyFocusedRect);
        }
    }
    return false;
}

From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java

/**
 * When looking for focus in children of a scroll view, need to be a little
 * more careful not to give focus to something that is scrolled off screen.
 *
 * This is more expensive than the default {@link android.view.ViewGroup}
 * implementation, otherwise this behavior might have been made the default.
 *///from   www.j a v a  2s  . com
@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {

    // convert from forward / backward notation to up / down / left / right
    // (ugh).
    if (direction == View.FOCUS_FORWARD) {
        direction = View.FOCUS_DOWN;
    } else if (direction == View.FOCUS_BACKWARD) {
        direction = View.FOCUS_UP;
    }

    final View nextFocus = previouslyFocusedRect == null
            ? FocusFinder.getInstance().findNextFocus(this, null, direction)
            : FocusFinder.getInstance().findNextFocusFromRect(this, previouslyFocusedRect, direction);

    if (nextFocus == null) {
        return false;
    }

    if (isOffScreen(nextFocus)) {
        return false;
    }

    return nextFocus.requestFocus(direction, previouslyFocusedRect);
}

From source file:administrator.example.com.myscrollview.VerticalViewPager.java

/**
 * We only want the current page that is being shown to be focusable.
 *//*w  w w  .  ja v  a 2 s  . c o  m*/
@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
    int index;
    int increment;
    int end;
    int count = getChildCount();
    if ((direction & FOCUS_FORWARD) != 0) {
        index = 0;
        increment = 1;
        end = count;
    } else {
        index = count - 1;
        increment = -1;
        end = -1;
    } /* end of if */
    for (int i = index; i != end; i += increment) {
        View child = getChildAt(i);
        if (child.getVisibility() == VISIBLE) {
            ItemInfo ii = infoForChild(child);
            if (ii != null && ii.position == mCurItem) {
                if (child.requestFocus(direction, previouslyFocusedRect)) {
                    return true;
                } /* end of if */
            } /* end of if */
        } /* end of if */
    } /* end of for */
    return false;
}

From source file:com.hippo.widget.BothScrollView.java

/**
 * When looking for focus in children of a scroll view, need to be a little
 * more careful not to give focus to something that is scrolled off screen.
 *
 * This is more expensive than the default {@link android.view.ViewGroup}
 * implementation, otherwise this behavior might have been made the default.
 *///from  w w w  . j  a  v a 2 s.c  om
@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {

    // convert from forward / backward notation to up / down / left / right
    // (ugh).
    if (direction == View.FOCUS_FORWARD) {
        direction = View.FOCUS_RIGHT;
    } else if (direction == View.FOCUS_BACKWARD) {
        direction = View.FOCUS_LEFT;
    }

    final View nextFocus = previouslyFocusedRect == null
            ? FocusFinder.getInstance().findNextFocus(this, null, direction)
            : FocusFinder.getInstance().findNextFocusFromRect(this, previouslyFocusedRect, direction);

    if (nextFocus == null) {
        return false;
    }

    if (isOffScreen(nextFocus)) {
        return false;
    }

    return nextFocus.requestFocus(direction, previouslyFocusedRect);
}

From source file:com.folioreader.view.HorizontalViewPager.java

/**
 * We only want the current page that is being shown to be focusable.
 *///ww w  . j a  va  2 s .c o m
@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
    int index;
    int increment;
    int end;
    int count = getChildCount();
    if ((direction & FOCUS_FORWARD) != 0) {
        index = 0;
        increment = 1;
        end = count;
    } else {
        index = count - 1;
        increment = -1;
        end = -1;
    }
    for (int i = index; i != end; i += increment) {
        View child = getChildAt(i);
        if (child.getVisibility() == VISIBLE) {
            ItemInfo ii = infoForChild(child);
            if (ii != null && ii.position == mCurItem && child.requestFocus(direction, previouslyFocusedRect)) {
                return true;
            }
        }
    }
    return false;
}

From source file:cc.flydev.launcher.Page.java

@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
    int focusablePage;
    if (mNextPage != INVALID_PAGE) {
        focusablePage = mNextPage;//from w w w  . jav a 2 s . c o  m
    } else {
        focusablePage = mCurrentPage;
    }
    View v = getPageAt(focusablePage);
    if (v != null) {
        return v.requestFocus(direction, previouslyFocusedRect);
    }
    return false;
}

From source file:android.support.custom.view.VerticalViewPager.java

/**
 * We only want the current page that is being shown to be focusable.
 *//*from w  ww .j  ava 2  s.c o  m*/
@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
    int index;
    int increment;
    int end;
    int count = getChildCount();
    //TODO check
    if ((direction & FOCUS_DOWN) != 0) {
        index = 0;
        increment = 1;
        end = count;
    } else {
        index = count - 1;
        increment = -1;
        end = -1;
    }
    for (int i = index; i != end; i += increment) {
        View child = getChildAt(i);
        if (child.getVisibility() == VISIBLE) {
            ItemInfo ii = infoForChild(child);
            if (ii != null && ii.position == mCurItem) {
                if (child.requestFocus(direction, previouslyFocusedRect)) {
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:VerticalViewPager.java

/**
 * We only want the current page that is being shown to be focusable.
 *///from   www.  j a  v  a 2 s.  c  om
@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
    int index;
    int increment;
    int end;
    int count = getChildCount();
    if ((direction & FOCUS_FORWARD) != 0) {
        index = 0;
        increment = 1;
        end = count;
    } else {
        index = count - 1;
        increment = -1;
        end = -1;
    }
    for (int i = index; i != end; i += increment) {
        View child = getChildAt(i);
        if (child.getVisibility() == VISIBLE) {
            ItemInfo ii = infoForChild(child);
            if (ii != null && ii.position == mCurItem) {
                if (child.requestFocus(direction, previouslyFocusedRect)) {
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:com.stone.card.VerticalViewPager.java

/**
 * We only want the current page that is being shown to be focusable.
 *///from  www. j a va 2 s . c  o  m
@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
    int index;
    int increment;
    int end;
    int count = getChildCount();
    // TODO check
    if ((direction & FOCUS_DOWN) != 0) {
        index = 0;
        increment = 1;
        end = count;
    } else {
        index = count - 1;
        increment = -1;
        end = -1;
    }
    for (int i = index; i != end; i += increment) {
        View child = getChildAt(i);
        if (child.getVisibility() == VISIBLE) {
            ItemInfo ii = infoForChild(child);
            if (ii != null && ii.position == mCurItem) {
                if (child.requestFocus(direction, previouslyFocusedRect)) {
                    return true;
                }
            }
        }
    }
    return false;
}