List of usage examples for android.appwidget AppWidgetProviderInfo WIDGET_CATEGORY_SEARCHBOX
int WIDGET_CATEGORY_SEARCHBOX
To view the source code for android.appwidget AppWidgetProviderInfo WIDGET_CATEGORY_SEARCHBOX.
Click Source Link
From source file:com.android.launcher3.QsbContainerView.java
/** * 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./* w w w . j a v a 2 s.c o m*/ */ 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) && info.configure == null) { if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) { return info; } else if (defaultWidgetForSearchPackage == null) { defaultWidgetForSearchPackage = info; } } } return defaultWidgetForSearchPackage; }
From source file:com.atwal.wakeup.battery.util.Utilities.java
/** * 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.//from w ww .java 2 s. c o m */ @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; }
From source file:com.klinker.android.launcher.launcher3.Launcher.java
public View getOrCreateQsbBar() { if (!AppSettings.getInstance(this).showSearchBar) { return null; }/*from w w w.j av a 2 s . c o m*/ if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { return mLauncherCallbacks.getQsbBar(); } if (mQsb == null) { AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this); if (searchProvider == null) { return null; } Bundle opts = new Bundle(); opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX); SharedPreferences sp = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE); int widgetId = sp.getInt(QSB_WIDGET_ID, -1); AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId); if (!searchProvider.provider.flattenToString().equals(sp.getString(QSB_WIDGET_PROVIDER, null)) || (widgetInfo == null) || !widgetInfo.provider.equals(searchProvider.provider)) { // A valid widget is not already bound. if (widgetId > -1) { mAppWidgetHost.deleteAppWidgetId(widgetId); widgetId = -1; } // Try to bind a new widget widgetId = generateViewId(); sp.edit().putInt(QSB_WIDGET_ID, widgetId) .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString()).commit(); } mAppWidgetHost.setQsbWidgetId(widgetId); if (widgetId != -1) { mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider); mQsb.updateAppWidgetOptions(opts); mQsb.setPadding(0, 0, 0, 0); mSearchDropTargetBar.addView(mQsb); mSearchDropTargetBar.setQsbSearchBar(mQsb); createClickableSearch(); } } return mQsb; }
From source file:xyz.klinker.blur.launcher3.Launcher.java
public View getOrCreateQsbBar() { if (launcherCallbacksProvidesSearch()) { return mLauncherCallbacks.getQsbBar(); }/*from ww w . j av a 2s . co m*/ if (mQsb == null) { AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this); if (searchProvider == null) { return null; } Bundle opts = new Bundle(); opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX); // Determine the min and max dimensions of the widget. LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile portraitProfile = app.getInvariantDeviceProfile().portraitProfile; DeviceProfile landscapeProfile = app.getInvariantDeviceProfile().landscapeProfile; float density = getResources().getDisplayMetrics().density; Point searchDimens = portraitProfile.getSearchBarDimensForWidgetOpts(getResources()); int maxHeight = (int) (searchDimens.y / density); int minHeight = maxHeight; int maxWidth = (int) ((searchDimens.x / density) / 5) * 3; int minWidth = maxWidth; if (!landscapeProfile.isVerticalBarLayout()) { searchDimens = landscapeProfile.getSearchBarDimensForWidgetOpts(getResources()); maxHeight = (int) Math.max(maxHeight, searchDimens.y / density); minHeight = (int) Math.min(minHeight, searchDimens.y / density); maxWidth = (int) Math.max(maxWidth, searchDimens.x / density); minWidth = (int) Math.min(minWidth, searchDimens.x / density); } opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, maxHeight); opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, minHeight); opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, maxWidth); opts.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, minWidth); if (LOGD) { Log.d(TAG, "QSB widget options: maxHeight=" + maxHeight + " minHeight=" + minHeight + " maxWidth=" + maxWidth + " minWidth=" + minWidth); } if (mLauncherCallbacks != null) { opts.putAll(mLauncherCallbacks.getAdditionalSearchWidgetOptions()); } int widgetId = mSharedPrefs.getInt(QSB_WIDGET_ID, -1); AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId); if (!searchProvider.provider.flattenToString().equals(mSharedPrefs.getString(QSB_WIDGET_PROVIDER, null)) || (widgetInfo == null) || !widgetInfo.provider.equals(searchProvider.provider)) { // A valid widget is not already bound. if (widgetId > -1) { mAppWidgetHost.deleteAppWidgetId(widgetId); widgetId = -1; } // Try to bind a new widget widgetId = View.generateViewId(); mSharedPrefs.edit().putInt(QSB_WIDGET_ID, widgetId) .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString()).apply(); } mAppWidgetHost.setQsbWidgetId(widgetId); if (widgetId != -1) { mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider); mQsb.setId(R.id.qsb_widget); mQsb.updateAppWidgetOptions(opts); // on tablets, we don't need this widget taking up the whole screen. It looks better // with some padding on the sides if (getResources().getBoolean(R.bool.reduce_search_width)) { Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); mQsb.setPadding(size.x / 8, 0, size.x / 8, 0); } else { mQsb.setPadding(0, 0, 0, 0); } mSearchDropTargetBar.addView(mQsb); mSearchDropTargetBar.setQsbSearchBar(mQsb); if (AppSettings.getInstance(this).showSearchBar) { createClickableSearch(1); } else { mQsb.getLayoutParams().width = 0; } } } return mQsb; }
From source file:g7.bluesky.launcher3.Launcher.java
public View getQsbBar() { if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) { return mLauncherCallbacks.getQsbBar(); }// ww w . java 2s. c om if (mQsb == null) { AppWidgetProviderInfo searchProvider = Utilities.getSearchWidgetProvider(this); if (searchProvider == null) { return null; } Bundle opts = new Bundle(); opts.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX); SharedPreferences sp = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE); int widgetId = sp.getInt(QSB_WIDGET_ID, -1); AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId); if (!searchProvider.provider.flattenToString().equals(sp.getString(QSB_WIDGET_PROVIDER, null)) || (widgetInfo == null) || !widgetInfo.provider.equals(searchProvider.provider)) { // A valid widget is not already bound. if (widgetId > -1) { mAppWidgetHost.deleteAppWidgetId(widgetId); widgetId = -1; } // Try to bind a new widget widgetId = mAppWidgetHost.allocateAppWidgetId(); if (!AppWidgetManagerCompat.getInstance(this).bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) { mAppWidgetHost.deleteAppWidgetId(widgetId); widgetId = -1; } sp.edit().putInt(QSB_WIDGET_ID, widgetId) .putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString()).commit(); } if (widgetId != -1) { mQsb = mAppWidgetHost.createView(this, widgetId, searchProvider); mQsb.updateAppWidgetOptions(opts); mQsb.setPadding(0, 0, 0, 0); mSearchDropTargetBar.addView(mQsb); } } return mQsb; }