Class ShadowAppWidgetManager

    • Constructor Detail

      • ShadowAppWidgetManager

        public ShadowAppWidgetManager()
    • Method Detail

      • __constructor__

        protected void __constructor__​(Context context,
      • updateAppWidget

        protected void updateAppWidget​(int appWidgetId,
                                       RemoteViews views)
        Simulates updating an AppWidget with a new set of views
        appWidgetId - id of widget
        views - views to update
      • addInstalledProvider

        public void addInstalledProvider​(AppWidgetProviderInfo appWidgetProviderInfo)
      • removeInstalledProvider

        public boolean removeInstalledProvider​(AppWidgetProviderInfo appWidgetProviderInfo)
      • getAppWidgetOptions

        protected Bundle getAppWidgetOptions​(int appWidgetId)
        Gets the appWidgetOptions Bundle stored in a local cache.
      • updateAppWidgetOptions

        protected void updateAppWidgetOptions​(int appWidgetId,
                                              Bundle options)
        Update the locally cached appWidgetOptions Bundle. Instead of triggering associated AppWidgetProvider.onAppWidgetOptionsChanged through Intent, this implementation calls the method directly.
      • bindAppWidgetIdIfAllowed

        protected boolean bindAppWidgetIdIfAllowed​(int appWidgetId,
                                                   ComponentName provider)
        Create an internal presentation of the widget and cache it locally. This implementation doesn't trigger AppWidgetProvider.onUpdate
      • bindAppWidgetIdIfAllowed

        protected boolean bindAppWidgetIdIfAllowed​(int appWidgetId,
                                                   ComponentName provider,
                                                   Bundle options)
        Create an internal presentation of the widget locally and store the options Bundle with it. This implementation doesn't trigger AppWidgetProvider.onUpdate
      • isRequestPinAppWidgetSupported

        protected boolean isRequestPinAppWidgetSupported()
        Returns true if setSupportedToRequestPinAppWidget is called with true
      • requestPinAppWidget

        protected boolean requestPinAppWidget​(ComponentName provider,
                                              Bundle extras,
                                              PendingIntent successCallback)
        This implementation currently uses requestPinAppWidgetSupported to determine if it should bind the app widget provided and execute the successCallback.

        Note: This implementation doesn't trigger AppWidgetProvider.onUpdate.

        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 as AppWidgetManager.EXTRA_APPWIDGET_ID.
        successCallback - Called after binding the app widget, if possible.
        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.
        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.
        appWidgetProviderClass - the app widget provider class
        widgetLayoutId - id of the layout to inflate
        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.
        appWidgetProviderClass - the app widget provider class
        widgetLayoutId - id of the layout to inflate
        howManyToCreate - number of new widgets to create
        the IDs of the new widgets
      • getViewFor

        public View getViewFor​(int widgetId)
        widgetId - id of the desired widget
        the widget associated with widgetId
      • getAppWidgetProviderFor

        public AppWidgetProvider getAppWidgetProviderFor​(int widgetId)
        widgetId - id of the widget whose provider is to be returned
        the AppWidgetProvider associated with widgetId
      • 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.
        alwaysRecreate - whether or not to always recreate the views
      • getAlwaysRecreateViewsDuringUpdate

        public boolean getAlwaysRecreateViewsDuringUpdate()
        the state of thealwaysRecreateViewsDuringUpdate flag
      • setAllowedToBindAppWidgets

        public void setAllowedToBindAppWidgets​(boolean allowed)
      • setRequestPinAppWidgetSupported

        public void setRequestPinAppWidgetSupported​(boolean supported)
      • setValidWidgetProviderComponentName

        public void setValidWidgetProviderComponentName​(boolean validWidgetProviderComponentName)