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 View cancelBtn = findViewById(R.id.cancel_button); 112 if (cancelBtn != null) { 113 cancelBtn.setOnClickListener(view -> { 114 mCallback.reset(); 115 }); 116 } 117 } 118 119 @Override showUsabilityHint()120 public void showUsabilityHint() { 121 } 122 123 @Override getWrongPasswordStringId()124 public int getWrongPasswordStringId() { 125 return R.string.kg_wrong_pin; 126 } 127 128 @Override startAppearAnimation()129 public void startAppearAnimation() { 130 enableClipping(false); 131 setAlpha(1f); 132 setTranslationY(mAppearAnimationUtils.getStartTranslation()); 133 AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */, 134 0, mAppearAnimationUtils.getInterpolator()); 135 mAppearAnimationUtils.startAnimation2d(mViews, 136 new Runnable() { 137 @Override 138 public void run() { 139 enableClipping(true); 140 } 141 }); 142 } 143 144 @Override startDisappearAnimation(final Runnable finishRunnable)145 public boolean startDisappearAnimation(final Runnable finishRunnable) { 146 enableClipping(false); 147 setTranslationY(0); 148 AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 280 /* duration */, 149 mDisappearYTranslation, mDisappearAnimationUtils.getInterpolator()); 150 DisappearAnimationUtils disappearAnimationUtils = mKeyguardUpdateMonitor 151 .needsSlowUnlockTransition() 152 ? mDisappearAnimationUtilsLocked 153 : mDisappearAnimationUtils; 154 disappearAnimationUtils.startAnimation2d(mViews, 155 new Runnable() { 156 @Override 157 public void run() { 158 enableClipping(true); 159 if (finishRunnable != null) { 160 finishRunnable.run(); 161 } 162 } 163 }); 164 return true; 165 } 166 enableClipping(boolean enable)167 private void enableClipping(boolean enable) { 168 mContainer.setClipToPadding(enable); 169 mContainer.setClipChildren(enable); 170 mRow1.setClipToPadding(enable); 171 mRow2.setClipToPadding(enable); 172 mRow3.setClipToPadding(enable); 173 setClipChildren(enable); 174 } 175 176 @Override hasOverlappingRendering()177 public boolean hasOverlappingRendering() { 178 return false; 179 } 180 } 181