Search in sources :

Example 41 with SearchView

use of android.support.v7.widget.SearchView in project Varis-Android by dkhmelenko.

the class MainActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.menu_main, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = null;
    if (searchItem != null) {
        mSearchView = (SearchView) searchItem.getActionView();
    }
    if (mSearchView != null) {
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(String query) {
                boolean submitProhibited = true;
                if (query.length() > SEARCH_LIMIT) {
                    // save search query to history
                    SearchRecentSuggestions suggestionsProvider = new SearchRecentSuggestions(MainActivity.this, SearchHistoryProvider.AUTHORITY, SearchHistoryProvider.MODE);
                    suggestionsProvider.saveRecentQuery(query, null);
                    submitProhibited = false;
                }
                return submitProhibited;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                reloadSearchHistoryAdapter(newText);
                return true;
            }
        });
        mSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {

            @Override
            public boolean onSuggestionClick(int position) {
                mSearchView.setQuery(mQueryItems.get(position), true);
                return true;
            }

            @Override
            public boolean onSuggestionSelect(int position) {
                return true;
            }
        });
        reloadSearchHistoryAdapter("");
        // restore query if it was
        if (!TextUtils.isEmpty(mSavedQuery)) {
            mSearchView.setQuery(mSavedQuery, false);
            mSearchView.setIconified(false);
        }
    }
    return super.onCreateOptionsMenu(menu);
}
Also used : SearchView(android.support.v7.widget.SearchView) MenuInflater(android.view.MenuInflater) SearchManager(android.app.SearchManager) MenuItem(android.view.MenuItem) SearchRecentSuggestions(android.provider.SearchRecentSuggestions)

Example 42 with SearchView

use of android.support.v7.widget.SearchView in project NetGuard by M66B.

the class ActivityMain method updateSearch.

private void updateSearch(String search) {
    if (menuSearch != null) {
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuSearch);
        if (search == null) {
            if (menuSearch.isActionViewExpanded())
                adapter.getFilter().filter(searchView.getQuery().toString());
        } else {
            MenuItemCompat.expandActionView(menuSearch);
            searchView.setQuery(search, true);
        }
    }
}
Also used : SearchView(android.support.v7.widget.SearchView)

Example 43 with SearchView

use of android.support.v7.widget.SearchView in project NetGuard by M66B.

the class ActivityMain method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (Build.VERSION.SDK_INT < MIN_SDK)
        return false;
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    // Search
    menuSearch = menu.findItem(R.id.menu_search);
    MenuItemCompat.setOnActionExpandListener(menuSearch, new MenuItemCompat.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            if (getIntent().hasExtra(EXTRA_SEARCH))
                finish();
            return true;
        }
    });
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuSearch);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            if (adapter != null)
                adapter.getFilter().filter(query);
            searchView.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (adapter != null)
                adapter.getFilter().filter(newText);
            return true;
        }
    });
    searchView.setOnCloseListener(new SearchView.OnCloseListener() {

        @Override
        public boolean onClose() {
            Intent intent = getIntent();
            intent.removeExtra(EXTRA_SEARCH);
            if (adapter != null)
                adapter.getFilter().filter(null);
            return true;
        }
    });
    String search = getIntent().getStringExtra(EXTRA_SEARCH);
    if (search != null) {
        MenuItemCompat.expandActionView(menuSearch);
        searchView.setQuery(search, true);
    }
    markPro(menu.findItem(R.id.menu_log), ActivityPro.SKU_LOG);
    if (!IAB.isPurchasedAny(this))
        markPro(menu.findItem(R.id.menu_pro), null);
    if (!Util.hasValidFingerprint(this) || getIntentInvite(this).resolveActivity(getPackageManager()) == null)
        menu.removeItem(R.id.menu_invite);
    if (getIntentSupport().resolveActivity(getPackageManager()) == null)
        menu.removeItem(R.id.menu_support);
    return true;
}
Also used : MenuItemCompat(android.support.v4.view.MenuItemCompat) SearchView(android.support.v7.widget.SearchView) MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem) Intent(android.content.Intent) SpannableString(android.text.SpannableString)

Example 44 with SearchView

use of android.support.v7.widget.SearchView in project BookReader by JustWayward.

the class ReadCHMActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_chm_reader, menu);
    //在菜单中找到对应控件的item
    MenuItem searchMenuItem = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
    searchView.setOnCloseListener(new SearchView.OnCloseListener() {

        @Override
        public boolean onClose() {
            mWebView.clearMatches();
            return false;
        }
    });
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            mWebView.findAllAsync(newText);
            try {
                for (Method m : WebView.class.getDeclaredMethods()) {
                    if (m.getName().equals("setFindIsUp")) {
                        m.setAccessible(true);
                        m.invoke(mWebView, true);
                        break;
                    }
                }
            } catch (Exception ignored) {
            }
            return false;
        }
    });
    return true;
}
Also used : SearchView(android.support.v7.widget.SearchView) MenuItem(android.view.MenuItem) Method(java.lang.reflect.Method) WebView(android.webkit.WebView) IOException(java.io.IOException)

Example 45 with SearchView

use of android.support.v7.widget.SearchView in project BookReader by JustWayward.

the class SearchActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_search, menu);
    //在菜单中找到对应控件的item
    searchMenuItem = menu.findItem(R.id.action_search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            key = query;
            mPresenter.getSearchResultList(query);
            saveSearchHistory(query);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (TextUtils.isEmpty(newText)) {
                if (mListPopupWindow.isShowing())
                    mListPopupWindow.dismiss();
                initTagGroup();
            } else {
                mPresenter.getAutoCompleteList(newText);
            }
            return false;
        }
    });
    // 外部调用搜索,则打开页面立即进行搜索
    search(key);
    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new //设置打开关闭动作监听
    MenuItemCompat.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            initTagGroup();
            return true;
        }
    });
    return true;
}
Also used : MenuItemCompat(android.support.v4.view.MenuItemCompat) SearchView(android.support.v7.widget.SearchView) MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem)

Aggregations

SearchView (android.support.v7.widget.SearchView)74 MenuItem (android.view.MenuItem)47 View (android.view.View)24 SearchManager (android.app.SearchManager)13 MenuItemCompat (android.support.v4.view.MenuItemCompat)13 TextView (android.widget.TextView)13 RecyclerView (android.support.v7.widget.RecyclerView)12 MenuInflater (android.view.MenuInflater)11 ImageView (android.widget.ImageView)11 Toolbar (android.support.v7.widget.Toolbar)9 ListView (android.widget.ListView)8 AdapterView (android.widget.AdapterView)7 MaterialSearchView (com.miguelcatalan.materialsearchview.MaterialSearchView)7 Nullable (android.support.annotation.Nullable)6 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)6 SuppressLint (android.annotation.SuppressLint)5 ActionBar (android.support.v7.app.ActionBar)5 ArrayList (java.util.ArrayList)5 Button (android.widget.Button)4 List (java.util.List)4