KeyguardPINView.java revision d5692742c1ff056e9fe55a495632229c86ed5384
1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.internal.policy.impl.keyguard;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.view.View;
22import android.view.ViewParent;
23
24import com.android.internal.widget.LockPatternUtils;
25import java.util.List;
26
27import android.app.admin.DevicePolicyManager;
28import android.content.res.Configuration;
29import android.graphics.Rect;
30
31import com.android.internal.widget.PasswordEntryKeyboardView;
32
33import android.os.CountDownTimer;
34import android.os.SystemClock;
35import android.text.Editable;
36import android.text.InputType;
37import android.text.SpannableStringBuilder;
38import android.text.TextWatcher;
39import android.text.method.DigitsKeyListener;
40import android.text.method.TextKeyListener;
41import android.text.style.TextAppearanceSpan;
42import android.view.KeyEvent;
43import android.view.inputmethod.EditorInfo;
44import android.view.inputmethod.InputMethodInfo;
45import android.view.inputmethod.InputMethodManager;
46import android.view.inputmethod.InputMethodSubtype;
47import android.widget.Button;
48import android.widget.EditText;
49import android.widget.LinearLayout;
50import android.widget.TextView;
51import android.widget.TextView.OnEditorActionListener;
52
53import com.android.internal.R;
54
55/**
56 * Displays a PIN pad for unlocking.
57 */
58public class KeyguardPINView extends KeyguardAbsKeyInputView
59        implements KeyguardSecurityView, OnEditorActionListener, TextWatcher {
60
61    // To avoid accidental lockout due to events while the device in in the pocket, ignore
62    // any passwords with length less than or equal to this length.
63    private static final int MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT = 3;
64
65    // Enable this if we want to hide the on-screen PIN keyboard when a physical one is showing
66    private static final boolean ENABLE_HIDE_KEYBOARD = false;
67
68    public KeyguardPINView(Context context) {
69        this(context, null);
70    }
71
72    public KeyguardPINView(Context context, AttributeSet attrs) {
73        super(context, attrs);
74    }
75
76    protected void resetState() {
77        mSecurityMessageDisplay.setMessage(R.string.kg_pin_instructions, false);
78        mPasswordEntry.setEnabled(true);
79    }
80
81    @Override
82    protected void onFinishInflate() {
83        super.onFinishInflate();
84
85        final View ok = findViewById(R.id.key_enter);
86        if (ok != null) {
87            ok.setOnClickListener(new View.OnClickListener() {
88                @Override
89                public void onClick(View v) {
90                    verifyPasswordAndUnlock();
91                }
92            });
93        }
94
95        // The delete button is of the PIN keyboard itself in some (e.g. tablet) layouts,
96        // not a separate view
97        View pinDelete = findViewById(R.id.delete_button);
98        if (pinDelete != null) {
99            pinDelete.setVisibility(View.VISIBLE);
100            pinDelete.setOnClickListener(new OnClickListener() {
101                public void onClick(View v) {
102                    CharSequence str = mPasswordEntry.getText();
103                    if (str.length() > 0) {
104                        mPasswordEntry.setText(str.subSequence(0, str.length()-1));
105                    }
106                }
107            });
108        }
109
110        mPasswordEntry.setKeyListener(DigitsKeyListener.getInstance());
111        mPasswordEntry.setInputType(InputType.TYPE_CLASS_NUMBER
112                | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
113
114        mPasswordEntry.requestFocus();
115    }
116
117    @Override
118    public void showUsabilityHint() {
119    }
120}
121
122