fix(haptics): не вибрировать при выключенном системном виброотклике
This commit is contained in:
1 parent
4f7e1f7c97
commit
7afdc97333
1 file changed
+9
@@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.VibrationEffect
|
import android.os.VibrationEffect
|
||||||
import android.os.Vibrator
|
import android.os.Vibrator
|
||||||
|
import android.provider.Settings
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apple-like haptic patterns for a tactile, musical feel.
|
* Apple-like haptic patterns for a tactile, musical feel.
|
||||||
@@ -31,6 +32,14 @@ object HapticUtil {
|
|||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
fun perform(context: Context, pattern: Pattern) {
|
fun perform(context: Context, pattern: Pattern) {
|
||||||
|
// Прямой Vibrator игнорирует системный «Виброотклик при касании» —
|
||||||
|
// проверяем настройку сами (performHapticFeedback здесь не подходит: нет View).
|
||||||
|
val hapticsEnabled = try {
|
||||||
|
Settings.System.getInt(
|
||||||
|
context.contentResolver, Settings.System.HAPTIC_FEEDBACK_ENABLED, 1
|
||||||
|
) == 1
|
||||||
|
} catch (_: Exception) { true }
|
||||||
|
if (!hapticsEnabled) return
|
||||||
val vibrator = context.getSystemService(Vibrator::class.java) ?: return
|
val vibrator = context.getSystemService(Vibrator::class.java) ?: return
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
val effect = when (pattern) {
|
val effect = when (pattern) {
|
||||||
|
|||||||
Reference in new issue
Block a user