package com.android.internal.policy.impl;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.res.Configuration;
import android.os.RemoteException;
import android.os.ServiceManager;
import com.android.internal.telephony.ITelephony;
import com.android.internal.widget.LockPatternUtils;
import android.text.Editable;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.internal.R;
/**
* Displays a dialer like interface to unlock the SIM PIN.
*/
public class SimUnlockScreen extends LinearLayout implements KeyguardScreen, View.OnClickListener,
KeyguardUpdateMonitor.InfoCallback {
private static final int DIGIT_PRESS_WAKE_MILLIS = 5000;
private final KeyguardUpdateMonitor mUpdateMonitor;
private final KeyguardScreenCallback mCallback;
private TextView mHeaderText;
private TextView mPinText;
private TextView mOkButton;
private Button mEmergencyCallButton;
private View mBackSpaceButton;
private final int[] mEnteredPin = {0, 0, 0, 0, 0, 0, 0, 0};
private int mEnteredDigits = 0;
private ProgressDialog mSimUnlockProgressDialog = null;
private LockPatternUtils mLockPatternUtils;
private int mCreationOrientation;
private int mKeyboardHidden;
private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
public SimUnlockScreen(Context context, Configuration configuration,
KeyguardUpdateMonitor updateMonitor, KeyguardScreenCallback callback,
LockPatternUtils lockpatternutils) {
super(context);
mUpdateMonitor = updateMonitor;
mCallback = callback;
mCreationOrientation = configuration.orientation;
mKeyboardHidden = configuration.hardKeyboardHidden;
mLockPatternUtils = lockpatternutils;
LayoutInflater inflater = LayoutInflater.from(context);
if (mKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
inflater.inflate(R.layout.keyguard_screen_sim_pin_landscape, this, true);
} else {
inflater.inflate(R.layout.keyguard_screen_sim_pin_portrait, this, true);
new TouchInput();
}
mHeaderText = (TextView) findViewById(R.id.headerText);
mPinText = (TextView) findViewById(R.id.pinDisplay);
mBackSpaceButton = findViewById(R.id.backspace);
mBackSpaceButton.setOnClickListener(this);
mEmergencyCallButton = (Button) findViewById(R.id.emergencyCall);
mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyCallButton);
mOkButton = (TextView) findViewById(R.id.ok);
mHeaderText.setText(R.string.keyguard_password_enter_pin_code);
mPinText.setFocusable(false);
mEmergencyCallButton.setOnClickListener(this);
mOkButton.setOnClickListener(this);
setFocusableInTouchMode(true);
}
/** {@inheritDoc} */
public boolean needsInput() {
return true;
}
/** {@inheritDoc} */
public void onPause() {
}
/** {@inheritDoc} */
public void onResume() {
// start fresh
mHeaderText.setText(R.string.keyguard_password_enter_pin_code);
// make sure that the number of entered digits is consistent when we
// erase the SIM unlock code, including orientation changes.
mPinText.setText("");
mEnteredDigits = 0;
mLockPatternUtils.updateEmergencyCallButtonState(mEmergencyCallButton);
}
/** {@inheritDoc} */
public void cleanUp() {
// hide the dialog.
if (mSimUnlockProgressDialog != null) {
mSimUnlockProgressDialog.hide();
}
mUpdateMonitor.removeCallback(this);
}
/**
* Since the IPC can block, we want to run the request in a separate thread
* with a callback.
*/
private abstract class CheckSimPin extends Thread {
private final String mPin;
protected CheckSimPin(String pin) {
mPin = pin;
}
abstract void onSimLockChangedResponse(boolean success);
@Override
public void run() {
try {
final boolean result = ITelephony.Stub.asInterface(ServiceManager
.checkService("phone")).supplyPin(mPin);
post(new Runnable() {
public void run() {
onSimLockChangedResponse(result);
}
});
} catch (RemoteException e) {
post(new Runnable() {
public void run() {
onSimLockChangedResponse(false);
}
});
}
}
}
public void onClick(View v) {
if (v == mBackSpaceButton) {
final Editable digits = mPinText.getEditableText();
final int len = digits.length();
if (len > 0) {
digits.delete(len-1, len);
mEnteredDigits--;
}
mCallback.pokeWakelock();
} else if (v == mEmergencyCallButton) {
mCallback.takeEmergencyCallAction();
} else if (v == mOkButton) {
checkPin();
}
}
private Dialog getSimUnlockProgressDialog() {
if (mSimUnlockProgressDialog == null) {
mSimUnlockProgressDialog = new ProgressDialog(mContext);
mSimUnlockProgressDialog.setMessage(
mContext.getString(R.string.lockscreen_sim_unlock_progress_dialog_message));
mSimUnlockProgressDialog.setIndeterminate(true);
mSimUnlockProgressDialog.setCancelable(false);
mSimUnlockProgressDialog.getWindow().setType(
WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
if (!mContext.getResources().getBoolean(
com.android.internal.R.bool.config_sf_slowBlur)) {
mSimUnlockProgressDialog.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
}
}
return mSimUnlockProgressDialog;
}
private void checkPin() {
// make sure that the pin is at least 4 digits long.
if (mEnteredDigits < 4) {
// otherwise, display a message to the user, and don't submit.
mHeaderText.setText(R.string.invalidPin);
mPinText.setText("");
mEnteredDigits = 0;
mCallback.pokeWakelock();
return;
}
getSimUnlockProgressDialog().show();
new CheckSimPin(mPinText.getText().toString()) {
void onSimLockChangedResponse(boolean success) {
if (mSimUnlockProgressDialog != null) {
mSimUnlockProgressDialog.hide();
}
if (success) {
// before closing the keyguard, report back that
// the sim is unlocked so it knows right away
mUpdateMonitor.reportSimPinUnlocked();
mCallback.goToUnlockScreen();
} else {
mHeaderText.setText(R.string.keyguard_password_wrong_pin_code);
mPinText.setText("");
mEnteredDigits = 0;
}
mCallback.pokeWakelock();
}
}.start();
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
mCallback.goToLockScreen();
return true;
}
final char match = event.getMatch(DIGITS);
if (match != 0) {
reportDigit(match - '0');
return true;
}
if (keyCode
SimUnlockScreen.rar_V2
版权申诉
150 浏览量
2022-09-20
21:21:49
上传
评论
收藏 3KB RAR 举报
weixin_42653672
- 粉丝: 93
- 资源: 1万+
最新资源
- Screenshot_2024-05-28-11-40-58-177_com.tencent.mm.jpg
- 基于Dart的Flutter小提琴调音器APP设计源码 - violinhelper
- 基于JavaScript和CSS的随寻订购网页设计源码 - web-order
- 基于MATLAB的声纹识别系统设计源码 - VoiceprintRecognition
- 基于Java的微服务插件集合设计源码 - wsy-plugins
- 基于Vue和微信小程序的监理日志系统设计源码 - supervisionLog
- 基于Java和LCN分布式事务框架的设计源码 - tx-lcn
- 基于Java和JavaScript的茶叶评级管理系统设计源码 - tea
- IMG_5680.JPG
- IMG_0437.jpg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