Java Code Examples for org.chromium.ui.UiUtils#hideKeyboard()

The following examples show how to use org.chromium.ui.UiUtils#hideKeyboard() . 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: CompositorViewHolder.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void hideKeyboard(Runnable postHideTask) {
    // When this is called we actually want to hide the keyboard whatever owns it.
    // This includes hiding the keyboard, and dropping focus from the URL bar.
    // See http://crbug/236424
    // TODO(aberent) Find a better place to put this, possibly as part of a wider
    // redesign of focus control.
    if (mUrlBar != null) mUrlBar.clearFocus();
    boolean wasVisible = false;
    if (hasFocus()) {
        wasVisible = UiUtils.hideKeyboard(this);
    }
    if (wasVisible) {
        mPostHideKeyboardTask = postHideTask;
    } else {
        postHideTask.run();
    }
}
 
Example 2
Source File: CompositorViewHolder.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void hideKeyboard(Runnable postHideTask) {
    // When this is called we actually want to hide the keyboard whatever owns it.
    // This includes hiding the keyboard, and dropping focus from the URL bar.
    // See http://crbug/236424
    // TODO(aberent) Find a better place to put this, possibly as part of a wider
    // redesign of focus control.
    if (mUrlBar != null) mUrlBar.clearFocus();
    boolean wasVisible = false;
    if (hasFocus()) {
        wasVisible = UiUtils.hideKeyboard(this);
    }
    if (wasVisible) {
        mPostHideKeyboardTask = postHideTask;
    } else {
        postHideTask.run();
    }
}
 
Example 3
Source File: LocationBarLayout.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void revertChanges() {
    if (!mUrlHasFocus) {
        setUrlToPageUrl();
    } else {
        Tab tab = mToolbarDataProvider.getTab();
        if (NativePageFactory.isNativePageUrl(tab.getUrl(), tab.isIncognito())) {
            setUrlBarText("", null);
        } else {
            setUrlBarText(
                    mToolbarDataProvider.getText(), getCurrentTabUrl());
            selectAll();
        }
        hideSuggestions();
        UiUtils.hideKeyboard(mUrlBar);
    }
}
 
Example 4
Source File: EmptyBackgroundViewTablet.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public void setEmptyContainerState(boolean shouldShow) {
    Animator nextAnimator = null;

    if (shouldShow && getVisibility() != View.VISIBLE
            && mCurrentTransitionAnimation != mAnimateInAnimation) {
        nextAnimator = mAnimateInAnimation;
        UiUtils.hideKeyboard(this);
    } else if (!shouldShow && getVisibility() != View.GONE
            && mCurrentTransitionAnimation != mAnimateOutAnimation) {
        nextAnimator = mAnimateOutAnimation;
    }

    if (nextAnimator != null) {
        if (mCurrentTransitionAnimation != null) mCurrentTransitionAnimation.cancel();
        mCurrentTransitionAnimation = nextAnimator;
        mCurrentTransitionAnimation.start();
    }
}
 
Example 5
Source File: SelectableListToolbar.java    From 365browser with Apache License 2.0 6 votes vote down vote up
protected void showSelectionView(List<E> selectedItems, boolean wasSelectionEnabled) {
    getMenu().setGroupVisible(mNormalGroupResId, false);
    getMenu().setGroupVisible(mSelectedGroupResId, true);
    if (mHasSearchView) mSearchView.setVisibility(View.GONE);

    setNavigationButton(NAVIGATION_BUTTON_SELECTION_BACK);
    setBackgroundColor(mSelectionBackgroundColor);
    setOverflowIcon(mSelectionMenuButton);

    switchToNumberRollView(selectedItems, wasSelectionEnabled);

    if (mIsSearching) UiUtils.hideKeyboard(mSearchEditText);

    onThemeChanged(false);
    updateDisplayStyleIfNecessary();
}
 
Example 6
Source File: LocationBarLayout.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void revertChanges() {
    if (!mUrlHasFocus) {
        setUrlToPageUrl();
    } else {
        Tab tab = mToolbarDataProvider.getTab();
        if (NativePageFactory.isNativePageUrl(tab.getUrl(), tab.isIncognito())) {
            setUrlBarText("", null);
        } else {
            setUrlBarText(
                    mToolbarDataProvider.getText(), getCurrentTabUrl());
            selectAll();
        }
        hideSuggestions();
        UiUtils.hideKeyboard(mUrlBar);
    }
}
 
