File tree Expand file tree Collapse file tree
java/com/github/muellerma/tabletoptools Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,4 +28,5 @@ Translations have to be approved before being merged into the app. To become a t
2828
2929* Feature graphic by https://unsplash.com/@accrualbowtie
3030* Some icons by Google and https://materialdesignicons.com/
31- * Some audio files from https://soundbible.com/
31+ * Sound for the timer by https://soundbible.com/
32+ * Sound for buzzer by https://mixkit.co
Original file line number Diff line number Diff line change 11package com.github.muellerma.tabletoptools.ui.fragments
22
3+ import android.media.AudioAttributes
4+ import android.media.AudioManager
5+ import android.media.MediaPlayer
36import android.os.*
47import android.util.Log
58import android.view.*
@@ -11,6 +14,7 @@ import androidx.core.view.isVisible
1114import androidx.lifecycle.Lifecycle
1215import com.github.muellerma.tabletoptools.R
1316import com.github.muellerma.tabletoptools.databinding.FragmentBuzzersBinding
17+ import com.github.muellerma.tabletoptools.utils.Prefs
1418import com.google.android.material.dialog.MaterialAlertDialogBuilder
1519import kotlinx.coroutines.delay
1620import kotlinx.coroutines.launch
@@ -96,6 +100,18 @@ class BuzzersFragment : AbstractBaseFragment() {
96100 vibrator.vibrate(500 )
97101 }
98102
103+ val sound = Prefs (requireContext()).buzzerSound
104+ if (sound != null ) {
105+ val audioManager = requireContext().getSystemService<AudioManager >()!!
106+ val player = MediaPlayer .create(
107+ requireContext(),
108+ sound,
109+ AudioAttributes .Builder ().build(),
110+ audioManager.generateAudioSessionId()
111+ )
112+ player.start()
113+ }
114+
99115 buzzers.forEach {
100116 if (it != pressedButton) {
101117 it.isEnabled = false
Original file line number Diff line number Diff line change @@ -8,8 +8,7 @@ import com.github.muellerma.tabletoptools.R
88import com.github.muellerma.tabletoptools.ui.fragments.TimerFragment
99
1010class Prefs (private val context : Context ) {
11- var sharedPrefs: SharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
12- private set
11+ private var sharedPrefs: SharedPreferences = PreferenceManager .getDefaultSharedPreferences(context)
1312
1413 val maxDiceCount: Int
1514 get() = sharedPrefs.getString(" dices_max_count" , " 10" )?.toInt() ? : 10
@@ -56,4 +55,11 @@ class Prefs(private val context: Context) {
5655 }
5756 }
5857
58+ val buzzerSound: Int?
59+ get() {
60+ return when (sharedPrefs.getString(" buzzer_sound" , null )) {
61+ " buzzer" -> R .raw.buzzer
62+ else -> null
63+ }
64+ }
5965}
Original file line number Diff line number Diff line change 2525 <item >@string/menu_timer_value</item >
2626 <item >@string/menu_buzzers_value</item >
2727 </string-array >
28+
29+ <string-array name =" buzzer_sound" >
30+ <item >@string/buzzer_sound_none</item >
31+ <item >@string/buzzer_sound_buzzer</item >
32+ </string-array >
33+ <string-array name =" buzzer_sound_values" translatable =" false" >
34+ <item >none</item >
35+ <item >buzzer</item >
36+ </string-array >
2837</resources >
Original file line number Diff line number Diff line change 7878 <string name =" menu_preferences" >Settings</string >
7979 <string name =" keep_screen_on_enabled" >Keep screen on</string >
8080 <string name =" keep_screen_on_disabled" >Don\'t keep screen on</string >
81+ <string name =" buzzer_sound" >Sound</string >
82+ <string name =" buzzer_sound_none" >None</string >
83+ <string name =" buzzer_sound_buzzer" >Buzzer</string >
8184
8285 <!-- About menu -->
8386 <string name =" about" >About</string >
Original file line number Diff line number Diff line change 2929 android : title =" @string/dice_show_roll_inc_slider"
3030 android : defaultValue =" false" />
3131 </PreferenceCategory >
32+ <PreferenceCategory android : title =" @string/menu_buzzers" >
33+ <ListPreference
34+ android : key =" buzzer_sound"
35+ android : title =" @string/buzzer_sound"
36+ android : entryValues =" @array/buzzer_sound_values"
37+ android : entries =" @array/buzzer_sound"
38+ android : defaultValue =" none"
39+ android : summary =" %s" />
40+ </PreferenceCategory >
3241 <PreferenceCategory >
3342 <Preference
3443 android : key =" about"
You can’t perform that action at this time.
0 commit comments