blob: 15d2ea7c32803761ac17b3a33cdeb040ca668cd3 [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;
Michael Jurka1254f2f2012-10-25 11:44:31 -070020import android.util.AttributeSet;
21import android.view.View;
Jorim Jaggi15a77f72014-05-28 16:20:03 +020022import android.view.ViewGroup;
Jorim Jaggi76a16232014-08-08 17:00:47 +020023import android.view.animation.AnimationUtils;
Daniel Sandler69bdee72012-10-23 16:45:50 -040024
Jorim Jaggi56733532015-06-09 15:25:40 -070025import com.android.settingslib.animation.AppearAnimationUtils;
26import com.android.settingslib.animation.DisappearAnimationUtils;
Sunny Goyal87fccf02019-08-13 17:39:10 -070027import com.android.systemui.R;
Jorim Jaggi56733532015-06-09 15:25:40 -070028
Daniel Sandler69bdee72012-10-23 16:45:50 -040029/**
30 * Displays a PIN pad for unlocking.
31 */
Selim Cinek4e8b9ed2014-06-20 16:37:04 -070032public class KeyguardPINView extends KeyguardPinBasedInputView {
Daniel Sandler69bdee72012-10-23 16:45:50 -040033
Jorim Jaggi15a77f72014-05-28 16:20:03 +020034 private final AppearAnimationUtils mAppearAnimationUtils;
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010035 private final DisappearAnimationUtils mDisappearAnimationUtils;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070036 private final DisappearAnimationUtils mDisappearAnimationUtilsLocked;
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010037 private ViewGroup mContainer;
Jorim Jaggi15a77f72014-05-28 16:20:03 +020038 private ViewGroup mRow0;
39 private ViewGroup mRow1;
40 private ViewGroup mRow2;
41 private ViewGroup mRow3;
42 private View mDivider;
Jorim Jaggi76a16232014-08-08 17:00:47 +020043 private int mDisappearYTranslation;
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010044 private View[][] mViews;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070045 private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
Jorim Jaggi15a77f72014-05-28 16:20:03 +020046
Daniel Sandler69bdee72012-10-23 16:45:50 -040047 public KeyguardPINView(Context context) {
48 this(context, null);
49 }
50
51 public KeyguardPINView(Context context, AttributeSet attrs) {
52 super(context, attrs);
Jorim Jaggi15a77f72014-05-28 16:20:03 +020053 mAppearAnimationUtils = new AppearAnimationUtils(context);
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010054 mDisappearAnimationUtils = new DisappearAnimationUtils(context,
55 125, 0.6f /* translationScale */,
Jorim Jaggi94f6f0612015-06-25 14:47:24 -070056 0.45f /* delayScale */, AnimationUtils.loadInterpolator(
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010057 mContext, android.R.interpolator.fast_out_linear_in));
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070058 mDisappearAnimationUtilsLocked = new DisappearAnimationUtils(context,
59 (long) (125 * KeyguardPatternView.DISAPPEAR_MULTIPLIER_LOCKED),
60 0.6f /* translationScale */,
61 0.45f /* delayScale */, AnimationUtils.loadInterpolator(
62 mContext, android.R.interpolator.fast_out_linear_in));
Jorim Jaggi76a16232014-08-08 17:00:47 +020063 mDisappearYTranslation = getResources().getDimensionPixelSize(
64 R.dimen.disappear_y_translation);
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070065 mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(context);
Daniel Sandler69bdee72012-10-23 16:45:50 -040066 }
67
Jim Miller4db942c2016-05-16 18:06:50 -070068 @Override
Daniel Sandler69bdee72012-10-23 16:45:50 -040069 protected void resetState() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -070070 super.resetState();
Lucas Dupin2e838ac2019-04-17 16:50:58 -070071 if (mSecurityMessageDisplay != null) {
72 mSecurityMessageDisplay.setMessage("");
73 }
Daniel Sandler69bdee72012-10-23 16:45:50 -040074 }
75
76 @Override
Daniel Sandler8a26bf52012-10-30 13:29:50 -040077 protected int getPasswordTextViewId() {
78 return R.id.pinEntry;
79 }
80
81 @Override
Daniel Sandler69bdee72012-10-23 16:45:50 -040082 protected void onFinishInflate() {
83 super.onFinishInflate();
84
Alan Viverette51efddb2017-04-05 10:00:01 -040085 mContainer = findViewById(R.id.container);
86 mRow0 = findViewById(R.id.row0);
87 mRow1 = findViewById(R.id.row1);
88 mRow2 = findViewById(R.id.row2);
89 mRow3 = findViewById(R.id.row3);
Jorim Jaggi15a77f72014-05-28 16:20:03 +020090 mDivider = findViewById(R.id.divider);
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010091 mViews = new View[][]{
92 new View[]{
93 mRow0, null, null
94 },
95 new View[]{
96 findViewById(R.id.key1), findViewById(R.id.key2),
97 findViewById(R.id.key3)
98 },
99 new View[]{
100 findViewById(R.id.key4), findViewById(R.id.key5),
101 findViewById(R.id.key6)
102 },
103 new View[]{
104 findViewById(R.id.key7), findViewById(R.id.key8),
105 findViewById(R.id.key9)
106 },
107 new View[]{
Lucas Dupin33b4c282018-10-24 15:26:34 -0700108 findViewById(R.id.delete_button), findViewById(R.id.key0),
109 findViewById(R.id.key_enter)
Selim Cinekf9c0e8f2014-11-11 13:41:02 +0100110 },
111 new View[]{
112 null, mEcaView, null
113 }};
Jian Jin44e4d822018-04-06 12:40:50 -0700114
115 View cancelBtn = findViewById(R.id.cancel_button);
116 if (cancelBtn != null) {
117 cancelBtn.setOnClickListener(view -> {
118 mCallback.reset();
Aarthi Balachander0a427ef2018-07-13 15:00:58 -0700119 mCallback.onCancelClicked();
Jian Jin44e4d822018-04-06 12:40:50 -0700120 });
121 }
Daniel Sandler69bdee72012-10-23 16:45:50 -0400122 }
Adam Cohen6fb841f2012-10-24 13:15:38 -0700123
124 @Override
125 public void showUsabilityHint() {
126 }
Daniel Sandler16d90922012-11-01 12:41:14 -0400127
128 @Override
129 public int getWrongPasswordStringId() {
130 return R.string.kg_wrong_pin;
131 }
Jorim Jaggic14f8292014-05-27 02:25:45 +0200132
133 @Override
134 public void startAppearAnimation() {
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200135 enableClipping(false);
Jorim Jaggifb28c0e2014-08-22 16:28:42 +0200136 setAlpha(1f);
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200137 setTranslationY(mAppearAnimationUtils.getStartTranslation());
Jorim Jaggi613f55f2015-07-16 15:30:10 -0700138 AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */,
139 0, mAppearAnimationUtils.getInterpolator());
Jorim Jaggi56733532015-06-09 15:25:40 -0700140 mAppearAnimationUtils.startAnimation2d(mViews,
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200141 new Runnable() {
142 @Override
143 public void run() {
144 enableClipping(true);
145 }
146 });
147 }
148
Jorim Jaggi76a16232014-08-08 17:00:47 +0200149 @Override
Selim Cinekf9c0e8f2014-11-11 13:41:02 +0100150 public boolean startDisappearAnimation(final Runnable finishRunnable) {
151 enableClipping(false);
152 setTranslationY(0);
Jorim Jaggi613f55f2015-07-16 15:30:10 -0700153 AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 280 /* duration */,
154 mDisappearYTranslation, mDisappearAnimationUtils.getInterpolator());
Jorim Jaggi031f7952016-09-01 16:39:26 -0700155 DisappearAnimationUtils disappearAnimationUtils = mKeyguardUpdateMonitor
156 .needsSlowUnlockTransition()
Jorim Jaggi6bd38902016-09-06 15:27:56 -0700157 ? mDisappearAnimationUtilsLocked
158 : mDisappearAnimationUtils;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -0700159 disappearAnimationUtils.startAnimation2d(mViews,
Selim Cinekf9c0e8f2014-11-11 13:41:02 +0100160 new Runnable() {
161 @Override
162 public void run() {
163 enableClipping(true);
164 if (finishRunnable != null) {
165 finishRunnable.run();
166 }
167 }
168 });
Jorim Jaggi76a16232014-08-08 17:00:47 +0200169 return true;
170 }
171
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200172 private void enableClipping(boolean enable) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100173 mContainer.setClipToPadding(enable);
174 mContainer.setClipChildren(enable);
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200175 mRow1.setClipToPadding(enable);
176 mRow2.setClipToPadding(enable);
177 mRow3.setClipToPadding(enable);
178 setClipChildren(enable);
Jorim Jaggic14f8292014-05-27 02:25:45 +0200179 }
Jorim Jaggi76a16232014-08-08 17:00:47 +0200180
181 @Override
182 public boolean hasOverlappingRendering() {
183 return false;
184 }
Michael Jurka1254f2f2012-10-25 11:44:31 -0700185}