Java Code Examples for android.app.SearchManager#getGlobalSearchActivity()

The following examples show how to use android.app.SearchManager#getGlobalSearchActivity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchWidgetProvider.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
/**
 * -     * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX}
 * -     * provided by the same package which is set to be global search activity.
 * -     * If widgetCategory is not supported, or no such widget is found, returns the first widget
 * -     * provided by the package.
 * -
 */
public static AppWidgetProviderInfo get(Context context) {
    SearchManager searchManager =
            (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
    ComponentName searchComponent = searchManager.getGlobalSearchActivity();
    if (searchComponent == null) return null;
    String providerPkg = searchComponent.getPackageName();

    AppWidgetProviderInfo defaultWidgetForSearchPackage = null;

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) {
        if (info.provider.getPackageName().equals(providerPkg) && info.configure == null) {
            if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) {
                return info;
            } else if (defaultWidgetForSearchPackage == null) {
                defaultWidgetForSearchPackage = info;
            }
        }
    }
    return defaultWidgetForSearchPackage;
}
 
Example 2
Source File: IntentUtil.java    From paper-launcher with MIT License 5 votes vote down vote up
public static void startGoogleSearchActivity(View view) {
    final Context context = view.getContext();

    final SearchManager searchManager =
            (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
    if (searchManager == null) {
        return;
    }

    ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
    if (globalSearchActivity == null) {
        return;
    }

    Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(globalSearchActivity);

    Bundle appSearchData = new Bundle();
    appSearchData.putString("source", context.getPackageName());

    intent.putExtra(SearchManager.APP_DATA, appSearchData);
    intent.setSourceBounds(getViewBounds(view));
    try {
        context.startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        ex.printStackTrace();
    }
}
 
Example 3
Source File: Utilities.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX}
 * provided by the same package which is set to be global search activity.
 * If widgetCategory is not supported, or no such widget is found, returns the first widget
 * provided by the package.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static AppWidgetProviderInfo getSearchWidgetProvider(Context context) {
    SearchManager searchManager =
            (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
    ComponentName searchComponent = searchManager.getGlobalSearchActivity();
    if (searchComponent == null) return null;
    String providerPkg = searchComponent.getPackageName();

    AppWidgetProviderInfo defaultWidgetForSearchPackage = null;

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) {
        if (info.provider.getPackageName().equals(providerPkg)) {
            if (ATLEAST_JB_MR1) {
                if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) {
                    return info;
                } else if (defaultWidgetForSearchPackage == null) {
                    defaultWidgetForSearchPackage = info;
                }
            } else {
                return info;
            }
        }
    }
    return defaultWidgetForSearchPackage;
}
 
Example 4
Source File: Utilities.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
public static boolean searchActivityExists(Context context) {
    final SearchManager searchManager =
            (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
    ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();

    return globalSearchActivity != null;
}
 
Example 5
Source File: LauncherProvider.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
private ComponentName getSearchWidgetProvider() {
    SearchManager searchManager =
            (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
    ComponentName searchComponent = searchManager.getGlobalSearchActivity();
    if (searchComponent == null) return null;
    return getProviderInPackage(searchComponent.getPackageName());
}
 
Example 6
Source File: Utilities.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX}
 * provided by the same package which is set to be global search activity.
 * If widgetCategory is not supported, or no such widget is found, returns the first widget
 * provided by the package.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static AppWidgetProviderInfo getSearchWidgetProvider(Context context) {
    SearchManager searchManager =
            (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
    ComponentName searchComponent = searchManager.getGlobalSearchActivity();
    if (searchComponent == null) return null;
    String providerPkg = searchComponent.getPackageName();

    AppWidgetProviderInfo defaultWidgetForSearchPackage = null;

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) {
        if (info.provider.getPackageName().equals(providerPkg)) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) {
                    return info;
                } else if (defaultWidgetForSearchPackage == null) {
                    defaultWidgetForSearchPackage = info;
                }
            } else {
                return info;
            }
        }
    }
    return defaultWidgetForSearchPackage;
}
 
Example 7
Source File: Launcher.java    From TurboLauncher with Apache License 2.0 4 votes vote down vote up
protected boolean updateGlobalSearchIcon() {
	final View searchButtonContainer = findViewById(R.id.search_button_container);
	final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
	final View voiceButtonContainer = findViewById(R.id.voice_button_container);
	final View voiceButton = findViewById(R.id.voice_button);

	final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
	ComponentName activityName = searchManager.getGlobalSearchActivity();
	if (activityName != null) {
		int coi = getCurrentOrientationIndexForGlobalIcons();
		sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
				R.id.search_button, activityName,
				R.drawable.ic_home_search_normal_holo,
				TOOLBAR_SEARCH_ICON_METADATA_NAME);
		if (sGlobalSearchIcon[coi] == null) {
			sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
					R.id.search_button, activityName,
					R.drawable.ic_home_search_normal_holo,
					TOOLBAR_ICON_METADATA_NAME);
		}

		if (searchButtonContainer != null)
			searchButtonContainer.setVisibility(View.VISIBLE);
		searchButton.setVisibility(View.VISIBLE);
		invalidatePressedFocusedStates(searchButtonContainer, searchButton);
		return true;
	} else {
		// We disable both search and voice search when there is no global
		// search provider
		if (searchButtonContainer != null)
			searchButtonContainer.setVisibility(View.GONE);
		if (voiceButtonContainer != null)
			voiceButtonContainer.setVisibility(View.GONE);
		if (searchButton != null)
			searchButton.setVisibility(View.GONE);
		if (voiceButton != null)
			voiceButton.setVisibility(View.GONE);
		updateVoiceButtonProxyVisible(false);
		return false;
	}
}