Example 7
Source File: CompositorViewHolder.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void hideKeyboard(Runnable postHideTask) {
    // When this is called we actually want to hide the keyboard whatever owns it.
    // This includes hiding the keyboard, and dropping focus from the URL bar.
    // See http://crbug/236424
    // TODO(aberent) Find a better place to put this, possibly as part of a wider
    // redesign of focus control.
    if (mUrlBar != null) mUrlBar.clearFocus();
    boolean wasVisible = false;
    if (hasFocus()) {
        wasVisible = UiUtils.hideKeyboard(this);
    }
    if (wasVisible) {
        mPostHideKeyboardTask = postHideTask;
    } else {
        postHideTask.run();
    }
}
 
Example 8
Source File: EmptyBackgroundViewTablet.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
public void setEmptyContainerState(boolean shouldShow) {
    Animator nextAnimator = null;

    if (shouldShow && getVisibility() != View.VISIBLE
            && mCurrentTransitionAnimation != mAnimateInAnimation) {
        nextAnimator = mAnimateInAnimation;
        UiUtils.hideKeyboard(this);
    } else if (!shouldShow && getVisibility() != View.GONE
            && mCurrentTransitionAnimation != mAnimateOutAnimation) {
        nextAnimator = mAnimateOutAnimation;
    }

    if (nextAnimator != null) {
        if (mCurrentTransitionAnimation != null) mCurrentTransitionAnimation.cancel();
        mCurrentTransitionAnimation = nextAnimator;
        mCurrentTransitionAnimation.start();
    }
}
 
Example 9
Source File: BookmarkSearchView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected void onVisibilityChanged(View changedView, int visibility) {
    super.onVisibilityChanged(changedView, visibility);
    // This method might be called very early. Null check on bookmark model here.
    if (mBookmarkModel == null) return;

    if (visibility == View.VISIBLE) {
        mBookmarkModel.addObserver(mModelObserver);
        updateHistoryList();
        mSearchText.requestFocus();
        UiUtils.showKeyboard(mSearchText);
    } else {
        UiUtils.hideKeyboard(mSearchText);
        mBookmarkModel.removeObserver(mModelObserver);
        resetUI();
        clearFocus();
    }
}
 
Example 10
Source File: SelectableListToolbar.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Hides the search edit text box and related views.
 */
public void hideSearchView() {
    assert mHasSearchView;

    if (!mIsSearching) return;

    mIsSearching = false;
    mSearchEditText.setText("");
    UiUtils.hideKeyboard(mSearchEditText);
    showNormalView();

    mSearchDelegate.onEndSearch();
}
 
Example 11
Source File: GeolocationSnackbarController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onAction(Object actionData) {
    View view = (View) actionData;
    UiUtils.hideKeyboard(view);

    Context context = view.getContext();
    Intent intent = PreferencesLauncher.createIntentForSettingsPage(
            context, SearchEnginePreference.class.getName());
    context.startActivity(intent);
}
 
Example 12
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 13
Source File: FindToolbar.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void hideKeyboardAndStartFinding(boolean forward) {
    if (mFindInPageBridge == null) return;

    final String findQuery = mFindQuery.getText().toString();
    if (findQuery.length() == 0) return;

    UiUtils.hideKeyboard(mFindQuery);
    mFindInPageBridge.startFinding(findQuery, forward, false);
    mFindInPageBridge.activateFindInPageResultForAccessibility();
    mAccessibilityDidActivateResult = true;
}
 
