Browse Source

React to hardware search button presses by opening the search view (by expanding the menu option).

pull/11/head
Eric Kok 11 years ago
parent
commit
54b2b206ea
  1. 12
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  2. 10
      core/src/org/transdroid/core/gui/search/SearchActivity.java

12
core/src/org/transdroid/core/gui/TorrentsActivity.java

@ -135,6 +135,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
protected ServerStatusView serverStatusView; protected ServerStatusView serverStatusView;
@SystemService @SystemService
protected SearchManager searchManager; protected SearchManager searchManager;
private MenuItem searchMenu = null;
// Settings // Settings
@Bean @Bean
@ -262,10 +263,11 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// For Android 2.1+, add an expandable SearchView to the action bar // For Android 2.1+, add an expandable SearchView to the action bar
MenuItem item = menu.findItem(R.id.action_search); MenuItem item = menu.findItem(R.id.action_search);
if (android.os.Build.VERSION.SDK_INT >= 8) { if (android.os.Build.VERSION.SDK_INT >= 8) {
final SearchView searchView = new SearchView(this); SearchView searchView = new SearchView(this);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setQueryRefinementEnabled(true); searchView.setQueryRefinementEnabled(true);
item.setActionView(searchView); item.setActionView(searchView);
searchMenu = item;
} }
} }
return true; return true;
@ -486,6 +488,14 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
} }
@Override
public boolean onSearchRequested() {
if (searchMenu != null) {
searchMenu.expandActionView();
}
return true;
}
@OptionsItem(resName = "action_add_fromurl") @OptionsItem(resName = "action_add_fromurl")
protected void startUrlEntryDialog() { protected void startUrlEntryDialog() {
UrlEntryDialog.startUrlEntry(this); UrlEntryDialog.startUrlEntry(this);

10
core/src/org/transdroid/core/gui/search/SearchActivity.java

@ -77,6 +77,7 @@ public class SearchActivity extends SherlockFragmentActivity implements OnNaviga
protected SearchHelper searchHelper; protected SearchHelper searchHelper;
@SystemService @SystemService
protected SearchManager searchManager; protected SearchManager searchManager;
private MenuItem searchMenu = null;
private SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, private SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
TorrentSearchHistoryProvider.AUTHORITY, TorrentSearchHistoryProvider.MODE); TorrentSearchHistoryProvider.AUTHORITY, TorrentSearchHistoryProvider.MODE);
@ -154,6 +155,7 @@ public class SearchActivity extends SherlockFragmentActivity implements OnNaviga
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setQueryRefinementEnabled(true); searchView.setQueryRefinementEnabled(true);
item.setActionView(searchView); item.setActionView(searchView);
searchMenu = item;
} }
} }
return true; return true;
@ -198,6 +200,14 @@ public class SearchActivity extends SherlockFragmentActivity implements OnNaviga
} }
@Override
public boolean onSearchRequested() {
if (searchMenu != null) {
searchMenu.expandActionView();
}
return true;
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
@OptionsItem(android.R.id.home) @OptionsItem(android.R.id.home)
protected void navigateUp() { protected void navigateUp() {

Loading…
Cancel
Save