use of android.app.SearchManager in project android_frameworks_base by DirtyUnicorns.
the class PhoneWindow method launchDefaultSearch.
/**
* Helper method for adding launch-search to most applications. Opens the
* search window using default settings.
*
* @return true if search window opened
*/
private boolean launchDefaultSearch(KeyEvent event) {
boolean result;
final Callback cb = getCallback();
if (cb == null || isDestroyed()) {
result = false;
} else {
sendCloseSystemWindows("search");
int deviceId = event.getDeviceId();
SearchEvent searchEvent = null;
if (deviceId != 0) {
searchEvent = new SearchEvent(InputDevice.getDevice(deviceId));
}
try {
result = cb.onSearchRequested(searchEvent);
} catch (AbstractMethodError e) {
Log.e(TAG, "WindowCallback " + cb.getClass().getName() + " does not implement" + " method onSearchRequested(SearchEvent); fa", e);
result = cb.onSearchRequested();
}
}
if (!result && (getContext().getResources().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
// On TVs, if the app doesn't implement search, we want to launch assist.
Bundle args = new Bundle();
args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, event.getDeviceId());
return ((SearchManager) getContext().getSystemService(Context.SEARCH_SERVICE)).launchLegacyAssist(null, UserHandle.myUserId(), args);
}
return result;
}
use of android.app.SearchManager 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.app.SearchManager in project platform_packages_apps_launcher by android.
the class Launcher method stopSearch.
/**
* Cancel search dialog if it is open.
*/
void stopSearch() {
// Close search dialog
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchManager.stopSearch();
// Restore search widget to its normal position
Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
if (searchWidget != null) {
searchWidget.stopSearch(false);
}
}
use of android.app.SearchManager in project platform_packages_apps_launcher by android.
the class Launcher method showSearchDialog.
/**
* Show the search dialog immediately, without changing the search widget.
*
* @see Activity#startSearch(String, boolean, android.os.Bundle, boolean)
*/
void showSearchDialog(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, boolean globalSearch) {
if (initialQuery == null) {
// Use any text typed in the launcher as the initial query
initialQuery = getTypedText();
clearTypedText();
}
if (appSearchData == null) {
appSearchData = new Bundle();
appSearchData.putString(SearchManager.SOURCE, "launcher-search");
}
final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
final Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
if (searchWidget != null) {
// This gets called when the user leaves the search dialog to go back to
// the Launcher.
searchManager.setOnCancelListener(new SearchManager.OnCancelListener() {
public void onCancel() {
searchManager.setOnCancelListener(null);
stopSearch();
}
});
}
searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), appSearchData, globalSearch);
}
use of android.app.SearchManager in project platform_frameworks_base by android.
the class PhoneWindowManager method launchAssistAction.
private void launchAssistAction(String hint, int deviceId) {
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
if (!isUserSetupComplete()) {
// Disable opening assist window during setup
return;
}
Bundle args = null;
if (deviceId > Integer.MIN_VALUE) {
args = new Bundle();
args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
}
if ((mContext.getResources().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
// On TV, use legacy handling until assistants are implemented in the proper way.
((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)).launchLegacyAssist(hint, UserHandle.myUserId(), args);
} else {
if (hint != null) {
if (args == null) {
args = new Bundle();
}
args.putBoolean(hint, true);
}
StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
if (statusbar != null) {
statusbar.startAssist(args);
}
}
}
Aggregations