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.animation.Animator;
     20 import android.animation.ObjectAnimator;
     21 import android.content.Context;
     22 import android.util.AttributeSet;
     23 import android.view.RenderNode;
     24 import android.view.RenderNodeAnimator;
     25 import android.view.View;
     26 import android.view.ViewGroup;
     27 import android.view.animation.AnimationUtils;
     28 
     29 import com.android.settingslib.animation.AppearAnimationUtils;
     30 import com.android.settingslib.animation.DisappearAnimationUtils;
     31 
     32 /**
     33  * Displays a PIN pad for unlocking.
     34  */
     35 public class KeyguardPINView extends KeyguardPinBasedInputView {
     36 
     37     private final AppearAnimationUtils mAppearAnimationUtils;
     38     private final DisappearAnimationUtils mDisappearAnimationUtils;
     39     private ViewGroup mContainer;
     40     private ViewGroup mRow0;
     41     private ViewGroup mRow1;
     42     private ViewGroup mRow2;
     43     private ViewGroup mRow3;
     44     private View mDivider;
     45     private int mDisappearYTranslation;
     46     private View[][] mViews;
     47 
     48     public KeyguardPINView(Context context) {
     49         this(context, null);
     50     }
     51 
     52     public KeyguardPINView(Context context, AttributeSet attrs) {
     53         super(context, attrs);
     54         mAppearAnimationUtils = new AppearAnimationUtils(context);
     55         mDisappearAnimationUtils = new DisappearAnimationUtils(context,
     56                 125, 0.6f /* translationScale */,
     57                 0.45f /* delayScale */, AnimationUtils.loadInterpolator(
     58                         mContext, android.R.interpolator.fast_out_linear_in));
     59         mDisappearYTranslation = getResources().getDimensionPixelSize(
     60                 R.dimen.disappear_y_translation);
     61     }
     62 
     63     @Override
     64     protected void resetState() {
     65         super.resetState();
     66         mSecurityMessageDisplay.setMessage(R.string.kg_pin_instructions, false);
     67     }
     68 
     69     @Override
     70     protected int getPasswordTextViewId() {
     71         return R.id.pinEntry;
     72     }
     73 
     74     @Override
     75     protected void onFinishInflate() {
     76         super.onFinishInflate();
     77 
     78         mContainer = (ViewGroup) findViewById(R.id.container);
     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);
     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                 }};
    106     }
    107 
    108     @Override
    109     public void showUsabilityHint() {
    110     }
    111 
    112     @Override
    113     public int getWrongPasswordStringId() {
    114         return R.string.kg_wrong_pin;
    115     }
    116 
    117     @Override
    118     public void startAppearAnimation() {
    119         enableClipping(false);
    120         setAlpha(1f);
    121         setTranslationY(mAppearAnimationUtils.getStartTranslation());
    122         AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */,
    123                 0, mAppearAnimationUtils.getInterpolator());
    124         mAppearAnimationUtils.startAnimation2d(mViews,
    125                 new Runnable() {
    126                     @Override
    127                     public void run() {
    128                         enableClipping(true);
    129                     }
    130                 });
    131     }
    132 
    133     @Override
    134     public boolean startDisappearAnimation(final Runnable finishRunnable) {
    135         enableClipping(false);
    136         setTranslationY(0);
    137         AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 280 /* duration */,
    138                 mDisappearYTranslation, mDisappearAnimationUtils.getInterpolator());
    139         mDisappearAnimationUtils.startAnimation2d(mViews,
    140                 new Runnable() {
    141                     @Override
    142                     public void run() {
    143                         enableClipping(true);
    144                         if (finishRunnable != null) {
    145                             finishRunnable.run();
    146                         }
    147                     }
    148                 });
    149         return true;
    150     }
    151 
    152     private void enableClipping(boolean enable) {
    153         mContainer.setClipToPadding(enable);
    154         mContainer.setClipChildren(enable);
    155         mRow1.setClipToPadding(enable);
    156         mRow2.setClipToPadding(enable);
    157         mRow3.setClipToPadding(enable);
    158         setClipChildren(enable);
    159     }
    160 
    161     @Override
    162     public boolean hasOverlappingRendering() {
    163         return false;
    164     }
    165 }
    166