blob: 6808c0f73998e169a34c5429c8ea12e61e551f02 [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;
27
Daniel Sandler69bdee72012-10-23 16:45:50 -040028/**
29 * Displays a PIN pad for unlocking.
30 */
Selim Cinek4e8b9ed2014-06-20 16:37:04 -070031public class KeyguardPINView extends KeyguardPinBasedInputView {
Daniel Sandler69bdee72012-10-23 16:45:50 -040032
Jorim Jaggi15a77f72014-05-28 16:20:03 +020033 private final AppearAnimationUtils mAppearAnimationUtils;
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010034 private final DisappearAnimationUtils mDisappearAnimationUtils;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070035 private final DisappearAnimationUtils mDisappearAnimationUtilsLocked;
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010036 private ViewGroup mContainer;
Jorim Jaggi15a77f72014-05-28 16:20:03 +020037 private ViewGroup mRow0;
38 private ViewGroup mRow1;
39 private ViewGroup mRow2;
40 private ViewGroup mRow3;
41 private View mDivider;
Jorim Jaggi76a16232014-08-08 17:00:47 +020042 private int mDisappearYTranslation;
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010043 private View[][] mViews;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070044 private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
Jorim Jaggi15a77f72014-05-28 16:20:03 +020045
Daniel Sandler69bdee72012-10-23 16:45:50 -040046 public KeyguardPINView(Context context) {
47 this(context, null);
48 }
49
50 public KeyguardPINView(Context context, AttributeSet attrs) {
51 super(context, attrs);
Jorim Jaggi15a77f72014-05-28 16:20:03 +020052 mAppearAnimationUtils = new AppearAnimationUtils(context);
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010053 mDisappearAnimationUtils = new DisappearAnimationUtils(context,
54 125, 0.6f /* translationScale */,
Jorim Jaggi94f6f0612015-06-25 14:47:24 -070055 0.45f /* delayScale */, AnimationUtils.loadInterpolator(
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010056 mContext, android.R.interpolator.fast_out_linear_in));
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070057 mDisappearAnimationUtilsLocked = new DisappearAnimationUtils(context,
58 (long) (125 * KeyguardPatternView.DISAPPEAR_MULTIPLIER_LOCKED),
59 0.6f /* translationScale */,
60 0.45f /* delayScale */, AnimationUtils.loadInterpolator(
61 mContext, android.R.interpolator.fast_out_linear_in));
Jorim Jaggi76a16232014-08-08 17:00:47 +020062 mDisappearYTranslation = getResources().getDimensionPixelSize(
63 R.dimen.disappear_y_translation);
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070064 mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(context);
Daniel Sandler69bdee72012-10-23 16:45:50 -040065 }
66
Jim Miller4db942c2016-05-16 18:06:50 -070067 @Override
Daniel Sandler69bdee72012-10-23 16:45:50 -040068 protected void resetState() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -070069 super.resetState();
Lucas Dupin2e838ac2019-04-17 16:50:58 -070070 if (mSecurityMessageDisplay != null) {
71 mSecurityMessageDisplay.setMessage("");
72 }
Daniel Sandler69bdee72012-10-23 16:45:50 -040073 }
74
75 @Override
Daniel Sandler8a26bf52012-10-30 13:29:50 -040076 protected int getPasswordTextViewId() {
77 return R.id.pinEntry;
78 }
79
80 @Override
Daniel Sandler69bdee72012-10-23 16:45:50 -040081 protected void onFinishInflate() {
82 super.onFinishInflate();
83
Alan Viverette51efddb2017-04-05 10:00:01 -040084 mContainer = findViewById(R.id.container);
85 mRow0 = findViewById(R.id.row0);
86 mRow1 = findViewById(R.id.row1);
87 mRow2 = findViewById(R.id.row2);
88 mRow3 = findViewById(R.id.row3);
Jorim Jaggi15a77f72014-05-28 16:20:03 +020089 mDivider = findViewById(R.id.divider);
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010090 mViews = new View[][]{
91 new View[]{
92 mRow0, null, null
93 },
94 new View[]{
95 findViewById(R.id.key1), findViewById(R.id.key2),
96 findViewById(R.id.key3)
97 },
98 new View[]{
99 findViewById(R.id.key4), findViewById(R.id.key5),
100 findViewById(R.id.key6)
101 },
102 new View[]{
103 findViewById(R.id.key7), findViewById(R.id.key8),
104 findViewById(R.id.key9)
105 },
106 new View[]{
Lucas Dupin33b4c282018-10-24 15:26:34 -0700107 findViewById(R.id.delete_button), findViewById(R.id.key0),
108 findViewById(R.id.key_enter)
Selim Cinekf9c0e8f2014-11-11 13:41:02 +0100109 },
110 new View[]{
111 null, mEcaView, null
112 }};
Jian Jin44e4d822018-04-06 12:40:50 -0700113
114 View cancelBtn = findViewById(R.id.cancel_button);
115 if (cancelBtn != null) {
116 cancelBtn.setOnClickListener(view -> {
117 mCallback.reset();
Aarthi Balachander0a427ef2018-07-13 15:00:58 -0700118 mCallback.onCancelClicked();
Jian Jin44e4d822018-04-06 12:40:50 -0700119 });
120 }
Daniel Sandler69bdee72012-10-23 16:45:50 -0400121 }
Adam Cohen6fb841f2012-10-24 13:15:38 -0700122
123 @Override
124 public void showUsabilityHint() {
125 }
Daniel Sandler16d90922012-11-01 12:41:14 -0400126
127 @Override
128 public int getWrongPasswordStringId() {
129 return R.string.kg_wrong_pin;
130 }
Jorim Jaggic14f8292014-05-27 02:25:45 +0200131
132 @Override
133 public void startAppearAnimation() {
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200134 enableClipping(false);
Jorim Jaggifb28c0e2014-08-22 16:28:42 +0200135 setAlpha(1f);
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200136 setTranslationY(mAppearAnimationUtils.getStartTranslation());
Jorim Jaggi613f55f2015-07-16 15:30:10 -0700137 AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */,
138 0, mAppearAnimationUtils.getInterpolator());
Jorim Jaggi56733532015-06-09 15:25:40 -0700139 mAppearAnimationUtils.startAnimation2d(mViews,
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200140 new Runnable() {
141 @Override
142 public void run() {
143 enableClipping(true);
144 }
145 });
146 }
147
Jorim Jaggi76a16232014-08-08 17:00:47 +0200148 @Override
Selim Cinekf9c0e8f2014-11-11 13:41:02 +0100149 public boolean startDisappearAnimation(final Runnable finishRunnable) {
150 enableClipping(false);
151 setTranslationY(0);
Jorim Jaggi613f55f2015-07-16 15:30:10 -0700152 AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 280 /* duration */,
153 mDisappearYTranslation, mDisappearAnimationUtils.getInterpolator());
Jorim Jaggi031f7952016-09-01 16:39:26 -0700154 DisappearAnimationUtils disappearAnimationUtils = mKeyguardUpdateMonitor
155 .needsSlowUnlockTransition()
Jorim Jaggi6bd38902016-09-06 15:27:56 -0700156 ? mDisappearAnimationUtilsLocked
157 : mDisappearAnimationUtils;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -0700158 disappearAnimationUtils.startAnimation2d(mViews,
Selim Cinekf9c0e8f2014-11-11 13:41:02 +0100159 new Runnable() {
160 @Override
161 public void run() {
162 enableClipping(true);
163 if (finishRunnable != null) {
164 finishRunnable.run();
165 }
166 }
167 });
Jorim Jaggi76a16232014-08-08 17:00:47 +0200168 return true;
169 }
170
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200171 private void enableClipping(boolean enable) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100172 mContainer.setClipToPadding(enable);
173 mContainer.setClipChildren(enable);
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200174 mRow1.setClipToPadding(enable);
175 mRow2.setClipToPadding(enable);
176 mRow3.setClipToPadding(enable);
177 setClipChildren(enable);
Jorim Jaggic14f8292014-05-27 02:25:45 +0200178 }
Jorim Jaggi76a16232014-08-08 17:00:47 +0200179
180 @Override
181 public boolean hasOverlappingRendering() {
182 return false;
183 }
Michael Jurka1254f2f2012-10-25 11:44:31 -0700184}