use of android.widget.SearchView in project sbt-android by scala-android.
the class SearchActivity method setNoResultsVisibility.
private void setNoResultsVisibility(int visibility) {
if (visibility == View.VISIBLE) {
if (noResults == null) {
noResults = (BaselineGridTextView) ((ViewStub) findViewById(R.id.stub_no_search_results)).inflate();
noResults.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchView.setQuery("", false);
searchView.requestFocus();
ImeUtils.showIme(searchView);
}
});
}
String message = String.format(getString(R.string.no_search_results), searchView.getQuery().toString());
SpannableStringBuilder ssb = new SpannableStringBuilder(message);
ssb.setSpan(new StyleSpan(Typeface.ITALIC), message.indexOf('“') + 1, message.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
noResults.setText(ssb);
}
if (noResults != null) {
noResults.setVisibility(visibility);
}
}
use of android.widget.SearchView in project MGit by maks.
the class RepoListActivity method configSearchAction.
public void configSearchAction(MenuItem searchItem) {
SearchView searchView = (SearchView) searchItem.getActionView();
if (searchView == null)
return;
SearchListener searchListener = new SearchListener();
MenuItemCompat.setOnActionExpandListener(searchItem, searchListener);
searchView.setIconifiedByDefault(true);
searchView.setOnQueryTextListener(searchListener);
}
use of android.widget.SearchView in project MGit by maks.
the class ViewFileActivity method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.view_file, menu);
if (mActivityMode == TAG_MODE_SSH_KEY) {
menu.removeItem(R.id.action_edit);
menu.removeItem(R.id.action_edit_in_other_app);
menu.removeItem(R.id.action_choose_language);
} else {
menu.removeItem(R.id.action_copy_all);
}
if (mActivityMode != TAG_MODE_SSH_KEY) {
MenuItem mi = menu.findItem(R.id.action_edit);
setSaveStatus(mi);
mi.setVisible(mCurrentTab == FILE_FRAGMENT_INDEX);
mi = menu.findItem(R.id.action_edit_in_other_app);
mi.setVisible(mCurrentTab == FILE_FRAGMENT_INDEX);
mi = menu.findItem(R.id.action_choose_language);
mi.setVisible(mCurrentTab == FILE_FRAGMENT_INDEX);
}
if (mRepo != null) {
MenuItem searchItem = menu.findItem(R.id.action_search);
MenuItemCompat.setOnActionExpandListener(searchItem, mTabItemPagerAdapter);
SearchView searchView = (SearchView) searchItem.getActionView();
if (searchView != null) {
searchView.setIconifiedByDefault(true);
searchView.setOnQueryTextListener(mTabItemPagerAdapter);
}
searchItem.setVisible(mCurrentTab == COMMITS_FRAGMENT_INDEX);
} else {
menu.removeItem(R.id.action_search);
}
return true;
}
use of android.widget.SearchView in project OpenBikeSharing by bparmentier.
the class BikeNetworksListActivity method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.bike_networks_list, menu);
SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
}
@Override
public // TODO: avoid redundancy
boolean onQueryTextChange(String s) {
if (bikeNetworks == null) {
return false;
}
searchedBikeNetworks = new ArrayList<>();
for (BikeNetworkInfo network : bikeNetworks) {
if (network.getName().toLowerCase().contains(s.toLowerCase()) || network.getLocation().getCity().toLowerCase().contains(s.toLowerCase())) {
searchedBikeNetworks.add(network);
}
}
bikeNetworksListAdapter = new BikeNetworksListAdapter(BikeNetworksListActivity.this, android.R.layout.simple_expandable_list_item_2, android.R.id.text1, searchedBikeNetworks);
listView.setAdapter(bikeNetworksListAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(BikeNetworksListActivity.this);
SharedPreferences.Editor editor = settings.edit();
editor.putString(PREF_KEY_NETWORK_ID, searchedBikeNetworks.get(position).getId());
editor.putString(PREF_KEY_NETWORK_NAME, searchedBikeNetworks.get(position).getName());
editor.putString(PREF_KEY_NETWORK_CITY, searchedBikeNetworks.get(position).getLocation().getCity());
editor.putLong(PREF_KEY_NETWORK_LATITUDE, Double.doubleToRawLongBits(searchedBikeNetworks.get(position).getLocation().getLatitude()));
editor.putLong(PREF_KEY_NETWORK_LONGITUDE, Double.doubleToRawLongBits(searchedBikeNetworks.get(position).getLocation().getLongitude()));
editor.apply();
Toast.makeText(BikeNetworksListActivity.this, searchedBikeNetworks.get(position).getName() + " (" + searchedBikeNetworks.get(position).getLocation().getCity() + ") " + getString(R.string.network_selected), Toast.LENGTH_SHORT).show();
Intent resultIntent = new Intent();
resultIntent.putExtra(KEY_NETWORK_ID, searchedBikeNetworks.get(position).getId());
if (getParent() == null) {
setResult(Activity.RESULT_OK, resultIntent);
} else {
getParent().setResult(Activity.RESULT_OK, resultIntent);
}
finish();
}
});
return true;
}
});
return true;
}
use of android.widget.SearchView in project android_packages_apps_Settings by DirtyUnicorns.
the class SearchFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.search_panel, container, false);
mResultsRecyclerView = view.findViewById(R.id.list_results);
mResultsRecyclerView.setAdapter(mSearchAdapter);
mResultsRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mResultsRecyclerView.addOnScrollListener(mScrollListener);
mNoResultsView = view.findViewById(R.id.no_results_layout);
Toolbar toolbar = view.findViewById(R.id.search_toolbar);
getActivity().setActionBar(toolbar);
getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
mSearchView = toolbar.findViewById(R.id.search_view);
mSearchView.setQuery(mQuery, false);
mSearchView.setOnQueryTextListener(this);
mSearchView.requestFocus();
// Updating internal views inside SearchView was the easiest way to get this too look right.
// Instead of grabbing the TextView directly, we grab it as a view and do an instanceof
// check. This ensures if we return, say, a LinearLayout in the tests, they won't fail.
View searchText = mSearchView.findViewById(com.android.internal.R.id.search_src_text);
if (searchText instanceof TextView) {
TextView searchTextView = (TextView) searchText;
searchTextView.setTextColor(getContext().getColorStateList(com.android.internal.R.color.text_color_primary));
searchTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.search_bar_text_size));
}
View editFrame = mSearchView.findViewById(com.android.internal.R.id.search_edit_frame);
if (editFrame != null) {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) editFrame.getLayoutParams();
params.setMarginStart(0);
editFrame.setLayoutParams(params);
}
ActionBarShadowController.attachToRecyclerView(view.findViewById(R.id.search_bar_container), getLifecycle(), mResultsRecyclerView);
return view;
}
Aggregations