adjust initial alarm volume before media player starts playing.

This commit is contained in:
fatih ergin 2023-08-21 22:57:28 +03:00
parent 9046c4a2d6
commit a51886870e

View File

@ -22,8 +22,8 @@ import com.simplemobiletools.commons.helpers.*
class ReminderActivity : SimpleActivity() { class ReminderActivity : SimpleActivity() {
private val INCREASE_VOLUME_DELAY = 300L private val INCREASE_VOLUME_DELAY = 300L
private val increaseVolumeHandler = Handler() private val increaseVolumeHandler = Handler(Looper.getMainLooper())
private val maxReminderDurationHandler = Handler() private val maxReminderDurationHandler = Handler(Looper.getMainLooper())
private val swipeGuideFadeHandler = Handler() private val swipeGuideFadeHandler = Handler()
private val vibrationHandler = Handler(Looper.getMainLooper()) private val vibrationHandler = Handler(Looper.getMainLooper())
private var isAlarmReminder = false private var isAlarmReminder = false
@ -198,19 +198,19 @@ class ReminderActivity : SimpleActivity() {
} }
if (config.increaseVolumeGradually) { if (config.increaseVolumeGradually) {
scheduleVolumeIncrease(maxVol) scheduleVolumeIncrease(maxVol, 0)
} }
} catch (e: Exception) { } catch (e: Exception) {
} }
} }
} }
private fun scheduleVolumeIncrease(maxVolume: Float) { private fun scheduleVolumeIncrease(maxVolume: Float, delay: Long) {
increaseVolumeHandler.postDelayed({ increaseVolumeHandler.postDelayed({
lastVolumeValue = (lastVolumeValue + 0.1f).coerceAtMost(maxVolume) lastVolumeValue = (lastVolumeValue + 0.1f).coerceAtMost(maxVolume)
audioManager?.setStreamVolume(AudioManager.STREAM_ALARM, lastVolumeValue.toInt(), 0) audioManager?.setStreamVolume(AudioManager.STREAM_ALARM, lastVolumeValue.toInt(), 0)
scheduleVolumeIncrease(maxVolume) scheduleVolumeIncrease(maxVolume, INCREASE_VOLUME_DELAY)
}, INCREASE_VOLUME_DELAY) }, delay)
} }
override fun onNewIntent(intent: Intent?) { override fun onNewIntent(intent: Intent?) {