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

The following examples show how to use android.widget.SearchView#setSearchableInfo() . 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: 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 3
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 4
Source File: BaseFragment.java    From glimmr with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 5
Source File: Api11Adapter.java    From mytracks with Apache License 2.0 6 votes vote down vote up
@Override
public void configureSearchWidget(
    Activity activity, MenuItem menuItem, final TrackController trackController) {
  SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
  SearchView searchView = (SearchView) menuItem.getActionView();
  searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));
  searchView.setQueryRefinementEnabled(true);
  searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
    
      @Override
    public void onFocusChange(View v, boolean hasFocus) {
        // Hide and show trackController when search widget has focus/no focus
        if (trackController != null) {
          if (hasFocus) {
            trackController.hide();
          } else {
            trackController.show();
          }
        }        
    }
  });
}
 
Example 6
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 7
Source File: WeatherListFragment.java    From rain-or-shine with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.fragment_weather, menu);
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
}
 
Example 8
Source File: Listactivity.java    From ImapNote2 with GNU General Public License v3.0 5 votes vote down vote up
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.list, menu);

// Associate searchable configuration with the SearchView
SearchManager searchManager =
       (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
        (SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(
        searchManager.getSearchableInfo(getComponentName()));
 SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() {
     @Override
     public boolean onQueryTextChange(String newText) {
         // this is your adapter that will be filtered
         listToView.getFilter().filter(newText);
         return true;
     }

     @Override
     public boolean onQueryTextSubmit(String query) {
         // this is your adapter that will be filtered
         listToView.getFilter().filter(query);
         return true;
     }
 };
 searchView.setOnQueryTextListener(textChangeListener);

return true;
}
 
Example 9
Source File: BaseActivity.java    From glimmr with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);
    SearchManager searchManager =
        (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView =
        (SearchView) menu.findItem(R.id.menu_search).getActionView();
    searchView.setSearchableInfo(
            searchManager.getSearchableInfo(getComponentName()));
    return super.onCreateOptionsMenu(menu);
}
 
Example 10
Source File: MainActivity.java    From ampdroid with MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
	// Inflate the menu; this adds items to the action bar if it is present.
	getMenuInflater().inflate(R.menu.main, menu);

	SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
	SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
	searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

	return true;
}
 
Example 11
Source File: MainActivity.java    From Qshp with MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    return super.onCreateOptionsMenu(menu);
}
 
Example 12
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 13
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 14
Source File: MainActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
	getMenuInflater().inflate(R.menu.main, menu);
	// Get the SearchView and set the searchable configuration
	SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
	SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
			.getActionView();
	searchView.setSearchableInfo(searchManager
			.getSearchableInfo(getComponentName()));
	// searchView.setIconifiedByDefault(false);

	return true;
}
 
Example 15
Source File: SearchViewCompatHoneycomb.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static void setSearchableInfo(View searchView, ComponentName searchableComponent) {
    SearchView sv = ((SearchView) searchView);
    SearchManager searchManager = (SearchManager)
            sv.getContext().getSystemService(Context.SEARCH_SERVICE);
    sv.setSearchableInfo(searchManager.getSearchableInfo(searchableComponent));
}
 
Example 16
Source File: SearchViewCompatHoneycomb.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public static void setSearchableInfo(View searchView, ComponentName searchableComponent) {
    SearchView sv = ((SearchView) searchView);
    SearchManager searchManager = (SearchManager)
            sv.getContext().getSystemService(Context.SEARCH_SERVICE);
    sv.setSearchableInfo(searchManager.getSearchableInfo(searchableComponent));
}
 
Example 17
Source File: SearchViewCompatHoneycomb.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
public static void setSearchableInfo(View searchView, ComponentName searchableComponent) {
    SearchView sv = ((SearchView) searchView);
    SearchManager searchManager = (SearchManager)
            sv.getContext().getSystemService(Context.SEARCH_SERVICE);
    sv.setSearchableInfo(searchManager.getSearchableInfo(searchableComponent));
}
 
Example 18
Source File: SearchViewCompatHoneycomb.java    From guideshow with MIT License 4 votes vote down vote up
public static void setSearchableInfo(View searchView, ComponentName searchableComponent) {
    SearchView sv = ((SearchView) searchView);
    SearchManager searchManager = (SearchManager)
            sv.getContext().getSystemService(Context.SEARCH_SERVICE);
    sv.setSearchableInfo(searchManager.getSearchableInfo(searchableComponent));
}
 
Example 19
Source File: CHMFrag.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreateOptionsMenu(android.view.Menu menu, android.view.MenuInflater inflater) {
	super.onCreateOptionsMenu(menu, inflater);
	inflater.inflate(R.menu.menu_chm, menu);

       SearchManager searchManager =
		(SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
       SearchView searchView =
		(SearchView) menu.findItem(R.id.menu_search).getActionView();
       searchView.setSearchableInfo(
		searchManager.getSearchableInfo(activity.getComponentName()));
       searchView.setOnCloseListener(new SearchView.OnCloseListener() {
			@Override
			public boolean onClose() {
				webview.clearMatches();
				return false;
			}
		});
       searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
			@Override
			public boolean onQueryTextSubmit(String query) {
				return false;
			}

			@Override
			public boolean onQueryTextChange(String newText) {
				webview.findAllAsync(newText);
				try {
					for (Method m : WebView.class.getDeclaredMethods()) {
						if (m.getName().equals("setFindIsUp")) {
							m.setAccessible(true);
							m.invoke((webview), true);
							break;
						}
					}
				} catch (Exception ignored) {
				}
				return false;
			}
		});
       
   }
 
Example 20
Source File: Utils.java    From Android-RecurrencePicker with Apache License 2.0 2 votes vote down vote up
/**
 * This sets up a search view to use Calendar's search suggestions provider
 * and to allow refining the search.
 *
 * @param view The {@link android.widget.SearchView} to set up
 * @param act  The activity using the view
 */
public static void setUpSearchView(SearchView view, Activity act) {
    SearchManager searchManager = (SearchManager) act.getSystemService(Context.SEARCH_SERVICE);
    view.setSearchableInfo(searchManager.getSearchableInfo(act.getComponentName()));
    view.setQueryRefinementEnabled(true);
}