Search in sources :

Example 1 with WindowDelegate

use of org.chromium.chrome.browser.WindowDelegate in project AndroidChromium by JackyAndroid.

the class LocationBarPhone method finishUrlFocusChange.

/**
     * Handles any actions to be performed after all other actions triggered by the URL focus
     * change.  This will be called after any animations are performed to transition from one
     * focus state to the other.
     * @param hasFocus Whether the URL field has gained focus.
     */
public void finishUrlFocusChange(boolean hasFocus) {
    final WindowDelegate windowDelegate = getWindowDelegate();
    if (!hasFocus) {
        // Remove the selection from the url text.  The ending selection position
        // will determine the scroll position when the url field is restored.  If
        // we do not clear this, it will scroll to the end of the text when you
        // enter/exit the tab stack.
        // We set the selection to 0 instead of removing the selection to avoid a crash that
        // happens if you clear the selection instead.
        //
        // Triggering the bug happens by:
        // 1.) Selecting some portion of the URL (where the two selection handles
        //     appear)
        // 2.) Trigger a text change in the URL bar (i.e. by triggering a new URL load
        //     by a command line intent)
        // 3.) Simultaneously moving one of the selection handles left and right.  This will
        //     occasionally throw an AssertionError on the bounds of the selection.
        Selection.setSelection(mUrlBar.getText(), 0);
        // The animation rendering may not yet be 100% complete and hiding the keyboard makes
        // the animation quite choppy.
        postDelayed(new Runnable() {

            @Override
            public void run() {
                UiUtils.hideKeyboard(mUrlBar);
            }
        }, KEYBOARD_HIDE_DELAY_MS);
        // of time in hopes the keyboard will be completely hidden before making this change).
        if (mKeyboardResizeModeTask == null && windowDelegate.getWindowSoftInputMode() != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) {
            mKeyboardResizeModeTask = new Runnable() {

                @Override
                public void run() {
                    windowDelegate.setWindowSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
                    mKeyboardResizeModeTask = null;
                }
            };
            postDelayed(mKeyboardResizeModeTask, KEYBOARD_MODE_CHANGE_DELAY_MS);
        }
        mUrlActionsContainer.setVisibility(GONE);
    } else {
        if (mKeyboardResizeModeTask != null) {
            removeCallbacks(mKeyboardResizeModeTask);
            mKeyboardResizeModeTask = null;
        }
        if (windowDelegate.getWindowSoftInputMode() != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) {
            windowDelegate.setWindowSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        }
        UiUtils.showKeyboard(mUrlBar);
        // updated to reflect the new position.
        if (getSuggestionList() != null && getSuggestionList().isShown()) {
            getSuggestionList().invalidateSuggestionViews();
        }
    }
    setUrlFocusChangeInProgress(false);
    NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
    if (hasFocus && ntp != null && ntp.isLocationBarShownInNTP()) {
        fadeInOmniboxResultsContainerBackground();
    }
}
Also used : WindowDelegate(org.chromium.chrome.browser.WindowDelegate) NewTabPage(org.chromium.chrome.browser.ntp.NewTabPage)

Aggregations

WindowDelegate (org.chromium.chrome.browser.WindowDelegate)1 NewTabPage (org.chromium.chrome.browser.ntp.NewTabPage)1