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

The following examples show how to use android.view.ViewGroup#requestChildFocus() . These examples are extracted from open source projects. 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 Project: delion   File: FocusAnimator.java    License: 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 Project: AndroidChromium   File: EditorTextField.java    License: 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
@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 Project: AndroidChromium   File: FocusAnimator.java    License: 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 Project: 365browser   File: EditorTextField.java    License: 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 Project: 365browser   File: FocusAnimator.java    License: 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 Project: 365browser   File: EditorDropdownField.java    License: 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);
}