1 /*
2  * Copyright (C) 2019 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 package com.android.keyguard.clock;
17 
18 import android.view.View;
19 
20 /**
21  * Controls transition to dark state by cross fading between views.
22  */
23 final class CrossFadeDarkController {
24 
25     private final View mFadeInView;
26     private final View mFadeOutView;
27 
28     /**
29      * Creates a new controller that fades between views.
30      *
31      * @param fadeInView View to fade in when transitioning to AOD.
32      * @param fadeOutView View to fade out when transitioning to AOD.
33      */
CrossFadeDarkController(View fadeInView, View fadeOutView)34     CrossFadeDarkController(View fadeInView, View fadeOutView) {
35         mFadeInView = fadeInView;
36         mFadeOutView = fadeOutView;
37     }
38 
39     /**
40      * Sets the amount the system has transitioned to the dark state.
41      *
42      * @param darkAmount Amount of transition to dark state: 1f for AOD and 0f for lock screen.
43      */
setDarkAmount(float darkAmount)44     void setDarkAmount(float darkAmount) {
45         mFadeInView.setAlpha(Math.max(0f, 2f * darkAmount - 1f));
46         if (darkAmount == 0f) {
47             mFadeInView.setVisibility(View.GONE);
48         } else {
49             if (mFadeInView.getVisibility() == View.GONE) {
50                 mFadeInView.setVisibility(View.VISIBLE);
51             }
52         }
53         mFadeOutView.setAlpha(Math.max(0f, 1f - 2f * darkAmount));
54         if (darkAmount == 1f) {
55             mFadeOutView.setVisibility(View.GONE);
56         } else {
57             if (mFadeOutView.getVisibility() == View.GONE) {
58                 mFadeOutView.setVisibility(View.VISIBLE);
59             }
60         }
61     }
62 }
63