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.
-
Nested Class Summary
Nested classes/interfaces inherited from class android.content.BroadcastReceiver
BroadcastReceiver.PendingResult
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Intent extra constant for adjust position of the app widget.static final String
Intent extra constant for height of the app widget.static final String
Intent extra constant for the app widget type.static final String
Intent extra constant for width of the app widget.protected Context
Dynamic context used by this provider.static final int
Constant for the default app widget id.static final int
Bitmap quality of the widget background.static final int
Constant size in dips for eight cells.static final int
Constant size in dips for five cells.static final int
Constant size in dips for four cells.static final int
Constant size in dips for one cell.static final int
Constant size in dips for seven cells.static final int
Constant size in dips for six cells.static final int
Constant size in dips for three cells.static final int
Constant size in dips for two cells.static final int
Default header size in dips.Fields inherited from interface com.pranavpandey.android.dynamic.locale.DynamicLocale
HINDI, INDONESIA, PORTUGUESE, RUSSIAN, SPANISH, SPLIT, SYSTEM, TURKISH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
getCellsForSize
(int size) Converts the widget size into cells.Get the dynamic theme context used by this provider.Get the current locale used by this provider.getDefaultLocale
(Context context) getDynamicTheme
(int appWidgetId) This method will be called to get the dynamic app theme for this provideZ.float
int
Returns the current height of this widget provider.protected abstract String
Override this method to provide a shared preferences name for this app widget provider.protected abstract RemoteViews
getRemoteViews
(Context context) Override this method to get aRemoteViews
fo this widget provider.String[]
int
getThemeRes
(int appWidgetId) This method will be called to get the theme style resource for this provider.static Bitmap
getWidgetFrameBitmap
(int width, int height, float cornerRadius) Get a bitmap for the widget background according to the corner radius.static Bitmap
getWidgetFrameBitmapWithStroke
(int width, int height, float cornerRadius, int color) Get a bitmap for the widget background according to the corner radius.static Bitmap
getWidgetFrameBitmapWithStroke
(int width, int height, float cornerRadius, int color, int strokeColor) Get a bitmap for the widget background according to the corner radius.static Bitmap
getWidgetHeaderBitmap
(int width, int height, float cornerRadius, int color) Returns a bitmap for widget header according to the corner radius.int
getWidth()
Returns the current width of this widget provider.boolean
Checks whether the position should be adjusted.void
onAppWidgetOptionsChanged
(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) void
void
onDisabled
(Context context) void
void
onUpdate
(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) void
setAdjustPosition
(boolean adjustPosition) Sets whether the position should be adjusted.void
setHeight
(int height) Sets the current height of this widget provider.void
setWidth
(int width) Sets the current width of this widget provider.void
updateAppWidget
(Context context, AppWidgetManager appWidgetManager, int appWidgetId) Override this method to update a widget instance according to the id.protected void
updateWidgetDimensions
(Context context, AppWidgetManager appWidgetManager, int appWidgetId) Update widget width and height according to the current orientation.Methods inherited from class android.appwidget.AppWidgetProvider
onEnabled, onRestored
Methods inherited from class android.content.BroadcastReceiver
abortBroadcast, clearAbortBroadcast, getAbortBroadcast, getDebugUnregister, getResultCode, getResultData, getResultExtras, getSentFromPackage, getSentFromUid, goAsync, isInitialStickyBroadcast, isOrderedBroadcast, peekService, setDebugUnregister, setOrderedHint, setResult, setResultCode, setResultData, setResultExtras
-
Field Details
-
EXTRA_APP_WIDGET_WIDTH
Intent extra constant for width of the app widget.- See Also:
-
EXTRA_APP_WIDGET_HEIGHT
Intent extra constant for height of the app widget.- See Also:
-
EXTRA_APP_WIDGET_ADJUST_POSITION
Intent extra constant for adjust position of the app widget.- See Also:
-
EXTRA_APP_WIDGET_TYPE
Intent extra constant for the app widget type.- See Also:
-
NO_ID
public static final int NO_IDConstant for the default app widget id.- See Also:
-
WIDGET_CELL_SIZE_ONE
public static final int WIDGET_CELL_SIZE_ONEConstant size in dips for one cell.- See Also:
-
WIDGET_CELL_SIZE_TWO
public static final int WIDGET_CELL_SIZE_TWOConstant size in dips for two cells.- See Also:
-
WIDGET_CELL_SIZE_THREE
public static final int WIDGET_CELL_SIZE_THREEConstant size in dips for three cells.- See Also:
-
WIDGET_CELL_SIZE_FOUR
public static final int WIDGET_CELL_SIZE_FOURConstant size in dips for four cells.- See Also:
-
WIDGET_CELL_SIZE_FIVE
public static final int WIDGET_CELL_SIZE_FIVEConstant size in dips for five cells.- See Also:
-
WIDGET_CELL_SIZE_SIX
public static final int WIDGET_CELL_SIZE_SIXConstant size in dips for six cells.- See Also:
-
WIDGET_CELL_SIZE_SEVEN
public static final int WIDGET_CELL_SIZE_SEVENConstant size in dips for seven cells.- See Also:
-
WIDGET_CELL_SIZE_EIGHT
public static final int WIDGET_CELL_SIZE_EIGHTConstant size in dips for eight cells.- See Also:
-
WIDGET_BACKGROUND_QUALITY
public static final int WIDGET_BACKGROUND_QUALITYBitmap quality of the widget background.- See Also:
-
WIDGET_HEADER_SIZE
public static final int WIDGET_HEADER_SIZEDefault header size in dips.- See Also:
-
mContext
Dynamic context used by this provider.
-
-
Constructor Details
-
DynamicAppWidgetProvider
public DynamicAppWidgetProvider()
-
-
Method Details
-
onReceive
- Overrides:
onReceive
in classAppWidgetProvider
-
onUpdate
public void onUpdate(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager, @NonNull int[] appWidgetIds) - Overrides:
onUpdate
in classAppWidgetProvider
-
onAppWidgetOptionsChanged
public void onAppWidgetOptionsChanged(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager, int appWidgetId, @NonNull Bundle newOptions) - Overrides:
onAppWidgetOptionsChanged
in classAppWidgetProvider
-
onDeleted
- Overrides:
onDeleted
in classAppWidgetProvider
-
onDisabled
- Overrides:
onDisabled
in classAppWidgetProvider
-
getSupportedLocales
- Specified by:
getSupportedLocales
in interfaceDynamicLocale
-
getDefaultLocale
- Specified by:
getDefaultLocale
in interfaceDynamicLocale
-
getLocale
- Specified by:
getLocale
in interfaceDynamicLocale
-
setLocale
- Specified by:
setLocale
in interfaceDynamicLocale
-
getThemeRes
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
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 interfaceDynamicLocale
-
getRemoteViews
Override this method to get aRemoteViews
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
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
Get the dynamic theme context used by this provider.- Returns:
- The dynamic context used by this provider.
-
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
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.
-