summaryrefslogtreecommitdiffstats
path: root/core/java/android/appwidget/AppWidgetHostView.java
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2012-04-19 17:11:40 -0700
committerAdam Cohen <adamcohen@google.com>2012-04-19 18:01:46 -0700
commite8724c82ab1479f13c85a2c6219841e1fd95f2d2 (patch)
treef8886ae47bb75369819bc40cfe7aa393afeb638c /core/java/android/appwidget/AppWidgetHostView.java
parentf2740b347bce35cc68dfdddfe2da3a23e00a518e (diff)
downloadframeworks_base-e8724c82ab1479f13c85a2c6219841e1fd95f2d2.zip
frameworks_base-e8724c82ab1479f13c85a2c6219841e1fd95f2d2.tar.gz
frameworks_base-e8724c82ab1479f13c85a2c6219841e1fd95f2d2.tar.bz2
Adding callback for widget size changed, and potentially other extra info
Change-Id: I57738c92b6a0ba68ae66b19a533559470c64e6f1
Diffstat (limited to 'core/java/android/appwidget/AppWidgetHostView.java')
-rw-r--r--core/java/android/appwidget/AppWidgetHostView.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/core/java/android/appwidget/AppWidgetHostView.java b/core/java/android/appwidget/AppWidgetHostView.java
index 61a9dce..c1b8e7c 100644
--- a/core/java/android/appwidget/AppWidgetHostView.java
+++ b/core/java/android/appwidget/AppWidgetHostView.java
@@ -28,6 +28,7 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
+import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
@@ -206,6 +207,45 @@ 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)
+ */
+ public void updateAppWidgetSize(Bundle extras, int minWidth, int minHeight, int maxWidth, int maxHeight) {
+ if (extras == null) {
+ extras = new Bundle();
+ }
+ extras.putInt(AppWidgetManager.EXTRA_APPWIDGET_MIN_WIDTH, minWidth);
+ extras.putInt(AppWidgetManager.EXTRA_APPWIDGET_MIN_HEIGHT, minHeight);
+ extras.putInt(AppWidgetManager.EXTRA_APPWIDGET_MAX_WIDTH, maxWidth);
+ extras.putInt(AppWidgetManager.EXTRA_APPWIDGET_MAX_HEIGHT, maxHeight);
+ updateAppWidgetExtras(extras);
+ }
+
+ public void updateAppWidgetExtras(Bundle extras) {
+ AppWidgetManager.getInstance(mContext).updateAppWidgetExtras(mAppWidgetId, extras);
+ }
+
/** {@inheritDoc} */
@Override
public LayoutParams generateLayoutParams(AttributeSet attrs) {