Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -211,11 +230,10 @@ fun VibrationEffectSetting(
}
}

Button(onClick = { vibrator?.triggerVibration(sharedPreferences) }) {
Button(onClick = { vibrator.triggerVibration(sharedPreferences) }) {
Text(stringResource(R.string.test_vibration))
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ru-rRU/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<string name="vibration_amplitude_dialog_title">Амплитуда вибрации</string>
<string name="test_vibration">Проверить вибрацию</string>

<string name="vibration_not_available">Вибрация недоступна на этом устройстве</string>

<string name="app_filter">Фильтр приложений</string>
<string name="app_filter_disabled">Выключен</string>
<string name="app_filter_white_list">Разрешить</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<string name="vibration_amplitude_dialog_title">振动强度</string>
<string name="test_vibration">测试振动</string>

<string name="vibration_not_available">此设备不支持振动</string>

<string name="app_filter">应用过滤</string>
<string name="app_filter_disabled">禁用</string>
<string name="app_filter_white_list">允许列表</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<string name="vibration_amplitude_dialog_title">震動強度</string>
<string name="test_vibration">測試震動</string>

<string name="vibration_not_available">此裝置不支援震動</string>

<string name="app_filter">應用過濾</string>
<string name="app_filter_disabled">禁用</string>
<string name="app_filter_white_list">允許清單</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<string name="vibration_amplitude_dialog_title">Vibration Amplitude</string>
<string name="test_vibration">Test Vibration</string>

<string name="vibration_not_available">Vibration is not available on this device</string>

<string name="app_filter">App Filter</string>
<string name="app_filter_disabled">Disabled</string>
<string name="app_filter_white_list">White List</string>
Expand Down