Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2c1ce056 authored by Daniel Sandler's avatar Daniel Sandler
Browse files

Cleaning up password input.

Starting to try to show the IME at the right times.

Change-Id: Idc681304c309022666a03c26885a5c94ab4ec2a2
parent 51d39f2d
Loading
Loading
Loading
Loading
+0 −26
Original line number Diff line number Diff line
@@ -77,18 +77,6 @@
                        android:imeOptions="flagForceAscii|actionDone"
                        />

                    <!-- This delete button is only visible for numeric PIN entry -->
                    <ImageButton android:id="@+id/delete_button"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:src="@*android:drawable/ic_input_delete"
                        android:clickable="true"
                        android:padding="8dip"
                        android:background="?android:attr/selectableItemBackground"
                        android:visibility="gone"
                        />

                    <ImageView android:id="@+id/switch_ime_button"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
@@ -101,20 +89,6 @@
                        />

                </LinearLayout>

                <!-- Numeric keyboard -->
                <com.android.internal.widget.PasswordEntryKeyboardView android:id="@+id/keyboard"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="4dip"
                    android:layout_marginEnd="4dip"
                    android:paddingTop="4dip"
                    android:paddingBottom="4dip"
                    android:background="#40000000"
                    android:keyBackground="@*android:drawable/btn_keyboard_key_ics"
                    android:visibility="gone"
                    android:clickable="true"
                />
            </LinearLayout>
        </LinearLayout>
    </FrameLayout>
+0 −3
Original line number Diff line number Diff line
@@ -66,9 +66,6 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
    // any passwords with length less than or equal to this length.
    protected static final int MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT = 3;

    // Enable this if we want to hide the on-screen PIN keyboard when a physical one is showing
    protected static final boolean ENABLE_HIDE_KEYBOARD = false;

    public KeyguardAbsKeyInputView(Context context) {
        this(context, null);
    }
+23 −66
Original line number Diff line number Diff line
@@ -49,16 +49,14 @@ import android.widget.TextView.OnEditorActionListener;

import com.android.internal.widget.PasswordEntryKeyboardHelper;
/**
 * Displays a dialer-like interface or alphanumeric (latin-1) key entry for the user to enter
 * Displays an alphanumeric (latin-1) key entry for the user to enter
 * an unlock password
 */

public class KeyguardPasswordView extends KeyguardAbsKeyInputView
        implements KeyguardSecurityView, OnEditorActionListener, TextWatcher {

    private PasswordEntryKeyboardView mKeyboardView;
    private PasswordEntryKeyboardHelper mKeyboardHelper;
    private boolean mIsAlpha;
    InputMethodManager mImm;

    public KeyguardPasswordView(Context context) {
        super(context);
@@ -69,10 +67,8 @@ public class KeyguardPasswordView extends KeyguardAbsKeyInputView
    }

    protected void resetState() {
        mSecurityMessageDisplay.setMessage(
                mIsAlpha ? R.string.kg_password_instructions : R.string.kg_pin_instructions, false);
        mSecurityMessageDisplay.setMessage(R.string.kg_password_instructions, false);
        mPasswordEntry.setEnabled(true);
        mKeyboardView.setEnabled(true);
    }

    @Override
@@ -81,65 +77,29 @@ public class KeyguardPasswordView extends KeyguardAbsKeyInputView
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        final int quality = mLockPatternUtils.getKeyguardStoredPasswordQuality();
        mIsAlpha = DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC == quality
                || DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC == quality
                || DevicePolicyManager.PASSWORD_QUALITY_COMPLEX == quality;

        mKeyboardView = (PasswordEntryKeyboardView) findViewById(R.id.keyboard);
    public void onResume() {
        super.onResume();
        mImm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    }

        mKeyboardHelper = new PasswordEntryKeyboardHelper(mContext, mKeyboardView, this, false,
                new int[] {
                    R.xml.kg_password_kbd_numeric,
                    com.android.internal.R.xml.password_kbd_qwerty,
                    com.android.internal.R.xml.password_kbd_qwerty_shifted,
                    com.android.internal.R.xml.password_kbd_symbols,
                    com.android.internal.R.xml.password_kbd_symbols_shift
    @Override
    public void onPause() {
        super.onPause();
        mImm.hideSoftInputFromWindow(getWindowToken(), 0);
    }
        );
        mKeyboardHelper.setEnableHaptics(mLockPatternUtils.isTactileFeedbackEnabled());

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        boolean imeOrDeleteButtonVisible = false;
        if (mIsAlpha) {
            // We always use the system IME for alpha keyboard, so hide lockscreen's soft keyboard
            mKeyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_ALPHA);
            mKeyboardView.setVisibility(View.GONE);
        } else {
            mKeyboardHelper.setKeyboardMode(PasswordEntryKeyboardHelper.KEYBOARD_MODE_NUMERIC);

            // Use lockscreen's numeric keyboard if the physical keyboard isn't showing
            boolean hardKeyboardVisible = getResources().getConfiguration().hardKeyboardHidden
                    == Configuration.HARDKEYBOARDHIDDEN_NO;
            mKeyboardView.setVisibility(
                    (ENABLE_HIDE_KEYBOARD && hardKeyboardVisible) ? View.INVISIBLE : View.VISIBLE);

            // The delete button is of the PIN keyboard itself in some (e.g. tablet) layouts,
            // not a separate view
            View pinDelete = findViewById(R.id.delete_button);
            if (pinDelete != null) {
                pinDelete.setVisibility(View.VISIBLE);
                imeOrDeleteButtonVisible = true;
                pinDelete.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {
                        mKeyboardHelper.handleBackspace();
                    }
                });
            }
        }

        // This allows keyboards with overlapping qwerty/numeric keys to choose just numeric keys.
        if (mIsAlpha) {
        mImm = (InputMethodManager) getContext().getSystemService(
                Context.INPUT_METHOD_SERVICE);

        mPasswordEntry.setKeyListener(TextKeyListener.getInstance());
        mPasswordEntry.setInputType(InputType.TYPE_CLASS_TEXT
                | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        } else {
            mPasswordEntry.setKeyListener(DigitsKeyListener.getInstance());
            mPasswordEntry.setInputType(InputType.TYPE_CLASS_NUMBER
                    | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
        }

        // Poke the wakelock any time the text is selected or modified
        mPasswordEntry.setOnClickListener(new OnClickListener() {
@@ -166,15 +126,13 @@ public class KeyguardPasswordView extends KeyguardAbsKeyInputView

        // If there's more than one IME, enable the IME switcher button
        View switchImeButton = findViewById(R.id.switch_ime_button);
        final InputMethodManager imm = (InputMethodManager) getContext().getSystemService(
                Context.INPUT_METHOD_SERVICE);
        if (mIsAlpha && switchImeButton != null && hasMultipleEnabledIMEsOrSubtypes(imm, false)) {
        if (switchImeButton != null && hasMultipleEnabledIMEsOrSubtypes(mImm, false)) {
            switchImeButton.setVisibility(View.VISIBLE);
            imeOrDeleteButtonVisible = true;
            switchImeButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    mCallback.userActivity(0); // Leave the screen on a bit longer
                    imm.showInputMethodPicker();
                    mImm.showInputMethodPicker();
                }
            });
        }
@@ -243,4 +201,3 @@ public class KeyguardPasswordView extends KeyguardAbsKeyInputView
    public void showUsabilityHint() {
    }
}