Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [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; |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 18 | |
| 19 | import android.animation.Animator; |
Jim Miller | 8bbafed | 2012-11-07 17:32:30 -0800 | [diff] [blame] | 20 | import android.animation.AnimatorListenerAdapter; |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 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, |
Jim Miller | 8bbafed | 2012-11-07 17:32:30 -0800 | [diff] [blame] | 31 | final View ecaView, Drawable bouncerFrame, int duration) { |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 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); |
Jim Miller | 8bbafed | 2012-11-07 17:32:30 -0800 | [diff] [blame] | 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 | }); |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 52 | anim.start(); |
| 53 | } else { |
| 54 | ecaView.setAlpha(0f); |
Jim Miller | 8bbafed | 2012-11-07 17:32:30 -0800 | [diff] [blame] | 55 | ecaView.setVisibility(View.INVISIBLE); |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | if (bouncerFrame != null) { |
| 59 | if (duration > 0) { |
Chris Wren | 50bf545 | 2012-11-06 14:01:24 -0500 | [diff] [blame] | 60 | Animator anim = ObjectAnimator.ofInt(bouncerFrame, "alpha", 0, 255); |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 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) { |
Jim Miller | 8bbafed | 2012-11-07 17:32:30 -0800 | [diff] [blame] | 75 | ecaView.setVisibility(View.VISIBLE); |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 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) { |
Chris Wren | 50bf545 | 2012-11-06 14:01:24 -0500 | [diff] [blame] | 86 | Animator anim = ObjectAnimator.ofInt(bouncerFrame, "alpha", 255, 0); |
Chris Wren | c0ae9e6 | 2012-11-05 13:16:31 -0500 | [diff] [blame] | 87 | anim.setDuration(duration); |
| 88 | anim.start(); |
| 89 | } else { |
| 90 | bouncerFrame.setAlpha(0); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | } |