|
| 1 | +/* |
| 2 | + * Copyright (C) 2023 Paranoid Android |
| 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 android.os; |
| 18 | + |
| 19 | +import android.content.res.Resources; |
| 20 | +import android.os.VibrationEffect; |
| 21 | +import android.util.Slog; |
| 22 | + |
| 23 | +import com.android.internal.R; |
| 24 | + |
| 25 | +/** @hide */ |
| 26 | +public class RichTapVibrationEffect { |
| 27 | + |
| 28 | + private static final String TAG = "RichTapVibrationEffect"; |
| 29 | + |
| 30 | + public static boolean isSupported() { |
| 31 | + return Resources.getSystem().getBoolean(R.bool.config_usesRichtapVibration); |
| 32 | + } |
| 33 | + |
| 34 | + public static int[] getInnerEffect(int id) { |
| 35 | + switch (id) { |
| 36 | + case VibrationEffect.EFFECT_CLICK: |
| 37 | + return new int[]{1, 4097, 0, 100, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 38 | + case VibrationEffect.EFFECT_DOUBLE_CLICK: |
| 39 | + return new int[]{1, 4097, 0, 100, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4097, 70, 100, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 40 | + case VibrationEffect.EFFECT_TICK: |
| 41 | + return new int[]{1, 4097, 0, 100, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 42 | + case VibrationEffect.EFFECT_THUD: |
| 43 | + return new int[]{1, 4097, 0, 100, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 44 | + case VibrationEffect.EFFECT_POP: |
| 45 | + return new int[]{1, 4097, 0, 100, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 46 | + case VibrationEffect.EFFECT_HEAVY_CLICK: |
| 47 | + return new int[]{1, 4097, 0, 100, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 48 | + case VibrationEffect.EFFECT_TEXTURE_TICK: |
| 49 | + return new int[]{1, 4097, 0, 50, 33, 29, 0, 0, 0, 12, 59, 0, 22, 75, -21, 29, 0, 0, 4097, 30, 100, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 50 | + default: |
| 51 | + Slog.d(TAG, "Exception encountered!", new IllegalStateException("Unexpected effect id: " + id)); |
| 52 | + return null; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + public static int getInnerEffectStrength(int strength) { |
| 57 | + switch (strength) { |
| 58 | + case VibrationEffect.EFFECT_STRENGTH_LIGHT: |
| 59 | + return 150; |
| 60 | + case VibrationEffect.EFFECT_STRENGTH_MEDIUM: |
| 61 | + return 200; |
| 62 | + case VibrationEffect.EFFECT_STRENGTH_STRONG: |
| 63 | + return 250; |
| 64 | + default: |
| 65 | + Slog.e(TAG, "Wrong Effect Strength!!"); |
| 66 | + return 0; |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments