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.AnimatorListenerAdapter;
     21 import android.animation.ObjectAnimator;
     22 import android.graphics.drawable.Drawable;
     23 import android.view.View;
     24 
     25 /**
     26  * Some common functions that are useful for KeyguardSecurityViews.
     27  */
     28 public class KeyguardSecurityViewHelper {
     29 
     30     public static void showBouncer(SecurityMessageDisplay securityMessageDisplay,
     31             final View ecaView, Drawable bouncerFrame, int duration) {
     32         if (securityMessageDisplay != null) {
     33             securityMessageDisplay.showBouncer(duration);
     34         }
     35         if (ecaView != null) {
     36             if (duration > 0) {
     37                 Animator anim = ObjectAnimator.ofFloat(ecaView, "alpha", 0f);
     38                 anim.setDuration(duration);
     39                 anim.addListener(new AnimatorListenerAdapter() {
     40                     private boolean mCanceled;
     41                     @Override
     42                     public void onAnimationCancel(Animator animation) {
     43                         // Fail safe and show the emergency button in onAnimationEnd()
     44                         mCanceled = true;
     45                         ecaView.setAlpha(1f);
     46                     }
     47                     @Override
     48                     public void onAnimationEnd(Animator animation) {
     49                         ecaView.setVisibility(mCanceled ? View.VISIBLE : View.INVISIBLE);
     50                     }
     51                 });
     52                 anim.start();
     53             } else {
     54                 ecaView.setAlpha(0f);
     55                 ecaView.setVisibility(View.INVISIBLE);
     56             }
     57         }
     58         if (bouncerFrame != null) {
     59             if (duration > 0) {
     60                 Animator anim = ObjectAnimator.ofInt(bouncerFrame, "alpha", 0, 255);
     61                 anim.setDuration(duration);
     62                 anim.start();
     63             } else {
     64                 bouncerFrame.setAlpha(255);
     65             }
     66         }
     67     }
     68 
     69     public static void hideBouncer(SecurityMessageDisplay securityMessageDisplay,
     70             View ecaView, Drawable bouncerFrame, int duration) {
     71         if (securityMessageDisplay != null) {
     72             securityMessageDisplay.hideBouncer(duration);
     73         }
     74         if (ecaView != null) {
     75             ecaView.setVisibility(View.VISIBLE);
     76             if (duration > 0) {
     77                 Animator anim = ObjectAnimator.ofFloat(ecaView, "alpha", 1f);
     78                 anim.setDuration(duration);
     79                 anim.start();
     80             } else {
     81                 ecaView.setAlpha(1f);
     82             }
     83         }
     84         if (bouncerFrame != null) {
     85             if (duration > 0) {
     86                 Animator anim = ObjectAnimator.ofInt(bouncerFrame, "alpha", 255, 0);
     87                 anim.setDuration(duration);
     88                 anim.start();
     89             } else {
     90                 bouncerFrame.setAlpha(0);
     91             }
     92         }
     93     }
     94 }
     95