KeyguardSecurityView接口定义了各锁屏view最基本的方法
public interface KeyguardSecurityView {
static public final int SCREEN_ON = 1;
static public final int VIEW_REVEALED = 2;
//每个view都需要一个KeyguardSecurityCallback和LockPatternUtils
//这里允许set,还允许get KeyguardSecurityCallback
void setKeyguardCallback(KeyguardSecurityCallback callback);
void setLockPatternUtils(LockPatternUtils utils);
KeyguardSecurityCallback getCallback();
/** * Reset the view and prepare to take input. This should do things like clearing the * password or pattern and clear error messages. */
void reset();
//Emulate activity life cycle within the view.
void onPause(); //When called, the view should clean up and prepare to be removed.
void onResume(int reason); //When called, the view should prepare itself to be shown.
//Inquire whether this view requires IME (keyboard) interaction.
boolean needsInput();
void showUsabilityHint();
void showBouncer(int duration);
void hideBouncer(int duration);
}
这个接口一共有多少个实例?或者,一共有多少个锁屏的基本view?
一共有11+2个(一个是所有view的容器KeyguardSecurityViewFlipper,一个是其中几个view的抽象父类KeyguardAbsKeyInputView)。
所以实际一共有11个view:
下面这六个是KeyguardAbsKeyInputView的子类,这些view的特点是都只需要一个可以输入密码的TextView或EditText:
KeyguardAntiTheftLockView
KeyguardPasswordView--密码解锁
KeyguardPINView--PIN解锁
KeyguardSimPinPukView
KeyguardSimPinView
KeyguardSimPukView
KeyguardAccountView--账户解锁
KeyguardFaceUnlockView--人脸解锁
KeyguardPatternView--图案解锁
KeyguardSelectorView--滑动解锁
KeyguardVoiceUnlockView--语音解锁
下面逐一分析接口中各个方法的实现的差异
1. needsInput
只有两个方法返回ture,即需要IME(keyboard) interaction:KeyguardAccountView和KeyguardPasswordView。
需要IME的解锁方式,一定是需要输入字母的,其它需要输入密码的解锁方式(比如KeyguardPINView、KeyguardSimPinView等)只需要输入数字即可。所以它们不需要IME。
2. showUsabilityHint
只有一个view实现了这个方法:KeyguardSelectorView,其它的view都是空实现。
//KeyguardSelectorView.java
public void showUsabilityHint() {
mGlowPadView.ping();
}
//MediatekGlowPadView.java
/**
* Starts wave animation.
*/
public void ping() {
pingInternal();
doShakeAnimation();
}
关于showUsabilityHint方法的调用,在KeyguardHostView.java中有两处;
//KeyguardViewStateManager.java
public void showUsabilityHints() {
mMainQueue.postDelayed( new Runnable() {
@Override
public void run() {
mKeyguardSecurityContainer.showUsabilityHint();
}
} , SCREEN_ON_RING_HINT_DELAY);
......
}
//KeyguardHostView.java
//updateAndAddWidgets和onScreenTurnedOn中调用
mViewStateManager.showUsabilityHints()
//KeyguardHostView.java enableUserSelectorIfNecessary
UserSwitcherCallback callback = new UserSwitcherCallback() {
@Override
public void showUnlockHint() {
if (mKeyguardSelectorView != null) {
mKeyguardSelectorView.showUsabilityHint();
}
}
......
};
mKeyguardMultiUserSelectorView.setCallback(callback);