Search in sources :

Example 51 with SearchManager

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;
}
Also used : SearchManager(android.app.SearchManager) Bundle(android.os.Bundle) SearchEvent(android.view.SearchEvent)

Example 52 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)

Example 53 with SearchManager

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);
    }
}
Also used : ISearchManager(android.app.ISearchManager) SearchManager(android.app.SearchManager)

Example 54 with SearchManager

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);
}
Also used : ISearchManager(android.app.ISearchManager) SearchManager(android.app.SearchManager) Bundle(android.os.Bundle)

Example 55 with SearchManager

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);
        }
    }
}
Also used : StatusBarManagerInternal(com.android.server.statusbar.StatusBarManagerInternal) SearchManager(android.app.SearchManager) Bundle(android.os.Bundle)

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