Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 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 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 17 | package com.android.keyguard; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 18 | |
| 19 | import android.content.Context; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 20 | import android.text.Editable; |
| 21 | import android.text.InputType; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 22 | import android.text.TextWatcher; |
| 23 | import android.text.method.DigitsKeyListener; |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 24 | import android.util.AttributeSet; |
| 25 | import android.view.View; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 26 | import android.widget.TextView.OnEditorActionListener; |
| 27 | |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 28 | /** |
| 29 | * Displays a PIN pad for unlocking. |
| 30 | */ |
| 31 | public class KeyguardPINView extends KeyguardAbsKeyInputView |
| 32 | implements KeyguardSecurityView, OnEditorActionListener, TextWatcher { |
| 33 | |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 34 | 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 Millett | 1625e87 | 2012-11-01 15:00:12 -0400 | [diff] [blame] | 43 | 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 Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 48 | mPasswordEntry.setEnabled(true); |
| 49 | } |
| 50 | |
| 51 | @Override |
Daniel Sandler | 8a26bf5 | 2012-10-30 13:29:50 -0400 | [diff] [blame] | 52 | protected int getPasswordTextViewId() { |
| 53 | return R.id.pinEntry; |
| 54 | } |
| 55 | |
| 56 | @Override |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 57 | protected void onFinishInflate() { |
| 58 | super.onFinishInflate(); |
| 59 | |
Daniel Sandler | d569274 | 2012-10-24 00:21:32 -0400 | [diff] [blame] | 60 | final View ok = findViewById(R.id.key_enter); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 61 | if (ok != null) { |
| 62 | ok.setOnClickListener(new View.OnClickListener() { |
| 63 | @Override |
| 64 | public void onClick(View v) { |
Daniel Sandler | 7bc8af3 | 2012-10-25 11:12:56 -0400 | [diff] [blame] | 65 | doHapticKeyClick(); |
Daniel Sandler | 6a64ac5 | 2012-11-01 11:58:13 -0400 | [diff] [blame] | 66 | if (mPasswordEntry.isEnabled()) { |
| 67 | verifyPasswordAndUnlock(); |
| 68 | } |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 69 | } |
| 70 | }); |
alanv | 0cbbc57 | 2012-11-02 11:56:27 -0700 | [diff] [blame] | 71 | ok.setOnHoverListener(new LiftToActivateListener(getContext())); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 72 | } |
| 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 Sandler | 6a64ac5 | 2012-11-01 11:58:13 -0400 | [diff] [blame] | 81 | // 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 Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 87 | } |
Daniel Sandler | acb60fb | 2012-10-25 10:46:37 -0400 | [diff] [blame] | 88 | doHapticKeyClick(); |
| 89 | } |
| 90 | }); |
| 91 | pinDelete.setOnLongClickListener(new View.OnLongClickListener() { |
| 92 | public boolean onLongClick(View v) { |
Daniel Sandler | 6a64ac5 | 2012-11-01 11:58:13 -0400 | [diff] [blame] | 93 | // check for time-based lockouts |
| 94 | if (mPasswordEntry.isEnabled()) { |
| 95 | mPasswordEntry.setText(""); |
| 96 | } |
Daniel Sandler | acb60fb | 2012-10-25 10:46:37 -0400 | [diff] [blame] | 97 | doHapticKeyClick(); |
| 98 | return true; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 99 | } |
| 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 Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 109 | |
| 110 | @Override |
| 111 | public void showUsabilityHint() { |
| 112 | } |
Daniel Sandler | 16d9092 | 2012-11-01 12:41:14 -0400 | [diff] [blame] | 113 | |
| 114 | @Override |
| 115 | public int getWrongPasswordStringId() { |
| 116 | return R.string.kg_wrong_pin; |
| 117 | } |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 118 | } |