Package org.robolectric.shadows
Class ShadowAppWidgetManager
java.lang.Object
org.robolectric.shadows.ShadowAppWidgetManager
@Implements(android.appwidget.AppWidgetManager.class)
public class ShadowAppWidgetManager
extends Object
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void__constructor__(Context context, com.android.internal.appwidget.IAppWidgetService service) voidaddBoundWidget(int appWidgetId, AppWidgetProviderInfo providerInfo) voidaddInstalledProvider(AppWidgetProviderInfo appWidgetProviderInfo) voidaddInstalledProvidersForProfile(UserHandle userHandle, AppWidgetProviderInfo appWidgetProviderInfo) voidbindAppWidgetId(int appWidgetId, ComponentName provider) protected voidbindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options) protected booleanbindAppWidgetIdIfAllowed(int appWidgetId, ComponentName provider) Create an internal presentation of the widget and cache it locally.protected booleanbindAppWidgetIdIfAllowed(int appWidgetId, ComponentName provider, Bundle options) Create an internal presentation of the widget locally and store the optionsBundlewith it.intcreateWidget(Class<? extends AppWidgetProvider> appWidgetProviderClass, int widgetLayoutId) Creates a widget by inflating its layout.int[]createWidgets(Class<? extends AppWidgetProvider> appWidgetProviderClass, int widgetLayoutId, int howManyToCreate) Creates a bunch of widgets by inflating the same layout multiple times.booleanprotected int[]getAppWidgetIds(ComponentName provider) protected AppWidgetProviderInfogetAppWidgetInfo(int appWidgetId) protected BundlegetAppWidgetOptions(int appWidgetId) Gets the appWidgetOptions Bundle stored in a local cache.getAppWidgetProviderFor(int widgetId) protected List<AppWidgetProviderInfo> protected List<AppWidgetProviderInfo> getInstalledProvidersForPackage(String packageName, UserHandle profile) protected List<AppWidgetProviderInfo> getViewFor(int widgetId) protected RemoteViewsgetWidgetPreview(ComponentName provider, UserHandle user, int widgetCategories) Gets the widget preview for a given widget category in a local HashMap.protected booleanReturns true ifsetRequestPinAppWidgetSupported(boolean)is called withtruevoidputWidgetInfo(int appWidgetId, AppWidgetProviderInfo expectedWidgetInfo) Deprecated.voidreconstructWidgetViewAsIfPhoneWasRotated(int appWidgetId) Triggers a reapplication of the most recent set of actions against the widget, which is what happens when the phone is rotated.booleanremoveInstalledProvider(AppWidgetProviderInfo appWidgetProviderInfo) protected voidremoveWidgetPreview(ComponentName provider, int widgetCategories) Removes the widget preview for a given widget category in a local HashMap.protected booleanrequestPinAppWidget(ComponentName provider, Bundle extras, PendingIntent successCallback) This implementation currently usesrequestPinAppWidgetSupportedto determine if it should bind the app widget provided and execute thesuccessCallback.static voidreset()voidsetAllowedToBindAppWidgets(boolean allowed) voidsetAlwaysRecreateViewsDuringUpdate(boolean alwaysRecreate) Enables testing of widget behavior when all of the views are recreated on every update.voidsetRequestPinAppWidgetSupported(boolean supported) voidsetValidWidgetProviderComponentName(boolean validWidgetProviderComponentName) protected booleansetWidgetPreview(ComponentName provider, int widgetCategories, RemoteViews preview) Sets the widget preview for a given widget category in a local HashMap.protected voidupdateAppWidget(int[] appWidgetIds, RemoteViews views) protected voidupdateAppWidget(int appWidgetId, RemoteViews views) Simulates updating anAppWidgetwith a new set of viewsprotected voidupdateAppWidgetOptions(int appWidgetId, Bundle options) Update the locally cached appWidgetOptions Bundle.
-
Constructor Details
-
ShadowAppWidgetManager
public ShadowAppWidgetManager()
-
-
Method Details
-
reset
-
__constructor__
@Implementation protected void __constructor__(Context context, com.android.internal.appwidget.IAppWidgetService service) -
updateAppWidget
-
updateAppWidget
Simulates updating anAppWidgetwith a new set of views- Parameters:
appWidgetId- id of widgetviews- views to update
-
getAppWidgetIds
-
getInstalledProviders
-
getInstalledProvidersForProfile
@Implementation(minSdk=21) protected List<AppWidgetProviderInfo> getInstalledProvidersForProfile(UserHandle profile) -
getInstalledProvidersForPackage
@Implementation(minSdk=26) protected List<AppWidgetProviderInfo> getInstalledProvidersForPackage(String packageName, UserHandle profile) -
addInstalledProvider
-
removeInstalledProvider
-
addInstalledProvidersForProfile
public void addInstalledProvidersForProfile(UserHandle userHandle, AppWidgetProviderInfo appWidgetProviderInfo) -
addBoundWidget
-
putWidgetInfo
Deprecated. -
getAppWidgetInfo
-
getAppWidgetOptions
Gets the appWidgetOptions Bundle stored in a local cache. -
updateAppWidgetOptions
Update the locally cached appWidgetOptions Bundle. Instead of triggering associated AppWidgetProvider.onAppWidgetOptionsChanged through Intent, this implementation calls the method directly. -
bindAppWidgetId
-
bindAppWidgetId
@HiddenApi @Implementation protected void bindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options) -
bindAppWidgetIdIfAllowed
Create an internal presentation of the widget and cache it locally. This implementation doesn't triggerAppWidgetProvider.onUpdate -
bindAppWidgetIdIfAllowed
@Implementation protected boolean bindAppWidgetIdIfAllowed(int appWidgetId, ComponentName provider, Bundle options) Create an internal presentation of the widget locally and store the optionsBundlewith it. This implementation doesn't triggerAppWidgetProvider.onUpdate -
isRequestPinAppWidgetSupported
Returns true ifsetRequestPinAppWidgetSupported(boolean)is called withtrue -
requestPinAppWidget
@Implementation(minSdk=26) protected boolean requestPinAppWidget(ComponentName provider, @Nullable Bundle extras, @Nullable PendingIntent successCallback) This implementation currently usesrequestPinAppWidgetSupportedto determine if it should bind the app widget provided and execute thesuccessCallback.Note: This implementation doesn't trigger
AppWidgetProvider.onUpdate.- Parameters:
provider- The provider for the app widget to bind.extras- Returned in the callback along with the ID of the newly bound app widget, sent asAppWidgetManager.EXTRA_APPWIDGET_ID.successCallback- Called after binding the app widget, if possible.- Returns:
- true if the widget was installed, false otherwise.
-
setWidgetPreview
@Implementation(minSdk=35) protected boolean setWidgetPreview(ComponentName provider, int widgetCategories, RemoteViews preview) Sets the widget preview for a given widget category in a local HashMap. -
getWidgetPreview
@Implementation(minSdk=35) protected RemoteViews getWidgetPreview(ComponentName provider, UserHandle user, int widgetCategories) Gets the widget preview for a given widget category in a local HashMap. The UserHandle is ignored. -
removeWidgetPreview
@Implementation(minSdk=35) protected void removeWidgetPreview(ComponentName provider, int widgetCategories) Removes the widget preview for a given widget category in a local HashMap. -
reconstructWidgetViewAsIfPhoneWasRotated
public void reconstructWidgetViewAsIfPhoneWasRotated(int appWidgetId) Triggers a reapplication of the most recent set of actions against the widget, which is what happens when the phone is rotated. Does not attempt to simulate a change in screen geometry.- Parameters:
appWidgetId- the ID of the widget to be affected
-
createWidget
public int createWidget(Class<? extends AppWidgetProvider> appWidgetProviderClass, int widgetLayoutId) Creates a widget by inflating its layout.- Parameters:
appWidgetProviderClass- the app widget provider classwidgetLayoutId- id of the layout to inflate- Returns:
- the ID of the new widget
-
createWidgets
public int[] createWidgets(Class<? extends AppWidgetProvider> appWidgetProviderClass, int widgetLayoutId, int howManyToCreate) Creates a bunch of widgets by inflating the same layout multiple times.- Parameters:
appWidgetProviderClass- the app widget provider classwidgetLayoutId- id of the layout to inflatehowManyToCreate- number of new widgets to create- Returns:
- the IDs of the new widgets
-
getViewFor
- Parameters:
widgetId- id of the desired widget- Returns:
- the widget associated with
widgetId
-
getAppWidgetProviderFor
- Parameters:
widgetId- id of the widget whose provider is to be returned- Returns:
- the
AppWidgetProviderassociated withwidgetId
-
setAlwaysRecreateViewsDuringUpdate
public void setAlwaysRecreateViewsDuringUpdate(boolean alwaysRecreate) Enables testing of widget behavior when all of the views are recreated on every update. This is useful for ensuring that your widget will behave correctly even if it is restarted by the OS between events.- Parameters:
alwaysRecreate- whether or not to always recreate the views
-
getAlwaysRecreateViewsDuringUpdate
public boolean getAlwaysRecreateViewsDuringUpdate()- Returns:
- the state of the
alwaysRecreateViewsDuringUpdateflag
-
setAllowedToBindAppWidgets
public void setAllowedToBindAppWidgets(boolean allowed) -
setRequestPinAppWidgetSupported
public void setRequestPinAppWidgetSupported(boolean supported) -
setValidWidgetProviderComponentName
public void setValidWidgetProviderComponentName(boolean validWidgetProviderComponentName)
-