Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 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 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 17 | package com.android.keyguard; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 18 | |
| 19 | import android.content.Context; |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 20 | import android.util.AttributeSet; |
| 21 | import android.view.View; |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 22 | import android.view.ViewGroup; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 23 | import android.view.animation.AnimationUtils; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 24 | |
Jorim Jaggi | 5673353 | 2015-06-09 15:25:40 -0700 | [diff] [blame] | 25 | import com.android.settingslib.animation.AppearAnimationUtils; |
| 26 | import com.android.settingslib.animation.DisappearAnimationUtils; |
| 27 | |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 28 | /** |
| 29 | * Displays a PIN pad for unlocking. |
| 30 | */ |
Selim Cinek | 4e8b9ed | 2014-06-20 16:37:04 -0700 | [diff] [blame] | 31 | public class KeyguardPINView extends KeyguardPinBasedInputView { |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 32 | |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 33 | private final AppearAnimationUtils mAppearAnimationUtils; |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 34 | private final DisappearAnimationUtils mDisappearAnimationUtils; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 35 | private final DisappearAnimationUtils mDisappearAnimationUtilsLocked; |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 36 | private ViewGroup mContainer; |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 37 | private ViewGroup mRow0; |
| 38 | private ViewGroup mRow1; |
| 39 | private ViewGroup mRow2; |
| 40 | private ViewGroup mRow3; |
| 41 | private View mDivider; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 42 | private int mDisappearYTranslation; |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 43 | private View[][] mViews; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 44 | private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 45 | |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 46 | public KeyguardPINView(Context context) { |
| 47 | this(context, null); |
| 48 | } |
| 49 | |
| 50 | public KeyguardPINView(Context context, AttributeSet attrs) { |
| 51 | super(context, attrs); |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 52 | mAppearAnimationUtils = new AppearAnimationUtils(context); |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 53 | mDisappearAnimationUtils = new DisappearAnimationUtils(context, |
| 54 | 125, 0.6f /* translationScale */, |
Jorim Jaggi | 94f6f061 | 2015-06-25 14:47:24 -0700 | [diff] [blame] | 55 | 0.45f /* delayScale */, AnimationUtils.loadInterpolator( |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 56 | mContext, android.R.interpolator.fast_out_linear_in)); |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 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)); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 62 | mDisappearYTranslation = getResources().getDimensionPixelSize( |
| 63 | R.dimen.disappear_y_translation); |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 64 | mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(context); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 65 | } |
| 66 | |
Jim Miller | 4db942c | 2016-05-16 18:06:50 -0700 | [diff] [blame] | 67 | @Override |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 68 | protected void resetState() { |
Selim Cinek | 4e8b9ed | 2014-06-20 16:37:04 -0700 | [diff] [blame] | 69 | super.resetState(); |
Adrian Roos | db327e9 | 2016-10-12 16:41:28 -0700 | [diff] [blame] | 70 | mSecurityMessageDisplay.setMessage(""); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
Daniel Sandler | 8a26bf5 | 2012-10-30 13:29:50 -0400 | [diff] [blame] | 74 | protected int getPasswordTextViewId() { |
| 75 | return R.id.pinEntry; |
| 76 | } |
| 77 | |
| 78 | @Override |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 79 | protected void onFinishInflate() { |
| 80 | super.onFinishInflate(); |
| 81 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 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); |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 87 | mDivider = findViewById(R.id.divider); |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 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[]{ |
Lucas Dupin | 33b4c28 | 2018-10-24 15:26:34 -0700 | [diff] [blame^] | 105 | findViewById(R.id.delete_button), findViewById(R.id.key0), |
| 106 | findViewById(R.id.key_enter) |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 107 | }, |
| 108 | new View[]{ |
| 109 | null, mEcaView, null |
| 110 | }}; |
Jian Jin | 44e4d82 | 2018-04-06 12:40:50 -0700 | [diff] [blame] | 111 | |
| 112 | View cancelBtn = findViewById(R.id.cancel_button); |
| 113 | if (cancelBtn != null) { |
| 114 | cancelBtn.setOnClickListener(view -> { |
| 115 | mCallback.reset(); |
Aarthi Balachander | 0a427ef | 2018-07-13 15:00:58 -0700 | [diff] [blame] | 116 | mCallback.onCancelClicked(); |
Jian Jin | 44e4d82 | 2018-04-06 12:40:50 -0700 | [diff] [blame] | 117 | }); |
| 118 | } |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 119 | } |
Adam Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 120 | |
| 121 | @Override |
| 122 | public void showUsabilityHint() { |
| 123 | } |
Daniel Sandler | 16d9092 | 2012-11-01 12:41:14 -0400 | [diff] [blame] | 124 | |
| 125 | @Override |
| 126 | public int getWrongPasswordStringId() { |
| 127 | return R.string.kg_wrong_pin; |
| 128 | } |
Jorim Jaggi | c14f829 | 2014-05-27 02:25:45 +0200 | [diff] [blame] | 129 | |
| 130 | @Override |
| 131 | public void startAppearAnimation() { |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 132 | enableClipping(false); |
Jorim Jaggi | fb28c0e | 2014-08-22 16:28:42 +0200 | [diff] [blame] | 133 | setAlpha(1f); |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 134 | setTranslationY(mAppearAnimationUtils.getStartTranslation()); |
Jorim Jaggi | 613f55f | 2015-07-16 15:30:10 -0700 | [diff] [blame] | 135 | AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */, |
| 136 | 0, mAppearAnimationUtils.getInterpolator()); |
Jorim Jaggi | 5673353 | 2015-06-09 15:25:40 -0700 | [diff] [blame] | 137 | mAppearAnimationUtils.startAnimation2d(mViews, |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 138 | new Runnable() { |
| 139 | @Override |
| 140 | public void run() { |
| 141 | enableClipping(true); |
| 142 | } |
| 143 | }); |
| 144 | } |
| 145 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 146 | @Override |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 147 | public boolean startDisappearAnimation(final Runnable finishRunnable) { |
| 148 | enableClipping(false); |
| 149 | setTranslationY(0); |
Jorim Jaggi | 613f55f | 2015-07-16 15:30:10 -0700 | [diff] [blame] | 150 | AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 280 /* duration */, |
| 151 | mDisappearYTranslation, mDisappearAnimationUtils.getInterpolator()); |
Jorim Jaggi | 031f795 | 2016-09-01 16:39:26 -0700 | [diff] [blame] | 152 | DisappearAnimationUtils disappearAnimationUtils = mKeyguardUpdateMonitor |
| 153 | .needsSlowUnlockTransition() |
Jorim Jaggi | 6bd3890 | 2016-09-06 15:27:56 -0700 | [diff] [blame] | 154 | ? mDisappearAnimationUtilsLocked |
| 155 | : mDisappearAnimationUtils; |
Jorim Jaggi | e8fde5d | 2016-06-30 23:41:37 -0700 | [diff] [blame] | 156 | disappearAnimationUtils.startAnimation2d(mViews, |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 157 | new Runnable() { |
| 158 | @Override |
| 159 | public void run() { |
| 160 | enableClipping(true); |
| 161 | if (finishRunnable != null) { |
| 162 | finishRunnable.run(); |
| 163 | } |
| 164 | } |
| 165 | }); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 166 | return true; |
| 167 | } |
| 168 | |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 169 | private void enableClipping(boolean enable) { |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 170 | mContainer.setClipToPadding(enable); |
| 171 | mContainer.setClipChildren(enable); |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 172 | mRow1.setClipToPadding(enable); |
| 173 | mRow2.setClipToPadding(enable); |
| 174 | mRow3.setClipToPadding(enable); |
| 175 | setClipChildren(enable); |
Jorim Jaggi | c14f829 | 2014-05-27 02:25:45 +0200 | [diff] [blame] | 176 | } |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 177 | |
| 178 | @Override |
| 179 | public boolean hasOverlappingRendering() { |
| 180 | return false; |
| 181 | } |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 182 | } |