Example 14
Source File: LocationBarTablet.java    From delion with Apache License 2.0 5 votes vote down vote up
private void finishUrlFocusChange(boolean hasFocus) {
    if (hasFocus) {
        if (mSecurityButton.getVisibility() == VISIBLE) mSecurityButton.setVisibility(GONE);
        if (getWindowDelegate().getWindowSoftInputMode()
                != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) {
            getWindowDelegate().setWindowSoftInputMode(
                    WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        }
        UiUtils.showKeyboard(mUrlBar);
    } else {
        if (mSecurityButton.getVisibility() == GONE
                && mSecurityButton.getDrawable() != null
                && mSecurityButton.getDrawable().getIntrinsicWidth() > 0
                && mSecurityButton.getDrawable().getIntrinsicHeight() > 0) {
            mSecurityButton.setVisibility(VISIBLE);
        }
        UiUtils.hideKeyboard(mUrlBar);
        Selection.setSelection(mUrlBar.getText(), 0);
        // Convert the keyboard back to resize mode (delay the change for an arbitrary
        // amount of time in hopes the keyboard will be completely hidden before making
        // this change).
        if (getWindowDelegate().getWindowSoftInputMode()
                != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) {
            postDelayed(mKeyboardResizeModeTask, KEYBOARD_MODE_CHANGE_DELAY_MS);
        }
    }
    setUrlFocusChangeInProgress(false);
}
 
Example 15
Source File: SelectableListToolbar.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Destroys and cleans up itself.
 */
void destroy() {
    mIsDestroyed = true;
    if (mSelectionDelegate != null) mSelectionDelegate.removeObserver(this);
    mObservers.clear();
    UiUtils.hideKeyboard(mSearchEditText);
}
 
Example 16
Source File: LocationBarLayout.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void backKeyPressed() {
    hideSuggestions();
    UiUtils.hideKeyboard(mUrlBar);
    // Revert the URL to match the current page.
    setUrlToPageUrl();
    // Focus the page.
    Tab currentTab = getCurrentTab();
    if (currentTab != null) currentTab.requestFocus();
}
 
Example 17
Source File: FindResultBar.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressLint("ClickableViewAccessibility")
public boolean onTouchEvent(MotionEvent event) {
    if (!mDismissing && mTickmarks.size() > 0 && mTickmarks.size() == mMatches.length
            && !mWaitingForActivateAck && event.getAction() != MotionEvent.ACTION_CANCEL) {
        // We decided it's more important to get the keyboard out of the
        // way asap; the user can compensate if their next MotionEvent
        // scrolls somewhere unintended.
        UiUtils.hideKeyboard(this);

        // Identify which drawn tickmark is closest to the user's finger.
        int closest = Collections.binarySearch(mTickmarks,
                new Tickmark(event.getY(), event.getY()));
        if (closest < 0) {
            // No exact match, so must determine nearest.
            int insertionPoint = -1 - closest;
            if (insertionPoint == 0) {
                closest = 0;
            } else if (insertionPoint == mTickmarks.size()) {
                closest = mTickmarks.size() - 1;
            } else {
                float distanceA = Math.abs(event.getY()
                        - mTickmarks.get(insertionPoint - 1).centerY());
                float distanceB = Math.abs(event.getY()
                        - mTickmarks.get(insertionPoint).centerY());
                closest = insertionPoint - (distanceA <= distanceB ? 1 : 0);
            }
        }

        // Now activate the find match corresponding to that tickmark.
        // Since mTickmarks may be outdated, we can't just pass the index.
        // Instead we send the renderer the coordinates of the center of the
        // find match's rect (as originally received in setMatchRects), and
        // it will activate whatever find result is currently closest to
        // that point (which will usually be the same one).
        mWaitingForActivateAck = true;
        mFindInPageBridge.activateNearestFindResult(
                mMatches[closest].centerX(),
                mMatches[closest].centerY());
    }
    return true; // Consume the event, whether or not we acted upon it.
}
 
Example 18
Source File: LocationBarLayout.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (KeyNavigationUtil.isGoDown(event)
            && mSuggestionList != null
            && mSuggestionList.isShown()) {
        int suggestionCount = mSuggestionListAdapter.getCount();
        if (mSuggestionList.getSelectedItemPosition() < suggestionCount - 1) {
            if (suggestionCount > 0) mIgnoreOmniboxItemSelection = false;
        } else {
            // Do not pass down events when the last item is already selected as it will
            // dismiss the suggestion list.
            return true;
        }

        if (mSuggestionList.getSelectedItemPosition()
                == ListView.INVALID_POSITION) {
            // When clearing the selection after a text change, state is not reset
            // correctly so hitting down again will cause it to start from the previous
            // selection point. We still have to send the key down event to let the list
            // view items take focus, but then we select the first item explicitly.
            boolean result = mSuggestionList.onKeyDown(keyCode, event);
            mSuggestionList.setSelection(0);
            return result;
        } else {
            return mSuggestionList.onKeyDown(keyCode, event);
        }
    } else if (KeyNavigationUtil.isGoUp(event)
            && mSuggestionList != null
            && mSuggestionList.isShown()) {
        if (mSuggestionList.getSelectedItemPosition() != 0
                && mSuggestionListAdapter.getCount() > 0) {
            mIgnoreOmniboxItemSelection = false;
        }
        return mSuggestionList.onKeyDown(keyCode, event);
    } else if (KeyNavigationUtil.isGoRight(event)
            && mSuggestionList != null
            && mSuggestionList.isShown()
            && mSuggestionList.getSelectedItemPosition()
                    != ListView.INVALID_POSITION) {
        OmniboxResultItem selectedItem =
                (OmniboxResultItem) mSuggestionListAdapter.getItem(
                        mSuggestionList.getSelectedItemPosition());
        // Set the UrlBar text to empty, so that it will trigger a text change when we
        // set the text to the suggestion again.
        setUrlBarText("", null);
        mUrlBar.setText(selectedItem.getSuggestion().getFillIntoEdit());
        mSuggestionList.setSelection(0);
        mUrlBar.setSelection(mUrlBar.getText().length());
        return true;
    } else if (KeyNavigationUtil.isEnter(event)
            && LocationBarLayout.this.getVisibility() == VISIBLE) {
        UiUtils.hideKeyboard(mUrlBar);
        mSuggestionSelectionInProgress = true;
        final String urlText = mUrlBar.getTextWithAutocomplete();
        if (mNativeInitialized) {
            findMatchAndLoadUrl(urlText);
        } else {
            mDeferredNativeRunnables.add(new Runnable() {
                @Override
                public void run() {
                    findMatchAndLoadUrl(urlText);
                }
            });
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
            // Tell the framework to start tracking this event.
            getKeyDispatcherState().startTracking(event, this);
            return true;
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            getKeyDispatcherState().handleUpEvent(event);
            if (event.isTracking() && !event.isCanceled()) {
                backKeyPressed();
                return true;
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_ESCAPE) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
            revertChanges();
            return true;
        }
    }
    return false;
}
 
