List of usage examples for android.appwidget AppWidgetManager OPTION_APPWIDGET_HOST_CATEGORY
String OPTION_APPWIDGET_HOST_CATEGORY
To view the source code for android.appwidget AppWidgetManager OPTION_APPWIDGET_HOST_CATEGORY.
Click Source Link
From source file:Main.java
public static final boolean isKeyguardWidget(int appWidgetId, Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context.getApplicationContext()); return appWidgetManager.getAppWidgetOptions(appWidgetId).getInt( AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1) == AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD; }//from ww w . j a v a2 s .co m return false; }
From source file:org.openbitcoinwidget.WidgetProvider.java
private static boolean isWidgetShownOnLockScreen(AppWidgetManager appWidgetManager, int appWidgetId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { // The below functionality was introduced in API version 16 (Jelly Bean) Bundle myOptions = appWidgetManager.getAppWidgetOptions(appWidgetId); // Get the value of OPTION_APPWIDGET_HOST_CATEGORY int category = myOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1); // If the value is WIDGET_CATEGORY_KEYGUARD, it's a lockscreen widget return category == AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD; }//from w ww .ja va 2s . c o m return false; }
From source file:br.com.bioscada.apps.biotracks.widgets.TrackWidgetProvider.java
@TargetApi(16) @Override/*from w w w .j a v a 2 s . c om*/ public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) { super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions); if (newOptions != null) { int newSize; if (newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1) == AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) { newSize = 1; } else { int height = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT); if (height == 0) { newSize = 2; } else if (height >= FOUR_CELLS) { newSize = 4; } else if (height >= THREE_CELLS) { newSize = 3; } else if (height >= TWO_CELLS) { newSize = 2; } else { newSize = 1; } } int size = ApiAdapterFactory.getApiAdapter().getAppWidgetSize(appWidgetManager, appWidgetId); if (size != newSize) { ApiAdapterFactory.getApiAdapter().setAppWidgetSize(appWidgetManager, appWidgetId, newSize); updateAppWidget(context, appWidgetManager, appWidgetId, -1L); } } }
From source file:com.ultrafunk.network_info.config.ConfigActivity.java
private static boolean isLockscreenWidget(AppWidgetManager appWidgetManager, int appWidgetId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Bundle widgetOptions = appWidgetManager.getAppWidgetOptions(appWidgetId); int category = widgetOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1); return category == AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD; }/*from w w w . j av a2 s. com*/ return false; }
From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java
private void updateClock(Context context, AppWidgetManager appWidgetManager, int appWidgetId, float ratio) { RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget); // Launch setinngs when clicking on the time in the widget only if not a lock screen widget Bundle newOptions = appWidgetManager.getAppWidgetOptions(appWidgetId); if (newOptions != null && newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1) != AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) { Intent mIntent = new Intent(Intent.ACTION_MAIN); mIntent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName component = new ComponentName("com.android.settings", "com.android.settings.Settings"); mIntent.setComponent(component); widget.setOnClickPendingIntent(R.id.digital_appwidget, PendingIntent.getActivity(context, 0, mIntent, 0)); }//from w ww . ja va2 s . co m //cg sai.pan begin refreshWifiStatus(context, widget); refreshBtStatus(context, widget); refreshAirplaneStatus(context, widget, Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0); mLocationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE); refreshGpsStatus(context, widget, mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)); //refreshDataStatus(context, widget, Settings.Global.getInt(context.getContentResolver(), Settings.Global.MOBILE_DATA, 0) != 0); requestLocation(context); //cg sai.pan end // SPRD for bug421127 add am/pm for widget WidgetUtils.setTimeFormat(widget, (int) context.getResources().getDimension(R.dimen.widget_label_font_size), R.id.the_clock); WidgetUtils.setClockSize(context, widget, ratio); // Set today's date format CharSequence dateFormat = DateFormat.getBestDateTimePattern(Locale.getDefault(), context.getString(R.string.abbrev_wday_month_day_no_year)); widget.setCharSequence(R.id.date, "setFormat12Hour", dateFormat); widget.setCharSequence(R.id.date, "setFormat24Hour", dateFormat); appWidgetManager.updateAppWidget(appWidgetId, widget); }
From source file:com.klinker.android.launcher.launcher3.Launcher.java
public View getOrCreateQsbBar() { if (!AppSettings.getInstance(this).showSearchBar) { return null; }//from ww w .jav a2 s. c om 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 w w w.j a v a 2 s . 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); // 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(); }// w w w . j ava 2s.c o 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); 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; }