/
Jojer
/
RepTrack
Обзор
Документация
Войти
/
Jojer
/
RepTrack
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
app/src/main/java/com/example/reptrack/service/sound/TimerSoundManager.kt
51 строка
2 KB
MaximOdincov
31.05.2026 3
31 май 2026, 19:34
31 май 2026, 19:34
7ce8ed7
Код
Авторство
О чём код?
package com.example.reptrack.service.sound import android.content.Context import android.media.Ringtone import android.media.RingtoneManager import android.os.Build import android.os.VibrationEffect import android.os.Vibrator import android.os.VibratorManager class TimerSoundManager(private val context: Context) { fun playCompletionSound() { // Play notification sound try { val notificationUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) val ringtone: Ringtone? = RingtoneManager.getRingtone(context, notificationUri) ringtone?.play() } catch (e: Exception) { e.printStackTrace() } // Vibrate with pattern vibrate() } private fun vibrate() { try { val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { val vm = context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager vm.defaultVibrator } else { @Suppress("DEPRECATION") context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // More noticeable pattern: vibrate, pause, vibrate, pause, vibrate val pattern = longArrayOf(0, 500, 300, 500, 300, 500, 300, 500) val amplitudes = intArrayOf(0, 255, 0, 255, 0, 255, 0, 255) vibrator.vibrate(VibrationEffect.createWaveform(pattern, amplitudes, -1)) } else { @Suppress("DEPRECATION") val pattern = longArrayOf(0, 500, 300, 500, 300, 500, 300, 500) vibrator.vibrate(pattern, -1) } } catch (e: Exception) { e.printStackTrace() } } }