Skip to content

Commit 8a7785c

Browse files
author
Adam Cohen
committed
Cleaning up the way in which the challenge influences widget size on first measure pass
-> This change ensures that on first draw, the widget is the appropriate size if the security challenge is covering it. -> This change is in preparation for some new policy surrounding widget sizing -- with this new policy, a given widget may need to be small even if the page is not being covered by the challenge. Hence, we propogate this small size to all the pages, whether or not they are covered. The pages will eventually use this. -> Ensure that paging hints are shown correctly (with the new sticky widget logic the page can be switched, and we weren't always seeing the appropriate hints). -> Also ensuring that the page is set correctly on first draw -- generally this change should make it so everything is right on the first draw. Change-Id: I7e03be9b027aed0ebb0fada05652b4226fd23897
1 parent 1108a2c commit 8a7785c

File tree

4 files changed

+100
-37
lines changed

4 files changed

+100
-37
lines changed

policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewStateManager.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
2424
private KeyguardWidgetPager mPagedView;
2525
private ChallengeLayout mChallengeLayout;
2626
private Runnable mHideHintsRunnable;
27-
private KeyguardSecurityView mKeyguardSecurityContainer;
2827
private int[] mTmpPoint = new int[2];
28+
private int[] mTmpLoc = new int[2];
29+
30+
private KeyguardSecurityView mKeyguardSecurityContainer;
2931
private static final int SCREEN_ON_HINT_DURATION = 1000;
3032
private static final int SCREEN_ON_RING_HINT_DELAY = 300;
3133
Handler mMainQueue = new Handler(Looper.myLooper());
@@ -91,7 +93,7 @@ public void onPageSwitch(View newPage, int newPageIndex) {
9193
boolean challengeOverlapping = mChallengeLayout.isChallengeOverlapping();
9294
if (challengeOverlapping && !newCurPage.isSmall()
9395
&& mPageListeningToSlider != newPageIndex) {
94-
shrinkWidget(newCurPage);
96+
newCurPage.shrinkWidget();
9597
}
9698
}
9799
mCurrentPage = newPageIndex;
@@ -104,15 +106,6 @@ private int getChallengeTopRelativeToFrame(KeyguardWidgetFrame frame, int top) {
104106
return mTmpPoint[1];
105107
}
106108

107-
private void shrinkWidget(KeyguardWidgetFrame frame) {
108-
if (frame != null && mChallengeLayout != null &&
109-
mChallengeLayout instanceof SlidingChallengeLayout) {
110-
SlidingChallengeLayout scl = (SlidingChallengeLayout) mChallengeLayout;
111-
int top = scl.getMaxChallengeTop();
112-
frame.shrinkWidget(getChallengeTopRelativeToFrame(frame, top));
113-
}
114-
}
115-
116109
/**
117110
* Simple method to map a point from one view's coordinates to another's. Note: this method
118111
* doesn't account for transforms, so if the views will be transformed, this should not be used.
@@ -121,15 +114,15 @@ private void shrinkWidget(KeyguardWidgetFrame frame) {
121114
* @param toView The view into which the point should be mapped
122115
* @param pt The point
123116
*/
124-
public void mapPoint(View fromView, View toView, int pt[]) {
125-
int[] loc = new int[2];
126-
fromView.getLocationInWindow(loc);
127-
int x = loc[0];
128-
int y = loc[1];
117+
private void mapPoint(View fromView, View toView, int pt[]) {
118+
fromView.getLocationInWindow(mTmpLoc);
119+
120+
int x = mTmpLoc[0];
121+
int y = mTmpLoc[1];
129122

130-
toView.getLocationInWindow(loc);
131-
int vX = loc[0];
132-
int vY = loc[1];
123+
toView.getLocationInWindow(mTmpLoc);
124+
int vX = mTmpLoc[0];
125+
int vY = mTmpLoc[1];
133126

134127
pt[0] += x - vX;
135128
pt[1] += y - vY;
@@ -177,8 +170,7 @@ public void onScrollStateChanged(int scrollState) {
177170
if (!frame.isSmall()) {
178171
// We need to fetch the final page, in case the pages are in motion.
179172
mPageListeningToSlider = mPagedView.getNextPage();
180-
System.out.println("Shrink widget from scroll state changed!");
181-
shrinkWidget(frame);
173+
frame.shrinkWidget();
182174
}
183175
// View is on the move. Pause the security view until it completes.
184176
mKeyguardSecurityContainer.onPause();

policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetFrame.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public class KeyguardWidgetFrame extends FrameLayout {
6262
private float mBackgroundAlphaMultiplier = 1.0f;
6363
private Drawable mBackgroundDrawable;
6464
private Rect mBackgroundRect = new Rect();
65+
private static int mSmallWidgetHeight;
6566

6667
// Multiple callers may try and adjust the alpha of the frame. When a caller shows
6768
// the outlines, we give that caller control, and nobody else can fade them out.
@@ -97,6 +98,10 @@ protected void onDetachedFromWindow() {
9798
cancelLongPress();
9899
}
99100

101+
public void setMaxChallengeTop(int top) {
102+
mSmallWidgetHeight = top - getPaddingTop();
103+
}
104+
100105
@Override
101106
public boolean onInterceptTouchEvent(MotionEvent ev) {
102107
// Watch for longpress events at this level to make sure
@@ -276,7 +281,6 @@ private void setChallengeTop(int top, boolean updateWidgetSize) {
276281
* @param height The height of the widget, -1 for full height
277282
*/
278283
private void setWidgetHeight(int height) {
279-
System.out.println("Set widget height: " + this + " : " + height);
280284
boolean needLayout = false;
281285
View widget = getContent();
282286
if (widget != null) {
@@ -299,9 +303,9 @@ public void adjustFrame(int challengeTop) {
299303
setChallengeTop(challengeTop, false);
300304
}
301305

302-
public void shrinkWidget(int challengeTop) {
306+
public void shrinkWidget() {
303307
mIsSmall = true;
304-
setChallengeTop(challengeTop, true);
308+
setChallengeTop(mSmallWidgetHeight, true);
305309
}
306310

307311
public void resetSize() {

policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetPager.java

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
5656
private float mChildrenOutlineAlpha = 0;
5757
private float mSidePagesAlpha = 1f;
5858
protected int mScreenCenter;
59+
private boolean mHasLayout = false;
60+
private boolean mHasMeasure = false;
61+
private boolean mShowHintsOnLayout = false;
5962

6063
private static final long CUSTOM_WIDGET_USER_ACTIVITY_TIMEOUT = 30000;
6164

@@ -435,7 +438,64 @@ void hideOutlinesAndSidePages() {
435438
}
436439

437440
public void showInitialPageHints() {
438-
showOutlinesAndSidePages();
441+
if (mHasLayout) {
442+
showOutlinesAndSidePages();
443+
} else {
444+
// The layout hints depend on layout being run once
445+
mShowHintsOnLayout = true;
446+
}
447+
}
448+
449+
@Override
450+
public void onAttachedToWindow() {
451+
super.onAttachedToWindow();
452+
mHasMeasure = false;
453+
mHasLayout = false;
454+
}
455+
456+
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
457+
super.onLayout(changed, left, top, right, bottom);
458+
if (mShowHintsOnLayout) {
459+
post(new Runnable() {
460+
@Override
461+
public void run() {
462+
showOutlinesAndSidePages();
463+
}
464+
});
465+
mShowHintsOnLayout = false;
466+
}
467+
mHasLayout = true;
468+
}
469+
470+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
471+
int maxChallengeTop = -1;
472+
View parent = (View) getParent();
473+
boolean challengeShowing = false;
474+
// Widget pages need to know where the top of the sliding challenge is so that they
475+
// now how big the widget should be when the challenge is up. We compute it here and
476+
// then propagate it to each of our children.
477+
if (parent.getParent() instanceof SlidingChallengeLayout) {
478+
SlidingChallengeLayout scl = (SlidingChallengeLayout) parent.getParent();
479+
int top = scl.getMaxChallengeTop();
480+
481+
// This is a bit evil, but we need to map a coordinate relative to the SCL into a
482+
// coordinate relative to our children, hence we subtract the top padding.s
483+
maxChallengeTop = top - getPaddingTop();
484+
challengeShowing = scl.isChallengeShowing();
485+
}
486+
487+
int count = getChildCount();
488+
for (int i = 0; i < count; i++) {
489+
KeyguardWidgetFrame frame = getWidgetPageAt(i);
490+
frame.setMaxChallengeTop(maxChallengeTop);
491+
492+
// On the very first measure pass, if the challenge is showing, we need to make sure
493+
// that the widget on the current page is small.
494+
if (challengeShowing && i == mCurrentPage && !mHasMeasure) {
495+
frame.shrinkWidget();
496+
}
497+
}
498+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
439499
}
440500

441501
void animateOutlinesAndSidePages(final boolean show) {

policy/src/com/android/internal/policy/impl/keyguard/SlidingChallengeLayout.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,9 @@ protected void onMeasure(int widthSpec, int heightSpec) {
681681
final View oldChallengeView = mChallengeView;
682682
mChallengeView = null;
683683
final int count = getChildCount();
684+
685+
// First iteration through the children finds special children and sets any associated
686+
// state.
684687
for (int i = 0; i < count; i++) {
685688
final View child = getChildAt(i);
686689
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
@@ -699,10 +702,22 @@ protected void onMeasure(int widthSpec, int heightSpec) {
699702
} else if (lp.childType == LayoutParams.CHILD_TYPE_SCRIM) {
700703
setScrimView(child);
701704
}
702-
703705
if (child.getVisibility() == GONE) continue;
706+
}
707+
708+
// We want to measure the challenge view first, for various reasons that I'd rather
709+
// not get into here.
710+
if (mChallengeView != null) {
711+
measureChildWithMargins(mChallengeView, widthSpec, 0, heightSpec, 0);
712+
}
704713

705-
measureChildWithMargins(child, widthSpec, 0, heightSpec, 0);
714+
// Measure the rest of the children
715+
for (int i = 0; i < count; i++) {
716+
final View child = getChildAt(i);
717+
// Don't measure the challenge view twice!
718+
if (child != mChallengeView) {
719+
measureChildWithMargins(child, widthSpec, 0, heightSpec, 0);
720+
}
706721
}
707722
}
708723

@@ -747,14 +762,6 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
747762
}
748763

749764
if (!mHasLayout) {
750-
// We want to trigger the initial listener updates outside of layout pass,
751-
// in case the listeners trigger requestLayout().
752-
post(new Runnable() {
753-
@Override
754-
public void run() {
755-
sendInitialListenerUpdates();
756-
}
757-
});
758765
if (mFrameDrawable != null) {
759766
mFrameDrawable.setAlpha(0);
760767
}
@@ -845,7 +852,7 @@ public int getMaxChallengeTop() {
845852
if (mChallengeView == null) return 0;
846853

847854
final int layoutBottom = getLayoutBottom();
848-
final int challengeHeight = mChallengeView.getHeight();
855+
final int challengeHeight = mChallengeView.getMeasuredHeight();
849856
return layoutBottom - challengeHeight;
850857
}
851858

@@ -895,7 +902,7 @@ private int getLayoutBottom() {
895902
final int bottomMargin = (mChallengeView == null)
896903
? 0
897904
: ((LayoutParams) mChallengeView.getLayoutParams()).bottomMargin;
898-
final int layoutBottom = getHeight() - getPaddingBottom() - bottomMargin;
905+
final int layoutBottom = getMeasuredHeight() - getPaddingBottom() - bottomMargin;
899906
return layoutBottom;
900907
}
901908

0 commit comments

Comments
 (0)