From c88d11f9493e65d318dcd3b094ef446e1905ebfd Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Fri, 27 Apr 2012 18:33:18 -0700 Subject: Pushing widget resize callback responsibility to AppWidgetHost Change-Id: I33ca691deee11f8249eed6733a9ac82ed9bfbd15 --- core/java/android/appwidget/AppWidgetHostView.java | 36 ++++++++++------------ 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'core/java/android/appwidget/AppWidgetHostView.java') diff --git a/core/java/android/appwidget/AppWidgetHostView.java b/core/java/android/appwidget/AppWidgetHostView.java index c1b8e7ce2521..c707ea3a9e0a 100644 --- a/core/java/android/appwidget/AppWidgetHostView.java +++ b/core/java/android/appwidget/AppWidgetHostView.java @@ -207,31 +207,20 @@ public class AppWidgetHostView extends FrameLayout { super.dispatchRestoreInstanceState(jail); } - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - int oldWidth = getMeasuredWidth(); - int oldHeight = getMeasuredHeight(); - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - int newWidth = getMeasuredWidth(); - int newHeight = getMeasuredHeight(); - - // TODO: this is just a hack for now -- we actually have the AppWidgetHost - // be responsible for updating the size of the widget. - if (oldWidth != newWidth || oldHeight != newHeight) { - final float density = mContext.getResources().getDisplayMetrics().density; - final int newWidthDips = (int) (newWidth / density); - final int newHeightDips = (int) (newHeight / density); - updateAppWidgetSize(null, newWidthDips, newHeightDips, newWidthDips, newHeightDips); - } - } - /** * Provide guidance about the size of this widget to the AppWidgetManager. This information * gets embedded into the AppWidgetExtras and causes a callback to the AppWidgetProvider. + * @see AppWidgetProvider#onAppWidgetExtrasChanged(Context, AppWidgetManager, int, Bundle) + * + * @param extras The bundle of extra information, in addition to the size information + * can be null. + * @param minWidth The minimum width that the widget will be displayed at. + * @param minHeight The maximum height that the widget will be displayed at. + * @param maxWidth The maximum height that the widget will be displayed at. * - * @see AppWidgetProvider#onAppWidgetExtrasChanged(Context, AppWidgetManager, int, Bundle) */ - public void updateAppWidgetSize(Bundle extras, int minWidth, int minHeight, int maxWidth, int maxHeight) { + public void updateAppWidgetSize(Bundle extras, int minWidth, int minHeight, int maxWidth, + int maxHeight) { if (extras == null) { extras = new Bundle(); } @@ -242,6 +231,13 @@ public class AppWidgetHostView extends FrameLayout { updateAppWidgetExtras(extras); } + /** + * Specify some extra information for the widget provider. Causes a callback to the + * AppWidgetProvider. + * @see AppWidgetProvider#onAppWidgetExtrasChanged(Context, AppWidgetManager, int, Bundle) + * + * @param extras The bundle of extra information. + */ public void updateAppWidgetExtras(Bundle extras) { AppWidgetManager.getInstance(mContext).updateAppWidgetExtras(mAppWidgetId, extras); } -- cgit v1.2.3