KeyguardPINView.java revision 7bc8af3abcc09e8093e5af7ea9cd6c4de1cd0b87
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 doHapticKeyClick(); 91 verifyPasswordAndUnlock(); 92 } 93 }); 94 } 95 96 // The delete button is of the PIN keyboard itself in some (e.g. tablet) layouts, 97 // not a separate view 98 View pinDelete = findViewById(R.id.delete_button); 99 if (pinDelete != null) { 100 pinDelete.setVisibility(View.VISIBLE); 101 pinDelete.setOnClickListener(new OnClickListener() { 102 public void onClick(View v) { 103 CharSequence str = mPasswordEntry.getText(); 104 if (str.length() > 0) { 105 mPasswordEntry.setText(str.subSequence(0, str.length()-1)); 106 } 107 doHapticKeyClick(); 108 } 109 }); 110 pinDelete.setOnLongClickListener(new View.OnLongClickListener() { 111 public boolean onLongClick(View v) { 112 mPasswordEntry.setText(""); 113 doHapticKeyClick(); 114 return true; 115 } 116 }); 117 } 118 119 mPasswordEntry.setKeyListener(DigitsKeyListener.getInstance()); 120 mPasswordEntry.setInputType(InputType.TYPE_CLASS_NUMBER 121 | InputType.TYPE_NUMBER_VARIATION_PASSWORD); 122 123 mPasswordEntry.requestFocus(); 124 } 125 126 @Override 127 public void showUsabilityHint() { 128 } 129}