Class DynamicAppWidgetProvider<T extends AppTheme<?>>

java.lang.Object
android.content.BroadcastReceiver
android.appwidget.AppWidgetProvider
com.pranavpandey.android.dynamic.support.provider.DynamicAppWidgetProvider<T>
Type Parameters:
T - The type of the app theme attached to this provider.
All Implemented Interfaces:
DynamicLocale

public abstract class DynamicAppWidgetProvider<T extends AppTheme<?>> extends AppWidgetProvider implements DynamicLocale
A customisable AppWidgetProvider to provide basic configuration functionality.

Extend it and modify according to the requirements.

  • Field Details

    • EXTRA_APP_WIDGET_WIDTH

      public static final String EXTRA_APP_WIDGET_WIDTH
      Intent extra constant for width of the app widget.
      See Also:
    • EXTRA_APP_WIDGET_HEIGHT

      public static final String EXTRA_APP_WIDGET_HEIGHT
      Intent extra constant for height of the app widget.
      See Also:
    • EXTRA_APP_WIDGET_ADJUST_POSITION

      public static final String EXTRA_APP_WIDGET_ADJUST_POSITION
      Intent extra constant for adjust position of the app widget.
      See Also:
    • EXTRA_APP_WIDGET_TYPE

      public static final String EXTRA_APP_WIDGET_TYPE
      Intent extra constant for the app widget type.
      See Also:
    • NO_ID

      public static final int NO_ID
      Constant for the default app widget id.
      See Also:
    • WIDGET_CELL_SIZE_ONE

      public static final int WIDGET_CELL_SIZE_ONE
      Constant size in dips for one cell.
      See Also:
    • WIDGET_CELL_SIZE_TWO

      public static final int WIDGET_CELL_SIZE_TWO
      Constant size in dips for two cells.
      See Also:
    • WIDGET_CELL_SIZE_THREE

      public static final int WIDGET_CELL_SIZE_THREE
      Constant size in dips for three cells.
      See Also:
    • WIDGET_CELL_SIZE_FOUR

      public static final int WIDGET_CELL_SIZE_FOUR
      Constant size in dips for four cells.
      See Also:
    • WIDGET_CELL_SIZE_FIVE

      public static final int WIDGET_CELL_SIZE_FIVE
      Constant size in dips for five cells.
      See Also:
    • WIDGET_CELL_SIZE_SIX

      public static final int WIDGET_CELL_SIZE_SIX
      Constant size in dips for six cells.
      See Also:
    • WIDGET_CELL_SIZE_SEVEN

      public static final int WIDGET_CELL_SIZE_SEVEN
      Constant size in dips for seven cells.
      See Also:
    • WIDGET_CELL_SIZE_EIGHT

      public static final int WIDGET_CELL_SIZE_EIGHT
      Constant size in dips for eight cells.
      See Also:
    • WIDGET_BACKGROUND_QUALITY

      public static final int WIDGET_BACKGROUND_QUALITY
      Bitmap quality of the widget background.
      See Also:
    • WIDGET_HEADER_SIZE

      public static final int WIDGET_HEADER_SIZE
      Default header size in dips.
      See Also:
    • mContext

      protected Context mContext
      Dynamic context used by this provider.
  • Constructor Details

    • DynamicAppWidgetProvider

      public DynamicAppWidgetProvider()
  • Method Details

    • onReceive

      public void onReceive(@NonNull Context context, @NonNull Intent intent)
      Overrides:
      onReceive in class AppWidgetProvider
    • onUpdate

      public void onUpdate(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager, @NonNull int[] appWidgetIds)
      Overrides:
      onUpdate in class AppWidgetProvider
    • onAppWidgetOptionsChanged

      public void onAppWidgetOptionsChanged(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager, int appWidgetId, @NonNull Bundle newOptions)
      Overrides:
      onAppWidgetOptionsChanged in class AppWidgetProvider
    • onDeleted

      public void onDeleted(@NonNull Context context, @NonNull int[] appWidgetIds)
      Overrides:
      onDeleted in class AppWidgetProvider
    • onDisabled

      public void onDisabled(@NonNull Context context)
      Overrides:
      onDisabled in class AppWidgetProvider
    • getSupportedLocales

      @Nullable public String[] getSupportedLocales()
      Specified by:
      getSupportedLocales in interface DynamicLocale
    • getDefaultLocale

      @NonNull public Locale getDefaultLocale(@NonNull Context context)
      Specified by:
      getDefaultLocale in interface DynamicLocale
    • getLocale

      @Nullable public Locale getLocale()
      Specified by:
      getLocale in interface DynamicLocale
    • setLocale

      @NonNull public Context setLocale(@NonNull Context context)
      Specified by:
      setLocale in interface DynamicLocale
    • getThemeRes

      @StyleRes public int getThemeRes(int appWidgetId)
      This method will be called to get the theme style resource for this provider.

      Override this method to supply your own customised style.

      Parameters:
      appWidgetId - The app widget id to be used.
      Returns:
      The theme style resource for this provider.
      See Also:
    • getDynamicTheme

      @Nullable public T getDynamicTheme(int appWidgetId)
      This method will be called to get the dynamic app theme for this provideZ.

      Override this method to supply your own customised theme.

      Parameters:
      appWidgetId - The app widget id to be used.
      Returns:
      The dynamic app theme for this provider.
    • getFontScale

      public float getFontScale()
      Specified by:
      getFontScale in interface DynamicLocale
    • getRemoteViews

      @NonNull protected abstract RemoteViews getRemoteViews(@NonNull Context context)
      Override this method to get a RemoteViews fo this widget provider.

      It can be according to the widget height and width to provide dynamic layouts.

      Parameters:
      context - The context associated with this widget provider.
      Returns:
      The remote views for this provider.
    • getPreferences

      @NonNull protected abstract String getPreferences()
      Override this method to provide a shared preferences name for this app widget provider.
      Returns:
      The shared preferences for this widget provider.
    • updateAppWidget

      @CallSuper public void updateAppWidget(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager, int appWidgetId)
      Override this method to update a widget instance according to the id.

      It will be useful while implementing a configuration activity via DynamicWidgetActivity.

      Parameters:
      context - The context associated with this widget provider.
      appWidgetManager - The app widget manager.
      appWidgetId - The app widget id to be updated.
    • updateWidgetDimensions

      protected void updateWidgetDimensions(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager, int appWidgetId)
      Update widget width and height according to the current orientation.
      Parameters:
      context - The context associated with this widget provider.
      appWidgetManager - The app widget manager.
      appWidgetId - The app widget id to update the dimensions.
    • getContext

      @NonNull public Context getContext()
      Get the dynamic theme context used by this provider.
      Returns:
      The dynamic context used by this provider.
    • getCurrentLocale

      @NonNull public Locale getCurrentLocale()
      Get the current locale used by this provider.
      Returns:
      The current locale used by this provider.
    • getWidth

      public int getWidth()
      Returns the current width of this widget provider.
      Returns:
      The current width of this widget provider.
    • setWidth

      public void setWidth(int width)
      Sets the current width of this widget provider.
      Parameters:
      width - The width to be set.
    • getHeight

      public int getHeight()
      Returns the current height of this widget provider.
      Returns:
      The current height of this widget provider.
    • setHeight

      public void setHeight(int height)
      Sets the current height of this widget provider.
      Parameters:
      height - The height to be set.
    • setAdjustPosition

      public void setAdjustPosition(boolean adjustPosition)
      Sets whether the position should be adjusted.
      Parameters:
      adjustPosition - true if the position should be adjusted.
    • isAdjustPosition

      public boolean isAdjustPosition()
      Checks whether the position should be adjusted.
      Returns:
      true if the position should be adjusted.
    • getCellsForSize

      public static int getCellsForSize(int size)
      Converts the widget size into cells.
      Parameters:
      size - The size to be converted into cells.
      Returns:
      The number of cells according to the supplied size.
    • getWidgetFrameBitmap

      @Nullable public static Bitmap getWidgetFrameBitmap(int width, int height, float cornerRadius)
      Get a bitmap for the widget background according to the corner radius.
      Parameters:
      width - The width in dip for the bitmap.
      height - The height in dip for the bitmap.
      cornerRadius - The corner size in dip for the bitmap.
      Returns:
      The bitmap for the widget background according to the supplied parameters.
    • getWidgetFrameBitmapWithStroke

      @Nullable public static Bitmap getWidgetFrameBitmapWithStroke(int width, int height, float cornerRadius, @ColorInt int color, @ColorInt int strokeColor)
      Get a bitmap for the widget background according to the corner radius.
      Parameters:
      width - The width in dip for the bitmap.
      height - The height in dip for the bitmap.
      cornerRadius - The corner size in dip for the bitmap.
      color - The color to be used.
      strokeColor - The stroke color to be used.
      Returns:
      The bitmap for the widget background according to the supplied parameters.
    • getWidgetFrameBitmapWithStroke

      @Nullable public static Bitmap getWidgetFrameBitmapWithStroke(int width, int height, float cornerRadius, @ColorInt int color)
      Get a bitmap for the widget background according to the corner radius.
      Parameters:
      width - The width in dip for the bitmap.
      height - The height in dip for the bitmap.
      cornerRadius - The corner size in dip for the bitmap.
      color - The color to be used.
      Returns:
      The bitmap for the widget background according to the supplied parameters.
    • getWidgetHeaderBitmap

      @Nullable public static Bitmap getWidgetHeaderBitmap(int width, int height, float cornerRadius, @ColorInt int color)
      Returns a bitmap for widget header according to the corner radius.
      Parameters:
      width - The width in dip for the bitmap.
      height - The height in dip for the bitmap.
      cornerRadius - The corner size in dip for the bitmap.
      color - The color to be used.
      Returns:
      The bitmap for the widget background according to the supplied parameters.