Home | History | Annotate | Download | only in keyguard
      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 
     46     public KeyguardPINView(Context context) {
     47         this(context, null);
     48     }
     49 
     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
     68     protected void resetState() {
     69         super.resetState();
     70         if (mSecurityMessageDisplay != null) {
     71             mSecurityMessageDisplay.setMessage("");
     72         }
     73     }
     74 
     75     @Override
     76     protected int getPasswordTextViewId() {
     77         return R.id.pinEntry;
     78     }
     79 
     80     @Override
     81     protected void onFinishInflate() {
     82         super.onFinishInflate();
     83 
     84         mContainer = findViewById(R.id.container);
     85         mRow0 = findViewById(R.id.row0);
     86         mRow1 = findViewById(R.id.row1);
     87         mRow2 = findViewById(R.id.row2);
     88         mRow3 = findViewById(R.id.row3);
     89         mDivider = findViewById(R.id.divider);
     90         mViews = new View[][]{
     91                 new View[]{
     92                         mRow0, null, null
     93                 },
     94                 new View[]{
     95                         findViewById(R.id.key1), findViewById(R.id.key2),
     96                         findViewById(R.id.key3)
     97                 },
     98                 new View[]{
     99                         findViewById(R.id.key4), findViewById(R.id.key5),
    100                         findViewById(R.id.key6)
    101                 },
    102                 new View[]{
    103                         findViewById(R.id.key7), findViewById(R.id.key8),
    104                         findViewById(R.id.key9)
    105                 },
    106                 new View[]{
    107                         findViewById(R.id.delete_button), findViewById(R.id.key0),
    108                         findViewById(R.id.key_enter)
    109                 },
    110                 new View[]{
    111                         null, mEcaView, null
    112                 }};
    113 
    114         View cancelBtn = findViewById(R.id.cancel_button);
    115         if (cancelBtn != null) {
    116             cancelBtn.setOnClickListener(view -> {
    117                 mCallback.reset();
    118                 mCallback.onCancelClicked();
    119             });
    120         }
    121     }
    122 
    123     @Override
    124     public void showUsabilityHint() {
    125     }
    126 
    127     @Override
    128     public int getWrongPasswordStringId() {
    129         return R.string.kg_wrong_pin;
    130     }
    131 
    132     @Override
    133     public void startAppearAnimation() {
    134         enableClipping(false);
    135         setAlpha(1f);
    136         setTranslationY(mAppearAnimationUtils.getStartTranslation());
    137         AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */,
    138                 0, mAppearAnimationUtils.getInterpolator());
    139         mAppearAnimationUtils.startAnimation2d(mViews,
    140                 new Runnable() {
    141                     @Override
    142                     public void run() {
    143                         enableClipping(true);
    144                     }
    145                 });
    146     }
    147 
    148     @Override
    149     public boolean startDisappearAnimation(final Runnable finishRunnable) {
    150         enableClipping(false);
    151         setTranslationY(0);
    152         AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 280 /* duration */,
    153                 mDisappearYTranslation, mDisappearAnimationUtils.getInterpolator());
    154         DisappearAnimationUtils disappearAnimationUtils = mKeyguardUpdateMonitor
    155                 .needsSlowUnlockTransition()
    156                         ? mDisappearAnimationUtilsLocked
    157                         : mDisappearAnimationUtils;
    158         disappearAnimationUtils.startAnimation2d(mViews,
    159                 new Runnable() {
    160                     @Override
    161                     public void run() {
    162                         enableClipping(true);
    163                         if (finishRunnable != null) {
    164                             finishRunnable.run();
    165                         }
    166                     }
    167                 });
    168         return true;
    169     }
    170 
    171     private void enableClipping(boolean enable) {
    172         mContainer.setClipToPadding(enable);
    173         mContainer.setClipChildren(enable);
    174         mRow1.setClipToPadding(enable);
    175         mRow2.setClipToPadding(enable);
    176         mRow3.setClipToPadding(enable);
    177         setClipChildren(enable);
    178     }
    179 
    180     @Override
    181     public boolean hasOverlappingRendering() {
    182         return false;
    183     }
    184 }
    185