added button to test and adjust alarm volume.
parent
a180288d4f
commit
99ab795320
|
|
@ -1,8 +1,5 @@
|
||||||
<component name="ProjectCodeStyleConfiguration">
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
<code_scheme name="Project" version="173">
|
<code_scheme name="Project" version="173">
|
||||||
<AndroidXmlCodeStyleSettings>
|
|
||||||
<option name="ARRANGEMENT_SETTINGS_MIGRATED_TO_191" value="true" />
|
|
||||||
</AndroidXmlCodeStyleSettings>
|
|
||||||
<JetCodeStyleSettings>
|
<JetCodeStyleSettings>
|
||||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||||
</JetCodeStyleSettings>
|
</JetCodeStyleSettings>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
<option name="testRunner" value="PLATFORM" />
|
||||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
|
|
@ -12,7 +14,6 @@
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
<option name="resolveModulePerSourceSet" value="false" />
|
<option name="resolveModulePerSourceSet" value="false" />
|
||||||
<option name="testRunner" value="PLATFORM" />
|
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="BintrayJCenter" />
|
||||||
|
<option name="name" value="BintrayJCenter" />
|
||||||
|
<option name="url" value="https://jcenter.bintray.com/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="maven" />
|
||||||
|
<option name="name" value="maven" />
|
||||||
|
<option name="url" value="https://jitpack.io" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="Google" />
|
||||||
|
<option name="name" value="Google" />
|
||||||
|
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -16,8 +16,8 @@ configurations.all {
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 29
|
compileSdkVersion 30
|
||||||
buildToolsVersion "29.0.2"
|
buildToolsVersion "30.0.0"
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
|
@ -28,7 +28,7 @@ android {
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "fr.forum_thalie.tsumugi"
|
applicationId "fr.forum_thalie.tsumugi"
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 30
|
||||||
versionCode 115
|
versionCode 115
|
||||||
versionName "1.1.5"
|
versionName "1.1.5"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ class MainActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
|
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||||
super.onRestoreInstanceState(savedInstanceState ?: Bundle())
|
super.onRestoreInstanceState(savedInstanceState ?: Bundle())
|
||||||
// Now that BottomNavigationBar has restored its instance state
|
// Now that BottomNavigationBar has restored its instance state
|
||||||
// and its selectedItemId, we can proceed with setting up the
|
// and its selectedItemId, we can proceed with setting up the
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package fr.forum_thalie.tsumugi.alarm
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import fr.forum_thalie.tsumugi.Actions
|
||||||
|
import fr.forum_thalie.tsumugi.RadioService
|
||||||
|
|
||||||
|
|
||||||
|
fun playOnFallback(c: Context) {
|
||||||
|
val a = Actions.PLAY_OR_FALLBACK
|
||||||
|
val i = Intent(c, RadioService::class.java)
|
||||||
|
i.putExtra("action", a.name)
|
||||||
|
c.startService(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resume(c: Context)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resumeStop(c: Context) {
|
||||||
|
val a = Actions.PLAY
|
||||||
|
val i = Intent(c, RadioService::class.java)
|
||||||
|
i.putExtra("action", a.name)
|
||||||
|
c.startService(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resumePlay(c: Context) {
|
||||||
|
val a = Actions.PLAY
|
||||||
|
val i = Intent(c, RadioService::class.java)
|
||||||
|
i.putExtra("action", a.name)
|
||||||
|
c.startService(i)
|
||||||
|
}
|
||||||
|
|
@ -2,15 +2,29 @@ package fr.forum_thalie.tsumugi.preferences
|
||||||
|
|
||||||
import android.app.TimePickerDialog
|
import android.app.TimePickerDialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.media.AudioManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.view.KeyEvent
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.preference.*
|
import androidx.preference.*
|
||||||
import fr.forum_thalie.tsumugi.*
|
import fr.forum_thalie.tsumugi.*
|
||||||
import fr.forum_thalie.tsumugi.R
|
import fr.forum_thalie.tsumugi.R
|
||||||
import fr.forum_thalie.tsumugi.alarm.RadioAlarm
|
import fr.forum_thalie.tsumugi.alarm.RadioAlarm
|
||||||
|
import fr.forum_thalie.tsumugi.playerstore.PlayerStore
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.GlobalScope.coroutineContext
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
|
|
||||||
class AlarmFragment : PreferenceFragmentCompat() {
|
class AlarmFragment : PreferenceFragmentCompat() {
|
||||||
|
|
||||||
|
|
@ -130,11 +144,87 @@ class AlarmFragment : PreferenceFragmentCompat() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
val testAlarmVolume: Preference? = findPreference("testAlarmVolume")
|
||||||
|
testAlarmVolume!!.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||||
|
|
||||||
|
// get previous state: if it's playing, we'll resume playing as multimedia; if it was stopped, we'll stop
|
||||||
|
val isPlayingMultimedia: Boolean = PlayerStore.instance.isPlaying.value ?: false
|
||||||
|
|
||||||
|
val builder1 = AlertDialog.Builder(requireContext())
|
||||||
|
builder1.setTitle(R.string.test_alarm_volume)
|
||||||
|
builder1.setMessage(R.string.popupTestAlarmVolume)
|
||||||
|
builder1.setCancelable(false)
|
||||||
|
builder1.setPositiveButton(
|
||||||
|
getString(R.string.finished)
|
||||||
|
) { dialog, _ ->
|
||||||
|
// put the radio back to media sound, or off if it was off.
|
||||||
|
if (isPlayingMultimedia)
|
||||||
|
{
|
||||||
|
actionOnService(Actions.PLAY)
|
||||||
|
} else {
|
||||||
|
actionOnService(Actions.STOP)
|
||||||
|
}
|
||||||
|
dialog.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
val adjustAlarmVolume: (Int) -> Unit = debounce<Int>(50, coroutineContext) {
|
||||||
|
val keyCode = it
|
||||||
|
|
||||||
|
val audioManager = requireContext().getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
|
val currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_ALARM)
|
||||||
|
val minVolume = 0 // audioManager.getStreamMinVolume(AudioManager.STREAM_ALARM) <- require API28+
|
||||||
|
val maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM)
|
||||||
|
Log.d(tag, "current, max = $currentVolume, $maxVolume")
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||||
|
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, max(currentVolume - 1, minVolume), AudioManager.FLAG_SHOW_UI)
|
||||||
|
|
||||||
|
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP){
|
||||||
|
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, min(currentVolume + 1, maxVolume), AudioManager.FLAG_SHOW_UI)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
builder1.setOnKeyListener { dialogInterface, i, event ->
|
||||||
|
adjustAlarmVolume(i)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
val alert11 = builder1.create()
|
||||||
|
|
||||||
|
// start as alarm
|
||||||
|
actionOnService(Actions.PLAY_OR_FALLBACK)
|
||||||
|
|
||||||
|
alert11.show()
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
alarmDays?.isEnabled = isWakingUp?.isChecked ?: false
|
alarmDays?.isEnabled = isWakingUp?.isChecked ?: false
|
||||||
timeSet?.isEnabled = isWakingUp?.isChecked ?: false
|
timeSet?.isEnabled = isWakingUp?.isChecked ?: false
|
||||||
snoozeDuration?.isEnabled = isWakingUp?.isChecked ?: false
|
snoozeDuration?.isEnabled = isWakingUp?.isChecked ?: false
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun actionOnService (a: Actions) {
|
||||||
|
// start as alarm
|
||||||
|
val i = Intent(requireContext(), RadioService::class.java)
|
||||||
|
i.putExtra("action", a.name)
|
||||||
|
requireContext().startService(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun <T> debounce(delayMs: Long = 500L,
|
||||||
|
coroutineContext: CoroutineContext,
|
||||||
|
f: (T) -> Unit): (T) -> Unit {
|
||||||
|
var debounceJob: Job? = null
|
||||||
|
return { param: T ->
|
||||||
|
if (debounceJob?.isCompleted != false) {
|
||||||
|
debounceJob = CoroutineScope(coroutineContext).launch {
|
||||||
|
delay(delayMs)
|
||||||
|
f(param)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -56,5 +56,9 @@
|
||||||
<string name="action_refresh">Raffraîchir les données</string>
|
<string name="action_refresh">Raffraîchir les données</string>
|
||||||
<string name="autoPlay">\"Play\" au branchement de la prise casque</string>
|
<string name="autoPlay">\"Play\" au branchement de la prise casque</string>
|
||||||
<string name="settings">Paramètres</string>
|
<string name="settings">Paramètres</string>
|
||||||
|
<string name="test_alarm_volume">Tester et ajuster le volume de l\'alarme</string>
|
||||||
|
<string name="test_alarm_volume_summary">Touchez pour écouter et régler le volume</string>
|
||||||
|
<string name="popupTestAlarmVolume">La radio est à présent lancée en mode alarme. Ajustez le volume avec les boutons de volume de votre appareil.</string>
|
||||||
|
<string name="finished">Terminé</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
|
|
@ -76,5 +76,9 @@
|
||||||
<string name="action_refresh">Refresh data</string>
|
<string name="action_refresh">Refresh data</string>
|
||||||
<string name="autoPlay">Auto play when plugging headphones</string>
|
<string name="autoPlay">Auto play when plugging headphones</string>
|
||||||
<string name="settings">Settings</string>
|
<string name="settings">Settings</string>
|
||||||
|
<string name="test_alarm_volume">Test and change alarm volume</string>
|
||||||
|
<string name="test_alarm_volume_summary">Touch this to listen to the alarm volume and set it up</string>
|
||||||
|
<string name="popupTestAlarmVolume">The radio stream is now started in alarm mode. Adjust the volume with the volume buttons on your device.</string>
|
||||||
|
<string name="finished">Done</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
|
|
@ -37,4 +37,10 @@
|
||||||
android:summary="%s"
|
android:summary="%s"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
app:iconSpaceReserved="false"
|
||||||
|
android:key="testAlarmVolume"
|
||||||
|
android:title="@string/test_alarm_volume"
|
||||||
|
android:summary="@string/test_alarm_volume_summary" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
Loading…
Reference in New Issue