• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.keyguard;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.view.HapticFeedbackConstants;
22 import android.view.KeyEvent;
23 import android.view.View;
24 
25 import com.android.internal.widget.LockscreenCredential;
26 import com.android.systemui.R;
27 
28 /**
29  * Base class for PIN and password unlock screens.
30  */
31 public abstract class KeyguardAbsKeyInputView extends KeyguardInputView {
32     protected View mEcaView;
33     protected boolean mEnableHaptics;
34 
35     // To avoid accidental lockout due to events while the device in in the pocket, ignore
36     // any passwords with length less than or equal to this length.
37     protected static final int MINIMUM_PASSWORD_LENGTH_BEFORE_REPORT = 3;
38     private KeyDownListener mKeyDownListener;
39 
KeyguardAbsKeyInputView(Context context)40     public KeyguardAbsKeyInputView(Context context) {
41         this(context, null);
42     }
43 
KeyguardAbsKeyInputView(Context context, AttributeSet attrs)44     public KeyguardAbsKeyInputView(Context context, AttributeSet attrs) {
45         super(context, attrs);
46     }
47 
setEnableHaptics(boolean enableHaptics)48     void setEnableHaptics(boolean enableHaptics) {
49         mEnableHaptics = enableHaptics;
50     }
51 
getPasswordTextViewId()52     protected abstract int getPasswordTextViewId();
resetState()53     protected abstract void resetState();
54 
55     @Override
onFinishInflate()56     protected void onFinishInflate() {
57         mEcaView = findViewById(R.id.keyguard_selector_fade_container);
58     }
59 
60     /*
61      * Override this if you have a different string for "wrong password"
62      *
63      * Note that PIN/PUK have their own implementation of verifyPasswordAndUnlock and so don't need this
64      */
getWrongPasswordStringId()65     protected int getWrongPasswordStringId() {
66         return R.string.kg_wrong_password;
67     }
68 
resetPasswordText(boolean animate, boolean announce)69     protected abstract void resetPasswordText(boolean animate, boolean announce);
getEnteredCredential()70     protected abstract LockscreenCredential getEnteredCredential();
setPasswordEntryEnabled(boolean enabled)71     protected abstract void setPasswordEntryEnabled(boolean enabled);
setPasswordEntryInputEnabled(boolean enabled)72     protected abstract void setPasswordEntryInputEnabled(boolean enabled);
73 
74     @Override
onKeyDown(int keyCode, KeyEvent event)75     public boolean onKeyDown(int keyCode, KeyEvent event) {
76         return mKeyDownListener != null && mKeyDownListener.onKeyDown(keyCode, event);
77     }
78 
getPromptReasonStringRes(int reason)79     protected abstract int getPromptReasonStringRes(int reason);
80 
81     // Cause a VIRTUAL_KEY vibration
doHapticKeyClick()82     public void doHapticKeyClick() {
83         if (mEnableHaptics) {
84             performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
85                     HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING
86                     | HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
87         }
88     }
89 
setKeyDownListener(KeyDownListener keyDownListener)90     public void setKeyDownListener(KeyDownListener keyDownListener) {
91         mKeyDownListener = keyDownListener;
92     }
93 
94     public interface KeyDownListener {
onKeyDown(int keyCode, KeyEvent keyEvent)95         boolean onKeyDown(int keyCode, KeyEvent keyEvent);
96     }
97 }
98 
99