• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.keyguard;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.view.animation.AnimationUtils;
24 
25 import com.android.settingslib.animation.AppearAnimationUtils;
26 import com.android.settingslib.animation.DisappearAnimationUtils;
27 import com.android.systemui.Dependency;
28 import com.android.systemui.R;
29 
30 /**
31  * Displays a PIN pad for unlocking.
32  */
33 public class KeyguardPINView extends KeyguardPinBasedInputView {
34 
35     private final AppearAnimationUtils mAppearAnimationUtils;
36     private final DisappearAnimationUtils mDisappearAnimationUtils;
37     private final DisappearAnimationUtils mDisappearAnimationUtilsLocked;
38     private ViewGroup mContainer;
39     private ViewGroup mRow0;
40     private ViewGroup mRow1;
41     private ViewGroup mRow2;
42     private ViewGroup mRow3;
43     private View mDivider;
44     private int mDisappearYTranslation;
45     private View[][] mViews;
46     private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
47 
KeyguardPINView(Context context)48     public KeyguardPINView(Context context) {
49         this(context, null);
50     }
51 
KeyguardPINView(Context context, AttributeSet attrs)52     public KeyguardPINView(Context context, AttributeSet attrs) {
53         super(context, attrs);
54         mAppearAnimationUtils = new AppearAnimationUtils(context);
55         mDisappearAnimationUtils = new DisappearAnimationUtils(context,
56                 125, 0.6f /* translationScale */,
57                 0.45f /* delayScale */, AnimationUtils.loadInterpolator(
58                         mContext, android.R.interpolator.fast_out_linear_in));
59         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));
64         mDisappearYTranslation = getResources().getDimensionPixelSize(
65                 R.dimen.disappear_y_translation);
66         mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
67     }
68 
69     @Override
resetState()70     protected void resetState() {
71         super.resetState();
72         if (mSecurityMessageDisplay != null) {
73             mSecurityMessageDisplay.setMessage("");
74         }
75     }
76 
77     @Override
getPasswordTextViewId()78     protected int getPasswordTextViewId() {
79         return R.id.pinEntry;
80     }
81 
82     @Override
onFinishInflate()83     protected void onFinishInflate() {
84         super.onFinishInflate();
85 
86         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);
91         mDivider = findViewById(R.id.divider);
92         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                         findViewById(R.id.delete_button), findViewById(R.id.key0),
110                         findViewById(R.id.key_enter)
111                 },
112                 new View[]{
113                         null, mEcaView, null
114                 }};
115 
116         View cancelBtn = findViewById(R.id.cancel_button);
117         if (cancelBtn != null) {
118             cancelBtn.setOnClickListener(view -> {
119                 mCallback.reset();
120                 mCallback.onCancelClicked();
121             });
122         }
123     }
124 
125     @Override
showUsabilityHint()126     public void showUsabilityHint() {
127     }
128 
129     @Override
getWrongPasswordStringId()130     public int getWrongPasswordStringId() {
131         return R.string.kg_wrong_pin;
132     }
133 
134     @Override
startAppearAnimation()135     public void startAppearAnimation() {
136         enableClipping(false);
137         setAlpha(1f);
138         setTranslationY(mAppearAnimationUtils.getStartTranslation());
139         AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */,
140                 0, mAppearAnimationUtils.getInterpolator());
141         mAppearAnimationUtils.startAnimation2d(mViews,
142                 new Runnable() {
143                     @Override
144                     public void run() {
145                         enableClipping(true);
146                     }
147                 });
148     }
149 
150     @Override
startDisappearAnimation(final Runnable finishRunnable)151     public boolean startDisappearAnimation(final Runnable finishRunnable) {
152         enableClipping(false);
153         setTranslationY(0);
154         AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 280 /* duration */,
155                 mDisappearYTranslation, mDisappearAnimationUtils.getInterpolator());
156         DisappearAnimationUtils disappearAnimationUtils = mKeyguardUpdateMonitor
157                 .needsSlowUnlockTransition()
158                         ? mDisappearAnimationUtilsLocked
159                         : mDisappearAnimationUtils;
160         disappearAnimationUtils.startAnimation2d(mViews,
161                 new Runnable() {
162                     @Override
163                     public void run() {
164                         enableClipping(true);
165                         if (finishRunnable != null) {
166                             finishRunnable.run();
167                         }
168                     }
169                 });
170         return true;
171     }
172 
enableClipping(boolean enable)173     private void enableClipping(boolean enable) {
174         mContainer.setClipToPadding(enable);
175         mContainer.setClipChildren(enable);
176         mRow1.setClipToPadding(enable);
177         mRow2.setClipToPadding(enable);
178         mRow3.setClipToPadding(enable);
179         setClipChildren(enable);
180     }
181 
182     @Override
hasOverlappingRendering()183     public boolean hasOverlappingRendering() {
184         return false;
185     }
186 }
187