• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.systemui.Flags
21 import kotlin.time.Duration.Companion.milliseconds
22 
23 object KeyguardBottomAreaVibrations {
24 
25     val ShakeAnimationDuration =
26         if (Flags.msdlFeedback()) {
27             285.milliseconds
28         } else {
29             300.milliseconds
30         }
31     val ShakeAnimationCycles =
32         if (Flags.msdlFeedback()) {
33             3f
34         } else {
35             5f
36         }
37 
38     private const val SmallVibrationScale = 0.3f
39     private const val BigVibrationScale = 0.6f
40 
41     val Shake =
42         VibrationEffect.startComposition()
<lambda>null43             .apply {
44                 val vibrationDelayMs =
45                     (ShakeAnimationDuration.inWholeMilliseconds / (ShakeAnimationCycles * 2))
46                         .toInt()
47 
48                 val vibrationCount = ShakeAnimationCycles.toInt() * 2
49                 repeat(vibrationCount) {
50                     addPrimitive(
51                         VibrationEffect.Composition.PRIMITIVE_TICK,
52                         SmallVibrationScale,
53                         vibrationDelayMs,
54                     )
55                 }
56             }
57             .compose()
58 
59     val Activated =
60         VibrationEffect.startComposition()
61             .addPrimitive(VibrationEffect.Composition.PRIMITIVE_TICK, BigVibrationScale, 0)
62             .addPrimitive(VibrationEffect.Composition.PRIMITIVE_QUICK_RISE, 0.1f, 0)
63             .compose()
64 
65     val Deactivated =
66         VibrationEffect.startComposition()
67             .addPrimitive(VibrationEffect.Composition.PRIMITIVE_TICK, BigVibrationScale, 0)
68             .addPrimitive(VibrationEffect.Composition.PRIMITIVE_QUICK_FALL, 0.1f, 0)
69             .compose()
70 }
71