@@ -63,7 +63,18 @@ public class KeyguardWidgetFrame extends FrameLayout {
6363 private float mBackgroundAlphaMultiplier = 1.0f ;
6464 private Drawable mBackgroundDrawable ;
6565 private Rect mBackgroundRect = new Rect ();
66+ private int mLastMeasuredWidth = -1 ;
67+ private int mLastMeasuredHeight = 1 ;
68+
69+ // These variables are all needed in order to size things properly before we're actually
70+ // measured.
6671 private int mSmallWidgetHeight ;
72+ private int mSmallFrameHeight ;
73+ private boolean mWidgetLockedSmall = false ;
74+ private int mMaxChallengeTop = -1 ;
75+
76+ // This will hold the width value before we've actually been measured
77+ private int mFrameHeight ;
6778
6879 // Multiple callers may try and adjust the alpha of the frame. When a caller shows
6980 // the outlines, we give that caller control, and nobody else can fade them out.
@@ -99,10 +110,6 @@ protected void onDetachedFromWindow() {
99110 cancelLongPress ();
100111 }
101112
102- public void setMaxChallengeTop (int top ) {
103- mSmallWidgetHeight = top - getPaddingTop ();
104- }
105-
106113 @ Override
107114 public boolean onInterceptTouchEvent (MotionEvent ev ) {
108115 // Watch for longpress events at this level to make sure
@@ -262,22 +269,6 @@ public void setContentAlpha(float alpha) {
262269 }
263270 }
264271
265- /**
266- * Set the top location of the challenge.
267- *
268- * @param top The top of the challenge, in _local_ coordinates, or -1 to indicate the challenge
269- * is down.
270- */
271- private void setChallengeTop (int top , boolean updateWidgetSize ) {
272- // The widget starts below the padding, and extends to the top of the challengs.
273- int widgetHeight = top - getPaddingTop ();
274- int frameHeight = top + getPaddingBottom ();
275- setFrameHeight (frameHeight );
276- if (updateWidgetSize ) {
277- setWidgetHeight (widgetHeight );
278- }
279- }
280-
281272 /**
282273 * Depending on whether the security is up, the widget size needs to change
283274 *
@@ -298,28 +289,49 @@ private void setWidgetHeight(int height) {
298289 }
299290 }
300291
292+ public void setMaxChallengeTop (int top ) {
293+ boolean dirty = mMaxChallengeTop != top ;
294+ mSmallWidgetHeight = top - getPaddingTop ();
295+ mSmallFrameHeight = top + getPaddingBottom ();
296+ if (dirty && mIsSmall ) {
297+ setWidgetHeight (mSmallWidgetHeight );
298+ setFrameHeight (mSmallFrameHeight );
299+ } else if (dirty && mWidgetLockedSmall ) {
300+ setWidgetHeight (mSmallWidgetHeight );
301+ }
302+ }
303+
301304 public boolean isSmall () {
302305 return mIsSmall ;
303306 }
304307
305308 public void adjustFrame (int challengeTop ) {
306- setChallengeTop (challengeTop , false );
309+ int frameHeight = challengeTop + getPaddingBottom ();
310+ setFrameHeight (frameHeight );
307311 }
308312
309313 public void shrinkWidget () {
310314 mIsSmall = true ;
311- setChallengeTop (mSmallWidgetHeight , true );
315+ setWidgetHeight (mSmallWidgetHeight );
316+ setFrameHeight (mSmallFrameHeight );
317+ }
318+
319+ public void setWidgetLockedSmall (boolean locked ) {
320+ setWidgetHeight (mSmallWidgetHeight );
321+ mWidgetLockedSmall = locked ;
312322 }
313323
314324 public void resetSize () {
315325 mIsSmall = false ;
326+ if (!mWidgetLockedSmall ) {
327+ setWidgetHeight (LayoutParams .MATCH_PARENT );
328+ }
316329 setFrameHeight (getMeasuredHeight ());
317- setWidgetHeight (LayoutParams .MATCH_PARENT );
318330 }
319331
320332 public void setFrameHeight (int height ) {
321- height = Math . min ( height , getMeasuredHeight ()) ;
322- mBackgroundRect .set (0 , 0 , getMeasuredWidth (), height );
333+ mFrameHeight = height ;
334+ mBackgroundRect .set (0 , 0 , getMeasuredWidth (), Math . min ( mFrameHeight , getMeasuredHeight ()) );
323335 invalidate ();
324336 }
325337
@@ -359,10 +371,38 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
359371 mGradientColor , 0 , Shader .TileMode .CLAMP );
360372 mRightToLeftGradient = new LinearGradient (x1 , 0f , x0 , 0f ,
361373 mGradientColor , 0 , Shader .TileMode .CLAMP );
362- mBackgroundRect .set (0 , 0 , w , h );
374+
375+ if (!mIsSmall ) {
376+ mFrameHeight = h ;
377+ }
378+
379+ mBackgroundRect .set (0 , 0 , getMeasuredWidth (), Math .min (h , mFrameHeight ));
363380 invalidate ();
364381 }
365382
383+ protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
384+ super .onMeasure (widthMeasureSpec , heightMeasureSpec );
385+ performAppWidgetSizeCallbacksIfNecessary ();
386+ }
387+
388+ private void performAppWidgetSizeCallbacksIfNecessary () {
389+ View content = getContent ();
390+ if (!(content instanceof AppWidgetHostView )) return ;
391+
392+ boolean sizeDirty = content .getMeasuredWidth () != mLastMeasuredWidth ||
393+ content .getMeasuredHeight () != mLastMeasuredHeight ;
394+ if (sizeDirty ) {
395+
396+ }
397+
398+ AppWidgetHostView awhv = (AppWidgetHostView ) content ;
399+ float density = getResources ().getDisplayMetrics ().density ;
400+
401+ int width = (int ) (content .getMeasuredWidth () / density );
402+ int height = (int ) (content .getMeasuredHeight () / density );
403+ awhv .updateAppWidgetSize (null , width , height , width , height , true );
404+ }
405+
366406 void setOverScrollAmount (float r , boolean left ) {
367407 if (Float .compare (mOverScrollAmount , r ) != 0 ) {
368408 mOverScrollAmount = r ;
0 commit comments