blob: 4f5152aca6f38ebcfda5fcd9521978ed2a1a4b94 [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
Jorim Jaggi613f55f2015-07-16 15:30:10 -070019import android.animation.Animator;
20import android.animation.ObjectAnimator;
Daniel Sandler69bdee72012-10-23 16:45:50 -040021import android.content.Context;
Michael Jurka1254f2f2012-10-25 11:44:31 -070022import android.util.AttributeSet;
Jorim Jaggi613f55f2015-07-16 15:30:10 -070023import android.view.RenderNode;
24import android.view.RenderNodeAnimator;
Michael Jurka1254f2f2012-10-25 11:44:31 -070025import android.view.View;
Jorim Jaggi15a77f72014-05-28 16:20:03 +020026import android.view.ViewGroup;
Jorim Jaggi76a16232014-08-08 17:00:47 +020027import android.view.animation.AnimationUtils;
Daniel Sandler69bdee72012-10-23 16:45:50 -040028
Jorim Jaggi56733532015-06-09 15:25:40 -070029import com.android.settingslib.animation.AppearAnimationUtils;
30import com.android.settingslib.animation.DisappearAnimationUtils;
31
Daniel Sandler69bdee72012-10-23 16:45:50 -040032/**
33 * Displays a PIN pad for unlocking.
34 */
Selim Cinek4e8b9ed2014-06-20 16:37:04 -070035public class KeyguardPINView extends KeyguardPinBasedInputView {
Daniel Sandler69bdee72012-10-23 16:45:50 -040036
Jorim Jaggi15a77f72014-05-28 16:20:03 +020037 private final AppearAnimationUtils mAppearAnimationUtils;
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010038 private final DisappearAnimationUtils mDisappearAnimationUtils;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070039 private final DisappearAnimationUtils mDisappearAnimationUtilsLocked;
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010040 private ViewGroup mContainer;
Jorim Jaggi15a77f72014-05-28 16:20:03 +020041 private ViewGroup mRow0;
42 private ViewGroup mRow1;
43 private ViewGroup mRow2;
44 private ViewGroup mRow3;
45 private View mDivider;
Jorim Jaggi76a16232014-08-08 17:00:47 +020046 private int mDisappearYTranslation;
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010047 private View[][] mViews;
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070048 private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
Jorim Jaggi15a77f72014-05-28 16:20:03 +020049
Daniel Sandler69bdee72012-10-23 16:45:50 -040050 public KeyguardPINView(Context context) {
51 this(context, null);
52 }
53
54 public KeyguardPINView(Context context, AttributeSet attrs) {
55 super(context, attrs);
Jorim Jaggi15a77f72014-05-28 16:20:03 +020056 mAppearAnimationUtils = new AppearAnimationUtils(context);
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010057 mDisappearAnimationUtils = new DisappearAnimationUtils(context,
58 125, 0.6f /* translationScale */,
Jorim Jaggi94f6f0612015-06-25 14:47:24 -070059 0.45f /* delayScale */, AnimationUtils.loadInterpolator(
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010060 mContext, android.R.interpolator.fast_out_linear_in));
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070061 mDisappearAnimationUtilsLocked = new DisappearAnimationUtils(context,
62 (long) (125 * KeyguardPatternView.DISAPPEAR_MULTIPLIER_LOCKED),
63 0.6f /* translationScale */,
64 0.45f /* delayScale */, AnimationUtils.loadInterpolator(
65 mContext, android.R.interpolator.fast_out_linear_in));
Jorim Jaggi76a16232014-08-08 17:00:47 +020066 mDisappearYTranslation = getResources().getDimensionPixelSize(
67 R.dimen.disappear_y_translation);
Jorim Jaggie8fde5d2016-06-30 23:41:37 -070068 mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(context);
Daniel Sandler69bdee72012-10-23 16:45:50 -040069 }
70
Jim Miller4db942c2016-05-16 18:06:50 -070071 @Override
Daniel Sandler69bdee72012-10-23 16:45:50 -040072 protected void resetState() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -070073 super.resetState();
Jorim Jaggi8a8941a2014-12-19 19:49:38 +010074 mSecurityMessageDisplay.setMessage(R.string.kg_pin_instructions, false);
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
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010086 mContainer = (ViewGroup) findViewById(R.id.container);
Jorim Jaggi15a77f72014-05-28 16:20:03 +020087 mRow0 = (ViewGroup) findViewById(R.id.row0);
88 mRow1 = (ViewGroup) findViewById(R.id.row1);
89 mRow2 = (ViewGroup) findViewById(R.id.row2);
90 mRow3 = (ViewGroup) findViewById(R.id.row3);
91 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[]{
109 null, findViewById(R.id.key0), findViewById(R.id.key_enter)
110 },
111 new View[]{
112 null, mEcaView, null
113 }};
Daniel Sandler69bdee72012-10-23 16:45:50 -0400114 }
Adam Cohen6fb841f2012-10-24 13:15:38 -0700115
116 @Override
117 public void showUsabilityHint() {
118 }
Daniel Sandler16d90922012-11-01 12:41:14 -0400119
120 @Override
121 public int getWrongPasswordStringId() {
122 return R.string.kg_wrong_pin;
123 }
Jorim Jaggic14f8292014-05-27 02:25:45 +0200124
125 @Override
126 public void startAppearAnimation() {
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200127 enableClipping(false);
Jorim Jaggifb28c0e2014-08-22 16:28:42 +0200128 setAlpha(1f);
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200129 setTranslationY(mAppearAnimationUtils.getStartTranslation());
Jorim Jaggi613f55f2015-07-16 15:30:10 -0700130 AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */,
131 0, mAppearAnimationUtils.getInterpolator());
Jorim Jaggi56733532015-06-09 15:25:40 -0700132 mAppearAnimationUtils.startAnimation2d(mViews,
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200133 new Runnable() {
134 @Override
135 public void run() {
136 enableClipping(true);
137 }
138 });
139 }
140
Jorim Jaggi76a16232014-08-08 17:00:47 +0200141 @Override
Selim Cinekf9c0e8f2014-11-11 13:41:02 +0100142 public boolean startDisappearAnimation(final Runnable finishRunnable) {
143 enableClipping(false);
144 setTranslationY(0);
Jorim Jaggi613f55f2015-07-16 15:30:10 -0700145 AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 280 /* duration */,
146 mDisappearYTranslation, mDisappearAnimationUtils.getInterpolator());
Jorim Jaggie8fde5d2016-06-30 23:41:37 -0700147 DisappearAnimationUtils disappearAnimationUtils = mKeyguardUpdateMonitor.isUserUnlocked()
148 ? mDisappearAnimationUtils
149 : mDisappearAnimationUtilsLocked;
150 disappearAnimationUtils.startAnimation2d(mViews,
Selim Cinekf9c0e8f2014-11-11 13:41:02 +0100151 new Runnable() {
152 @Override
153 public void run() {
154 enableClipping(true);
155 if (finishRunnable != null) {
156 finishRunnable.run();
157 }
158 }
159 });
Jorim Jaggi76a16232014-08-08 17:00:47 +0200160 return true;
161 }
162
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200163 private void enableClipping(boolean enable) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100164 mContainer.setClipToPadding(enable);
165 mContainer.setClipChildren(enable);
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200166 mRow1.setClipToPadding(enable);
167 mRow2.setClipToPadding(enable);
168 mRow3.setClipToPadding(enable);
169 setClipChildren(enable);
Jorim Jaggic14f8292014-05-27 02:25:45 +0200170 }
Jorim Jaggi76a16232014-08-08 17:00:47 +0200171
172 @Override
173 public boolean hasOverlappingRendering() {
174 return false;
175 }
Michael Jurka1254f2f2012-10-25 11:44:31 -0700176}