2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.keyguard;
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;
29 import com.android.settingslib.animation.AppearAnimationUtils;
30 import com.android.settingslib.animation.DisappearAnimationUtils;
33 * Displays a PIN pad for unlocking.
35 public class KeyguardPINView extends KeyguardPinBasedInputView {
37 private final AppearAnimationUtils mAppearAnimationUtils;
38 private final DisappearAnimationUtils mDisappearAnimationUtils;
39 private final DisappearAnimationUtils mDisappearAnimationUtilsLocked;
40 private ViewGroup mContainer;
41 private ViewGroup mRow0;
42 private ViewGroup mRow1;
43 private ViewGroup mRow2;
44 private ViewGroup mRow3;
45 private View mDivider;
46 private int mDisappearYTranslation;
47 private View[][] mViews;
48 private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
50 public KeyguardPINView(Context context) {
54 public KeyguardPINView(Context context, AttributeSet attrs) {
55 super(context, attrs);
56 mAppearAnimationUtils = new AppearAnimationUtils(context);
57 mDisappearAnimationUtils = new DisappearAnimationUtils(context,
58 125, 0.6f /* translationScale */,
59 0.45f /* delayScale */, AnimationUtils.loadInterpolator(
60 mContext, android.R.interpolator.fast_out_linear_in));
61 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));
66 mDisappearYTranslation = getResources().getDimensionPixelSize(
67 R.dimen.disappear_y_translation);
68 mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(context);
72 protected void resetState() {
74 mSecurityMessageDisplay.setMessage(R.string.kg_pin_instructions, false);
78 protected int getPasswordTextViewId() {
83 protected void onFinishInflate() {
84 super.onFinishInflate();
86 mContainer = (ViewGroup) findViewById(R.id.container);
87 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);
92 mViews = new View[][]{
97 findViewById(R.id.key1), findViewById(R.id.key2),
98 findViewById(R.id.key3)
101 findViewById(R.id.key4), findViewById(R.id.key5),
102 findViewById(R.id.key6)
105 findViewById(R.id.key7), findViewById(R.id.key8),
106 findViewById(R.id.key9)
109 null, findViewById(R.id.key0), findViewById(R.id.key_enter)
117 public void showUsabilityHint() {
121 public int getWrongPasswordStringId() {
122 return R.string.kg_wrong_pin;
126 public void startAppearAnimation() {
127 enableClipping(false);
129 setTranslationY(mAppearAnimationUtils.getStartTranslation());
130 AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */,
131 0, mAppearAnimationUtils.getInterpolator());
132 mAppearAnimationUtils.startAnimation2d(mViews,
136 enableClipping(true);
142 public boolean startDisappearAnimation(final Runnable finishRunnable) {
143 enableClipping(false);
145 AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 280 /* duration */,
146 mDisappearYTranslation, mDisappearAnimationUtils.getInterpolator());
147 DisappearAnimationUtils disappearAnimationUtils = mKeyguardUpdateMonitor.isUserUnlocked()
148 ? mDisappearAnimationUtils
149 : mDisappearAnimationUtilsLocked;
150 disappearAnimationUtils.startAnimation2d(mViews,
154 enableClipping(true);
155 if (finishRunnable != null) {
156 finishRunnable.run();
163 private void enableClipping(boolean enable) {
164 mContainer.setClipToPadding(enable);
165 mContainer.setClipChildren(enable);
166 mRow1.setClipToPadding(enable);
167 mRow2.setClipToPadding(enable);
168 mRow3.setClipToPadding(enable);
169 setClipChildren(enable);
173 public boolean hasOverlappingRendering() {