• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.launcher3.util;
18 
19 import static com.android.launcher3.LauncherAnimUtils.VIEW_ALPHA;
20 
21 import android.view.View;
22 
23 import com.android.launcher3.anim.AlphaUpdateListener;
24 
25 /**
26  * Utility class to handle separating a single value as a factor of multiple values
27  */
28 public class MultiValueAlpha extends MultiPropertyFactory<View> {
29 
30     private static final FloatBiFunction ALPHA_AGGREGATOR = (a, b) -> a * b;
31 
32     // Whether we should change from INVISIBLE to VISIBLE and vice versa at low alpha values.
33     private boolean mUpdateVisibility;
34 
MultiValueAlpha(View view, int size)35     public MultiValueAlpha(View view, int size) {
36         super(view, VIEW_ALPHA, size, ALPHA_AGGREGATOR, 1f);
37     }
38 
39     /** Sets whether we should update between INVISIBLE and VISIBLE based on alpha. */
setUpdateVisibility(boolean updateVisibility)40     public void setUpdateVisibility(boolean updateVisibility) {
41         mUpdateVisibility = updateVisibility;
42     }
43 
44     @Override
apply(float value)45     protected void apply(float value) {
46         super.apply(value);
47         if (mUpdateVisibility) {
48             AlphaUpdateListener.updateVisibility(mTarget);
49         }
50     }
51 }
52