diff --git a/app/src/main/java/ru/hepolise/volumekeytrackcontrol/ui/component/VibrationEffectSetting.kt b/app/src/main/java/ru/hepolise/volumekeytrackcontrol/ui/component/VibrationEffectSetting.kt
index 11de58d..c3c2539 100644
--- a/app/src/main/java/ru/hepolise/volumekeytrackcontrol/ui/component/VibrationEffectSetting.kt
+++ b/app/src/main/java/ru/hepolise/volumekeytrackcontrol/ui/component/VibrationEffectSetting.kt
@@ -13,9 +13,11 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material3.Button
+import androidx.compose.material3.Card
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExposedDropdownMenuAnchorType
@@ -33,6 +35,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.unit.dp
import androidx.core.content.edit
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.EFFECT
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.VIBRATION_AMPLITUDE
@@ -77,6 +80,22 @@ fun VibrationEffectSetting(
) {
val (vibrationType, vibrationLength, vibrationAmplitude) = value
+ val isVibrationAvailable = vibrator != null && vibrator.hasVibrator()
+
+ if (!isVibrationAvailable) {
+ Card(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(8.dp)
+ ) {
+ Text(
+ text = stringResource(R.string.vibration_not_available),
+ modifier = Modifier.padding(16.dp)
+ )
+ }
+ return
+ }
+
var effectExpanded by remember { mutableStateOf(false) }
ExposedDropdownMenuBox(
expanded = effectExpanded,
@@ -211,11 +230,10 @@ fun VibrationEffectSetting(
}
}
- Button(onClick = { vibrator?.triggerVibration(sharedPreferences) }) {
+ Button(onClick = { vibrator.triggerVibration(sharedPreferences) }) {
Text(stringResource(R.string.test_vibration))
}
}
}
}
-
}
\ No newline at end of file
diff --git a/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/VibratorUtil.kt b/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/VibratorUtil.kt
index a5d7432..f842cca 100644
--- a/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/VibratorUtil.kt
+++ b/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/VibratorUtil.kt
@@ -3,6 +3,7 @@ package ru.hepolise.volumekeytrackcontrol.util
import android.content.Context
import android.content.SharedPreferences
import android.os.Build
+import android.os.VibrationAttributes
import android.os.VibrationEffect
import android.os.Vibrator
import android.os.VibratorManager
@@ -27,15 +28,28 @@ object VibratorUtil {
fun Vibrator.triggerVibration(prefs: SharedPreferences? = SharedPreferencesUtil.prefs()) {
val vibrationType = prefs.getVibrationType()
if (vibrationType == VibrationType.Disabled) return
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && vibrationType != VibrationType.Manual) {
- this.vibrate(VibrationEffect.createPredefined(vibrationType.value))
+
+ val vibe =
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && vibrationType != VibrationType.Manual) {
+ VibrationEffect.createPredefined(vibrationType.value)
} else {
- this.vibrate(
VibrationEffect.createOneShot(
prefs.getVibrationLength().toLong(),
prefs.getVibrationAmplitude()
)
- )
+ }
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+ try {
+ val attributes = VibrationAttributes.Builder()
+ .setUsage(VibrationAttributes.USAGE_ALARM)
+ .build()
+ this.vibrate(vibe, attributes)
+ } catch (_: Exception) {
+ this.vibrate(vibe)
+ }
+ } else {
+ this.vibrate(vibe)
}
}
}
diff --git a/app/src/main/res/values-ru-rRU/strings.xml b/app/src/main/res/values-ru-rRU/strings.xml
index a6232c4..de2e4de 100644
--- a/app/src/main/res/values-ru-rRU/strings.xml
+++ b/app/src/main/res/values-ru-rRU/strings.xml
@@ -23,6 +23,8 @@
Амплитуда вибрации
Проверить вибрацию
+ Вибрация недоступна на этом устройстве
+
Фильтр приложений
Выключен
Разрешить
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index 3752a4a..85b48fc 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -24,6 +24,8 @@
振动强度
测试振动
+ 此设备不支持振动
+
应用过滤
禁用
允许列表
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index b57c0ed..4e70022 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -24,6 +24,8 @@
震動強度
測試震動
+ 此裝置不支援震動
+
應用過濾
禁用
允許清單
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index fc55336..730d6d7 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -25,6 +25,8 @@
Vibration Amplitude
Test Vibration
+ Vibration is not available on this device
+
App Filter
Disabled
White List