blob: 12ea1d586e103336ab5e663b9544893497a88acf [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;
Dave Mankoffe2294692019-08-14 11:53:13 -040027import com.android.systemui.Dependency;
Hyunyoung Song8f9d34c2019-08-30 14:47:43 -070028import com.android.systemui.R;
Jorim Jaggi56733532015-06-09 15:25:40 -070029
Daniel Sandler69bdee72012-10-23 16:45:50 -040030/**
31 * Displays a PIN pad for unlocking.
32 */
Selim Cinek4e8b9ed2014-06-20 16:37:04 -070033public class KeyguardPINView extends KeyguardPinBasedInputView {
Daniel Sandler69bdee72012-10-23 16:45:50 -040034
Jorim Jaggi15a77f72014-05-28 16:20:03 +020035 private final AppearAnimationUtils mAppearAnimationUtils;
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010036 private final DisappearAnimationUtils mDisappearAnimationUtils;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070037 private final DisappearAnimationUtils mDisappearAnimationUtilsLocked;
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010038 private ViewGroup mContainer;
Jorim Jaggi15a77f72014-05-28 16:20:03 +020039 private ViewGroup mRow0;
40 private ViewGroup mRow1;
41 private ViewGroup mRow2;
42 private ViewGroup mRow3;
43 private View mDivider;
Jorim Jaggi76a16232014-08-08 17:00:47 +020044 private int mDisappearYTranslation;
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010045 private View[][] mViews;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070046 private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
Jorim Jaggi15a77f72014-05-28 16:20:03 +020047
Daniel Sandler69bdee72012-10-23 16:45:50 -040048 public KeyguardPINView(Context context) {
49 this(context, null);
50 }
51
52 public KeyguardPINView(Context context, AttributeSet attrs) {
53 super(context, attrs);
Jorim Jaggi15a77f72014-05-28 16:20:03 +020054 mAppearAnimationUtils = new AppearAnimationUtils(context);
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010055 mDisappearAnimationUtils = new DisappearAnimationUtils(context,
56 125, 0.6f /* translationScale */,
Jorim Jaggi94f6f0612015-06-25 14:47:24 -070057 0.45f /* delayScale */, AnimationUtils.loadInterpolator(
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010058 mContext, android.R.interpolator.fast_out_linear_in));
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070059 mDisappearAnimationUtilsLocked = new DisappearAnimationUtils(context,
60 (long) (125 * KeyguardPatternView.DISAPPEAR_MULTIPLIER_LOCKED),
61 0.6f /* translationScale */,
62 0.45f /* delayScale */, AnimationUtils.loadInterpolator(
63 mContext, android.R.interpolator.fast_out_linear_in));
Jorim Jaggi76a16232014-08-08 17:00:47 +020064 mDisappearYTranslation = getResources().getDimensionPixelSize(
65 R.dimen.disappear_y_translation);
Dave Mankoffe2294692019-08-14 11:53:13 -040066 mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
Daniel Sandler69bdee72012-10-23 16:45:50 -040067 }
68
Jim Miller4db942c2016-05-16 18:06:50 -070069 @Override
Daniel Sandler69bdee72012-10-23 16:45:50 -040070 protected void resetState() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -070071 super.resetState();
Lucas Dupin2e838ac2019-04-17 16:50:58 -070072 if (mSecurityMessageDisplay != null) {
73 mSecurityMessageDisplay.setMessage("");
74 }
Daniel Sandler69bdee72012-10-23 16:45:50 -040075 }
76
77 @Override
Daniel Sandler8a26bf52012-10-30 13:29:50 -040078 protected int getPasswordTextViewId() {
79 return R.id.pinEntry;
80 }
81
82 @Override
Daniel Sandler69bdee72012-10-23 16:45:50 -040083 protected void onFinishInflate() {
84 super.onFinishInflate();
85
Alan Viverette51efddb2017-04-05 10:00:01 -040086 mContainer = findViewById(R.id.container);
87 mRow0 = findViewById(R.id.row0);
88 mRow1 = findViewById(R.id.row1);
89 mRow2 = findViewById(R.id.row2);
90 mRow3 = findViewById(R.id.row3);
Jorim Jaggi15a77f72014-05-28 16:20:03 +020091 mDivider = findViewById(R.id.divider);
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010092 mViews = new View[][]{
93 new View[]{
94 mRow0, null, null
95 },
96 new View[]{
97 findViewById(R.id.key1), findViewById(R.id.key2),
98 findViewById(R.id.key3)
99 },
100 new View[]{
101 findViewById(R.id.key4), findViewById(R.id.key5),
102 findViewById(R.id.key6)
103 },
104 new View[]{
105 findViewById(R.id.key7), findViewById(R.id.key8),
106 findViewById(R.id.key9)
107 },
108 new View[]{
Lucas Dupin33b4c282018-10-24 15:26:34 -0700109 findViewById(R.id.delete_button), findViewById(R.id.key0),
110 findViewById(R.id.key_enter)
Selim Cinekf9c0e8f2014-11-11 13:41:02 +0100111 },
112 new View[]{
113 null, mEcaView, null
114 }};
Jian Jin44e4d822018-04-06 12:40:50 -0700115
116 View cancelBtn = findViewById(R.id.cancel_button);
117 if (cancelBtn != null) {
118 cancelBtn.setOnClickListener(view -> {
119 mCallback.reset();
Aarthi Balachander0a427ef2018-07-13 15:00:58 -0700120 mCallback.onCancelClicked();
Jian Jin44e4d822018-04-06 12:40:50 -0700121 });
122 }
Daniel Sandler69bdee72012-10-23 16:45:50 -0400123 }
Adam Cohen6fb841f2012-10-24 13:15:38 -0700124
125 @Override
126 public void showUsabilityHint() {
127 }
Daniel Sandler16d90922012-11-01 12:41:14 -0400128
129 @Override
130 public int getWrongPasswordStringId() {
131 return R.string.kg_wrong_pin;
132 }
Jorim Jaggic14f8292014-05-27 02:25:45 +0200133
134 @Override
135 public void startAppearAnimation() {
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200136 enableClipping(false);
Jorim Jaggifb28c0e2014-08-22 16:28:42 +0200137 setAlpha(1f);
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200138 setTranslationY(mAppearAnimationUtils.getStartTranslation());
Jorim Jaggi613f55f2015-07-16 15:30:10 -0700139 AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */,
140 0, mAppearAnimationUtils.getInterpolator());
Jorim Jaggi56733532015-06-09 15:25:40 -0700141 mAppearAnimationUtils.startAnimation2d(mViews,
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200142 new Runnable() {
143 @Override
144 public void run() {
145 enableClipping(true);
146 }
147 });
148 }
149
Jorim Jaggi76a16232014-08-08 17:00:47 +0200150 @Override
Selim Cinekf9c0e8f2014-11-11 13:41:02 +0100151 public boolean startDisappearAnimation(final Runnable finishRunnable) {
152 enableClipping(false);
153 setTranslationY(0);
Jorim Jaggi613f55f2015-07-16 15:30:10 -0700154 AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 280 /* duration */,
155 mDisappearYTranslation, mDisappearAnimationUtils.getInterpolator());
Jorim Jaggi031f7952016-09-01 16:39:26 -0700156 DisappearAnimationUtils disappearAnimationUtils = mKeyguardUpdateMonitor
157 .needsSlowUnlockTransition()
Jorim Jaggi6bd38902016-09-06 15:27:56 -0700158 ? mDisappearAnimationUtilsLocked
159 : mDisappearAnimationUtils;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -0700160 disappearAnimationUtils.startAnimation2d(mViews,
Selim Cinekf9c0e8f2014-11-11 13:41:02 +0100161 new Runnable() {
162 @Override
163 public void run() {
164 enableClipping(true);
165 if (finishRunnable != null) {
166 finishRunnable.run();
167 }
168 }
169 });
Jorim Jaggi76a16232014-08-08 17:00:47 +0200170 return true;
171 }
172
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200173 private void enableClipping(boolean enable) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100174 mContainer.setClipToPadding(enable);
175 mContainer.setClipChildren(enable);
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200176 mRow1.setClipToPadding(enable);
177 mRow2.setClipToPadding(enable);
178 mRow3.setClipToPadding(enable);
179 setClipChildren(enable);
Jorim Jaggic14f8292014-05-27 02:25:45 +0200180 }
Jorim Jaggi76a16232014-08-08 17:00:47 +0200181
182 @Override
183 public boolean hasOverlappingRendering() {
184 return false;
185 }
Michael Jurka1254f2f2012-10-25 11:44:31 -0700186}