Example 19
Source File: FindResultBar.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressLint("ClickableViewAccessibility")
public boolean onTouchEvent(MotionEvent event) {
    if (!mDismissing && mTickmarks.size() > 0 && mTickmarks.size() == mMatches.length
            && !mWaitingForActivateAck && event.getAction() != MotionEvent.ACTION_CANCEL) {
        // We decided it's more important to get the keyboard out of the
        // way asap; the user can compensate if their next MotionEvent
        // scrolls somewhere unintended.
        UiUtils.hideKeyboard(this);

        // Identify which drawn tickmark is closest to the user's finger.
        int closest = Collections.binarySearch(mTickmarks,
                new Tickmark(event.getY(), event.getY()));
        if (closest < 0) {
            // No exact match, so must determine nearest.
            int insertionPoint = -1 - closest;
            if (insertionPoint == 0) {
                closest = 0;
            } else if (insertionPoint == mTickmarks.size()) {
                closest = mTickmarks.size() - 1;
            } else {
                float distanceA = Math.abs(event.getY()
                        - mTickmarks.get(insertionPoint - 1).centerY());
                float distanceB = Math.abs(event.getY()
                        - mTickmarks.get(insertionPoint).centerY());
                closest = insertionPoint - (distanceA <= distanceB ? 1 : 0);
            }
        }

        // Now activate the find match corresponding to that tickmark.
        // Since mTickmarks may be outdated, we can't just pass the index.
        // Instead we send the renderer the coordinates of the center of the
        // find match's rect (as originally received in setMatchRects), and
        // it will activate whatever find result is currently closest to
        // that point (which will usually be the same one).
        mWaitingForActivateAck = true;
        mFindInPageBridge.activateNearestFindResult(
                mMatches[closest].centerX(),
                mMatches[closest].centerY());
    }
    return true; // Consume the event, whether or not we acted upon it.
}
 
Example 20
Source File: FindResultBar.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressLint("ClickableViewAccessibility")
public boolean onTouchEvent(MotionEvent event) {
    if (!mDismissing && mTickmarks.size() > 0 && mTickmarks.size() == mMatches.length
            && !mWaitingForActivateAck && event.getAction() != MotionEvent.ACTION_CANCEL) {
        // We decided it's more important to get the keyboard out of the
        // way asap; the user can compensate if their next MotionEvent
        // scrolls somewhere unintended.
        UiUtils.hideKeyboard(this);

        // Identify which drawn tickmark is closest to the user's finger.
        int closest = Collections.binarySearch(mTickmarks,
                new Tickmark(event.getY(), event.getY()));
        if (closest < 0) {
            // No exact match, so must determine nearest.
            int insertionPoint = -1 - closest;
            if (insertionPoint == 0) {
                closest = 0;
            } else if (insertionPoint == mTickmarks.size()) {
                closest = mTickmarks.size() - 1;
            } else {
                float distanceA = Math.abs(event.getY()
                        - mTickmarks.get(insertionPoint - 1).centerY());
                float distanceB = Math.abs(event.getY()
                        - mTickmarks.get(insertionPoint).centerY());
                closest = insertionPoint - (distanceA <= distanceB ? 1 : 0);
            }
        }

        // Now activate the find match corresponding to that tickmark.
        // Since mTickmarks may be outdated, we can't just pass the index.
        // Instead we send the renderer the coordinates of the center of the
        // find match's rect (as originally received in setMatchRects), and
        // it will activate whatever find result is currently closest to
        // that point (which will usually be the same one).
        mWaitingForActivateAck = true;
        mFindInPageBridge.activateNearestFindResult(
                mMatches[closest].centerX(),
                mMatches[closest].centerY());
    }
    return true; // Consume the event, whether or not we acted upon it.
}