FileDocCategorySizeDatePackage
KeyguardPasswordView.javaAPI DocAndroid 5.1 API10865Thu Mar 12 22:22:42 GMT 2015com.android.keyguard

KeyguardPasswordView

public class KeyguardPasswordView extends KeyguardAbsKeyInputView implements android.text.TextWatcher, android.widget.TextView.OnEditorActionListener, KeyguardSecurityView
Displays an alphanumeric (latin-1) key entry for the user to enter an unlock password

Fields Summary
private final boolean
mShowImeAtScreenOn
private final int
mDisappearYTranslation
android.view.inputmethod.InputMethodManager
mImm
private android.widget.TextView
mPasswordEntry
private android.view.animation.Interpolator
mLinearOutSlowInInterpolator
private android.view.animation.Interpolator
mFastOutLinearInInterpolator
Constructors Summary
public KeyguardPasswordView(android.content.Context context)

        this(context, null);
    
public KeyguardPasswordView(android.content.Context context, android.util.AttributeSet attrs)

        super(context, attrs);
        mShowImeAtScreenOn = context.getResources().
                getBoolean(R.bool.kg_show_ime_at_screen_on);
        mDisappearYTranslation = getResources().getDimensionPixelSize(
                R.dimen.disappear_y_translation);
        mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(
                context, android.R.interpolator.linear_out_slow_in);
        mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator(
                context, android.R.interpolator.fast_out_linear_in);
    
Methods Summary
public voidafterTextChanged(android.text.Editable s)

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

        if (mCallback != null) {
            mCallback.userActivity();
        }
    
protected java.lang.StringgetPasswordText()

        return mPasswordEntry.getText().toString();
    
protected intgetPasswordTextViewId()

        return R.id.passwordEntry;
    
public intgetWrongPasswordStringId()

        return R.string.kg_wrong_password;
    
private booleanhasMultipleEnabledIMEsOrSubtypes(android.view.inputmethod.InputMethodManager imm, boolean shouldIncludeAuxiliarySubtypes)
Method adapted from com.android.inputmethod.latin.Utils

param
imm The input method manager
param
shouldIncludeAuxiliarySubtypes
return
true if we have multiple IMEs to choose from

        final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();

        // Number of the filtered IMEs
        int filteredImisCount = 0;

        for (InputMethodInfo imi : enabledImis) {
            // We can return true immediately after we find two or more filtered IMEs.
            if (filteredImisCount > 1) return true;
            final List<InputMethodSubtype> subtypes =
                    imm.getEnabledInputMethodSubtypeList(imi, true);
            // IMEs that have no subtypes should be counted.
            if (subtypes.isEmpty()) {
                ++filteredImisCount;
                continue;
            }

            int auxCount = 0;
            for (InputMethodSubtype subtype : subtypes) {
                if (subtype.isAuxiliary()) {
                    ++auxCount;
                }
            }
            final int nonAuxCount = subtypes.size() - auxCount;

            // IMEs that have one or more non-auxiliary subtypes should be counted.
            // If shouldIncludeAuxiliarySubtypes is true, IMEs that have two or more auxiliary
            // subtypes should be counted as well.
            if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) {
                ++filteredImisCount;
                continue;
            }
        }

        return filteredImisCount > 1
        // imm.getEnabledInputMethodSubtypeList(null, false) will return the current IME's enabled
        // input method subtype (The current IME should be LatinIME.)
                || imm.getEnabledInputMethodSubtypeList(null, false).size() > 1;
    
public booleanneedsInput()

        return true;
    
public booleanonEditorAction(android.widget.TextView v, int actionId, android.view.KeyEvent event)

        // Check if this was the result of hitting the enter key
        final boolean isSoftImeEvent = event == null
                && (actionId == EditorInfo.IME_NULL
                || actionId == EditorInfo.IME_ACTION_DONE
                || actionId == EditorInfo.IME_ACTION_NEXT);
        final boolean isKeyboardEnterKey = event != null
                && KeyEvent.isConfirmKey(event.getKeyCode())
                && event.getAction() == KeyEvent.ACTION_DOWN;
        if (isSoftImeEvent || isKeyboardEnterKey) {
            verifyPasswordAndUnlock();
            return true;
        }
        return false;
    
