diff --git a/dolby/res/drawable/ic_ieq_balanced.xml b/dolby/res/drawable/ic_ieq_balanced.xml
new file mode 100644
index 0000000..961a73a
--- /dev/null
+++ b/dolby/res/drawable/ic_ieq_balanced.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
diff --git a/dolby/res/drawable/ic_ieq_detailed.xml b/dolby/res/drawable/ic_ieq_detailed.xml
new file mode 100644
index 0000000..375b5c6
--- /dev/null
+++ b/dolby/res/drawable/ic_ieq_detailed.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
diff --git a/dolby/res/drawable/ic_ieq_off.xml b/dolby/res/drawable/ic_ieq_off.xml
new file mode 100644
index 0000000..ce609cb
--- /dev/null
+++ b/dolby/res/drawable/ic_ieq_off.xml
@@ -0,0 +1,13 @@
+
+
+
diff --git a/dolby/res/drawable/ic_ieq_warm.xml b/dolby/res/drawable/ic_ieq_warm.xml
new file mode 100644
index 0000000..6a12d2a
--- /dev/null
+++ b/dolby/res/drawable/ic_ieq_warm.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
diff --git a/dolby/res/layout/ieq_icon_layout.xml b/dolby/res/layout/ieq_icon_layout.xml
new file mode 100644
index 0000000..f04165c
--- /dev/null
+++ b/dolby/res/layout/ieq_icon_layout.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
diff --git a/dolby/res/values/arrays.xml b/dolby/res/values/arrays.xml
index 2f07d4b..bc952a2 100644
--- a/dolby/res/values/arrays.xml
+++ b/dolby/res/values/arrays.xml
@@ -85,4 +85,18 @@
- 64
+
+ - @string/dolby_off
+ - @string/dolby_balanced
+ - @string/dolby_warm
+ - @string/dolby_detailed
+
+
+
+ - 0
+ - 1
+ - 2
+ - 3
+
+
diff --git a/dolby/res/values/strings.xml b/dolby/res/values/strings.xml
index 417f9b2..f82c491 100644
--- a/dolby/res/values/strings.xml
+++ b/dolby/res/values/strings.xml
@@ -61,4 +61,10 @@
Preset name already exists!
Preset name is too long!
+
+ Intelligent equalizer
+ Balanced
+ Warm
+ Detailed
+
diff --git a/dolby/res/xml/dolby_settings.xml b/dolby/res/xml/dolby_settings.xml
index af852d6..8040feb 100644
--- a/dolby/res/xml/dolby_settings.xml
+++ b/dolby/res/xml/dolby_settings.xml
@@ -33,6 +33,12 @@
android:targetClass="co.aospa.dolby.xiaomi.geq.EqualizerActivity" />
+
+
diff --git a/dolby/src/co/aospa/dolby/xiaomi/DolbyActivity.kt b/dolby/src/co/aospa/dolby/xiaomi/DolbyActivity.kt
index fecb074..5f9f2e8 100644
--- a/dolby/src/co/aospa/dolby/xiaomi/DolbyActivity.kt
+++ b/dolby/src/co/aospa/dolby/xiaomi/DolbyActivity.kt
@@ -7,6 +7,7 @@
package co.aospa.dolby.xiaomi
import android.os.Bundle
+import co.aospa.dolby.xiaomi.preference.DolbySettingsFragment
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity
import com.android.settingslib.widget.R
diff --git a/dolby/src/co/aospa/dolby/xiaomi/DolbyConstants.kt b/dolby/src/co/aospa/dolby/xiaomi/DolbyConstants.kt
index e54b424..a434ce4 100644
--- a/dolby/src/co/aospa/dolby/xiaomi/DolbyConstants.kt
+++ b/dolby/src/co/aospa/dolby/xiaomi/DolbyConstants.kt
@@ -14,6 +14,7 @@ class DolbyConstants {
HEADPHONE_VIRTUALIZER(101),
SPEAKER_VIRTUALIZER(102),
VOLUME_LEVELER_ENABLE(103),
+ IEQ_PRESET(104),
DIALOGUE_ENHANCER_ENABLE(105),
DIALOGUE_ENHANCER_AMOUNT(108),
GEQ_BAND_GAINS(110, 20),
@@ -30,6 +31,7 @@ class DolbyConstants {
const val PREF_ENABLE = "dolby_enable"
const val PREF_PROFILE = "dolby_profile"
const val PREF_PRESET = "dolby_preset"
+ const val PREF_IEQ = "dolby_ieq"
const val PREF_HP_VIRTUALIZER = "dolby_virtualizer"
const val PREF_SPK_VIRTUALIZER = "dolby_spk_virtualizer"
const val PREF_STEREO = "dolby_stereo"
@@ -40,6 +42,7 @@ class DolbyConstants {
val PROFILE_SPECIFIC_PREFS = setOf(
PREF_PRESET,
+ PREF_IEQ,
PREF_HP_VIRTUALIZER,
PREF_SPK_VIRTUALIZER,
PREF_STEREO,
diff --git a/dolby/src/co/aospa/dolby/xiaomi/DolbyController.kt b/dolby/src/co/aospa/dolby/xiaomi/DolbyController.kt
index 9636225..07a50e0 100644
--- a/dolby/src/co/aospa/dolby/xiaomi/DolbyController.kt
+++ b/dolby/src/co/aospa/dolby/xiaomi/DolbyController.kt
@@ -121,6 +121,13 @@ internal class DolbyController private constructor(
prefs.getString(DolbyConstants.PREF_PRESET, getPreset(profile)),
profile
)
+ setIeqPreset(
+ prefs.getString(
+ DolbyConstants.PREF_IEQ,
+ getIeqPreset(profile).toString()
+ ).toInt(),
+ profile
+ )
setHeadphoneVirtEnabled(
prefs.getBoolean(DolbyConstants.PREF_HP_VIRTUALIZER, getHeadphoneVirtEnabled(profile)),
profile
@@ -283,6 +290,17 @@ internal class DolbyController private constructor(
dolbyEffect.setDapParameter(DsParam.DIALOGUE_ENHANCER_AMOUNT, value, profile)
}
+ fun getIeqPreset(profile: Int = this.profile) =
+ dolbyEffect.getDapParameterInt(DsParam.IEQ_PRESET, profile).also {
+ dlog(TAG, "getIeqPreset: $it")
+ }
+
+ fun setIeqPreset(value: Int, profile: Int = this.profile) {
+ dlog(TAG, "setIeqPreset: $value")
+ checkEffect()
+ dolbyEffect.setDapParameter(DsParam.IEQ_PRESET, value, profile)
+ }
+
companion object {
private const val TAG = "DolbyController"
private const val EFFECT_PRIORITY = 100
diff --git a/dolby/src/co/aospa/dolby/xiaomi/preference/DolbyIeqPreference.kt b/dolby/src/co/aospa/dolby/xiaomi/preference/DolbyIeqPreference.kt
new file mode 100644
index 0000000..215fa6f
--- /dev/null
+++ b/dolby/src/co/aospa/dolby/xiaomi/preference/DolbyIeqPreference.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2024 Paranoid Android
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package co.aospa.dolby.xiaomi.preference
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.View
+import android.widget.ImageView
+import androidx.appcompat.content.res.AppCompatResources
+import androidx.preference.ListPreference
+import androidx.preference.PreferenceViewHolder
+import co.aospa.dolby.xiaomi.R
+
+// Preference with icon on the right side
+class DolbyIeqPreference(
+ context: Context,
+ attrs: AttributeSet?,
+) : ListPreference(context, attrs) {
+
+ init {
+ widgetLayoutResource = R.layout.ieq_icon_layout
+ }
+
+ override fun onBindViewHolder(holder: PreferenceViewHolder) {
+ super.onBindViewHolder(holder)
+ val iconView = holder.findViewById(R.id.ieq_icon)!! as ImageView
+ val icon = AppCompatResources.getDrawable(context, getIeqIconResId())
+ iconView.setImageDrawable(icon)
+ }
+
+ private fun getIeqIconResId(): Int {
+ val ieqValue = value?.toIntOrNull() ?: 0
+ return when (ieqValue) {
+ 0 -> R.drawable.ic_ieq_off
+ 1 -> R.drawable.ic_ieq_balanced
+ 2 -> R.drawable.ic_ieq_warm
+ 3 -> R.drawable.ic_ieq_detailed
+ else -> 0 // should never hit this!
+ }
+ }
+}
diff --git a/dolby/src/co/aospa/dolby/xiaomi/DolbyPreferenceStore.kt b/dolby/src/co/aospa/dolby/xiaomi/preference/DolbyPreferenceStore.kt
similarity index 95%
rename from dolby/src/co/aospa/dolby/xiaomi/DolbyPreferenceStore.kt
rename to dolby/src/co/aospa/dolby/xiaomi/preference/DolbyPreferenceStore.kt
index 918a37b..810440a 100644
--- a/dolby/src/co/aospa/dolby/xiaomi/DolbyPreferenceStore.kt
+++ b/dolby/src/co/aospa/dolby/xiaomi/preference/DolbyPreferenceStore.kt
@@ -4,12 +4,13 @@
* SPDX-License-Identifier: Apache-2.0
*/
-package co.aospa.dolby.xiaomi
+package co.aospa.dolby.xiaomi.preference
import android.content.Context
import android.content.SharedPreferences
import androidx.preference.PreferenceDataStore
import androidx.preference.PreferenceManager
+import co.aospa.dolby.xiaomi.DolbyConstants
class DolbyPreferenceStore(
private val context: Context
diff --git a/dolby/src/co/aospa/dolby/xiaomi/DolbySettingsFragment.kt b/dolby/src/co/aospa/dolby/xiaomi/preference/DolbySettingsFragment.kt
similarity index 78%
rename from dolby/src/co/aospa/dolby/xiaomi/DolbySettingsFragment.kt
rename to dolby/src/co/aospa/dolby/xiaomi/preference/DolbySettingsFragment.kt
index 80a818a..02263ac 100644
--- a/dolby/src/co/aospa/dolby/xiaomi/DolbySettingsFragment.kt
+++ b/dolby/src/co/aospa/dolby/xiaomi/preference/DolbySettingsFragment.kt
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
-package co.aospa.dolby.xiaomi
+package co.aospa.dolby.xiaomi.preference
import android.media.AudioAttributes
import android.media.AudioDeviceCallback
@@ -19,7 +19,20 @@ import androidx.preference.Preference
import androidx.preference.Preference.OnPreferenceChangeListener
import androidx.preference.PreferenceFragment
import androidx.preference.SwitchPreference
+import co.aospa.dolby.xiaomi.DolbyConstants
+import co.aospa.dolby.xiaomi.DolbyConstants.Companion.PREF_BASS
+import co.aospa.dolby.xiaomi.DolbyConstants.Companion.PREF_DIALOGUE
+import co.aospa.dolby.xiaomi.DolbyConstants.Companion.PREF_ENABLE
+import co.aospa.dolby.xiaomi.DolbyConstants.Companion.PREF_HP_VIRTUALIZER
+import co.aospa.dolby.xiaomi.DolbyConstants.Companion.PREF_IEQ
+import co.aospa.dolby.xiaomi.DolbyConstants.Companion.PREF_PRESET
+import co.aospa.dolby.xiaomi.DolbyConstants.Companion.PREF_PROFILE
+import co.aospa.dolby.xiaomi.DolbyConstants.Companion.PREF_RESET
+import co.aospa.dolby.xiaomi.DolbyConstants.Companion.PREF_SPK_VIRTUALIZER
+import co.aospa.dolby.xiaomi.DolbyConstants.Companion.PREF_STEREO
+import co.aospa.dolby.xiaomi.DolbyConstants.Companion.PREF_VOLUME
import co.aospa.dolby.xiaomi.DolbyConstants.Companion.dlog
+import co.aospa.dolby.xiaomi.DolbyController
import co.aospa.dolby.xiaomi.R
import com.android.settingslib.widget.MainSwitchPreference
import com.android.settingslib.widget.OnMainSwitchChangeListener
@@ -28,34 +41,37 @@ class DolbySettingsFragment : PreferenceFragment(),
OnPreferenceChangeListener, OnMainSwitchChangeListener {
private val switchBar by lazy {
- findPreference(DolbyConstants.PREF_ENABLE)!!
+ findPreference(PREF_ENABLE)!!
}
private val profilePref by lazy {
- findPreference(DolbyConstants.PREF_PROFILE)!!
+ findPreference(PREF_PROFILE)!!
}
private val presetPref by lazy {
- findPreference(DolbyConstants.PREF_PRESET)!!
+ findPreference(PREF_PRESET)!!
+ }
+ private val ieqPref by lazy {
+ findPreference(PREF_IEQ)!!
}
private val stereoPref by lazy {
- findPreference(DolbyConstants.PREF_STEREO)!!
+ findPreference(PREF_STEREO)!!
}
private val dialoguePref by lazy {
- findPreference(DolbyConstants.PREF_DIALOGUE)!!
+ findPreference(PREF_DIALOGUE)!!
}
private val bassPref by lazy {
- findPreference(DolbyConstants.PREF_BASS)!!
+ findPreference(PREF_BASS)!!
}
private val hpVirtPref by lazy {
- findPreference(DolbyConstants.PREF_HP_VIRTUALIZER)!!
+ findPreference(PREF_HP_VIRTUALIZER)!!
}
private val spkVirtPref by lazy {
- findPreference(DolbyConstants.PREF_SPK_VIRTUALIZER)!!
+ findPreference(PREF_SPK_VIRTUALIZER)!!
}
private val volumePref by lazy {
- findPreference(DolbyConstants.PREF_VOLUME)!!
+ findPreference(PREF_VOLUME)!!
}
private val resetPref by lazy {
- findPreference(DolbyConstants.PREF_RESET)!!
+ findPreference(PREF_RESET)!!
}
private val dolbyController by lazy { DolbyController.getInstance(context) }
@@ -112,6 +128,7 @@ class DolbySettingsFragment : PreferenceFragment(),
dialoguePref.onPreferenceChangeListener = this
bassPref.onPreferenceChangeListener = this
volumePref.onPreferenceChangeListener = this
+ ieqPref.onPreferenceChangeListener = this
resetPref.setOnPreferenceClickListener {
dolbyController.resetProfileSpecificSettings()
@@ -143,37 +160,41 @@ class DolbySettingsFragment : PreferenceFragment(),
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
dlog(TAG, "onPreferenceChange: key=${preference.key} value=$newValue")
when (preference.key) {
- DolbyConstants.PREF_PROFILE -> {
+ PREF_PROFILE -> {
val profile = newValue.toString().toInt()
dolbyController.profile = profile
(preferenceManager.preferenceDataStore as DolbyPreferenceStore).profile = profile
updateProfileSpecificPrefs()
}
- DolbyConstants.PREF_SPK_VIRTUALIZER -> {
+ PREF_SPK_VIRTUALIZER -> {
dolbyController.setSpeakerVirtEnabled(newValue as Boolean)
}
- DolbyConstants.PREF_HP_VIRTUALIZER -> {
+ PREF_HP_VIRTUALIZER -> {
dolbyController.setHeadphoneVirtEnabled(newValue as Boolean)
}
- DolbyConstants.PREF_STEREO -> {
+ PREF_STEREO -> {
dolbyController.setStereoWideningAmount(newValue.toString().toInt())
}
- DolbyConstants.PREF_DIALOGUE -> {
+ PREF_DIALOGUE -> {
dolbyController.setDialogueEnhancerAmount(newValue.toString().toInt())
}
- DolbyConstants.PREF_BASS -> {
+ PREF_BASS -> {
dolbyController.setBassEnhancerEnabled(newValue as Boolean)
}
- DolbyConstants.PREF_VOLUME -> {
+ PREF_VOLUME -> {
dolbyController.setVolumeLevelerEnabled(newValue as Boolean)
}
+ PREF_IEQ -> {
+ dolbyController.setIeqPreset(newValue.toString().toInt())
+ }
+
else -> return false
}
return true
@@ -205,6 +226,7 @@ class DolbySettingsFragment : PreferenceFragment(),
val enable = dsOn && (currentProfile != -1)
presetPref.setEnabled(enable)
spkVirtPref.setEnabled(enable)
+ ieqPref.setEnabled(enable)
dialoguePref.setEnabled(enable)
volumePref.setEnabled(enable)
resetPref.setEnabled(enable)
@@ -216,6 +238,16 @@ class DolbySettingsFragment : PreferenceFragment(),
presetPref.summary = dolbyController.getPresetName()
+ val ieqValue = dolbyController.getIeqPreset(currentProfile)
+ ieqPref.apply {
+ if (entryValues.contains(ieqValue.toString())) {
+ summary = "%s"
+ value = ieqValue.toString()
+ } else {
+ summary = unknownRes
+ }
+ }
+
val deValue = dolbyController.getDialogueEnhancerAmount(currentProfile).toString()
dialoguePref.apply {
if (entryValues.contains(deValue)) {