Java Code Examples for android.view.ViewGroup#requestChildFocus()

The following examples show how to use android.view.ViewGroup#requestChildFocus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FocusAnimator.java    From delion with Apache License 2.0 5 votes vote down vote up
/** Scroll the layout so that the focused child is on screen. */
private void requestChildFocus() {
    ViewGroup parent = (ViewGroup) mLayout.getParent();
    if (mLayout.getParent() == null) return;

    // Scroll the parent to make the focused child visible.
    if (mFocusedChild != null) parent.requestChildFocus(mLayout, mFocusedChild);

    // {@link View#requestChildFocus} fails to account for children changing their height, so
    // the scroll value may be past the actual maximum.
    int viewportHeight = parent.getBottom() - parent.getTop();
    int scrollMax = Math.max(0, mLayout.getMeasuredHeight() - viewportHeight);
    if (parent.getScrollY() > scrollMax) parent.setScrollY(scrollMax);
}
 
Example 2
Source File: EditorTextField.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void scrollToAndFocus() {
    ViewGroup parent = (ViewGroup) getParent();
    if (parent != null) parent.requestChildFocus(this, this);
    requestFocus();
    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}
 
Example 3
Source File: EditorDropdownField.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void scrollToAndFocus() {
    updateDisplayedError(!isValid());
    UiUtils.hideKeyboard(mDropdown);
    ViewGroup parent = (ViewGroup) mDropdown.getParent();
    if (parent != null) parent.requestChildFocus(mDropdown, mDropdown);
    mDropdown.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}
 
Example 4
Source File: FocusAnimator.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** Scroll the layout so that the focused child is on screen. */
private void requestChildFocus() {
    ViewGroup parent = (ViewGroup) mLayout.getParent();
    if (mLayout.getParent() == null) return;

    // Scroll the parent to make the focused child visible.
    if (mFocusedChild != null) parent.requestChildFocus(mLayout, mFocusedChild);

    // {@link View#requestChildFocus} fails to account for children changing their height, so
    // the scroll value may be past the actual maximum.
    int viewportHeight = parent.getBottom() - parent.getTop();
    int scrollMax = Math.max(0, mLayout.getMeasuredHeight() - viewportHeight);
    if (parent.getScrollY() > scrollMax) parent.setScrollY(scrollMax);
}
 
Example 5
Source File: EditorTextField.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void scrollToAndFocus() {
    ViewGroup parent = (ViewGroup) getParent();
    if (parent != null) parent.requestChildFocus(this, this);
    requestFocus();
    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}
 
Example 6
Source File: FocusAnimator.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Scroll the layout so that the focused child is on screen. */
private void requestChildFocus() {
    ViewGroup parent = (ViewGroup) mLayout.getParent();
    if (mLayout.getParent() == null) return;

    // Scroll the parent to make the focused child visible.
    if (mFocusedChild != null) parent.requestChildFocus(mLayout, mFocusedChild);

    // {@link View#requestChildFocus} fails to account for children changing their height, so
    // the scroll value may be past the actual maximum.
    int viewportHeight = parent.getBottom() - parent.getTop();
    int scrollMax = Math.max(0, mLayout.getMeasuredHeight() - viewportHeight);
    if (parent.getScrollY() > scrollMax) parent.setScrollY(scrollMax);
}
 
Example 7
Source File: EditorDropdownField.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void requestFocusAndHideKeyboard() {
    UiUtils.hideKeyboard(mDropdown);
    ViewGroup parent = (ViewGroup) mDropdown.getParent();
    if (parent != null) parent.requestChildFocus(mDropdown, mDropdown);
    mDropdown.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}