1 /*
<lambda>null2  * Copyright (C) 2022 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.systemui.surfaceeffects.ripple
18 
19 import androidx.annotation.VisibleForTesting
20 
21 /** Controller that handles playing [RippleAnimation]. */
22 class MultiRippleController(private val multipleRippleView: MultiRippleView) {
23 
24     companion object {
25         /** Max number of ripple animations at a time. */
26         @VisibleForTesting const val MAX_RIPPLE_NUMBER = 10
27     }
28 
29     /** Updates all the ripple colors during the animation. */
30     fun updateColor(color: Int) {
31         multipleRippleView.ripples.forEach { anim -> anim.updateColor(color) }
32     }
33 
34     fun play(rippleAnimation: RippleAnimation) {
35         if (multipleRippleView.ripples.size >= MAX_RIPPLE_NUMBER) {
36             return
37         }
38 
39         multipleRippleView.ripples.add(rippleAnimation)
40 
41         rippleAnimation.play {
42             // Remove ripple once the animation is done
43             multipleRippleView.ripples.remove(rippleAnimation)
44         }
45 
46         // Trigger drawing
47         multipleRippleView.invalidate()
48     }
49 }
50