Java Code Examples for android.widget.SearchView#setIconifiedByDefault()

The following examples show how to use android.widget.SearchView#setIconifiedByDefault() . 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: MainActivity.java    From Aria2App with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    getMenuInflater().inflate(R.menu.main_sorting, menu.findItem(R.id.main_sort).getSubMenu());

    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    MenuItem searchItem = menu.findItem(R.id.main_search);
    searchItem.setOnActionExpandListener(this);
    searchView = (SearchView) searchItem.getActionView();

    if (searchManager != null && searchView != null) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
        searchView.setOnCloseListener(this);
        searchView.setOnQueryTextListener(this);
    }

    return true;
}
 
Example 2
Source File: SearchActivity.java    From Aria2App with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.search, menu);
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    MenuItem searchItem = menu.findItem(R.id.search_search);
    searchItem.setOnActionExpandListener(this);

    searchView = (SearchView) searchItem.getActionView();
    if (searchManager != null) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
        searchView.setOnCloseListener(this);
        searchView.setOnQueryTextListener(this);
    }

    return true;
}
 
Example 3
Source File: GamesFragment.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.games_fragment, menu);

    if (getContext() == null) return;
    SearchManager searchManager = (SearchManager) getContext().getSystemService(Context.SEARCH_SERVICE);
    MenuItem item = menu.findItem(R.id.gamesFragment_search);
    item.setOnActionExpandListener(this);

    if (searchManager != null && getActivity() != null) {
        searchView = (SearchView) item.getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        searchView.setIconifiedByDefault(false);
        searchView.setOnCloseListener(this);
        searchView.setOnQueryTextListener(this);
    }
}
 
Example 4
Source File: NamesFragment.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.names_fragment, menu);

    if (getContext() == null) return;
    SearchManager searchManager = (SearchManager) getContext().getSystemService(Context.SEARCH_SERVICE);
    MenuItem item = menu.findItem(R.id.namesFragment_search);
    item.setOnActionExpandListener(this);

    if (searchManager != null && getActivity() != null) {
        searchView = (SearchView) item.getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        searchView.setIconifiedByDefault(false);
        searchView.setOnCloseListener(this);
        searchView.setOnQueryTextListener(this);
    }
}
 
Example 5
Source File: MapActivity.java    From ETSMobile-Android2 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the options menu from XML
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_map, menu);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.menu_map_search).getActionView();
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false); // Do not iconify the widget;
    // expand it by default

    return true;
}
 
Example 6
Source File: ProgrammaticAutocompleteToolbarActivity.java    From android-places-demos with Apache License 2.0 5 votes vote down vote up
private void initSearchView(SearchView searchView) {
    searchView.setQueryHint(getString(R.string.search_a_place));
    searchView.setIconifiedByDefault(false);
    searchView.setFocusable(true);
    searchView.setIconified(false);
    searchView.requestFocusFromTouch();
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            progressBar.setIndeterminate(true);

            // Cancel any previous place prediction requests
            handler.removeCallbacksAndMessages(null);

            // Start a new place prediction request in 300 ms
            handler.postDelayed(() -> {
                getPlacePredictions(newText);
            }, 300);
            return true;
        }
    });
}
 
Example 7
Source File: ProgrammaticAutocompleteToolbarActivity.java    From android-places-demos with Apache License 2.0 5 votes vote down vote up
private void initSearchView(SearchView searchView) {
    searchView.setQueryHint(getString(R.string.search_a_place));
    searchView.setIconifiedByDefault(false);
    searchView.setFocusable(true);
    searchView.setIconified(false);
    searchView.requestFocusFromTouch();
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            progressBar.setIndeterminate(true);

            // Cancel any previous place prediction requests
            handler.removeCallbacksAndMessages(null);

            // Start a new place prediction request in 300 ms
            handler.postDelayed(() -> {
                getPlacePredictions(newText);
            }, 300);
            return true;
        }
    });
}
 
Example 8
Source File: MainActivity.java    From NoteCrypt with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.database_opened, menu);
    getMenuInflater().inflate(R.menu.main, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchMenuItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) searchMenuItem.getActionView();
    searchView.setSearchableInfo(searchManager != null ? searchManager.getSearchableInfo(getComponentName()) : null);
    searchView.setIconifiedByDefault(false);
    searchView.requestFocusFromTouch();
    return true;
}
 
Example 9
Source File: SearchShareesFragment.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.search_users_groups_layout, container, false);

    // Get the SearchView and set the searchable configuration
    SearchView searchView = (SearchView) view.findViewById(R.id.searchView);
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(
            getActivity().getComponentName())   // assumes parent activity is the searchable activity
    );
    searchView.setIconifiedByDefault(false);    // do not iconify the widget; expand it by default

    searchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); // avoid fullscreen with softkeyboard

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            Log_OC.v(TAG, "onQueryTextSubmit intercepted, query: " + query);
            return true;    // return true to prevent the query is processed to be queried;
            // a user / group will be picked only if selected in the list of suggestions
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;   // let it for the parent listener in the hierarchy / default behaviour
        }
    });

    return view;
}
 
Example 10
Source File: DialtactsActivity.java    From coursera-android with MIT License 5 votes vote down vote up
private void prepareSearchView() {
    final View searchViewLayout =
            getLayoutInflater().inflate(R.layout.dialtacts_custom_action_bar, null);
    mSearchView = (SearchView) searchViewLayout.findViewById(R.id.search_view);
    mSearchView.setOnQueryTextListener(mPhoneSearchQueryTextListener);
    mSearchView.setOnCloseListener(mPhoneSearchCloseListener);
    // Since we're using a custom layout for showing SearchView instead of letting the
    // search menu icon do that job, we need to manually configure the View so it looks
    // "shown via search menu".
    // - it should be iconified by default
    // - it should not be iconified at this time
    // See also comments for onActionViewExpanded()/onActionViewCollapsed()
    mSearchView.setIconifiedByDefault(true);
    mSearchView.setQueryHint(getString(R.string.hint_findContacts));
    mSearchView.setIconified(false);
    mSearchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                showInputMethod(view.findFocus());
            }
        }
    });

    if (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
        // Filter option menu should be shown on the right side of SearchView.
        final View filterOptionView = searchViewLayout.findViewById(R.id.search_option);
        filterOptionView.setVisibility(View.VISIBLE);
        filterOptionView.setOnClickListener(mFilterOptionClickListener);
    }

    getActionBar().setCustomView(searchViewLayout,
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
 
Example 11
Source File: ActivityMain.java    From XPrivacy with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
	MenuInflater inflater = getMenuInflater();
	if (inflater != null && PrivacyService.checkClient()) {
		// Inflate menu
		inflater.inflate(R.menu.main, menu);

		// Searchable
		SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));
		if (searchView != null) {
			searchView.setIconifiedByDefault(false);

			searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
				@Override
				public boolean onQueryTextChange(String newText) {
					searchQuery = newText;
					applyFilter();
					return true;
				}

				@Override
				public boolean onQueryTextSubmit(String query) {
					searchQuery = query;
					applyFilter();
					return true;
				}
			});
			searchView.setOnCloseListener(new SearchView.OnCloseListener() {
				@Override
				public boolean onClose() {
					searchQuery = "";
					applyFilter();
					return true;
				}
			});
		}

		return true;
	} else
		return false;
}