Search in sources :

Example 26 with SearchManager

use of android.app.SearchManager in project Etar-Calendar by Etar-Group.

the class CalendarController method launchSearch.

//    private void launchAlerts() {
//        Intent intent = new Intent();
//        intent.setClass(mContext, AlertActivity.class);
//        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        mContext.startActivity(intent);
//    }
private void launchSearch(long eventId, String query, ComponentName componentName) {
    final SearchManager searchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
    final SearchableInfo searchableInfo = searchManager.getSearchableInfo(componentName);
    final Intent intent = new Intent(Intent.ACTION_SEARCH);
    intent.putExtra(SearchManager.QUERY, query);
    intent.setComponent(searchableInfo.getSearchActivity());
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    mContext.startActivity(intent);
}
Also used : SearchManager(android.app.SearchManager) SearchableInfo(android.app.SearchableInfo) Intent(android.content.Intent)

Example 27 with SearchManager

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

the class AssistUtils method getAssistComponentForUser.

public ComponentName getAssistComponentForUser(int userId) {
    final String setting = Settings.Secure.getStringForUser(mContext.getContentResolver(), Settings.Secure.ASSISTANT, userId);
    if (setting != null) {
        return ComponentName.unflattenFromString(setting);
    }
    // Fallback to keep backward compatible behavior when there is no user setting.
    if (activeServiceSupportsAssistGesture()) {
        return getActiveServiceComponentName();
    }
    Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)).getAssistIntent(false);
    PackageManager pm = mContext.getPackageManager();
    ResolveInfo info = pm.resolveActivityAsUser(intent, PackageManager.MATCH_DEFAULT_ONLY, userId);
    if (info != null) {
        return new ComponentName(info.activityInfo.applicationInfo.packageName, info.activityInfo.name);
    }
    return null;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) SearchManager(android.app.SearchManager) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 28 with SearchManager

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

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 29 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 30 with SearchManager

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

the class PhoneWindowManager method launchAssistLongPressAction.

private void launchAssistLongPressAction() {
    performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
    sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
    // launch the search activity
    Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {
        // TODO: This only stops the factory-installed search manager.
        // Need to formalize an API to handle others
        SearchManager searchManager = getSearchManager();
        if (searchManager != null) {
            searchManager.stopSearch();
        }
        startActivityAsUser(intent, UserHandle.CURRENT);
    } catch (ActivityNotFoundException e) {
        Slog.w(TAG, "No activity to handle assist long press action.", e);
    }
}
Also used : SearchManager(android.app.SearchManager) ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent)

Aggregations

SearchManager (android.app.SearchManager)99 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 RecognizerIntent (android.speech.RecognizerIntent)12 SearchView (android.support.v7.widget.SearchView)12 MenuItem (android.view.MenuItem)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 AppWidgetHostView (android.appwidget.AppWidgetHostView)5 PackageManager (android.content.pm.PackageManager)5 ResolveInfo (android.content.pm.ResolveInfo)5 MenuInflater (android.view.MenuInflater)5