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
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
__constructor__
(Context context, com.android.internal.appwidget.IAppWidgetService service) void
addBoundWidget
(int appWidgetId, AppWidgetProviderInfo providerInfo) void
addInstalledProvider
(AppWidgetProviderInfo appWidgetProviderInfo) void
addInstalledProvidersForProfile
(UserHandle userHandle, AppWidgetProviderInfo appWidgetProviderInfo) void
bindAppWidgetId
(int appWidgetId, ComponentName provider) protected void
bindAppWidgetId
(int appWidgetId, ComponentName provider, Bundle options) protected boolean
bindAppWidgetIdIfAllowed
(int appWidgetId, ComponentName provider) Create an internal presentation of the widget and cache it locally.protected boolean
bindAppWidgetIdIfAllowed
(int appWidgetId, ComponentName provider, Bundle options) Create an internal presentation of the widget locally and store the optionsBundle
with it.int
createWidget
(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.boolean
protected int[]
getAppWidgetIds
(ComponentName provider) protected AppWidgetProviderInfo
getAppWidgetInfo
(int appWidgetId) protected Bundle
getAppWidgetOptions
(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 boolean
Returns true ifsetSupportedToRequestPinAppWidget
is called withtrue
void
putWidgetInfo
(int appWidgetId, AppWidgetProviderInfo expectedWidgetInfo) Deprecated.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.boolean
removeInstalledProvider
(AppWidgetProviderInfo appWidgetProviderInfo) protected boolean
requestPinAppWidget
(ComponentName provider, Bundle extras, PendingIntent successCallback) This implementation currently usesrequestPinAppWidgetSupported
to determine if it should bind the app widget provided and execute thesuccessCallback
.static void
reset()
void
setAllowedToBindAppWidgets
(boolean allowed) void
setAlwaysRecreateViewsDuringUpdate
(boolean alwaysRecreate) Enables testing of widget behavior when all of the views are recreated on every update.void
setRequestPinAppWidgetSupported
(boolean supported) void
setValidWidgetProviderComponentName
(boolean validWidgetProviderComponentName) protected void
updateAppWidget
(int[] appWidgetIds, RemoteViews views) protected void
updateAppWidget
(int appWidgetId, RemoteViews views) Simulates updating anAppWidget
with a new set of viewsprotected void
updateAppWidgetOptions
(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 anAppWidget
with 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 optionsBundle
with it. This implementation doesn't triggerAppWidgetProvider.onUpdate
-
isRequestPinAppWidgetSupported
Returns true ifsetSupportedToRequestPinAppWidget
is called withtrue
-
requestPinAppWidget
@Implementation(minSdk=26) protected boolean requestPinAppWidget(ComponentName provider, Bundle extras, PendingIntent successCallback) This implementation currently usesrequestPinAppWidgetSupported
to 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
AppWidgetProvider
associated 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
alwaysRecreateViewsDuringUpdate
flag
-
setAllowedToBindAppWidgets
public void setAllowedToBindAppWidgets(boolean allowed) -
setRequestPinAppWidgetSupported
public void setRequestPinAppWidgetSupported(boolean supported) -
setValidWidgetProviderComponentName
public void setValidWidgetProviderComponentName(boolean validWidgetProviderComponentName)
-