1 /*
2  * Copyright (C) 2023 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.keyguard.ui.binder
18 
19 import android.os.VibrationEffect
20 import kotlin.time.Duration.Companion.milliseconds
21 
22 object KeyguardBottomAreaVibrations {
23 
24     val ShakeAnimationDuration = 300.milliseconds
25     const val ShakeAnimationCycles = 5f
26 
27     private const val SmallVibrationScale = 0.3f
28     private const val BigVibrationScale = 0.6f
29 
30     val Shake =
31         VibrationEffect.startComposition()
<lambda>null32             .apply {
33                 val vibrationDelayMs =
34                     (ShakeAnimationDuration.inWholeMilliseconds / (ShakeAnimationCycles * 2))
35                     .toInt()
36 
37                 val vibrationCount = ShakeAnimationCycles.toInt() * 2
38                 repeat(vibrationCount) {
39                     addPrimitive(
40                         VibrationEffect.Composition.PRIMITIVE_TICK,
41                         SmallVibrationScale,
42                         vibrationDelayMs,
43                     )
44                 }
45             }
46             .compose()
47 
48     val Activated =
49         VibrationEffect.startComposition()
50             .addPrimitive(
51                 VibrationEffect.Composition.PRIMITIVE_TICK,
52                 BigVibrationScale,
53                 0,
54             )
55             .addPrimitive(
56                 VibrationEffect.Composition.PRIMITIVE_QUICK_RISE,
57                 0.1f,
58                 0,
59             )
60             .compose()
61 
62     val Deactivated =
63         VibrationEffect.startComposition()
64             .addPrimitive(
65                 VibrationEffect.Composition.PRIMITIVE_TICK,
66                 BigVibrationScale,
67                 0,
68             )
69             .addPrimitive(
70                 VibrationEffect.Composition.PRIMITIVE_QUICK_FALL,
71                 0.1f,
72                 0,
73             )
74             .compose()
75 }
76