blob: 3d1c3f3918f77566a3978f0864f7b8b092532e25 [file] [log] [blame]
Daniel Sandler69bdee72012-10-23 16:45:50 -04001/*
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
Jim Miller5ecd8112013-01-09 18:50:26 -080017package com.android.keyguard;
Daniel Sandler69bdee72012-10-23 16:45:50 -040018
19import android.content.Context;
Daniel Sandler69bdee72012-10-23 16:45:50 -040020import android.text.Editable;
21import android.text.InputType;
Daniel Sandler69bdee72012-10-23 16:45:50 -040022import android.text.TextWatcher;
23import android.text.method.DigitsKeyListener;
Michael Jurka1254f2f2012-10-25 11:44:31 -070024import android.util.AttributeSet;
25import android.view.View;
Daniel Sandler69bdee72012-10-23 16:45:50 -040026import android.widget.TextView.OnEditorActionListener;
27
Daniel Sandler69bdee72012-10-23 16:45:50 -040028/**
29 * Displays a PIN pad for unlocking.
30 */
31public class KeyguardPINView extends KeyguardAbsKeyInputView
32 implements KeyguardSecurityView, OnEditorActionListener, TextWatcher {
33
Daniel Sandler69bdee72012-10-23 16:45:50 -040034 public KeyguardPINView(Context context) {
35 this(context, null);
36 }
37
38 public KeyguardPINView(Context context, AttributeSet attrs) {
39 super(context, attrs);
40 }
41
42 protected void resetState() {
Danielle Millett1625e872012-11-01 15:00:12 -040043 if (KeyguardUpdateMonitor.getInstance(mContext).getMaxBiometricUnlockAttemptsReached()) {
44 mSecurityMessageDisplay.setMessage(R.string.faceunlock_multiple_failures, true);
45 } else {
46 mSecurityMessageDisplay.setMessage(R.string.kg_pin_instructions, false);
47 }
Daniel Sandler69bdee72012-10-23 16:45:50 -040048 mPasswordEntry.setEnabled(true);
49 }
50
51 @Override
Daniel Sandler8a26bf52012-10-30 13:29:50 -040052 protected int getPasswordTextViewId() {
53 return R.id.pinEntry;
54 }
55
56 @Override
Daniel Sandler69bdee72012-10-23 16:45:50 -040057 protected void onFinishInflate() {
58 super.onFinishInflate();
59
Daniel Sandlerd5692742012-10-24 00:21:32 -040060 final View ok = findViewById(R.id.key_enter);
Daniel Sandler69bdee72012-10-23 16:45:50 -040061 if (ok != null) {
62 ok.setOnClickListener(new View.OnClickListener() {
63 @Override
64 public void onClick(View v) {
Daniel Sandler7bc8af32012-10-25 11:12:56 -040065 doHapticKeyClick();
Daniel Sandler6a64ac52012-11-01 11:58:13 -040066 if (mPasswordEntry.isEnabled()) {
67 verifyPasswordAndUnlock();
68 }
Daniel Sandler69bdee72012-10-23 16:45:50 -040069 }
70 });
alanv0cbbc572012-11-02 11:56:27 -070071 ok.setOnHoverListener(new LiftToActivateListener(getContext()));
Daniel Sandler69bdee72012-10-23 16:45:50 -040072 }
73
74 // The delete button is of the PIN keyboard itself in some (e.g. tablet) layouts,
75 // not a separate view
76 View pinDelete = findViewById(R.id.delete_button);
77 if (pinDelete != null) {
78 pinDelete.setVisibility(View.VISIBLE);
79 pinDelete.setOnClickListener(new OnClickListener() {
80 public void onClick(View v) {
Daniel Sandler6a64ac52012-11-01 11:58:13 -040081 // check for time-based lockouts
82 if (mPasswordEntry.isEnabled()) {
83 CharSequence str = mPasswordEntry.getText();
84 if (str.length() > 0) {
85 mPasswordEntry.setText(str.subSequence(0, str.length()-1));
86 }
Daniel Sandler69bdee72012-10-23 16:45:50 -040087 }
Daniel Sandleracb60fb2012-10-25 10:46:37 -040088 doHapticKeyClick();
89 }
90 });
91 pinDelete.setOnLongClickListener(new View.OnLongClickListener() {
92 public boolean onLongClick(View v) {
Daniel Sandler6a64ac52012-11-01 11:58:13 -040093 // check for time-based lockouts
94 if (mPasswordEntry.isEnabled()) {
95 mPasswordEntry.setText("");
96 }
Daniel Sandleracb60fb2012-10-25 10:46:37 -040097 doHapticKeyClick();
98 return true;
Daniel Sandler69bdee72012-10-23 16:45:50 -040099 }
100 });
101 }
102
103 mPasswordEntry.setKeyListener(DigitsKeyListener.getInstance());
104 mPasswordEntry.setInputType(InputType.TYPE_CLASS_NUMBER
105 | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
106
107 mPasswordEntry.requestFocus();
108 }
Adam Cohen6fb841f2012-10-24 13:15:38 -0700109
110 @Override
111 public void showUsabilityHint() {
112 }
Daniel Sandler16d90922012-11-01 12:41:14 -0400113
114 @Override
115 public int getWrongPasswordStringId() {
116 return R.string.kg_wrong_pin;
117 }
Michael Jurka1254f2f2012-10-25 11:44:31 -0700118}