KeyguardViewStateManager.java revision 47c6cfaa3799951f999a4d2000cb628080708551
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 */ 16package com.android.internal.policy.impl.keyguard; 17 18import android.os.Handler; 19import android.os.Looper; 20import android.view.View; 21 22public class KeyguardViewStateManager implements SlidingChallengeLayout.OnChallengeScrolledListener { 23 24 private KeyguardWidgetPager mPagedView; 25 private int mCurrentPageIndex; 26 private ChallengeLayout mChallengeLayout; 27 private Runnable mHideHintsRunnable; 28 private KeyguardSecurityView mKeyguardSecurityContainer; 29 private int[] mTmpPoint = new int[2]; 30 private static final int SCREEN_ON_HINT_DURATION = 1000; 31 private static final int SCREEN_ON_RING_HINT_DELAY = 300; 32 Handler mMainQueue = new Handler(Looper.myLooper()); 33 34 int mChallengeTop = 0; 35 36 public KeyguardViewStateManager() { 37 } 38 39 public void setPagedView(KeyguardWidgetPager pagedView) { 40 mPagedView = pagedView; 41 } 42 43 public void setChallengeLayout(ChallengeLayout layout) { 44 mChallengeLayout = layout; 45 } 46 47 public void setSecurityViewContainer(KeyguardSecurityView container) { 48 mKeyguardSecurityContainer = container; 49 } 50 51 public void onPageBeginMoving() { 52 if (mChallengeLayout.isChallengeShowing()) { 53 mChallengeLayout.showChallenge(false); 54 } 55 if (mHideHintsRunnable != null) { 56 mMainQueue.removeCallbacks(mHideHintsRunnable); 57 mHideHintsRunnable = null; 58 } 59 } 60 61 public void onPageEndMoving() { 62 } 63 64 public void showBouncer(boolean show) { 65 mChallengeLayout.showBouncer(); 66 } 67 68 public void onPageSwitch(View newPage, int newPageIndex) { 69 // Reset the previous page size and ensure the current page is sized appropriately 70 if (mPagedView != null) { 71 KeyguardWidgetFrame oldPage = mPagedView.getWidgetPageAt(mCurrentPageIndex); 72 // Reset the old widget page to full size 73 if (oldPage != null) { 74 oldPage.resetSize(); 75 } 76 77 KeyguardWidgetFrame newCurPage = mPagedView.getWidgetPageAt(newPageIndex); 78 if (mChallengeLayout.isChallengeOverlapping()) { 79 sizeWidgetFrameToChallengeTop(newCurPage); 80 } 81 } 82 mCurrentPageIndex = newPageIndex; 83 } 84 85 private void sizeWidgetFrameToChallengeTop(KeyguardWidgetFrame frame) { 86 if (frame == null) return; 87 mTmpPoint[0] = 0; 88 mTmpPoint[1] = mChallengeTop; 89 mapPoint((View) mChallengeLayout, frame, mTmpPoint); 90 frame.setChallengeTop(mTmpPoint[1]); 91 } 92 93 /** 94 * Simple method to map a point from one view's coordinates to another's. Note: this method 95 * doesn't account for transforms, so if the views will be transformed, this should not be used. 96 * 97 * @param fromView The view to which the point is relative 98 * @param toView The view into which the point should be mapped 99 * @param pt The point 100 */ 101 public void mapPoint(View fromView, View toView, int pt[]) { 102 int[] loc = new int[2]; 103 fromView.getLocationInWindow(loc); 104 int x = loc[0]; 105 int y = loc[1]; 106 107 toView.getLocationInWindow(loc); 108 int vX = loc[0]; 109 int vY = loc[1]; 110 111 pt[0] += x - vX; 112 pt[1] += y - vY; 113 } 114 115 @Override 116 public void onScrollStateChanged(int scrollState) { 117 if (scrollState == SlidingChallengeLayout.SCROLL_STATE_IDLE) { 118 if (mPagedView == null) return; 119 120 boolean challengeOverlapping = mChallengeLayout.isChallengeOverlapping(); 121 int curPage = mPagedView.getCurrentPage(); 122 KeyguardWidgetFrame frame = mPagedView.getWidgetPageAt(curPage); 123 124 if (frame != null) { 125 if (!challengeOverlapping) { 126 frame.resetSize(); 127 } else { 128 sizeWidgetFrameToChallengeTop(frame); 129 } 130 } 131 132 if (challengeOverlapping) { 133 mPagedView.setOnlyAllowEdgeSwipes(true); 134 } else { 135 mPagedView.setOnlyAllowEdgeSwipes(false); 136 } 137 138 if (mChallengeLayout.isChallengeShowing()) { 139 mKeyguardSecurityContainer.onResume(); 140 } else { 141 mKeyguardSecurityContainer.onPause(); 142 } 143 } else { 144 // View is on the move. Pause the security view until it completes. 145 mKeyguardSecurityContainer.onPause(); 146 } 147 } 148 149 public void showUsabilityHints() { 150 mMainQueue.postDelayed( new Runnable() { 151 @Override 152 public void run() { 153 mKeyguardSecurityContainer.showUsabilityHint(); 154 } 155 } , SCREEN_ON_RING_HINT_DELAY); 156 mPagedView.showInitialPageHints(); 157 mHideHintsRunnable = new Runnable() { 158 @Override 159 public void run() { 160 mPagedView.hideOutlinesAndSidePages(); 161 mHideHintsRunnable = null; 162 } 163 }; 164 165 mMainQueue.postDelayed(mHideHintsRunnable, SCREEN_ON_HINT_DURATION); 166 } 167 168 @Override 169 public void onScrollPositionChanged(float scrollPosition, int challengeTop) { 170 mChallengeTop = challengeTop; 171 } 172 173} 174