2019-05-11 13:53:20 +00:00
|
|
|
/*
|
2020-10-06 08:46:04 +00:00
|
|
|
* Copyright (c) 2020 Hemanth Savarla.
|
2019-05-11 13:53:20 +00:00
|
|
|
*
|
|
|
|
* Licensed under the GNU General Public License v3
|
|
|
|
*
|
2020-10-06 08:46:04 +00:00
|
|
|
* This is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
2019-05-11 13:53:20 +00:00
|
|
|
*
|
|
|
|
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
2020-10-06 08:46:04 +00:00
|
|
|
*
|
2019-05-11 13:53:20 +00:00
|
|
|
*/
|
2019-04-20 05:29:45 +00:00
|
|
|
package code.name.monkey.retromusic.fragments.settings
|
2018-12-06 08:52:57 +00:00
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.media.audiofx.AudioEffect
|
|
|
|
import android.os.Bundle
|
|
|
|
import androidx.preference.Preference
|
2020-09-24 20:21:32 +00:00
|
|
|
import code.name.monkey.retromusic.EQUALIZER
|
2018-12-06 08:52:57 +00:00
|
|
|
import code.name.monkey.retromusic.R
|
|
|
|
import code.name.monkey.retromusic.util.NavigationUtil
|
2020-05-23 09:27:55 +00:00
|
|
|
|
2018-12-06 08:52:57 +00:00
|
|
|
/**
|
|
|
|
* @author Hemanth S (h4h13).
|
|
|
|
*/
|
|
|
|
|
|
|
|
class AudioSettings : AbsSettingsFragment() {
|
|
|
|
override fun invalidateSettings() {
|
2020-09-24 20:21:32 +00:00
|
|
|
val findPreference: Preference? = findPreference(EQUALIZER)
|
2020-05-23 13:53:10 +00:00
|
|
|
if (!hasEqualizer()) {
|
2020-09-24 20:21:32 +00:00
|
|
|
findPreference?.isEnabled = false
|
|
|
|
findPreference?.summary = resources.getString(R.string.no_equalizer)
|
2018-12-06 08:52:57 +00:00
|
|
|
} else {
|
2020-09-24 20:21:32 +00:00
|
|
|
findPreference?.isEnabled = true
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
2020-09-24 20:21:32 +00:00
|
|
|
findPreference?.setOnPreferenceClickListener {
|
2019-08-05 16:13:44 +00:00
|
|
|
NavigationUtil.openEqualizer(requireActivity())
|
2018-12-06 08:52:57 +00:00
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun hasEqualizer(): Boolean {
|
|
|
|
val effects = Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL)
|
|
|
|
|
2019-08-05 16:13:44 +00:00
|
|
|
val pm = requireActivity().packageManager
|
2018-12-06 08:52:57 +00:00
|
|
|
val ri = pm.resolveActivity(effects, 0)
|
|
|
|
return ri != null
|
|
|
|
}
|
|
|
|
|
2018-12-06 10:23:03 +00:00
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
2018-12-06 08:52:57 +00:00
|
|
|
addPreferencesFromResource(R.xml.pref_audio)
|
|
|
|
}
|
|
|
|
}
|