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