FileDocCategorySizeDatePackage
RestrictionsPinActivity.javaAPI DocAndroid 5.1 API6180Thu Mar 12 22:22:10 GMT 2015com.android.internal.app

RestrictionsPinActivity

public class RestrictionsPinActivity extends AlertActivity implements android.view.View.OnClickListener, android.text.TextWatcher, android.widget.TextView.OnEditorActionListener
This activity is launched by Settings and other apps to either create a new PIN or challenge for an existing PIN. The PIN is maintained by UserManager.

Fields Summary
protected android.os.UserManager
mUserManager
protected boolean
mHasRestrictionsPin
protected android.widget.EditText
mPinText
protected android.widget.TextView
mPinErrorMessage
private android.widget.Button
mOkButton
private android.widget.Button
mCancelButton
private Runnable
mCountdownRunnable
Constructors Summary
Methods Summary
public voidafterTextChanged(android.text.Editable s)

    
public voidbeforeTextChanged(java.lang.CharSequence s, int start, int count, int after)

    
protected voidinitUi()

        AlertController.AlertParams ap = mAlertParams;
        ap.mTitle = getString(R.string.restr_pin_enter_admin_pin);
        LayoutInflater inflater =
                (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        ap.mView = inflater.inflate(R.layout.restrictions_pin_challenge, null);

        mPinErrorMessage = (TextView) ap.mView.findViewById(R.id.pin_error_message);
        mPinText = (EditText) ap.mView.findViewById(R.id.pin_text);
        mOkButton = (Button) ap.mView.findViewById(R.id.pin_ok_button);
        mCancelButton = (Button) ap.mView.findViewById(R.id.pin_cancel_button);

        mPinText.addTextChangedListener(this);

        mOkButton.setOnClickListener(this);
        mCancelButton.setOnClickListener(this);
    
public voidonClick(android.view.View v)


    
        
        if (v == mOkButton) {
            performPositiveButtonAction();
        } else if (v == mCancelButton) {
            setResult(RESULT_CANCELED);
            finish();
        }
    
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);

        mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
        mHasRestrictionsPin = mUserManager.hasRestrictionsChallenge();
        initUi();
        setupAlert();
    
public booleanonEditorAction(android.widget.TextView v, int actionId, android.view.KeyEvent event)

        performPositiveButtonAction();
        return true;
    
public voidonResume()

        super.onResume();

        setPositiveButtonState(false);
        boolean hasPin = mUserManager.hasRestrictionsChallenge();
        if (hasPin) {
            mPinErrorMessage.setVisibility(View.INVISIBLE);
            mPinText.setOnEditorActionListener(this);
            updatePinTimer(-1);
        } else if (verifyingPin()) {
            setResult(RESULT_OK);
            finish();
        }
    
public voidonTextChanged(java.lang.CharSequence s, int start, int before, int count)

        CharSequence pin = mPinText.getText();
        setPositiveButtonState(pin != null && pin.length() >= 4);
    
protected voidperformPositiveButtonAction()

        int result = mUserManager.checkRestrictionsChallenge(mPinText.getText().toString());
        if (result == UserManager.PIN_VERIFICATION_SUCCESS) {
            setResult(RESULT_OK);
            finish();
        } else if (result >= 0) {
            mPinErrorMessage.setText(R.string.restr_pin_incorrect);
            mPinErrorMessage.setVisibility(View.VISIBLE);
            updatePinTimer(result);
            mPinText.setText("");
        }
    
protected voidsetPositiveButtonState(boolean enabled)

        mOkButton.setEnabled(enabled);
    
private booleanupdatePinTimer(int pinTimerMs)

        if (pinTimerMs < 0) {
            pinTimerMs = mUserManager.checkRestrictionsChallenge(null);
        }
        boolean enableInput;
        if (pinTimerMs >= 200) {
            // Do the count down timer for less than a minute, otherwise just say try again later.
            if (pinTimerMs <= 60000) {
                final int seconds = (pinTimerMs + 200) / 1000;
                final String formatString = getResources().getQuantityString(
                        R.plurals.restr_pin_countdown,
                        seconds);
                mPinErrorMessage.setText(String.format(formatString, seconds));
            } else {
                mPinErrorMessage.setText(R.string.restr_pin_try_later);
            }
            enableInput = false;
            mPinErrorMessage.setVisibility(View.VISIBLE);
            mPinText.setText("");
            mPinText.postDelayed(mCountdownRunnable, Math.min(1000, pinTimerMs));
        } else {
            enableInput = true;
            mPinErrorMessage.setText(R.string.restr_pin_incorrect);
        }
        mPinText.setEnabled(enableInput);
        setPositiveButtonState(enableInput);
        return enableInput;
    
protected booleanverifyingPin()

        return true;