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

The following examples show how to use android.widget.SearchView#setOnCloseListener() . 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: MainActivity.java    From XposedHider with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    SearchView sv = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    sv.setInputType(EditorInfo.TYPE_CLASS_TEXT);
    sv.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            mMatches.clear();
            newText = newText.toLowerCase();
            for (AppInfo app : mApps) {
                if (app.getLabel().toLowerCase().contains(newText) || app.getPackageName().contains(newText)) {
                    mMatches.add(app);
                }
            }
            if (mAdapter.getAppList().equals(mApps)) {
                mAdapter.setAppList(mMatches);
            }
            mAdapter.notifyDataSetChanged();
            setCheckedItems();
            return true;
        }
    });
    sv.setOnCloseListener(() -> {
        mAdapter.setAppList(mApps);
        mAdapter.notifyDataSetChanged();
        setCheckedItems();
        return false;
    });
    return true;
}
 
Example 6
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 7
Source File: MainActivity.java    From xunmi_android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    searchView = (SearchView)menu.findItem(R.id.searchView).getActionView();
    int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
    ImageView v = (ImageView) searchView.findViewById(searchImgId);
    v.setImageResource(R.drawable.search); 
    searchView.setOnQueryTextListener(MainActivity.this);
    searchView.setSubmitButtonEnabled(true);
		
    searchView.setOnCloseListener(MainActivity.this);
    return true;
}
 
Example 8
Source File: ListFragment.java    From holoaccent with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
	inflater.inflate(R.menu.list, menu);
	SearchView searchView = (SearchView)menu.findItem(R.id.search).getActionView();
	searchView.setOnQueryTextListener(mOnQueryTextListener);
	searchView.setOnCloseListener(mOnCloseListener);
	
	super.onCreateOptionsMenu(menu, inflater);
}
 
Example 9
Source File: ExcludeAppsFragment.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.allowed_apps, menu);

    SearchView searchView = (SearchView) menu.findItem( R.id.app_search_widget ).getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            mListView.setFilterText(query);
            mListView.setTextFilterEnabled(true);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            mListView.setFilterText(newText);
            if (TextUtils.isEmpty(newText))
                mListView.setTextFilterEnabled(false);
            else
                mListView.setTextFilterEnabled(true);

            return true;
        }
    });
    searchView.setOnCloseListener(() -> {
        mListView.clearTextFilter();
        mListAdapter.getFilter().filter("");
        return false;
    });

    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 10
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 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;
}