blob: ca2d61590aec7aa248b6661021dbf27e0487210d [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.InputType;
Daniel Sandler69bdee72012-10-23 16:45:50 -040021import android.text.TextWatcher;
22import android.text.method.DigitsKeyListener;
Michael Jurka1254f2f2012-10-25 11:44:31 -070023import android.util.AttributeSet;
24import android.view.View;
Daniel Sandler69bdee72012-10-23 16:45:50 -040025import android.widget.TextView.OnEditorActionListener;
26
Daniel Sandler69bdee72012-10-23 16:45:50 -040027/**
28 * Displays a PIN pad for unlocking.
29 */
30public class KeyguardPINView extends KeyguardAbsKeyInputView
31 implements KeyguardSecurityView, OnEditorActionListener, TextWatcher {
32
Daniel Sandler69bdee72012-10-23 16:45:50 -040033 public KeyguardPINView(Context context) {
34 this(context, null);
35 }
36
37 public KeyguardPINView(Context context, AttributeSet attrs) {
38 super(context, attrs);
39 }
40
41 protected void resetState() {
Danielle Millett1625e872012-11-01 15:00:12 -040042 if (KeyguardUpdateMonitor.getInstance(mContext).getMaxBiometricUnlockAttemptsReached()) {
43 mSecurityMessageDisplay.setMessage(R.string.faceunlock_multiple_failures, true);
44 } else {
45 mSecurityMessageDisplay.setMessage(R.string.kg_pin_instructions, false);
46 }
Daniel Sandler69bdee72012-10-23 16:45:50 -040047 mPasswordEntry.setEnabled(true);
48 }
49
50 @Override
Daniel Sandler8a26bf52012-10-30 13:29:50 -040051 protected int getPasswordTextViewId() {
52 return R.id.pinEntry;
53 }
54
55 @Override
Daniel Sandler69bdee72012-10-23 16:45:50 -040056 protected void onFinishInflate() {
57 super.onFinishInflate();
58
Daniel Sandlerd5692742012-10-24 00:21:32 -040059 final View ok = findViewById(R.id.key_enter);
Daniel Sandler69bdee72012-10-23 16:45:50 -040060 if (ok != null) {
61 ok.setOnClickListener(new View.OnClickListener() {
62 @Override
63 public void onClick(View v) {
Daniel Sandler7bc8af32012-10-25 11:12:56 -040064 doHapticKeyClick();
Daniel Sandler6a64ac52012-11-01 11:58:13 -040065 if (mPasswordEntry.isEnabled()) {
66 verifyPasswordAndUnlock();
67 }
Daniel Sandler69bdee72012-10-23 16:45:50 -040068 }
69 });
alanv0cbbc572012-11-02 11:56:27 -070070 ok.setOnHoverListener(new LiftToActivateListener(getContext()));
Daniel Sandler69bdee72012-10-23 16:45:50 -040071 }
72
73 // The delete button is of the PIN keyboard itself in some (e.g. tablet) layouts,
74 // not a separate view
75 View pinDelete = findViewById(R.id.delete_button);
76 if (pinDelete != null) {
77 pinDelete.setVisibility(View.VISIBLE);
78 pinDelete.setOnClickListener(new OnClickListener() {
79 public void onClick(View v) {
Daniel Sandler6a64ac52012-11-01 11:58:13 -040080 // check for time-based lockouts
81 if (mPasswordEntry.isEnabled()) {
82 CharSequence str = mPasswordEntry.getText();
83 if (str.length() > 0) {
84 mPasswordEntry.setText(str.subSequence(0, str.length()-1));
85 }
Daniel Sandler69bdee72012-10-23 16:45:50 -040086 }
Daniel Sandleracb60fb2012-10-25 10:46:37 -040087 doHapticKeyClick();
88 }
89 });
90 pinDelete.setOnLongClickListener(new View.OnLongClickListener() {
91 public boolean onLongClick(View v) {
Daniel Sandler6a64ac52012-11-01 11:58:13 -040092 // check for time-based lockouts
93 if (mPasswordEntry.isEnabled()) {
94 mPasswordEntry.setText("");
95 }
Daniel Sandleracb60fb2012-10-25 10:46:37 -040096 doHapticKeyClick();
97 return true;
Daniel Sandler69bdee72012-10-23 16:45:50 -040098 }
99 });
100 }
101
102 mPasswordEntry.setKeyListener(DigitsKeyListener.getInstance());
103 mPasswordEntry.setInputType(InputType.TYPE_CLASS_NUMBER
104 | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
105
106 mPasswordEntry.requestFocus();
107 }
Adam Cohen6fb841f2012-10-24 13:15:38 -0700108
109 @Override
110 public void showUsabilityHint() {
111 }
Daniel Sandler16d90922012-11-01 12:41:14 -0400112
113 @Override
114 public int getWrongPasswordStringId() {
115 return R.string.kg_wrong_pin;
116 }
Michael Jurka1254f2f2012-10-25 11:44:31 -0700117}