Skip to content

Commit 8a7eff1

Browse files
Adam CohenAndroid (Google) Code Review
authored andcommitted
Merge "Account for auto-padding in AppWidgetHostView#updateAppWidgetSize (issue 6454251)" into jb-dev
2 parents a87f234 + 88f041e commit 8a7eff1

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

core/java/android/appwidget/AppWidgetHostView.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)