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