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 | |
Jorim Jaggi | 613f55f | 2015-07-16 15:30:10 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.ObjectAnimator; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 21 | import android.content.Context; |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 22 | import android.util.AttributeSet; |
Jorim Jaggi | 613f55f | 2015-07-16 15:30:10 -0700 | [diff] [blame] | 23 | import android.view.RenderNode; |
| 24 | import android.view.RenderNodeAnimator; |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 25 | import android.view.View; |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 26 | import android.view.ViewGroup; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 27 | import android.view.animation.AnimationUtils; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 28 | |
Jorim Jaggi | 5673353 | 2015-06-09 15:25:40 -0700 | [diff] [blame] | 29 | import com.android.settingslib.animation.AppearAnimationUtils; |
| 30 | import com.android.settingslib.animation.DisappearAnimationUtils; |
| 31 | |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 32 | /** |
| 33 | * Displays a PIN pad for unlocking. |
| 34 | */ |
Selim Cinek | 4e8b9ed | 2014-06-20 16:37:04 -0700 | [diff] [blame] | 35 | public class KeyguardPINView extends KeyguardPinBasedInputView { |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 36 | |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 37 | private final AppearAnimationUtils mAppearAnimationUtils; |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 38 | private final DisappearAnimationUtils mDisappearAnimationUtils; |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 39 | private ViewGroup mContainer; |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 40 | private ViewGroup mRow0; |
| 41 | private ViewGroup mRow1; |
| 42 | private ViewGroup mRow2; |
| 43 | private ViewGroup mRow3; |
| 44 | private View mDivider; |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 45 | private int mDisappearYTranslation; |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 46 | private View[][] mViews; |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 47 | |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 48 | public KeyguardPINView(Context context) { |
| 49 | this(context, null); |
| 50 | } |
| 51 | |
| 52 | public KeyguardPINView(Context context, AttributeSet attrs) { |
| 53 | super(context, attrs); |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 54 | mAppearAnimationUtils = new AppearAnimationUtils(context); |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 55 | mDisappearAnimationUtils = new DisappearAnimationUtils(context, |
| 56 | 125, 0.6f /* translationScale */, |
Jorim Jaggi | 94f6f061 | 2015-06-25 14:47:24 -0700 | [diff] [blame] | 57 | 0.45f /* delayScale */, AnimationUtils.loadInterpolator( |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 58 | mContext, android.R.interpolator.fast_out_linear_in)); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 59 | mDisappearYTranslation = getResources().getDimensionPixelSize( |
| 60 | R.dimen.disappear_y_translation); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 61 | } |
| 62 | |
Jim Miller | 4db942c | 2016-05-16 18:06:50 -0700 | [diff] [blame^] | 63 | @Override |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 64 | protected void resetState() { |
Selim Cinek | 4e8b9ed | 2014-06-20 16:37:04 -0700 | [diff] [blame] | 65 | super.resetState(); |
Jorim Jaggi | 8a8941a | 2014-12-19 19:49:38 +0100 | [diff] [blame] | 66 | mSecurityMessageDisplay.setMessage(R.string.kg_pin_instructions, false); |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Override |
Daniel Sandler | 8a26bf5 | 2012-10-30 13:29:50 -0400 | [diff] [blame] | 70 | protected int getPasswordTextViewId() { |
| 71 | return R.id.pinEntry; |
| 72 | } |
| 73 | |
| 74 | @Override |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 75 | protected void onFinishInflate() { |
| 76 | super.onFinishInflate(); |
| 77 | |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 78 | mContainer = (ViewGroup) findViewById(R.id.container); |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 79 | mRow0 = (ViewGroup) findViewById(R.id.row0); |
| 80 | mRow1 = (ViewGroup) findViewById(R.id.row1); |
| 81 | mRow2 = (ViewGroup) findViewById(R.id.row2); |
| 82 | mRow3 = (ViewGroup) findViewById(R.id.row3); |
| 83 | mDivider = findViewById(R.id.divider); |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 84 | mViews = new View[][]{ |
| 85 | new View[]{ |
| 86 | mRow0, null, null |
| 87 | }, |
| 88 | new View[]{ |
| 89 | findViewById(R.id.key1), findViewById(R.id.key2), |
| 90 | findViewById(R.id.key3) |
| 91 | }, |
| 92 | new View[]{ |
| 93 | findViewById(R.id.key4), findViewById(R.id.key5), |
| 94 | findViewById(R.id.key6) |
| 95 | }, |
| 96 | new View[]{ |
| 97 | findViewById(R.id.key7), findViewById(R.id.key8), |
| 98 | findViewById(R.id.key9) |
| 99 | }, |
| 100 | new View[]{ |
| 101 | null, findViewById(R.id.key0), findViewById(R.id.key_enter) |
| 102 | }, |
| 103 | new View[]{ |
| 104 | null, mEcaView, null |
| 105 | }}; |
Daniel Sandler | 69bdee7 | 2012-10-23 16:45:50 -0400 | [diff] [blame] | 106 | } |
Adam Cohen | 6fb841f | 2012-10-24 13:15:38 -0700 | [diff] [blame] | 107 | |
| 108 | @Override |
| 109 | public void showUsabilityHint() { |
| 110 | } |
Daniel Sandler | 16d9092 | 2012-11-01 12:41:14 -0400 | [diff] [blame] | 111 | |
| 112 | @Override |
| 113 | public int getWrongPasswordStringId() { |
| 114 | return R.string.kg_wrong_pin; |
| 115 | } |
Jorim Jaggi | c14f829 | 2014-05-27 02:25:45 +0200 | [diff] [blame] | 116 | |
| 117 | @Override |
| 118 | public void startAppearAnimation() { |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 119 | enableClipping(false); |
Jorim Jaggi | fb28c0e | 2014-08-22 16:28:42 +0200 | [diff] [blame] | 120 | setAlpha(1f); |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 121 | setTranslationY(mAppearAnimationUtils.getStartTranslation()); |
Jorim Jaggi | 613f55f | 2015-07-16 15:30:10 -0700 | [diff] [blame] | 122 | AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */, |
| 123 | 0, mAppearAnimationUtils.getInterpolator()); |
Jorim Jaggi | 5673353 | 2015-06-09 15:25:40 -0700 | [diff] [blame] | 124 | mAppearAnimationUtils.startAnimation2d(mViews, |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 125 | new Runnable() { |
| 126 | @Override |
| 127 | public void run() { |
| 128 | enableClipping(true); |
| 129 | } |
| 130 | }); |
| 131 | } |
| 132 | |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 133 | @Override |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 134 | public boolean startDisappearAnimation(final Runnable finishRunnable) { |
| 135 | enableClipping(false); |
| 136 | setTranslationY(0); |
Jorim Jaggi | 613f55f | 2015-07-16 15:30:10 -0700 | [diff] [blame] | 137 | AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 280 /* duration */, |
| 138 | mDisappearYTranslation, mDisappearAnimationUtils.getInterpolator()); |
Jorim Jaggi | 5673353 | 2015-06-09 15:25:40 -0700 | [diff] [blame] | 139 | mDisappearAnimationUtils.startAnimation2d(mViews, |
Selim Cinek | f9c0e8f | 2014-11-11 13:41:02 +0100 | [diff] [blame] | 140 | new Runnable() { |
| 141 | @Override |
| 142 | public void run() { |
| 143 | enableClipping(true); |
| 144 | if (finishRunnable != null) { |
| 145 | finishRunnable.run(); |
| 146 | } |
| 147 | } |
| 148 | }); |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 149 | return true; |
| 150 | } |
| 151 | |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 152 | private void enableClipping(boolean enable) { |
Jorim Jaggi | 6b88cdf | 2014-12-22 20:56:50 +0100 | [diff] [blame] | 153 | mContainer.setClipToPadding(enable); |
| 154 | mContainer.setClipChildren(enable); |
Jorim Jaggi | 15a77f7 | 2014-05-28 16:20:03 +0200 | [diff] [blame] | 155 | mRow1.setClipToPadding(enable); |
| 156 | mRow2.setClipToPadding(enable); |
| 157 | mRow3.setClipToPadding(enable); |
| 158 | setClipChildren(enable); |
Jorim Jaggi | c14f829 | 2014-05-27 02:25:45 +0200 | [diff] [blame] | 159 | } |
Jorim Jaggi | 76a1623 | 2014-08-08 17:00:47 +0200 | [diff] [blame] | 160 | |
| 161 | @Override |
| 162 | public boolean hasOverlappingRendering() { |
| 163 | return false; |
| 164 | } |
Michael Jurka | 1254f2f | 2012-10-25 11:44:31 -0700 | [diff] [blame] | 165 | } |