Jim Miller | b5f3b70 | 2012-10-21 19:09:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 16 | package com.android.keyguard; |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 17 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 18 | import android.animation.Animator; |
| 19 | import android.animation.Animator.AnimatorListener; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Adam Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 21 | import android.os.Handler; |
| 22 | import android.os.Looper; |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 23 | import android.view.View; |
| 24 | |
Winson Chung | 48275d2 | 2012-11-05 10:56:31 -0800 | [diff] [blame] | 25 | public class KeyguardViewStateManager implements |
| 26 | SlidingChallengeLayout.OnChallengeScrolledListener, |
| 27 | ChallengeLayout.OnBouncerStateChangedListener { |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 28 | |
Jim Miller | c162dd0 | 2013-09-25 18:57:43 -0700 | [diff] [blame] | 29 | private static final String TAG = "KeyguardViewStateManager"; |
Adam Cohen | 7f6bb6e | 2012-11-04 14:00:05 -0800 | [diff] [blame] | 30 | private KeyguardWidgetPager mKeyguardWidgetPager; |
Jim Miller | 19a5267 | 2012-10-23 19:52:04 -0700 | [diff] [blame] | 31 | private ChallengeLayout mChallengeLayout; |
Adam Cohen | d6f8960 | 2012-11-06 11:46:25 -0800 | [diff] [blame] | 32 | private KeyguardHostView mKeyguardHostView; |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 33 | private int[] mTmpPoint = new int[2]; |
Adam Cohen | 8a7785c | 2012-10-29 22:01:33 -0700 | [diff] [blame] | 34 | private int[] mTmpLoc = new int[2]; |
| 35 | |
| 36 | private KeyguardSecurityView mKeyguardSecurityContainer; |
Adam Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 37 | private static final int SCREEN_ON_HINT_DURATION = 1000; |
Adam Cohen | 47c6cfa | 2012-10-27 18:29:52 -0700 | [diff] [blame] | 38 | private static final int SCREEN_ON_RING_HINT_DELAY = 300; |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 39 | private static final boolean SHOW_INITIAL_PAGE_HINTS = false; |
Adam Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 40 | Handler mMainQueue = new Handler(Looper.myLooper()); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 41 | |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 42 | int mLastScrollState = SlidingChallengeLayout.SCROLL_STATE_IDLE; |
| 43 | |
| 44 | // Paged view state |
| 45 | private int mPageListeningToSlider = -1; |
| 46 | private int mCurrentPage = -1; |
Adam Cohen | 8caabad | 2012-11-04 17:23:25 -0800 | [diff] [blame] | 47 | private int mPageIndexOnPageBeginMoving = -1; |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 48 | |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 49 | int mChallengeTop = 0; |
| 50 | |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 51 | private final AnimatorListener mPauseListener = new AnimatorListenerAdapter() { |
| 52 | public void onAnimationEnd(Animator animation) { |
| 53 | mKeyguardSecurityContainer.onPause(); |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | private final AnimatorListener mResumeListener = new AnimatorListenerAdapter() { |
| 58 | public void onAnimationEnd(Animator animation) { |
| 59 | if (((View)mKeyguardSecurityContainer).isShown()) { |
| 60 | mKeyguardSecurityContainer.onResume(0); |
| 61 | } |
| 62 | } |
| 63 | }; |
| 64 | |
Adam Cohen | d6f8960 | 2012-11-06 11:46:25 -0800 | [diff] [blame] | 65 | public KeyguardViewStateManager(KeyguardHostView hostView) { |
| 66 | mKeyguardHostView = hostView; |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | public void setPagedView(KeyguardWidgetPager pagedView) { |
Adam Cohen | 7f6bb6e | 2012-11-04 14:00:05 -0800 | [diff] [blame] | 70 | mKeyguardWidgetPager = pagedView; |
| 71 | updateEdgeSwiping(); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Jim Miller | 19a5267 | 2012-10-23 19:52:04 -0700 | [diff] [blame] | 74 | public void setChallengeLayout(ChallengeLayout layout) { |
| 75 | mChallengeLayout = layout; |
Adam Cohen | 7f6bb6e | 2012-11-04 14:00:05 -0800 | [diff] [blame] | 76 | updateEdgeSwiping(); |
| 77 | } |
| 78 | |
| 79 | private void updateEdgeSwiping() { |
| 80 | if (mChallengeLayout != null && mKeyguardWidgetPager != null) { |
| 81 | if (mChallengeLayout.isChallengeOverlapping()) { |
| 82 | mKeyguardWidgetPager.setOnlyAllowEdgeSwipes(true); |
| 83 | } else { |
| 84 | mKeyguardWidgetPager.setOnlyAllowEdgeSwipes(false); |
| 85 | } |
| 86 | } |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Winson Chung | 9dc9923 | 2012-10-29 17:43:18 -0700 | [diff] [blame] | 89 | public boolean isChallengeShowing() { |
| 90 | if (mChallengeLayout != null) { |
| 91 | return mChallengeLayout.isChallengeShowing(); |
| 92 | } |
| 93 | return false; |
| 94 | } |
| 95 | |
Winson Chung | 70aa528 | 2012-10-30 10:56:37 -0700 | [diff] [blame] | 96 | public boolean isChallengeOverlapping() { |
| 97 | if (mChallengeLayout != null) { |
| 98 | return mChallengeLayout.isChallengeOverlapping(); |
| 99 | } |
| 100 | return false; |
| 101 | } |
| 102 | |
Adam Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 103 | public void setSecurityViewContainer(KeyguardSecurityView container) { |
| 104 | mKeyguardSecurityContainer = container; |
| 105 | } |
| 106 | |
Jim Miller | b5f3b70 | 2012-10-21 19:09:23 -0700 | [diff] [blame] | 107 | public void showBouncer(boolean show) { |
Jim Miller | 19a5267 | 2012-10-23 19:52:04 -0700 | [diff] [blame] | 108 | mChallengeLayout.showBouncer(); |
Jim Miller | b5f3b70 | 2012-10-21 19:09:23 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 111 | public boolean isBouncing() { |
| 112 | return mChallengeLayout.isBouncing(); |
| 113 | } |
| 114 | |
Adam Cohen | 70009e4 | 2012-10-30 16:48:22 -0700 | [diff] [blame] | 115 | public void fadeOutSecurity(int duration) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 116 | ((View) mKeyguardSecurityContainer).animate().alpha(0f).setDuration(duration) |
Jim Miller | 6b0afad | 2013-10-28 19:08:42 -0700 | [diff] [blame] | 117 | .setListener(mPauseListener); |
Adam Cohen | 70009e4 | 2012-10-30 16:48:22 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | public void fadeInSecurity(int duration) { |
John Spurlock | 56d007b | 2013-10-28 18:40:56 -0400 | [diff] [blame] | 121 | ((View) mKeyguardSecurityContainer).animate().alpha(1f).setDuration(duration) |
Jim Miller | 6b0afad | 2013-10-28 19:08:42 -0700 | [diff] [blame] | 122 | .setListener(mResumeListener); |
Adam Cohen | 70009e4 | 2012-10-30 16:48:22 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Adam Cohen | 8caabad | 2012-11-04 17:23:25 -0800 | [diff] [blame] | 125 | public void onPageBeginMoving() { |
| 126 | if (mChallengeLayout.isChallengeOverlapping() && |
| 127 | mChallengeLayout instanceof SlidingChallengeLayout) { |
| 128 | SlidingChallengeLayout scl = (SlidingChallengeLayout) mChallengeLayout; |
Jim Miller | 6b0afad | 2013-10-28 19:08:42 -0700 | [diff] [blame] | 129 | scl.fadeOutChallenge(); |
Adam Cohen | 8caabad | 2012-11-04 17:23:25 -0800 | [diff] [blame] | 130 | mPageIndexOnPageBeginMoving = mKeyguardWidgetPager.getCurrentPage(); |
| 131 | } |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 132 | // We use mAppWidgetToShow to show a particular widget after you add it-- |
| 133 | // once the user swipes a page we clear that behavior |
| 134 | if (mKeyguardHostView != null) { |
| 135 | mKeyguardHostView.clearAppWidgetToShow(); |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 136 | mKeyguardHostView.setOnDismissAction(null); |
Michael Jurka | 1413889 | 2012-11-07 13:45:53 -0800 | [diff] [blame] | 137 | } |
Adam Cohen | 8caabad | 2012-11-04 17:23:25 -0800 | [diff] [blame] | 138 | if (mHideHintsRunnable != null) { |
| 139 | mMainQueue.removeCallbacks(mHideHintsRunnable); |
| 140 | mHideHintsRunnable = null; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | public void onPageEndMoving() { |
| 145 | mPageIndexOnPageBeginMoving = -1; |
| 146 | } |
| 147 | |
John Spurlock | bb5c941 | 2012-10-31 09:46:15 -0400 | [diff] [blame] | 148 | public void onPageSwitching(View newPage, int newPageIndex) { |
Adam Cohen | 7f6bb6e | 2012-11-04 14:00:05 -0800 | [diff] [blame] | 149 | if (mKeyguardWidgetPager != null && mChallengeLayout instanceof SlidingChallengeLayout) { |
John Spurlock | bb5c941 | 2012-10-31 09:46:15 -0400 | [diff] [blame] | 150 | boolean isCameraPage = newPage instanceof CameraWidgetFrame; |
Jim Miller | c816b8e | 2013-11-12 19:52:12 -0800 | [diff] [blame] | 151 | if (isCameraPage) { |
| 152 | CameraWidgetFrame camera = (CameraWidgetFrame) newPage; |
| 153 | camera.setUseFastTransition(mKeyguardWidgetPager.isWarping()); |
| 154 | } |
Jim Miller | c162dd0 | 2013-09-25 18:57:43 -0700 | [diff] [blame] | 155 | SlidingChallengeLayout scl = (SlidingChallengeLayout) mChallengeLayout; |
| 156 | scl.setChallengeInteractive(!isCameraPage); |
Jim Miller | fadccf1 | 2013-10-13 17:26:39 -0700 | [diff] [blame] | 157 | final int currentFlags = mKeyguardWidgetPager.getSystemUiVisibility(); |
| 158 | final int newFlags = isCameraPage ? (currentFlags | View.STATUS_BAR_DISABLE_SEARCH) |
| 159 | : (currentFlags & ~View.STATUS_BAR_DISABLE_SEARCH); |
| 160 | mKeyguardWidgetPager.setSystemUiVisibility(newFlags); |
John Spurlock | bb5c941 | 2012-10-31 09:46:15 -0400 | [diff] [blame] | 161 | } |
Adam Cohen | 8caabad | 2012-11-04 17:23:25 -0800 | [diff] [blame] | 162 | |
| 163 | // If the page we're settling to is the same as we started on, and the action of |
| 164 | // moving the page hid the security, we restore it immediately. |
| 165 | if (mPageIndexOnPageBeginMoving == mKeyguardWidgetPager.getNextPage() && |
| 166 | mChallengeLayout instanceof SlidingChallengeLayout) { |
| 167 | SlidingChallengeLayout scl = (SlidingChallengeLayout) mChallengeLayout; |
| 168 | scl.fadeInChallenge(); |
| 169 | mKeyguardWidgetPager.setWidgetToResetOnPageFadeOut(-1); |
| 170 | } |
| 171 | mPageIndexOnPageBeginMoving = -1; |
John Spurlock | bb5c941 | 2012-10-31 09:46:15 -0400 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | public void onPageSwitched(View newPage, int newPageIndex) { |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 175 | // Reset the previous page size and ensure the current page is sized appropriately. |
| 176 | // We only modify the page state if it is not currently under control by the slider. |
| 177 | // This prevents conflicts. |
Adam Cohen | 4ddcd57 | 2012-11-01 17:36:32 -0700 | [diff] [blame] | 178 | |
| 179 | // If the page hasn't switched, don't bother with any of this |
Adam Cohen | 2522880 | 2012-11-04 13:20:26 -0800 | [diff] [blame] | 180 | if (mCurrentPage == newPageIndex) return; |
Adam Cohen | 4ddcd57 | 2012-11-01 17:36:32 -0700 | [diff] [blame] | 181 | |
Adam Cohen | 7f6bb6e | 2012-11-04 14:00:05 -0800 | [diff] [blame] | 182 | if (mKeyguardWidgetPager != null && mChallengeLayout != null) { |
| 183 | KeyguardWidgetFrame prevPage = mKeyguardWidgetPager.getWidgetPageAt(mCurrentPage); |
Adam Cohen | 8caabad | 2012-11-04 17:23:25 -0800 | [diff] [blame] | 184 | if (prevPage != null && mCurrentPage != mPageListeningToSlider && mCurrentPage |
| 185 | != mKeyguardWidgetPager.getWidgetToResetOnPageFadeOut()) { |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 186 | prevPage.resetSize(); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Adam Cohen | 7f6bb6e | 2012-11-04 14:00:05 -0800 | [diff] [blame] | 189 | KeyguardWidgetFrame newCurPage = mKeyguardWidgetPager.getWidgetPageAt(newPageIndex); |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 190 | boolean challengeOverlapping = mChallengeLayout.isChallengeOverlapping(); |
| 191 | if (challengeOverlapping && !newCurPage.isSmall() |
| 192 | && mPageListeningToSlider != newPageIndex) { |
Jim Miller | 6b0afad | 2013-10-28 19:08:42 -0700 | [diff] [blame] | 193 | newCurPage.shrinkWidget(true); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 194 | } |
| 195 | } |
Adam Cohen | 8caabad | 2012-11-04 17:23:25 -0800 | [diff] [blame] | 196 | |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 197 | mCurrentPage = newPageIndex; |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 200 | public void onPageBeginWarp() { |
Jim Miller | c162dd0 | 2013-09-25 18:57:43 -0700 | [diff] [blame] | 201 | fadeOutSecurity(SlidingChallengeLayout.CHALLENGE_FADE_OUT_DURATION); |
| 202 | View frame = mKeyguardWidgetPager.getPageAt(mKeyguardWidgetPager.getPageWarpIndex()); |
| 203 | ((KeyguardWidgetFrame)frame).showFrame(this); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | public void onPageEndWarp() { |
Jim Miller | c162dd0 | 2013-09-25 18:57:43 -0700 | [diff] [blame] | 207 | fadeInSecurity(SlidingChallengeLayout.CHALLENGE_FADE_IN_DURATION); |
| 208 | View frame = mKeyguardWidgetPager.getPageAt(mKeyguardWidgetPager.getPageWarpIndex()); |
| 209 | ((KeyguardWidgetFrame)frame).hideFrame(this); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 212 | private int getChallengeTopRelativeToFrame(KeyguardWidgetFrame frame, int top) { |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 213 | mTmpPoint[0] = 0; |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 214 | mTmpPoint[1] = top; |
Jim Miller | 19a5267 | 2012-10-23 19:52:04 -0700 | [diff] [blame] | 215 | mapPoint((View) mChallengeLayout, frame, mTmpPoint); |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 216 | return mTmpPoint[1]; |
| 217 | } |
| 218 | |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 219 | /** |
| 220 | * Simple method to map a point from one view's coordinates to another's. Note: this method |
| 221 | * doesn't account for transforms, so if the views will be transformed, this should not be used. |
| 222 | * |
| 223 | * @param fromView The view to which the point is relative |
| 224 | * @param toView The view into which the point should be mapped |
| 225 | * @param pt The point |
| 226 | */ |
Adam Cohen | 8a7785c | 2012-10-29 22:01:33 -0700 | [diff] [blame] | 227 | private void mapPoint(View fromView, View toView, int pt[]) { |
| 228 | fromView.getLocationInWindow(mTmpLoc); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 229 | |
Adam Cohen | 8a7785c | 2012-10-29 22:01:33 -0700 | [diff] [blame] | 230 | int x = mTmpLoc[0]; |
| 231 | int y = mTmpLoc[1]; |
| 232 | |
| 233 | toView.getLocationInWindow(mTmpLoc); |
| 234 | int vX = mTmpLoc[0]; |
| 235 | int vY = mTmpLoc[1]; |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 236 | |
| 237 | pt[0] += x - vX; |
| 238 | pt[1] += y - vY; |
| 239 | } |
| 240 | |
Adam Cohen | 08c83ef | 2012-11-08 00:25:47 -0800 | [diff] [blame] | 241 | private void userActivity() { |
| 242 | if (mKeyguardHostView != null) { |
| 243 | mKeyguardHostView.onUserActivityTimeoutChanged(); |
| 244 | mKeyguardHostView.userActivity(); |
| 245 | } |
| 246 | } |
| 247 | |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 248 | @Override |
| 249 | public void onScrollStateChanged(int scrollState) { |
Adam Cohen | 7f6bb6e | 2012-11-04 14:00:05 -0800 | [diff] [blame] | 250 | if (mKeyguardWidgetPager == null || mChallengeLayout == null) return; |
Winson Chung | 48275d2 | 2012-11-05 10:56:31 -0800 | [diff] [blame] | 251 | |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 252 | boolean challengeOverlapping = mChallengeLayout.isChallengeOverlapping(); |
| 253 | |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 254 | if (scrollState == SlidingChallengeLayout.SCROLL_STATE_IDLE) { |
Adam Cohen | 7f6bb6e | 2012-11-04 14:00:05 -0800 | [diff] [blame] | 255 | KeyguardWidgetFrame frame = mKeyguardWidgetPager.getWidgetPageAt(mPageListeningToSlider); |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 256 | if (frame == null) return; |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 257 | |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 258 | if (!challengeOverlapping) { |
Adam Cohen | 7f6bb6e | 2012-11-04 14:00:05 -0800 | [diff] [blame] | 259 | if (!mKeyguardWidgetPager.isPageMoving()) { |
Adam Cohen | db1c5d5 | 2012-11-03 17:10:07 -0700 | [diff] [blame] | 260 | frame.resetSize(); |
Adam Cohen | 08c83ef | 2012-11-08 00:25:47 -0800 | [diff] [blame] | 261 | userActivity(); |
Adam Cohen | db1c5d5 | 2012-11-03 17:10:07 -0700 | [diff] [blame] | 262 | } else { |
Adam Cohen | 8caabad | 2012-11-04 17:23:25 -0800 | [diff] [blame] | 263 | mKeyguardWidgetPager.setWidgetToResetOnPageFadeOut(mPageListeningToSlider); |
Adam Cohen | db1c5d5 | 2012-11-03 17:10:07 -0700 | [diff] [blame] | 264 | } |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 265 | } |
Adam Cohen | 44dc141 | 2012-11-07 20:50:39 -0800 | [diff] [blame] | 266 | if (frame.isSmall()) { |
| 267 | // This is to make sure that if the scroller animation gets cut off midway |
| 268 | // that the frame doesn't stay in a partial down position. |
| 269 | frame.setFrameHeight(frame.getSmallFrameHeight()); |
| 270 | } |
Adam Cohen | d51700b3 | 2012-11-07 16:26:46 -0800 | [diff] [blame] | 271 | if (scrollState != SlidingChallengeLayout.SCROLL_STATE_FADING) { |
| 272 | frame.hideFrame(this); |
| 273 | } |
Adam Cohen | 7f6bb6e | 2012-11-04 14:00:05 -0800 | [diff] [blame] | 274 | updateEdgeSwiping(); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 275 | |
Jim Miller | bbba68a | 2012-10-24 22:21:40 -0700 | [diff] [blame] | 276 | if (mChallengeLayout.isChallengeShowing()) { |
Chris Wren | a042ac9 | 2012-11-07 11:37:06 -0500 | [diff] [blame] | 277 | mKeyguardSecurityContainer.onResume(KeyguardSecurityView.VIEW_REVEALED); |
Jim Miller | bbba68a | 2012-10-24 22:21:40 -0700 | [diff] [blame] | 278 | } else { |
| 279 | mKeyguardSecurityContainer.onPause(); |
| 280 | } |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 281 | mPageListeningToSlider = -1; |
| 282 | } else if (mLastScrollState == SlidingChallengeLayout.SCROLL_STATE_IDLE) { |
| 283 | // Whether dragging or settling, if the last state was idle, we use this signal |
| 284 | // to update the current page who will receive events from the sliding challenge. |
| 285 | // We resize the frame as appropriate. |
Adam Cohen | 7f6bb6e | 2012-11-04 14:00:05 -0800 | [diff] [blame] | 286 | mPageListeningToSlider = mKeyguardWidgetPager.getNextPage(); |
| 287 | KeyguardWidgetFrame frame = mKeyguardWidgetPager.getWidgetPageAt(mPageListeningToSlider); |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 288 | if (frame == null) return; |
| 289 | |
Winson Chung | 48275d2 | 2012-11-05 10:56:31 -0800 | [diff] [blame] | 290 | // Skip showing the frame and shrinking the widget if we are |
| 291 | if (!mChallengeLayout.isBouncing()) { |
Adam Cohen | d51700b3 | 2012-11-07 16:26:46 -0800 | [diff] [blame] | 292 | if (scrollState != SlidingChallengeLayout.SCROLL_STATE_FADING) { |
| 293 | frame.showFrame(this); |
| 294 | } |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 295 | |
Winson Chung | 48275d2 | 2012-11-05 10:56:31 -0800 | [diff] [blame] | 296 | // As soon as the security begins sliding, the widget becomes small (if it wasn't |
| 297 | // small to begin with). |
| 298 | if (!frame.isSmall()) { |
| 299 | // We need to fetch the final page, in case the pages are in motion. |
| 300 | mPageListeningToSlider = mKeyguardWidgetPager.getNextPage(); |
Adam Cohen | 44dc141 | 2012-11-07 20:50:39 -0800 | [diff] [blame] | 301 | frame.shrinkWidget(false); |
Winson Chung | 48275d2 | 2012-11-05 10:56:31 -0800 | [diff] [blame] | 302 | } |
| 303 | } else { |
| 304 | if (!frame.isSmall()) { |
| 305 | // We need to fetch the final page, in case the pages are in motion. |
| 306 | mPageListeningToSlider = mKeyguardWidgetPager.getNextPage(); |
| 307 | } |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 308 | } |
Winson Chung | 48275d2 | 2012-11-05 10:56:31 -0800 | [diff] [blame] | 309 | |
Jim Miller | bbba68a | 2012-10-24 22:21:40 -0700 | [diff] [blame] | 310 | // View is on the move. Pause the security view until it completes. |
| 311 | mKeyguardSecurityContainer.onPause(); |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 312 | } |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 313 | mLastScrollState = scrollState; |
| 314 | } |
| 315 | |
| 316 | @Override |
| 317 | public void onScrollPositionChanged(float scrollPosition, int challengeTop) { |
| 318 | mChallengeTop = challengeTop; |
Adam Cohen | 7f6bb6e | 2012-11-04 14:00:05 -0800 | [diff] [blame] | 319 | KeyguardWidgetFrame frame = mKeyguardWidgetPager.getWidgetPageAt(mPageListeningToSlider); |
Adam Cohen | 44dc141 | 2012-11-07 20:50:39 -0800 | [diff] [blame] | 320 | if (frame != null && mLastScrollState != SlidingChallengeLayout.SCROLL_STATE_FADING) { |
Adam Cohen | e364313 | 2012-10-28 18:29:17 -0700 | [diff] [blame] | 321 | frame.adjustFrame(getChallengeTopRelativeToFrame(frame, mChallengeTop)); |
| 322 | } |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Adam Cohen | 196cde9 | 2012-11-02 15:25:32 -0700 | [diff] [blame] | 325 | private Runnable mHideHintsRunnable = new Runnable() { |
| 326 | @Override |
| 327 | public void run() { |
Adam Cohen | 7f6bb6e | 2012-11-04 14:00:05 -0800 | [diff] [blame] | 328 | if (mKeyguardWidgetPager != null) { |
| 329 | mKeyguardWidgetPager.hideOutlinesAndSidePages(); |
Adam Cohen | 196cde9 | 2012-11-02 15:25:32 -0700 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | }; |
| 333 | |
Adam Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 334 | public void showUsabilityHints() { |
Adam Cohen | 47c6cfa | 2012-10-27 18:29:52 -0700 | [diff] [blame] | 335 | mMainQueue.postDelayed( new Runnable() { |
| 336 | @Override |
| 337 | public void run() { |
| 338 | mKeyguardSecurityContainer.showUsabilityHint(); |
| 339 | } |
| 340 | } , SCREEN_ON_RING_HINT_DELAY); |
Jim Miller | caf24fc | 2013-09-10 18:37:01 -0700 | [diff] [blame] | 341 | if (SHOW_INITIAL_PAGE_HINTS) { |
| 342 | mKeyguardWidgetPager.showInitialPageHints(); |
| 343 | } |
Adam Cohen | 196cde9 | 2012-11-02 15:25:32 -0700 | [diff] [blame] | 344 | if (mHideHintsRunnable != null) { |
| 345 | mMainQueue.postDelayed(mHideHintsRunnable, SCREEN_ON_HINT_DURATION); |
| 346 | } |
Adam Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 347 | } |
Jim Miller | e0566da | 2012-10-30 14:57:29 -0700 | [diff] [blame] | 348 | |
Winson Chung | 48275d2 | 2012-11-05 10:56:31 -0800 | [diff] [blame] | 349 | // ChallengeLayout.OnBouncerStateChangedListener |
| 350 | @Override |
| 351 | public void onBouncerStateChanged(boolean bouncerActive) { |
| 352 | if (bouncerActive) { |
| 353 | mKeyguardWidgetPager.zoomOutToBouncer(); |
| 354 | } else { |
| 355 | mKeyguardWidgetPager.zoomInFromBouncer(); |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 356 | if (mKeyguardHostView != null) { |
| 357 | mKeyguardHostView.setOnDismissAction(null); |
| 358 | } |
Winson Chung | 48275d2 | 2012-11-05 10:56:31 -0800 | [diff] [blame] | 359 | } |
| 360 | } |
Jim Miller | d6523da | 2012-10-21 16:47:02 -0700 | [diff] [blame] | 361 | } |