EmergencyButtonpublic class EmergencyButton extends android.widget.Button This class implements a smart emergency button that updates itself based
on telephony state. When the phone is idle, it is an emergency call button.
When there's a call in progress, it presents an appropriate message and
allows the user to return to the call. |
Fields Summary |
---|
private static final String | ACTION_EMERGENCY_DIAL | KeyguardUpdateMonitorCallback | mInfoCallback | private com.android.internal.widget.LockPatternUtils | mLockPatternUtils | private android.os.PowerManager | mPowerManager |
Methods Summary |
---|
protected void | onAttachedToWindow()
super.onAttachedToWindow();
KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mInfoCallback);
| protected void | onDetachedFromWindow()
super.onDetachedFromWindow();
KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mInfoCallback);
| 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();
}
});
updateEmergencyCallButton();
| public void | takeEmergencyCallAction()Shows the emergency dialer or returns the user to the existing call.
// TODO: implement a shorter timeout once new PowerManager API is ready.
// should be the equivalent to the old userActivity(EMERGENCY_CALL_TIMEOUT)
mPowerManager.userActivity(SystemClock.uptimeMillis(), true);
if (mLockPatternUtils.isInCall()) {
mLockPatternUtils.resumeCall();
} else {
final boolean bypassHandler = true;
KeyguardUpdateMonitor.getInstance(mContext).reportEmergencyCallAction(bypassHandler);
Intent intent = new Intent(ACTION_EMERGENCY_DIAL);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
getContext().startActivityAsUser(intent,
new UserHandle(mLockPatternUtils.getCurrentUser()));
}
| private void | updateEmergencyCallButton()
boolean enabled = false;
if (mLockPatternUtils.isInCall()) {
enabled = true; // always show "return to call" if phone is off-hook
} else if (mLockPatternUtils.isEmergencyCallCapable()) {
final boolean simLocked = KeyguardUpdateMonitor.getInstance(mContext).isSimPinVoiceSecure();
if (simLocked) {
// Some countries can't handle emergency calls while SIM is locked.
enabled = mLockPatternUtils.isEmergencyCallEnabledWhileSimLocked();
} else {
// True if we need to show a secure screen (pin/pattern/SIM pin/SIM puk);
// hides emergency button on "Slide" screen if device is not secure.
enabled = mLockPatternUtils.isSecure();
}
}
mLockPatternUtils.updateEmergencyCallButtonState(this, enabled, false);
|
|