mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-06-05 22:19:17 +02:00
respects to user defined alarm volume while increasing it gradually
This commit is contained in:
@ -21,6 +21,7 @@ import com.simplemobiletools.commons.helpers.*
|
|||||||
|
|
||||||
class ReminderActivity : SimpleActivity() {
|
class ReminderActivity : SimpleActivity() {
|
||||||
companion object {
|
companion object {
|
||||||
|
private const val MIN_ALARM_VOLUME_FOR_INCREASING_ALARMS = 1
|
||||||
private const val INCREASE_VOLUME_DELAY = 300L
|
private const val INCREASE_VOLUME_DELAY = 300L
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +37,6 @@ class ReminderActivity : SimpleActivity() {
|
|||||||
private var mediaPlayer: MediaPlayer? = null
|
private var mediaPlayer: MediaPlayer? = null
|
||||||
private var vibrator: Vibrator? = null
|
private var vibrator: Vibrator? = null
|
||||||
private var initialAlarmVolume: Int? = null
|
private var initialAlarmVolume: Int? = null
|
||||||
private var lastVolumeValue = 0.1f
|
|
||||||
private var dragDownX = 0f
|
private var dragDownX = 0f
|
||||||
private val binding: ActivityReminderBinding by viewBinding(ActivityReminderBinding::inflate)
|
private val binding: ActivityReminderBinding by viewBinding(ActivityReminderBinding::inflate)
|
||||||
|
|
||||||
@ -169,10 +169,7 @@ class ReminderActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun setupEffects() {
|
private fun setupEffects() {
|
||||||
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
val maxVol = audioManager?.getStreamMaxVolume(AudioManager.STREAM_ALARM)?.toFloat() ?: 10f
|
initialAlarmVolume = audioManager?.getStreamVolume(AudioManager.STREAM_ALARM) ?: 7
|
||||||
if (!isAlarmReminder || !config.increaseVolumeGradually) {
|
|
||||||
lastVolumeValue = maxVol
|
|
||||||
}
|
|
||||||
|
|
||||||
val doVibrate = alarm?.vibrate ?: config.timerVibrate
|
val doVibrate = alarm?.vibrate ?: config.timerVibrate
|
||||||
if (doVibrate && isOreoPlus()) {
|
if (doVibrate && isOreoPlus()) {
|
||||||
@ -200,19 +197,18 @@ class ReminderActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.increaseVolumeGradually) {
|
if (config.increaseVolumeGradually) {
|
||||||
initialAlarmVolume = audioManager?.getStreamVolume(AudioManager.STREAM_ALARM)
|
scheduleVolumeIncrease(MIN_ALARM_VOLUME_FOR_INCREASING_ALARMS.toFloat(), initialAlarmVolume!!.toFloat(), 0)
|
||||||
scheduleVolumeIncrease(maxVol, 0)
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun scheduleVolumeIncrease(maxVolume: Float, delay: Long) {
|
private fun scheduleVolumeIncrease(lastVolume: Float, maxVolume: Float, delay: Long) {
|
||||||
increaseVolumeHandler.postDelayed({
|
increaseVolumeHandler.postDelayed({
|
||||||
lastVolumeValue = (lastVolumeValue + 0.1f).coerceAtMost(maxVolume)
|
val newLastVolume = (lastVolume + 0.1f).coerceAtMost(maxVolume)
|
||||||
audioManager?.setStreamVolume(AudioManager.STREAM_ALARM, lastVolumeValue.toInt(), 0)
|
audioManager?.setStreamVolume(AudioManager.STREAM_ALARM, newLastVolume.toInt(), 0)
|
||||||
scheduleVolumeIncrease(maxVolume, INCREASE_VOLUME_DELAY)
|
scheduleVolumeIncrease(newLastVolume, maxVolume, INCREASE_VOLUME_DELAY)
|
||||||
}, delay)
|
}, delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user