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