学习Keyguard看到紧急呼叫 顺便看看学学。
关于锁屏流程及解锁 见Android学习——Keyguard之解锁屏
从点加载布局开始:
Keyguard\EmergencCarrierArea.java
protected void onFinishInflate() {//加载布局
super.onFinishInflate();
mCarrierText = (CarrierText) findViewById(R.id.carrier_text);
mEmergencyButton = (EmergencyButton) findViewById(R.id.emergency_call_button);
// The emergency button overlaps the carrier text, only noticeable when highlighted.
// So temporarily hide the carrier text while the emergency button is pressed.
//紧急按钮重叠载文,只有当高亮。因此,当按下紧急按钮暂时隐藏载体的文字。
mEmergencyButton.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
if (mCarrierText.getVisibility() != View.VISIBLE) return false;
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
mCarrierText.animate().alpha(0);//完全透明
break;
case MotionEvent.ACTION_UP:
mCarrierText.animate().alpha(1);//完全显示
break;
}
return false;
}});
}
显示紧急呼叫的界面后点击紧急呼叫:
Keyguard\EmergencyButton.java
onFinishInflate()
protected void onFinishInflate() {
super.onFinishInflate();
mLockPatternUtils = new LockPatternUtils(mContext);
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
setOnClickListener(new OnClickListener() {
public void onClick(View v) {//点击
takeEmergencyCallAction();
}
});
mIsSecure = mLockPatternUtils.isSecure(KeyguardUpdateMonitor.getCurrentUser());
updateEmergencyCallButton();
}
显示紧急拨号器或用户返回到现有的呼叫
takeEmergencyCallAction()
public void takeEmergencyCallAction() {
MetricsLogger.action(mContext, MetricsLogger.ACTION_EMERGENCY_CALL);
mPowerManager.userActivity(SystemClock.uptimeMillis(), true);
try {
ActivityManagerNative.getDefault().stopLockTaskMode();
} catch (RemoteException e) {
Slog.w(LOG_TAG, "Failed to stop app pinning");
}
if (isInCall()) {//正在通话
resumeCall();
if (mEmergencyButtonCallback != null) {
mEmergencyButtonCallback.onEmergencyButtonClickedWhenInCall();
}
} else {
KeyguardUpdateMonitor.getInstance(mContext).reportEmergencyCallAction(
true /* bypassHandler */);
int phoneId = getCurPhoneId();
if (phoneId == -1) {//-1是没PIN/PUK锁,0-3是PIN/PUK锁
phoneId = mEccPhoneIdForNoneSecurityMode;
}
mEmergencyButtonExt.customizeEmergencyIntent(INTENT_EMERGENCY_DIAL, phoneId);
getContext().startActivityAsUser(INTENT_EMERGENCY_DIAL,
ActivityOptions.makeCustomAnimation(getContext(), 0, 0).toBundle(),
new UserHandle(KeyguardUpdateMonitor.getCurrentUser()));
}
}
如果不能理解返回通话见下图,即正在打电话时回到锁屏状态下的keyguard界面。
剩下的不想说了···用到再跟