blob: 7ea767c004fb50a8a925f041cec640609ddd7c94 [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 Jaggi6b88cdf2014-12-22 20:56:50 +010039 private ViewGroup mContainer;
Jorim Jaggi15a77f72014-05-28 16:20:03 +020040 private ViewGroup mRow0;
41 private ViewGroup mRow1;
42 private ViewGroup mRow2;
43 private ViewGroup mRow3;
44 private View mDivider;
Jorim Jaggi76a16232014-08-08 17:00:47 +020045 private int mDisappearYTranslation;
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010046 private View[][] mViews;
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 Jaggi76a16232014-08-08 17:00:47 +020059 mDisappearYTranslation = getResources().getDimensionPixelSize(
60 R.dimen.disappear_y_translation);
Daniel Sandler69bdee72012-10-23 16:45:50 -040061 }
62
Jim Miller4db942c2016-05-16 18:06:50 -070063 @Override
Daniel Sandler69bdee72012-10-23 16:45:50 -040064 protected void resetState() {
Selim Cinek4e8b9ed2014-06-20 16:37:04 -070065 super.resetState();
Jorim Jaggi8a8941a2014-12-19 19:49:38 +010066 mSecurityMessageDisplay.setMessage(R.string.kg_pin_instructions, false);
Daniel Sandler69bdee72012-10-23 16:45:50 -040067 }
68
69 @Override
Daniel Sandler8a26bf52012-10-30 13:29:50 -040070 protected int getPasswordTextViewId() {
71 return R.id.pinEntry;
72 }
73
74 @Override
Daniel Sandler69bdee72012-10-23 16:45:50 -040075 protected void onFinishInflate() {
76 super.onFinishInflate();
77
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +010078 mContainer = (ViewGroup) findViewById(R.id.container);
Jorim Jaggi15a77f72014-05-28 16:20:03 +020079 mRow0 = (ViewGroup) findViewById(R.id.row0);
80 mRow1 = (ViewGroup) findViewById(R.id.row1);
81 mRow2 = (ViewGroup) findViewById(R.id.row2);
82 mRow3 = (ViewGroup) findViewById(R.id.row3);
83 mDivider = findViewById(R.id.divider);
Selim Cinekf9c0e8f2014-11-11 13:41:02 +010084 mViews = new View[][]{
85 new View[]{
86 mRow0, null, null
87 },
88 new View[]{
89 findViewById(R.id.key1), findViewById(R.id.key2),
90 findViewById(R.id.key3)
91 },
92 new View[]{
93 findViewById(R.id.key4), findViewById(R.id.key5),
94 findViewById(R.id.key6)
95 },
96 new View[]{
97 findViewById(R.id.key7), findViewById(R.id.key8),
98 findViewById(R.id.key9)
99 },
100 new View[]{
101 null, findViewById(R.id.key0), findViewById(R.id.key_enter)
102 },
103 new View[]{
104 null, mEcaView, null
105 }};
Daniel Sandler69bdee72012-10-23 16:45:50 -0400106 }
Adam Cohen6fb841f2012-10-24 13:15:38 -0700107
108 @Override
109 public void showUsabilityHint() {
110 }
Daniel Sandler16d90922012-11-01 12:41:14 -0400111
112 @Override
113 public int getWrongPasswordStringId() {
114 return R.string.kg_wrong_pin;
115 }
Jorim Jaggic14f8292014-05-27 02:25:45 +0200116
117 @Override
118 public void startAppearAnimation() {
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200119 enableClipping(false);
Jorim Jaggifb28c0e2014-08-22 16:28:42 +0200120 setAlpha(1f);
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200121 setTranslationY(mAppearAnimationUtils.getStartTranslation());
Jorim Jaggi613f55f2015-07-16 15:30:10 -0700122 AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */,
123 0, mAppearAnimationUtils.getInterpolator());
Jorim Jaggi56733532015-06-09 15:25:40 -0700124 mAppearAnimationUtils.startAnimation2d(mViews,
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200125 new Runnable() {
126 @Override
127 public void run() {
128 enableClipping(true);
129 }
130 });
131 }
132
Jorim Jaggi76a16232014-08-08 17:00:47 +0200133 @Override
Selim Cinekf9c0e8f2014-11-11 13:41:02 +0100134 public boolean startDisappearAnimation(final Runnable finishRunnable) {
135 enableClipping(false);
136 setTranslationY(0);
Jorim Jaggi613f55f2015-07-16 15:30:10 -0700137 AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 280 /* duration */,
138 mDisappearYTranslation, mDisappearAnimationUtils.getInterpolator());
Jorim Jaggi56733532015-06-09 15:25:40 -0700139 mDisappearAnimationUtils.startAnimation2d(mViews,
Selim Cinekf9c0e8f2014-11-11 13:41:02 +0100140 new Runnable() {
141 @Override
142 public void run() {
143 enableClipping(true);
144 if (finishRunnable != null) {
145 finishRunnable.run();
146 }
147 }
148 });
Jorim Jaggi76a16232014-08-08 17:00:47 +0200149 return true;
150 }
151
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200152 private void enableClipping(boolean enable) {
Jorim Jaggi6b88cdf2014-12-22 20:56:50 +0100153 mContainer.setClipToPadding(enable);
154 mContainer.setClipChildren(enable);
Jorim Jaggi15a77f72014-05-28 16:20:03 +0200155 mRow1.setClipToPadding(enable);
156 mRow2.setClipToPadding(enable);
157 mRow3.setClipToPadding(enable);
158 setClipChildren(enable);
Jorim Jaggic14f8292014-05-27 02:25:45 +0200159 }
Jorim Jaggi76a16232014-08-08 17:00:47 +0200160
161 @Override
162 public boolean hasOverlappingRendering() {
163 return false;
164 }
Michael Jurka1254f2f2012-10-25 11:44:31 -0700165}