Skip to content

Commit 8caabad

Browse files
author
Adam Cohen
committed
Making challenge come back if within the same gesture you return to the original page (issue 7422999)
Change-Id: I8ada54ca39ebebc15295f93a2d9029f3b7915acb
1 parent 7f6bb6e commit 8caabad

File tree

3 files changed

+124
-69
lines changed

3 files changed

+124
-69
lines changed

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

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChalle
4343
// Paged view state
4444
private int mPageListeningToSlider = -1;
4545
private int mCurrentPage = -1;
46+
private int mPageIndexOnPageBeginMoving = -1;
4647

4748
int mChallengeTop = 0;
4849

@@ -87,11 +88,24 @@ public void setSecurityViewContainer(KeyguardSecurityView container) {
8788
mKeyguardSecurityContainer = container;
8889
}
8990

91+
public void showBouncer(boolean show) {
92+
mChallengeLayout.showBouncer();
93+
}
94+
95+
public void fadeOutSecurity(int duration) {
96+
((View) mKeyguardSecurityContainer).animate().alpha(0).setDuration(duration);
97+
}
98+
99+
public void fadeInSecurity(int duration) {
100+
((View) mKeyguardSecurityContainer).animate().alpha(1f).setDuration(duration);
101+
}
102+
90103
public void onPageBeginMoving() {
91-
if (mChallengeLayout.isChallengeShowing() &&
104+
if (mChallengeLayout.isChallengeOverlapping() &&
92105
mChallengeLayout instanceof SlidingChallengeLayout) {
93106
SlidingChallengeLayout scl = (SlidingChallengeLayout) mChallengeLayout;
94-
scl.dismissChallengeWithFade();
107+
scl.fadeOutChallenge();
108+
mPageIndexOnPageBeginMoving = mKeyguardWidgetPager.getCurrentPage();
95109
}
96110
if (mHideHintsRunnable != null) {
97111
mMainQueue.removeCallbacks(mHideHintsRunnable);
@@ -100,25 +114,24 @@ public void onPageBeginMoving() {
100114
}
101115

102116
public void onPageEndMoving() {
103-
}
104-
105-
public void showBouncer(boolean show) {
106-
mChallengeLayout.showBouncer();
107-
}
108-
109-
public void fadeOutSecurity(int duration) {
110-
((View) mKeyguardSecurityContainer).animate().alpha(0).setDuration(duration);
111-
}
112-
113-
public void fadeInSecurity(int duration) {
114-
((View) mKeyguardSecurityContainer).animate().alpha(1f).setDuration(duration);
117+
mPageIndexOnPageBeginMoving = -1;
115118
}
116119

117120
public void onPageSwitching(View newPage, int newPageIndex) {
118121
if (mKeyguardWidgetPager != null && mChallengeLayout instanceof SlidingChallengeLayout) {
119122
boolean isCameraPage = newPage instanceof CameraWidgetFrame;
120123
((SlidingChallengeLayout) mChallengeLayout).setChallengeInteractive(!isCameraPage);
121124
}
125+
126+
// If the page we're settling to is the same as we started on, and the action of
127+
// moving the page hid the security, we restore it immediately.
128+
if (mPageIndexOnPageBeginMoving == mKeyguardWidgetPager.getNextPage() &&
129+
mChallengeLayout instanceof SlidingChallengeLayout) {
130+
SlidingChallengeLayout scl = (SlidingChallengeLayout) mChallengeLayout;
131+
scl.fadeInChallenge();
132+
mKeyguardWidgetPager.setWidgetToResetOnPageFadeOut(-1);
133+
}
134+
mPageIndexOnPageBeginMoving = -1;
122135
}
123136

124137
public void onPageSwitched(View newPage, int newPageIndex) {
@@ -131,7 +144,8 @@ public void onPageSwitched(View newPage, int newPageIndex) {
131144

132145
if (mKeyguardWidgetPager != null && mChallengeLayout != null) {
133146
KeyguardWidgetFrame prevPage = mKeyguardWidgetPager.getWidgetPageAt(mCurrentPage);
134-
if (prevPage != null && mCurrentPage != mPageListeningToSlider) {
147+
if (prevPage != null && mCurrentPage != mPageListeningToSlider && mCurrentPage
148+
!= mKeyguardWidgetPager.getWidgetToResetOnPageFadeOut()) {
135149
prevPage.resetSize();
136150
}
137151

@@ -142,6 +156,7 @@ public void onPageSwitched(View newPage, int newPageIndex) {
142156
newCurPage.shrinkWidget();
143157
}
144158
}
159+
145160
mCurrentPage = newPageIndex;
146161
}
147162

@@ -187,7 +202,7 @@ public void onScrollStateChanged(int scrollState) {
187202
if (!mKeyguardWidgetPager.isPageMoving()) {
188203
frame.resetSize();
189204
} else {
190-
mKeyguardWidgetPager.resetWidgetSizeOnPagesFaded(frame);
205+
mKeyguardWidgetPager.setWidgetToResetOnPageFadeOut(mPageListeningToSlider);
191206
}
192207
}
193208
frame.hideFrame(this);

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
7070

7171
private boolean mCameraWidgetEnabled;
7272

73-
private KeyguardWidgetFrame mWidgetToResetAfterFadeOut;
73+
private int mWidgetToResetAfterFadeOut;
7474

7575
// Background worker thread: used here for persistence, also made available to widget frames
7676
private final HandlerThread mBackgroundWorkerThread;
@@ -594,10 +594,14 @@ void animateOutlinesAndSidePages(final boolean show) {
594594
animateOutlinesAndSidePages(show, -1);
595595
}
596596

597-
public void resetWidgetSizeOnPagesFaded(KeyguardWidgetFrame widget) {
597+
public void setWidgetToResetOnPageFadeOut(int widget) {
598598
mWidgetToResetAfterFadeOut = widget;
599599
}
600600

601+
public int getWidgetToResetOnPageFadeOut() {
602+
return mWidgetToResetAfterFadeOut;
603+
}
604+
601605
void animateOutlinesAndSidePages(final boolean show, int duration) {
602606
if (mChildrenOutlineFadeAnimation != null) {
603607
mChildrenOutlineFadeAnimation.cancel();
@@ -648,13 +652,12 @@ public void onAnimationStart(Animator animation) {
648652
public void onAnimationEnd(Animator animation) {
649653
if (!show) {
650654
disablePageContentLayers();
651-
if (mWidgetToResetAfterFadeOut != null) {
652-
if (!(getWidgetPageAt(mCurrentPage) == mWidgetToResetAfterFadeOut &&
653-
mViewStateManager.isChallengeShowing())) {
654-
mWidgetToResetAfterFadeOut.resetSize();
655-
}
656-
mWidgetToResetAfterFadeOut = null;
655+
KeyguardWidgetFrame frame = getWidgetPageAt(mWidgetToResetAfterFadeOut);
656+
if (frame != null && !(frame == getWidgetPageAt(mCurrentPage) &&
657+
mViewStateManager.isChallengeOverlapping())) {
658+
frame.resetSize();
657659
}
660+
mWidgetToResetAfterFadeOut = -1;
658661
}
659662
}
660663
});

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

Lines changed: 82 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public class SlidingChallengeLayout extends ViewGroup implements ChallengeLayout
8686
public static final int SCROLL_STATE_SETTLING = 2;
8787
public static final int SCROLL_STATE_FADING = 3;
8888

89-
private static final int CHALLENGE_FADE_DURATION = 70;
89+
private static final int CHALLENGE_FADE_OUT_DURATION = 100;
90+
private static final int CHALLENGE_FADE_IN_DURATION = 160;
9091

9192
private static final int MAX_SETTLE_DURATION = 600; // ms
9293

@@ -442,9 +443,7 @@ void animateChallengeTo(int y, int velocity) {
442443
return;
443444
}
444445

445-
if (mFader != null) {
446-
mFader.cancel();
447-
}
446+
cancelTransitionsInProgress();
448447

449448
mChallengeInteractiveInternal = false;
450449
mChallengeView.setLayerType(LAYER_TYPE_HARDWARE, null);
@@ -984,6 +983,83 @@ public void computeScroll() {
984983
}
985984
}
986985

986+
private void cancelTransitionsInProgress() {
987+
if (!mScroller.isFinished()) {
988+
mScroller.abortAnimation();
989+
completeChallengeScroll();
990+
}
991+
if (mFader != null) {
992+
mFader.cancel();
993+
}
994+
}
995+
996+
public void fadeInChallenge() {
997+
fadeChallenge(true);
998+
}
999+
1000+
public void fadeOutChallenge() {
1001+
fadeChallenge(false);
1002+
}
1003+
1004+
public void fadeChallenge(final boolean show) {
1005+
if (mChallengeView != null) {
1006+
1007+
cancelTransitionsInProgress();
1008+
float alpha = show ? 1f : 0f;
1009+
int duration = show ? CHALLENGE_FADE_IN_DURATION : CHALLENGE_FADE_OUT_DURATION;
1010+
mFader = ObjectAnimator.ofFloat(mChallengeView, "alpha", alpha);
1011+
mFader.addListener(new AnimatorListenerAdapter() {
1012+
@Override
1013+
public void onAnimationStart(Animator animation) {
1014+
onFadeStart(show);
1015+
}
1016+
@Override
1017+
public void onAnimationEnd(Animator animation) {
1018+
onFadeEnd(show);
1019+
}
1020+
});
1021+
mFader.setDuration(duration);
1022+
mFader.start();
1023+
}
1024+
}
1025+
1026+
private int getMaxChallengeBottom() {
1027+
if (mChallengeView == null) return 0;
1028+
final int layoutBottom = getLayoutBottom();
1029+
final int challengeHeight = mChallengeView.getMeasuredHeight();
1030+
1031+
return (layoutBottom + challengeHeight - mChallengeBottomBound);
1032+
}
1033+
1034+
private int getMinChallengeBottom() {
1035+
return getLayoutBottom();
1036+
}
1037+
1038+
1039+
private void onFadeStart(boolean show) {
1040+
mChallengeInteractiveInternal = false;
1041+
mChallengeView.setLayerType(LAYER_TYPE_HARDWARE, null);
1042+
1043+
if (show) {
1044+
moveChallengeTo(getMinChallengeBottom());
1045+
}
1046+
1047+
setScrollState(SCROLL_STATE_FADING);
1048+
}
1049+
1050+
private void onFadeEnd(boolean show) {
1051+
mChallengeInteractiveInternal = true;
1052+
setChallengeShowing(show);
1053+
1054+
if (!show) {
1055+
moveChallengeTo(getMaxChallengeBottom());
1056+
}
1057+
1058+
mChallengeView.setLayerType(LAYER_TYPE_NONE, null);
1059+
mFader = null;
1060+
setScrollState(SCROLL_STATE_IDLE);
1061+
}
1062+
9871063
public int getMaxChallengeTop() {
9881064
if (mChallengeView == null) return 0;
9891065

@@ -1009,8 +1085,8 @@ private boolean moveChallengeTo(int bottom) {
10091085
final int layoutBottom = getLayoutBottom();
10101086
final int challengeHeight = mChallengeView.getHeight();
10111087

1012-
bottom = Math.max(layoutBottom,
1013-
Math.min(bottom, layoutBottom + challengeHeight - mChallengeBottomBound));
1088+
bottom = Math.max(getMinChallengeBottom(),
1089+
Math.min(bottom, getMaxChallengeBottom()));
10141090

10151091
float offset = 1.f - (float) (bottom - layoutBottom) /
10161092
(challengeHeight - mChallengeBottomBound);
@@ -1064,45 +1140,6 @@ public void showChallenge(boolean show) {
10641140
}
10651141
}
10661142

1067-
public void dismissChallengeWithFade() {
1068-
if (mChallengeView != null) {
1069-
if (!mScroller.isFinished()) {
1070-
mScroller.abortAnimation();
1071-
completeChallengeScroll();
1072-
}
1073-
1074-
mFader = ObjectAnimator.ofFloat(mChallengeView, "alpha", 0f);
1075-
mFader.addListener(new AnimatorListenerAdapter() {
1076-
@Override
1077-
public void onAnimationStart(Animator animation) {
1078-
onFadeStart();
1079-
}
1080-
@Override
1081-
public void onAnimationEnd(Animator animation) {
1082-
onFadeEnd();
1083-
}
1084-
});
1085-
mFader.setDuration(CHALLENGE_FADE_DURATION);
1086-
mFader.start();
1087-
}
1088-
}
1089-
1090-
private void onFadeStart() {
1091-
mChallengeInteractiveInternal = false;
1092-
mChallengeView.setLayerType(LAYER_TYPE_HARDWARE, null);
1093-
setScrollState(SCROLL_STATE_FADING);
1094-
}
1095-
1096-
private void onFadeEnd() {
1097-
mChallengeInteractiveInternal = true;
1098-
setChallengeShowing(false);
1099-
moveChallengeTo(getLayoutBottom() + mChallengeView.getMeasuredHeight());
1100-
mChallengeView.setAlpha(1f);
1101-
mChallengeView.setLayerType(LAYER_TYPE_NONE, null);
1102-
mFader = null;
1103-
setScrollState(SCROLL_STATE_IDLE);
1104-
}
1105-
11061143
private void showChallenge(int velocity) {
11071144
boolean show = false;
11081145
if (Math.abs(velocity) > mMinVelocity) {

0 commit comments

Comments
 (0)