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 Constructor Description ShadowAppWidgetManager() -
Method Summary
Modifier and Type Method Description protected void__constructor__(Context context)protected 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.booleangetAlwaysRecreateViewsDuringUpdate()protected int[]getAppWidgetIds(ComponentName provider)protected AppWidgetProviderInfogetAppWidgetInfo(int appWidgetId)protected BundlegetAppWidgetOptions(int appWidgetId)Gets the appWidgetOptions Bundle stored in a local cache.AppWidgetProvidergetAppWidgetProviderFor(int widgetId)protected List<AppWidgetProviderInfo>getInstalledProviders()protected List<AppWidgetProviderInfo>getInstalledProvidersForPackage(String packageName, UserHandle profile)protected List<AppWidgetProviderInfo>getInstalledProvidersForProfile(UserHandle profile)ViewgetViewFor(int widgetId)protected booleanisRequestPinAppWidgetSupported()Returns true ifsetSupportedToRequestPinAppWidgetis 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.protected booleanrequestPinAppWidget(ComponentName provider, Bundle extras, PendingIntent successCallback)This implementation currently usesrequestPinAppWidgetSupportedto determine if it should bind the app widget provided and execute thesuccessCallback.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 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
-
__constructor__
-
__constructor__
@Implementation(minSdk=21) 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
-
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(minSdk=17) protected void bindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options) -
bindAppWidgetIdIfAllowed
@Implementation protected boolean bindAppWidgetIdIfAllowed(int appWidgetId, ComponentName provider)Create an internal presentation of the widget and cache it locally. This implementation doesn't triggerAppWidgetProvider.onUpdate -
bindAppWidgetIdIfAllowed
@Implementation(minSdk=17) 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 ifsetSupportedToRequestPinAppWidgetis called withtrue -
requestPinAppWidget
@Implementation(minSdk=26) protected boolean requestPinAppWidget(ComponentName provider, Bundle extras, 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.
-
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)
-