Search in sources :

Example 66 with SearchView

use of android.widget.SearchView in project YalpStore by yeriomin.

the class BaseActivity method addQueryTextListener.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void addQueryTextListener(MenuItem searchItem) {
    SearchView searchView = (SearchView) searchItem.getActionView();
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    if (null != searchManager) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setQueryHint(getString(R.string.search_title));
    }
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(String query) {
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            Intent i = new Intent(BaseActivity.this, SearchActivity.class);
            i.setAction(Intent.ACTION_SEARCH);
            i.putExtra(SearchManager.QUERY, query);
            startActivity(i);
            return false;
        }
    });
}
Also used : SearchView(android.widget.SearchView) SearchManager(android.app.SearchManager) Intent(android.content.Intent) TargetApi(android.annotation.TargetApi)

Example 67 with SearchView

use of android.widget.SearchView in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ManageApplicationsTest method onCreateOptionsMenu_hasExpandSearchFlag_shouldExpandSearchView.

@Test
public void onCreateOptionsMenu_hasExpandSearchFlag_shouldExpandSearchView() {
    final SearchView searchView = mock(SearchView.class);
    final MenuItem searchMenu = mock(MenuItem.class);
    final MenuItem helpMenu = mock(MenuItem.class);
    when(searchMenu.getActionView()).thenReturn(searchView);
    when(mMenu.findItem(R.id.search_app_list_menu)).thenReturn(searchMenu);
    when(mMenu.add(anyInt(), /* groupId */
    anyInt(), /* itemId */
    anyInt(), /* order */
    anyInt())).thenReturn(helpMenu);
    doReturn("Test").when(mFragment).getText(anyInt());
    doNothing().when(mFragment).updateOptionsMenu();
    mFragment.mExpandSearch = true;
    mFragment.onCreateOptionsMenu(mMenu, mock(MenuInflater.class));
    verify(searchMenu).expandActionView();
}
Also used : SearchView(android.widget.SearchView) MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test)

Example 68 with SearchView

use of android.widget.SearchView in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ManageApplicationsTest method onRebuildComplete_hasSearchQuery_shouldFilterSearch.

@Test
public void onRebuildComplete_hasSearchQuery_shouldFilterSearch() {
    final String query = "Test";
    final RecyclerView recyclerView = mock(RecyclerView.class);
    final View emptyView = mock(View.class);
    ReflectionHelpers.setField(mFragment, "mRecyclerView", recyclerView);
    ReflectionHelpers.setField(mFragment, "mEmptyView", emptyView);
    final SearchView searchView = mock(SearchView.class);
    ReflectionHelpers.setField(mFragment, "mSearchView", searchView);
    when(searchView.isVisibleToUser()).thenReturn(true);
    when(searchView.getQuery()).thenReturn(query);
    final View listContainer = mock(View.class);
    when(listContainer.getVisibility()).thenReturn(View.VISIBLE);
    ReflectionHelpers.setField(mFragment, "mListContainer", listContainer);
    ReflectionHelpers.setField(mFragment, "mFilterAdapter", mock(ManageApplications.FilterSpinnerAdapter.class));
    final ArrayList<ApplicationsState.AppEntry> appList = new ArrayList<>();
    appList.add(mock(ApplicationsState.AppEntry.class));
    final ManageApplications.ApplicationsAdapter adapter = spy(new ManageApplications.ApplicationsAdapter(mState, mFragment, AppFilterRegistry.getInstance().get(FILTER_APPS_ALL), null));
    adapter.onRebuildComplete(appList);
    verify(adapter).filterSearch(query);
}
Also used : SearchView(android.widget.SearchView) ArrayList(java.util.ArrayList) RecyclerView(androidx.recyclerview.widget.RecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SearchView(android.widget.SearchView) Test(org.junit.Test)

Example 69 with SearchView

use of android.widget.SearchView in project glimmr by brk3.

the class BaseFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();
    inflater.inflate(R.menu.fragment_main_menu, menu);
    SearchManager searchManager = (SearchManager) mActivity.getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(mActivity.getComponentName()));
    if (mOAuth == null || mOAuth.getUser() == null) {
        menu.findItem(R.id.menu_login).setVisible(true);
        menu.findItem(R.id.menu_logout).setVisible(false);
    } else {
        menu.findItem(R.id.menu_login).setVisible(false);
        menu.findItem(R.id.menu_logout).setVisible(true);
    }
}
Also used : SearchView(android.widget.SearchView) SearchManager(android.app.SearchManager)

Example 70 with SearchView

use of android.widget.SearchView in project android_packages_apps_Settings by omnirom.

the class ManageApplicationsTest method onSaveInstanceState_searchViewSet_shouldSetBundleValue.

@Test
public void onSaveInstanceState_searchViewSet_shouldSetBundleValue() {
    final SearchView searchView = mock(SearchView.class);
    final Bundle bundle = new Bundle();
    ReflectionHelpers.setField(mFragment, "mResetAppsHelper", mock(ResetAppsHelper.class));
    ReflectionHelpers.setField(mFragment, "mFilter", mock(AppFilterItem.class));
    ReflectionHelpers.setField(mFragment, "mApplications", mock(ManageApplications.ApplicationsAdapter.class));
    ReflectionHelpers.setField(mFragment, "mSearchView", searchView);
    when(searchView.isIconified()).thenReturn(true);
    mFragment.onSaveInstanceState(bundle);
    assertThat(bundle.containsKey(ManageApplications.EXTRA_EXPAND_SEARCH_VIEW)).isTrue();
    assertThat(bundle.getBoolean(ManageApplications.EXTRA_EXPAND_SEARCH_VIEW)).isFalse();
}
Also used : SearchView(android.widget.SearchView) Bundle(android.os.Bundle) Test(org.junit.Test)

Aggregations

SearchView (android.widget.SearchView)72 View (android.view.View)37 TextView (android.widget.TextView)30 MenuItem (android.view.MenuItem)28 ImageView (android.widget.ImageView)16 ListView (android.widget.ListView)15 AdapterView (android.widget.AdapterView)14 RecyclerView (android.support.v7.widget.RecyclerView)12 SearchManager (android.app.SearchManager)11 Test (org.junit.Test)8 Activity (android.app.Activity)7 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 RecyclerView (androidx.recyclerview.widget.RecyclerView)7 SettingsActivity (com.android.settings.SettingsActivity)7 MenuInflater (android.view.MenuInflater)6 ViewGroup (android.view.ViewGroup)6 Toolbar (android.widget.Toolbar)6 Intent (android.content.Intent)4 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)4 Nullable (android.support.annotation.Nullable)3