@@ -208,8 +208,10 @@ protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
208208 }
209209
210210 /**
211- * Provide guidance about the size of this widget to the AppWidgetManager. This information
212- * gets embedded into the AppWidgetExtras and causes a callback to the AppWidgetProvider.
211+ * Provide guidance about the size of this widget to the AppWidgetManager. The widths and
212+ * heights should correspond to the full area the AppWidgetHostView is given. Padding added by
213+ * the framework will be accounted for automatically. This information gets embedded into the
214+ * AppWidget options and causes a callback to the AppWidgetProvider.
213215 * @see AppWidgetProvider#onAppWidgetOptionsChanged(Context, AppWidgetManager, int, Bundle)
214216 *
215217 * @param options The bundle of options, in addition to the size information,
@@ -225,10 +227,19 @@ public void updateAppWidgetSize(Bundle options, int minWidth, int minHeight, int
225227 if (options == null ) {
226228 options = new Bundle ();
227229 }
228- options .putInt (AppWidgetManager .OPTION_APPWIDGET_MIN_WIDTH , minWidth );
229- options .putInt (AppWidgetManager .OPTION_APPWIDGET_MIN_HEIGHT , minHeight );
230- options .putInt (AppWidgetManager .OPTION_APPWIDGET_MAX_WIDTH , maxWidth );
231- options .putInt (AppWidgetManager .OPTION_APPWIDGET_MAX_HEIGHT , maxHeight );
230+
231+ Rect padding = new Rect ();
232+ if (mInfo != null ) {
233+ padding = getDefaultPaddingForWidget (mContext , mInfo .provider , padding );
234+ }
235+
236+ int xPadding = padding .left + padding .right ;
237+ int yPadding = padding .top + padding .bottom ;
238+
239+ options .putInt (AppWidgetManager .OPTION_APPWIDGET_MIN_WIDTH , minWidth - xPadding );
240+ options .putInt (AppWidgetManager .OPTION_APPWIDGET_MIN_HEIGHT , minHeight - yPadding );
241+ options .putInt (AppWidgetManager .OPTION_APPWIDGET_MAX_WIDTH , maxWidth - xPadding );
242+ options .putInt (AppWidgetManager .OPTION_APPWIDGET_MAX_HEIGHT , maxHeight - yPadding );
232243 updateAppWidgetOptions (options );
233244 }
234245
0 commit comments