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
FieldsModifier and TypeFieldDescriptionstatic final StringIntent extra constant for adjust position of the app widget.static final StringIntent extra constant for height of the app widget.static final StringIntent extra constant for the app widget type.static final StringIntent extra constant for width of the app widget.protected ContextDynamic context used by this provider.static final intConstant for the default app widget id.static final intBitmap quality of the widget background.static final intConstant size in dips for eight cells.static final intConstant size in dips for five cells.static final intConstant size in dips for four cells.static final intConstant size in dips for one cell.static final intConstant size in dips for seven cells.static final intConstant size in dips for six cells.static final intConstant size in dips for three cells.static final intConstant size in dips for two cells.static final intDefault header size in dips.Fields inherited from interface com.pranavpandey.android.dynamic.locale.DynamicLocale
HINDI, INDONESIA, PORTUGUESE, RUSSIAN, SPANISH, SPLIT, SYSTEM, TURKISH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intgetCellsForSize(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.floatintReturns the current height of this widget provider.protected abstract StringOverride this method to provide a shared preferences name for this app widget provider.protected abstract RemoteViewsgetRemoteViews(Context context) Override this method to get aRemoteViewsfo this widget provider.String[]intgetThemeRes(int appWidgetId) This method will be called to get the theme style resource for this provider.static BitmapgetWidgetFrameBitmap(int width, int height, float cornerRadius) Get a bitmap for the widget background according to the corner radius.static BitmapgetWidgetFrameBitmapWithStroke(int width, int height, float cornerRadius, int color) Get a bitmap for the widget background according to the corner radius.static BitmapgetWidgetFrameBitmapWithStroke(int width, int height, float cornerRadius, int color, int strokeColor) Get a bitmap for the widget background according to the corner radius.static BitmapgetWidgetHeaderBitmap(int width, int height, float cornerRadius, int color) Returns a bitmap for widget header according to the corner radius.intgetWidth()Returns the current width of this widget provider.booleanChecks whether the position should be adjusted.voidonAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) voidvoidonDisabled(Context context) voidvoidonUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) voidsetAdjustPosition(boolean adjustPosition) Sets whether the position should be adjusted.voidsetHeight(int height) Sets the current height of this widget provider.voidsetWidth(int width) Sets the current width of this widget provider.voidupdateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) Override this method to update a widget instance according to the id.protected voidupdateWidgetDimensions(Context context, AppWidgetManager appWidgetManager, int appWidgetId) Update widget width and height according to the current orientation.Methods inherited from class android.appwidget.AppWidgetProvider
onEnabled, onRestoredMethods 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:
onReceivein classAppWidgetProvider
-
onUpdate
public void onUpdate(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager, @NonNull int[] appWidgetIds) - Overrides:
onUpdatein classAppWidgetProvider
-
onAppWidgetOptionsChanged
public void onAppWidgetOptionsChanged(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager, int appWidgetId, @NonNull Bundle newOptions) - Overrides:
onAppWidgetOptionsChangedin classAppWidgetProvider
-
onDeleted
- Overrides:
onDeletedin classAppWidgetProvider
-
onDisabled
- Overrides:
onDisabledin classAppWidgetProvider
-
getSupportedLocales
- Specified by:
getSupportedLocalesin interfaceDynamicLocale
-
getDefaultLocale
- Specified by:
getDefaultLocalein interfaceDynamicLocale
-
getLocale
- Specified by:
getLocalein interfaceDynamicLocale
-
setLocale
- Specified by:
setLocalein 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:
getFontScalein interfaceDynamicLocale
-
getRemoteViews
Override this method to get aRemoteViewsfo 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-trueif the position should be adjusted.
-
isAdjustPosition
public boolean isAdjustPosition()Checks whether the position should be adjusted.- Returns:
trueif 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.
-