• 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.animation.Animator;
20 import android.animation.ObjectAnimator;
21 import android.content.Context;
22 import android.util.AttributeSet;
23 import android.view.RenderNode;
24 import android.view.RenderNodeAnimator;
25 import android.view.View;
26 import android.view.ViewGroup;
27 import android.view.animation.AnimationUtils;
28 
29 import com.android.settingslib.animation.AppearAnimationUtils;
30 import com.android.settingslib.animation.DisappearAnimationUtils;
31 
32 /**
33  * Displays a PIN pad for unlocking.
34  */
35 public class KeyguardPINView extends KeyguardPinBasedInputView {
36 
37     private final AppearAnimationUtils mAppearAnimationUtils;
38     private final DisappearAnimationUtils mDisappearAnimationUtils;
39     private ViewGroup mContainer;
40     private ViewGroup mRow0;
41     private ViewGroup mRow1;
42     private ViewGroup mRow2;
43     private ViewGroup mRow3;
44     private View mDivider;
45     private int mDisappearYTranslation;
46     private View[][] mViews;
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         mDisappearYTranslation = getResources().getDimensionPixelSize(
60                 R.dimen.disappear_y_translation);
61     }
62 
resetState()63     protected void resetState() {
64         super.resetState();
65         mSecurityMessageDisplay.setMessage(R.string.kg_pin_instructions, false);
66     }
67 
68     @Override
getPasswordTextViewId()69     protected int getPasswordTextViewId() {
70         return R.id.pinEntry;
71     }
72 
73     @Override
onFinishInflate()74     protected void onFinishInflate() {
75         super.onFinishInflate();
76 
77         mContainer = (ViewGroup) findViewById(R.id.container);
78         mRow0 = (ViewGroup) findViewById(R.id.row0);
79         mRow1 = (ViewGroup) findViewById(R.id.row1);
80         mRow2 = (ViewGroup) findViewById(R.id.row2);
81         mRow3 = (ViewGroup) findViewById(R.id.row3);
82         mDivider = findViewById(R.id.divider);
83         mViews = new View[][]{
84                 new View[]{
85                         mRow0, null, null
86                 },
87                 new View[]{
88                         findViewById(R.id.key1), findViewById(R.id.key2),
89                         findViewById(R.id.key3)
90                 },
91                 new View[]{
92                         findViewById(R.id.key4), findViewById(R.id.key5),
93                         findViewById(R.id.key6)
94                 },
95                 new View[]{
96                         findViewById(R.id.key7), findViewById(R.id.key8),
97                         findViewById(R.id.key9)
98                 },
99                 new View[]{
100                         null, findViewById(R.id.key0), findViewById(R.id.key_enter)
101                 },
102                 new View[]{
103                         null, mEcaView, null
104                 }};
105     }
106 
107     @Override
showUsabilityHint()108     public void showUsabilityHint() {
109     }
110 
111     @Override
getWrongPasswordStringId()112     public int getWrongPasswordStringId() {
113         return R.string.kg_wrong_pin;
114     }
115 
116     @Override
startAppearAnimation()117     public void startAppearAnimation() {
118         enableClipping(false);
119         setAlpha(1f);
120         setTranslationY(mAppearAnimationUtils.getStartTranslation());
121         AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */,
122                 0, mAppearAnimationUtils.getInterpolator());
123         mAppearAnimationUtils.startAnimation2d(mViews,
124                 new Runnable() {
125                     @Override
126                     public void run() {
127                         enableClipping(true);
128                     }
129                 });
130     }
131 
132     @Override
startDisappearAnimation(final Runnable finishRunnable)133     public boolean startDisappearAnimation(final Runnable finishRunnable) {
134         enableClipping(false);
135         setTranslationY(0);
136         AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 280 /* duration */,
137                 mDisappearYTranslation, mDisappearAnimationUtils.getInterpolator());
138         mDisappearAnimationUtils.startAnimation2d(mViews,
139                 new Runnable() {
140                     @Override
141                     public void run() {
142                         enableClipping(true);
143                         if (finishRunnable != null) {
144                             finishRunnable.run();
145                         }
146                     }
147                 });
148         return true;
149     }
150 
enableClipping(boolean enable)151     private void enableClipping(boolean enable) {
152         mContainer.setClipToPadding(enable);
153         mContainer.setClipChildren(enable);
154         mRow1.setClipToPadding(enable);
155         mRow2.setClipToPadding(enable);
156         mRow3.setClipToPadding(enable);
157         setClipChildren(enable);
158     }
159 
160     @Override
hasOverlappingRendering()161     public boolean hasOverlappingRendering() {
162         return false;
163     }
164 }
165