Search in sources :

Example 41 with SearchManager

use of android.app.SearchManager in project materialistic by hidroh.

the class BaseListActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (mIsMultiPane) {
        getMenuInflater().inflate(R.menu.menu_item_compact, menu);
    }
    if (isSearchable()) {
        getMenuInflater().inflate(R.menu.menu_search, menu);
        MenuItem menuSearch = menu.findItem(R.id.menu_search);
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) mActionViewResolver.getActionView(menuSearch);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(this, SearchActivity.class)));
        searchView.setIconified(true);
        searchView.setQuery("", false);
    }
    return super.onCreateOptionsMenu(menu);
}
Also used : SearchView(android.support.v7.widget.SearchView) SearchManager(android.app.SearchManager) MenuItem(android.view.MenuItem) ComponentName(android.content.ComponentName)

Example 42 with SearchManager

use of android.app.SearchManager in project android_frameworks_base by AOSPA.

the class SearchManagerTest method testSearchManagerInvocations.

/**
     * The goal of this test is to confirm that we can start and then
     * stop a simple search.
     */
public void testSearchManagerInvocations() throws Exception {
    SearchManager searchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
    assertNotNull(searchManager);
    // These tests should simply run to completion w/o exceptions
    searchManager.startSearch(null, false, SEARCHABLE_ACTIVITY, null, false);
    searchManager.stopSearch();
    searchManager.startSearch("", false, SEARCHABLE_ACTIVITY, null, false);
    searchManager.stopSearch();
    searchManager.startSearch("test search string", false, SEARCHABLE_ACTIVITY, null, false);
    searchManager.stopSearch();
    searchManager.startSearch("test search string", true, SEARCHABLE_ACTIVITY, null, false);
    searchManager.stopSearch();
}
Also used : ISearchManager(android.app.ISearchManager) SearchManager(android.app.SearchManager)

Example 43 with SearchManager

use of android.app.SearchManager in project android_frameworks_base by AOSPA.

the class SearchManagerTest method testStartSearchIdempotent.

/**
     * Tests that startSearch() can be called multiple times without stopSearch()
     * in between.
     */
public void testStartSearchIdempotent() throws Exception {
    SearchManager searchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
    assertNotNull(searchManager);
    searchManager.startSearch(null, false, SEARCHABLE_ACTIVITY, null, false);
    searchManager.startSearch(null, false, SEARCHABLE_ACTIVITY, null, false);
    searchManager.stopSearch();
}
Also used : ISearchManager(android.app.ISearchManager) SearchManager(android.app.SearchManager)

Example 44 with SearchManager

use of android.app.SearchManager in project android_frameworks_base by crdroidandroid.

the class AssistManager method startAssistActivity.

private void startAssistActivity(Bundle args, @NonNull ComponentName assistComponent) {
    if (!mBar.isDeviceProvisioned()) {
        return;
    }
    // Close Recent Apps if needed
    mBar.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_SEARCH_PANEL | CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL);
    boolean structureEnabled = Settings.Secure.getIntForUser(mContext.getContentResolver(), Settings.Secure.ASSIST_STRUCTURE_ENABLED, 1, UserHandle.USER_CURRENT) != 0;
    final Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)).getAssistIntent(structureEnabled);
    if (intent == null) {
        return;
    }
    intent.setComponent(assistComponent);
    intent.putExtras(args);
    if (structureEnabled) {
        showDisclosure();
    }
    try {
        final ActivityOptions opts = ActivityOptions.makeCustomAnimation(mContext, R.anim.search_launch_enter, R.anim.search_launch_exit);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        AsyncTask.execute(new Runnable() {

            @Override
            public void run() {
                mContext.startActivityAsUser(intent, opts.toBundle(), new UserHandle(UserHandle.USER_CURRENT));
            }
        });
    } catch (ActivityNotFoundException e) {
        Log.w(TAG, "Activity not found for " + intent.getAction());
    }
}
Also used : SearchManager(android.app.SearchManager) ActivityNotFoundException(android.content.ActivityNotFoundException) UserHandle(android.os.UserHandle) Intent(android.content.Intent) ActivityOptions(android.app.ActivityOptions)

Example 45 with SearchManager

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);
}
Also used : SearchView(android.support.v7.widget.SearchView) MenuInflater(android.view.MenuInflater) SearchManager(android.app.SearchManager) MenuItem(android.view.MenuItem) SearchRecentSuggestions(android.provider.SearchRecentSuggestions)

Aggregations

SearchManager (android.app.SearchManager)101 Intent (android.content.Intent)31 ISearchManager (android.app.ISearchManager)26 ActivityNotFoundException (android.content.ActivityNotFoundException)20 ComponentName (android.content.ComponentName)20 Bundle (android.os.Bundle)14 SearchView (android.support.v7.widget.SearchView)14 MenuItem (android.view.MenuItem)14 RecognizerIntent (android.speech.RecognizerIntent)12 UserHandle (android.os.UserHandle)10 View (android.view.View)9 ImageView (android.widget.ImageView)8 SearchView (android.widget.SearchView)8 TextView (android.widget.TextView)8 ActivityOptions (android.app.ActivityOptions)7 LargeTest (android.test.suitebuilder.annotation.LargeTest)6 MenuInflater (android.view.MenuInflater)6 AppWidgetHostView (android.appwidget.AppWidgetHostView)5 PackageManager (android.content.pm.PackageManager)5 ResolveInfo (android.content.pm.ResolveInfo)5