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);
}
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);
}
}
}
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;
}
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;
}
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;
}
Aggregations