Search in sources :

Example 1 with SuggestionsAdapter

use of acr.browser.lightning.search.SuggestionsAdapter in project Lightning-Browser by anthonycr.

the class BrowserActivity method initializeSearchSuggestions.

/**
     * method to generate search suggestions for the AutoCompleteTextView from
     * previously searched URLs
     */
private void initializeSearchSuggestions(final AutoCompleteTextView getUrl) {
    mSuggestionsAdapter = new SuggestionsAdapter(this, mDarkTheme, isIncognito());
    getUrl.setThreshold(1);
    getUrl.setDropDownWidth(-1);
    getUrl.setDropDownAnchor(R.id.toolbar_layout);
    getUrl.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
            String url = null;
            CharSequence urlString = ((TextView) view.findViewById(R.id.url)).getText();
            if (urlString != null) {
                url = urlString.toString();
            }
            if (url == null || url.startsWith(getString(R.string.suggestion))) {
                CharSequence searchString = ((TextView) view.findViewById(R.id.title)).getText();
                if (searchString != null) {
                    url = searchString.toString();
                }
            }
            if (url == null) {
                return;
            }
            getUrl.setText(url);
            searchTheWeb(url);
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
            mPresenter.onAutoCompleteItemPressed();
        }
    });
    getUrl.setSelectAllOnFocus(true);
    getUrl.setAdapter(mSuggestionsAdapter);
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) InputMethodManager(android.view.inputmethod.InputMethodManager) SuggestionsAdapter(acr.browser.lightning.search.SuggestionsAdapter) ImageView(android.widget.ImageView) BookmarksView(acr.browser.lightning.browser.BookmarksView) BrowserView(acr.browser.lightning.browser.BrowserView) SearchView(acr.browser.lightning.view.SearchView) AutoCompleteTextView(android.widget.AutoCompleteTextView) LightningView(acr.browser.lightning.view.LightningView) BindView(butterknife.BindView) View(android.view.View) AdapterView(android.widget.AdapterView) WebView(android.webkit.WebView) TextView(android.widget.TextView) VideoView(android.widget.VideoView) TabsView(acr.browser.lightning.browser.TabsView)

Aggregations

BookmarksView (acr.browser.lightning.browser.BookmarksView)1 BrowserView (acr.browser.lightning.browser.BrowserView)1 TabsView (acr.browser.lightning.browser.TabsView)1 SuggestionsAdapter (acr.browser.lightning.search.SuggestionsAdapter)1 LightningView (acr.browser.lightning.view.LightningView)1 SearchView (acr.browser.lightning.view.SearchView)1 View (android.view.View)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 WebView (android.webkit.WebView)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 VideoView (android.widget.VideoView)1 BindView (butterknife.BindView)1