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