blob: 67a6f525ae8777f943beff06a1b409f6dfd6cbd9 [file] [log] [blame]
Chris Wrenc0ae9e62012-11-05 13:16:31 -05001/*
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 Miller5ecd8112013-01-09 18:50:26 -080017package com.android.keyguard;
Chris Wrenc0ae9e62012-11-05 13:16:31 -050018
19import android.animation.Animator;
Jim Miller8bbafed2012-11-07 17:32:30 -080020import android.animation.AnimatorListenerAdapter;
Chris Wrenc0ae9e62012-11-05 13:16:31 -050021import android.animation.ObjectAnimator;
22import android.graphics.drawable.Drawable;
23import android.view.View;
24
25/**
26 * Some common functions that are useful for KeyguardSecurityViews.
27 */
28public class KeyguardSecurityViewHelper {
29
30 public static void showBouncer(SecurityMessageDisplay securityMessageDisplay,
Jim Miller8bbafed2012-11-07 17:32:30 -080031 final View ecaView, Drawable bouncerFrame, int duration) {
Chris Wrenc0ae9e62012-11-05 13:16:31 -050032 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 Miller8bbafed2012-11-07 17:32:30 -080039 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 Wrenc0ae9e62012-11-05 13:16:31 -050052 anim.start();
53 } else {
54 ecaView.setAlpha(0f);
Jim Miller8bbafed2012-11-07 17:32:30 -080055 ecaView.setVisibility(View.INVISIBLE);
Chris Wrenc0ae9e62012-11-05 13:16:31 -050056 }
57 }
58 if (bouncerFrame != null) {
59 if (duration > 0) {
Chris Wren50bf5452012-11-06 14:01:24 -050060 Animator anim = ObjectAnimator.ofInt(bouncerFrame, "alpha", 0, 255);
Chris Wrenc0ae9e62012-11-05 13:16:31 -050061 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 Miller8bbafed2012-11-07 17:32:30 -080075 ecaView.setVisibility(View.VISIBLE);
Chris Wrenc0ae9e62012-11-05 13:16:31 -050076 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 Wren50bf5452012-11-06 14:01:24 -050086 Animator anim = ObjectAnimator.ofInt(bouncerFrame, "alpha", 255, 0);
Chris Wrenc0ae9e62012-11-05 13:16:31 -050087 anim.setDuration(duration);
88 anim.start();
89 } else {
90 bouncerFrame.setAlpha(0);
91 }
92 }
93 }
94}