KeyguardSecurityViewHelper.java revision 50bf54584239aa80781f32269396bd2059b2877d
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
17package com.android.internal.policy.impl.keyguard;
18
19import android.animation.Animator;
20import android.animation.ObjectAnimator;
21import android.graphics.drawable.Drawable;
22import android.view.View;
23
24/**
25 * Some common functions that are useful for KeyguardSecurityViews.
26 */
27public class KeyguardSecurityViewHelper {
28
29    public static void showBouncer(SecurityMessageDisplay securityMessageDisplay,
30            View ecaView, Drawable bouncerFrame, int duration) {
31        if (securityMessageDisplay != null) {
32            securityMessageDisplay.showBouncer(duration);
33        }
34        if (ecaView != null) {
35            if (duration > 0) {
36                Animator anim = ObjectAnimator.ofFloat(ecaView, "alpha", 0f);
37                anim.setDuration(duration);
38                anim.start();
39            } else {
40                ecaView.setAlpha(0f);
41            }
42        }
43        if (bouncerFrame != null) {
44            if (duration > 0) {
45                Animator anim = ObjectAnimator.ofInt(bouncerFrame, "alpha", 0, 255);
46                anim.setDuration(duration);
47                anim.start();
48            } else {
49                bouncerFrame.setAlpha(255);
50            }
51        }
52    }
53
54    public static void hideBouncer(SecurityMessageDisplay securityMessageDisplay,
55            View ecaView, Drawable bouncerFrame, int duration) {
56        if (securityMessageDisplay != null) {
57            securityMessageDisplay.hideBouncer(duration);
58        }
59        if (ecaView != null) {
60            if (duration > 0) {
61                Animator anim = ObjectAnimator.ofFloat(ecaView, "alpha", 1f);
62                anim.setDuration(duration);
63                anim.start();
64            } else {
65                ecaView.setAlpha(1f);
66            }
67        }
68        if (bouncerFrame != null) {
69            if (duration > 0) {
70                Animator anim = ObjectAnimator.ofInt(bouncerFrame, "alpha", 255, 0);
71                anim.setDuration(duration);
72                anim.start();
73            } else {
74                bouncerFrame.setAlpha(0);
75            }
76        }
77    }
78}
79