FileDocCategorySizeDatePackage
ChangeSimPinScreen.javaAPI DocAndroid 1.5 API10795Wed May 06 22:42:46 BST 2009com.android.phone

ChangeSimPinScreen

public class ChangeSimPinScreen extends android.app.Activity
"Change SIM PIN" UI for the Phone app.

Fields Summary
private static final String
LOG_TAG
private static final boolean
DBG
private static final int
EVENT_PIN_CHANGED
private EntryState
mState
private static final int
NO_ERROR
private static final int
PIN_MISMATCH
private static final int
PIN_INVALID_LENGTH
private static final int
MIN_PIN_LENGTH
private static final int
MAX_PIN_LENGTH
private com.android.internal.telephony.Phone
mPhone
private boolean
mChangePin2
private android.widget.TextView
mBadPinError
private android.widget.TextView
mMismatchError
private android.widget.EditText
mOldPin
private android.widget.EditText
mNewPin1
private android.widget.EditText
mNewPin2
private android.widget.EditText
mPUKCode
private android.widget.Button
mButton
private android.widget.Button
mPUKSubmit
private android.widget.ScrollView
mScrollView
private android.widget.LinearLayout
mSimPUKPanel
private android.os.Handler
mHandler
private View.OnClickListener
mClicked
private android.app.AlertDialog
mPUKAlert
Constructors Summary
Methods Summary
private voiddisplayPUKAlert()

        if (mPUKAlert == null) {
            mPUKAlert = new AlertDialog.Builder(this)
            .setMessage (R.string.puk_requested)
            .setCancelable(false)
            .show();
        } else {
            mPUKAlert.show();
        }
        //TODO: The 3 second delay here is somewhat arbitrary, reflecting the values
        //used elsewhere for similar code.  This should get revisited with the framework
        //crew to see if there is some standard we should adhere to.
        mHandler.postDelayed(new Runnable() {
            public void run() {
                mPUKAlert.dismiss();
            }
        }, 3000);
    
private voidhandleResult(android.os.AsyncResult ar)


        
        if (ar.exception == null) {
            if (DBG) log("handleResult: success!");

            if (mState == EntryState.ES_PUK) {
                mScrollView.setVisibility(View.VISIBLE);
                mSimPUKPanel.setVisibility(View.GONE);
            }            
            // TODO: show success feedback
            showConfirmation();

            mHandler.postDelayed(new Runnable() {
                public void run() {
                    finish();
                }
            }, 3000);

        } else if (ar.exception instanceof CommandException
           /*  && ((CommandException)ar.exception).getCommandError() ==
           CommandException.Error.PASSWORD_INCORRECT */ ) {
            if (mState == EntryState.ES_PIN) {
                if (DBG) log("handleResult: pin failed!");
                mOldPin.getText().clear();
                mBadPinError.setVisibility(View.VISIBLE);
                CommandException ce = (CommandException) ar.exception;
                if (ce.getCommandError() == CommandException.Error.SIM_PUK2) {
                    if (DBG) log("handleResult: puk requested!");
                    mState = EntryState.ES_PUK;
                    displayPUKAlert();
                    mScrollView.setVisibility(View.GONE);
                    mSimPUKPanel.setVisibility(View.VISIBLE);
                    mPUKCode.requestFocus();
                }
            } else if (mState == EntryState.ES_PUK) {
                //should really check to see if the error is CommandException.PASSWORD_INCORRECT...
                if (DBG) log("handleResult: puk2 failed!");
                displayPUKAlert();
                mPUKCode.getText().clear();
                mPUKCode.requestFocus();
            }
        }
    
private voidlog(java.lang.String msg)

        String prefix = mChangePin2 ? "[ChgPin2]" : "[ChgPin]";
        Log.d(LOG_TAG, prefix + msg);
    
public voidonCreate(android.os.Bundle icicle)


        
        super.onCreate(icicle);

        mPhone = PhoneFactory.getDefaultPhone();

        resolveIntent();

        setContentView(R.layout.change_sim_pin_screen);

        mOldPin = (EditText) findViewById(R.id.old_pin);
        mOldPin.setKeyListener(DigitsKeyListener.getInstance());
        mOldPin.setMovementMethod(null);
        mOldPin.setOnClickListener(mClicked);

        mNewPin1 = (EditText) findViewById(R.id.new_pin1);
        mNewPin1.setKeyListener(DigitsKeyListener.getInstance());
        mNewPin1.setMovementMethod(null);
        mNewPin1.setOnClickListener(mClicked);

        mNewPin2 = (EditText) findViewById(R.id.new_pin2);
        mNewPin2.setKeyListener(DigitsKeyListener.getInstance());
        mNewPin2.setMovementMethod(null);
        mNewPin2.setOnClickListener(mClicked);

        mBadPinError = (TextView) findViewById(R.id.bad_pin);
        mMismatchError = (TextView) findViewById(R.id.mismatch);

        mButton = (Button) findViewById(R.id.button);
        mButton.setOnClickListener(mClicked);

        mScrollView = (ScrollView) findViewById(R.id.scroll);
        
        mPUKCode = (EditText) findViewById(R.id.puk_code);
        mPUKCode.setKeyListener(DigitsKeyListener.getInstance());
        mPUKCode.setMovementMethod(null);
        mPUKCode.setOnClickListener(mClicked);
        
        mPUKSubmit = (Button) findViewById(R.id.puk_submit);
        mPUKSubmit.setOnClickListener(mClicked);

        mSimPUKPanel = (LinearLayout) findViewById(R.id.puk_panel);

        int id = mChangePin2 ? R.string.change_pin2 : R.string.change_pin;
        setTitle(getResources().getText(id));
        
        mState = EntryState.ES_PIN;
    
private voidreset()

        mScrollView.scrollTo(0, 0);
        mBadPinError.setVisibility(View.GONE);
        mMismatchError.setVisibility(View.GONE);
    
private voidresolveIntent()

        Intent intent = getIntent();
        mChangePin2 = intent.getBooleanExtra("pin2", mChangePin2);
    
private voidshowConfirmation()

        int id = mChangePin2 ? R.string.pin2_changed : R.string.pin_changed;
        Toast.makeText(this, id, Toast.LENGTH_SHORT).show();
    
private intvalidateNewPin(java.lang.String p1, java.lang.String p2)

        if (p1 == null) {
            return PIN_INVALID_LENGTH;
        }

        if (!p1.equals(p2)) {
            return PIN_MISMATCH;
        }

        int len1 = p1.length();

        if (len1 < MIN_PIN_LENGTH || len1 > MAX_PIN_LENGTH) {
            return PIN_INVALID_LENGTH;
        }

        return NO_ERROR;