protected voidonFinishInflate()

        super.onFinishInflate();

        boolean imeOrDeleteButtonVisible = false;

        mImm = (InputMethodManager) getContext().getSystemService(
                Context.INPUT_METHOD_SERVICE);

        mPasswordEntry = (TextView) findViewById(getPasswordTextViewId());
        mPasswordEntry.setKeyListener(TextKeyListener.getInstance());
        mPasswordEntry.setInputType(InputType.TYPE_CLASS_TEXT
                | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        mPasswordEntry.setOnEditorActionListener(this);
        mPasswordEntry.addTextChangedListener(this);

        // Poke the wakelock any time the text is selected or modified
        mPasswordEntry.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                mCallback.userActivity();
            }
        });

        // Set selected property on so the view can send accessibility events.
        mPasswordEntry.setSelected(true);

        mPasswordEntry.addTextChangedListener(new TextWatcher() {
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            public void afterTextChanged(Editable s) {
                if (mCallback != null) {
                    mCallback.userActivity();
                }
            }
        });

        mPasswordEntry.requestFocus();

        // If there's more than one IME, enable the IME switcher button
        View switchImeButton = findViewById(R.id.switch_ime_button);
        if (switchImeButton != null && hasMultipleEnabledIMEsOrSubtypes(mImm, false)) {
            switchImeButton.setVisibility(View.VISIBLE);
            imeOrDeleteButtonVisible = true;
            switchImeButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    mCallback.userActivity(); // Leave the screen on a bit longer
                    mImm.showInputMethodPicker();
                }
            });
        }

        // If no icon is visible, reset the start margin on the password field so the text is
        // still centered.
        if (!imeOrDeleteButtonVisible) {
            android.view.ViewGroup.LayoutParams params = mPasswordEntry.getLayoutParams();
            if (params instanceof MarginLayoutParams) {
                final MarginLayoutParams mlp = (MarginLayoutParams) params;
                mlp.setMarginStart(0);
                mPasswordEntry.setLayoutParams(params);
            }
        }
    
public voidonPause()

        super.onPause();
        mImm.hideSoftInputFromWindow(getWindowToken(), 0);
    
protected booleanonRequestFocusInDescendants(int direction, android.graphics.Rect previouslyFocusedRect)

        // send focus to the password field
        return mPasswordEntry.requestFocus(direction, previouslyFocusedRect);
    
public voidonResume(int reason)

        super.onResume(reason);

        // Wait a bit to focus the field so the focusable flag on the window is already set then.
        post(new Runnable() {
            @Override
            public void run() {
                if (isShown()) {
                    mPasswordEntry.requestFocus();
                    if (reason != KeyguardSecurityView.SCREEN_ON || mShowImeAtScreenOn) {
                        mImm.showSoftInput(mPasswordEntry, InputMethodManager.SHOW_IMPLICIT);
                    }
                }
            }
        });
    
public voidonTextChanged(java.lang.CharSequence s, int start, int before, int count)

    
public voidreset()

        super.reset();
        mPasswordEntry.requestFocus();
    
protected voidresetPasswordText(boolean animate)

        mPasswordEntry.setText("");
    
protected voidresetState()

        mSecurityMessageDisplay.setMessage(R.string.kg_password_instructions, false);
        mPasswordEntry.setEnabled(true);
    
protected voidsetPasswordEntryEnabled(boolean enabled)

        mPasswordEntry.setEnabled(enabled);
    
public voidshowUsabilityHint()

    
public voidstartAppearAnimation()

        setAlpha(0f);
        setTranslationY(0f);
        animate()
                .alpha(1)
                .withLayer()
                .setDuration(300)
                .setInterpolator(mLinearOutSlowInInterpolator);
    
public booleanstartDisappearAnimation(java.lang.Runnable finishRunnable)

        animate()
                .alpha(0f)
                .translationY(mDisappearYTranslation)
                .setInterpolator(mFastOutLinearInInterpolator)
                .setDuration(100)
                .withEndAction(finishRunnable);
        return true;