FileDocCategorySizeDatePackage
SimUnlockScreen.javaAPI DocAndroid 1.5 API12017Wed May 06 22:42:06 BST 2009com.android.internal.policy.impl

SimUnlockScreen

public class SimUnlockScreen extends android.widget.LinearLayout implements KeyguardScreen, KeyguardUpdateMonitor.ConfigurationChangeCallback, View.OnClickListener
Displays a dialer like interface to unlock the SIM PIN.

Fields Summary
private static final int
DIGIT_PRESS_WAKE_MILLIS
private final KeyguardUpdateMonitor
mUpdateMonitor
private final KeyguardScreenCallback
mCallback
private final boolean
mCreatedWithKeyboardOpen
private android.widget.TextView
mHeaderText
private android.widget.TextView
mPinText
private android.widget.TextView
mOkButton
private android.widget.TextView
mEmergencyCallButton
private android.view.View
mBackSpaceButton
private final int[]
mEnteredPin
private int
mEnteredDigits
private android.app.ProgressDialog
mSimUnlockProgressDialog
private static final char[]
DIGITS
Constructors Summary
public SimUnlockScreen(android.content.Context context, KeyguardUpdateMonitor updateMonitor, KeyguardScreenCallback callback)


        
              
        super(context);
        mUpdateMonitor = updateMonitor;
        mCallback = callback;
        mCreatedWithKeyboardOpen = mUpdateMonitor.isKeyboardOpen();

        if (mCreatedWithKeyboardOpen) {
            LayoutInflater.from(context).inflate(R.layout.keyguard_screen_sim_pin_landscape, this, true);
        } else {
            LayoutInflater.from(context).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 = (TextView) findViewById(R.id.emergencyCall);
        mOkButton = (TextView) findViewById(R.id.ok);

        mHeaderText.setText(R.string.keyguard_password_enter_pin_code);
        mPinText.setFocusable(false);

        mEmergencyCallButton.setOnClickListener(this);
        mOkButton.setOnClickListener(this);

        mUpdateMonitor.registerConfigurationChangeCallback(this);
        setFocusableInTouchMode(true);
    
Methods Summary
private voidcheckPin()


        // 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 voidcleanUp()
{@inheritDoc}

        // hide the dialog.
        if (mSimUnlockProgressDialog != null) {
            mSimUnlockProgressDialog.hide();
        }
        mUpdateMonitor.removeCallback(this);
    
private android.app.DialoggetSimUnlockProgressDialog()

        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);
            mSimUnlockProgressDialog.getWindow().setFlags(
                    WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
                    WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
        }
        return mSimUnlockProgressDialog;
    
public booleanneedsInput()
{@inheritDoc}

        return true;
    
public voidonClick(android.view.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();
        }
    
public booleanonKeyDown(int keyCode, android.view.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 == KeyEvent.KEYCODE_DEL) {
            if (mEnteredDigits > 0) {
                mPinText.onKeyDown(keyCode, event);
                mEnteredDigits--;
            }
            return true;
        }

        if (keyCode == KeyEvent.KEYCODE_ENTER) {
            checkPin();
            return true;
        }

        return false;
    
public voidonKeyboardChange(boolean isKeyboardOpen)

        if (isKeyboardOpen != mCreatedWithKeyboardOpen) {
            mCallback.recreateMe();
        }
    
public voidonOrientationChange(boolean inPortrait)

public voidonPause()
{@inheritDoc}


    
public voidonResume()
{@inheritDoc}

        // 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;
    
private voidreportDigit(int digit)

        if (mEnteredDigits == 0) {
            mPinText.setText("");
        }
        if (mEnteredDigits == 8) {
            return;
        }
        mPinText.append(Integer.toString(digit));
        mEnteredPin[mEnteredDigits++] = digit;