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