dolby: Update layout to material expressive design

Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
Pranav Vashi
2025-09-04 19:57:10 +05:30
committed by Joey
parent 5af4457253
commit ea228a83fe
3 changed files with 76 additions and 105 deletions

View File

@@ -26,7 +26,7 @@
<activity
android:name=".DolbyActivity"
android:label="@string/dolby_title"
android:theme="@style/Theme.SubSettingsBase"
android:theme="@style/Theme.SubSettingsBase.Expressive"
android:exported="true">
<intent-filter>
<action android:name="com.android.settings.action.IA_SETTINGS" />
@@ -50,7 +50,7 @@
<activity
android:name=".geq.EqualizerActivity"
android:label="@string/dolby_preset"
android:theme="@style/Theme.SubSettingsBase"
android:theme="@style/Theme.SubSettingsBase.Expressive"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@@ -10,14 +10,16 @@ import android.os.Bundle
import co.aospa.dolby.xiaomi.preference.DolbySettingsFragment
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity
private const val TAG = "DolbyActivity"
class DolbyActivity : CollapsingToolbarBaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
fragmentManager.beginTransaction()
.replace(com.android.settingslib.collapsingtoolbar.R.id.content_frame, DolbySettingsFragment(), TAG)
.commit()
supportFragmentManager
.beginTransaction()
.replace(
com.android.settingslib.collapsingtoolbar.R.id.content_frame,
DolbySettingsFragment(),
)
.commit()
}
}

View File

@@ -6,21 +6,20 @@
package co.aospa.dolby.xiaomi.preference
import android.content.Context
import android.media.AudioAttributes
import android.media.AudioDeviceCallback
import android.media.AudioDeviceInfo
import android.media.AudioManager
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import android.widget.CompoundButton
import android.widget.CompoundButton.OnCheckedChangeListener
import android.widget.Toast
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.Preference.OnPreferenceChangeListener
import androidx.preference.PreferenceFragment
import androidx.preference.SwitchPreferenceCompat
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
@@ -36,47 +35,33 @@ 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.SettingsBasePreferenceFragment
class DolbySettingsFragment : PreferenceFragment(),
OnPreferenceChangeListener, OnCheckedChangeListener {
class DolbySettingsFragment : SettingsBasePreferenceFragment(),
Preference.OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener {
private val switchBar by lazy {
findPreference<MainSwitchPreference>(PREF_ENABLE)!!
}
private val profilePref by lazy {
findPreference<ListPreference>(PREF_PROFILE)!!
}
private val presetPref by lazy {
findPreference<Preference>(PREF_PRESET)!!
}
private val ieqPref by lazy {
findPreference<DolbyIeqPreference>(PREF_IEQ)!!
}
private val stereoPref by lazy {
findPreference<ListPreference>(PREF_STEREO)!!
}
private val dialoguePref by lazy {
findPreference<ListPreference>(PREF_DIALOGUE)!!
}
private val bassPref by lazy {
findPreference<SwitchPreferenceCompat>(PREF_BASS)!!
}
private val hpVirtPref by lazy {
findPreference<SwitchPreferenceCompat>(PREF_HP_VIRTUALIZER)!!
}
private val spkVirtPref by lazy {
findPreference<SwitchPreferenceCompat>(PREF_SPK_VIRTUALIZER)!!
}
private val volumePref by lazy {
findPreference<SwitchPreferenceCompat>(PREF_VOLUME)!!
}
private val resetPref by lazy {
findPreference<Preference>(PREF_RESET)!!
}
private val appContext: Context
get() = requireContext().applicationContext
private val dolbyController by lazy { DolbyController.getInstance(context) }
private val audioManager by lazy { context.getSystemService(AudioManager::class.java)!! }
private val handler = Handler()
private val switchBar by lazy { findPreference<MainSwitchPreference>(PREF_ENABLE)!! }
private val profilePref by lazy { findPreference<ListPreference>(PREF_PROFILE)!! }
private val presetPref by lazy { findPreference<Preference>(PREF_PRESET)!! }
private val ieqPref by lazy { findPreference<DolbyIeqPreference>(PREF_IEQ)!! }
private val stereoPref by lazy { findPreference<ListPreference>(PREF_STEREO)!! }
private val dialoguePref by lazy { findPreference<ListPreference>(PREF_DIALOGUE)!! }
private val bassPref by lazy { findPreference<SwitchPreferenceCompat>(PREF_BASS)!! }
private val hpVirtPref by lazy { findPreference<SwitchPreferenceCompat>(PREF_HP_VIRTUALIZER)!! }
private val spkVirtPref by lazy { findPreference<SwitchPreferenceCompat>(PREF_SPK_VIRTUALIZER)!! }
private val volumePref by lazy { findPreference<SwitchPreferenceCompat>(PREF_VOLUME)!! }
private val resetPref by lazy { findPreference<Preference>(PREF_RESET)!! }
private val dolbyController by lazy(LazyThreadSafetyMode.NONE) {
DolbyController.getInstance(appContext)
}
private val audioManager by lazy(LazyThreadSafetyMode.NONE) {
appContext.getSystemService(AudioManager::class.java)
}
private val handler = Handler(Looper.getMainLooper())
private var isOnSpeaker = true
set(value) {
@@ -100,26 +85,29 @@ class DolbySettingsFragment : PreferenceFragment(),
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
dlog(TAG, "onCreatePreferences")
addPreferencesFromResource(R.xml.dolby_settings)
setPreferencesFromResource(R.xml.dolby_settings, rootKey)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val profile = dolbyController.profile
preferenceManager.preferenceDataStore = DolbyPreferenceStore(context).also {
preferenceManager.preferenceDataStore = DolbyPreferenceStore(appContext).also {
it.profile = profile
}
val dsOn = dolbyController.dsOn
switchBar.addOnSwitchChangeListener(this)
switchBar.setChecked(dsOn)
switchBar.isChecked = dsOn
profilePref.onPreferenceChangeListener = this
updateProfileIcon(profile)
profilePref.setEnabled(dsOn)
profilePref.isEnabled = dsOn
profilePref.apply {
if (entryValues.contains(profile.toString())) {
summary = "%s"
value = profile.toString()
} else {
summary = context.getString(R.string.dolby_unknown)
summary = getString(R.string.dolby_unknown)
}
}
@@ -135,21 +123,21 @@ class DolbySettingsFragment : PreferenceFragment(),
dolbyController.resetProfileSpecificSettings()
updateProfileSpecificPrefs()
Toast.makeText(
context,
context.getString(R.string.dolby_reset_profile_toast, profilePref.summary),
appContext,
getString(R.string.dolby_reset_profile_toast, profilePref.summary),
Toast.LENGTH_SHORT
).show()
true
}
audioManager.registerAudioDeviceCallback(audioDeviceCallback, handler)
audioManager?.registerAudioDeviceCallback(audioDeviceCallback, handler)
updateSpeakerState()
updateProfileSpecificPrefs()
}
override fun onDestroyView() {
dlog(TAG, "onDestroyView")
audioManager.unregisterAudioDeviceCallback(audioDeviceCallback)
audioManager?.unregisterAudioDeviceCallback(audioDeviceCallback)
super.onDestroyView()
}
@@ -168,35 +156,13 @@ class DolbySettingsFragment : PreferenceFragment(),
updateProfileIcon(profile)
updateProfileSpecificPrefs()
}
PREF_SPK_VIRTUALIZER -> {
dolbyController.setSpeakerVirtEnabled(newValue as Boolean)
}
PREF_HP_VIRTUALIZER -> {
dolbyController.setHeadphoneVirtEnabled(newValue as Boolean)
}
PREF_STEREO -> {
dolbyController.setStereoWideningAmount(newValue.toString().toInt())
}
PREF_DIALOGUE -> {
dolbyController.setDialogueEnhancerAmount(newValue.toString().toInt())
}
PREF_BASS -> {
dolbyController.setBassEnhancerEnabled(newValue as Boolean)
}
PREF_VOLUME -> {
dolbyController.setVolumeLevelerEnabled(newValue as Boolean)
}
PREF_IEQ -> {
dolbyController.setIeqPreset(newValue.toString().toInt())
}
PREF_SPK_VIRTUALIZER -> dolbyController.setSpeakerVirtEnabled(newValue as Boolean)
PREF_HP_VIRTUALIZER -> dolbyController.setHeadphoneVirtEnabled(newValue as Boolean)
PREF_STEREO -> dolbyController.setStereoWideningAmount(newValue.toString().toInt())
PREF_DIALOGUE -> dolbyController.setDialogueEnhancerAmount(newValue.toString().toInt())
PREF_BASS -> dolbyController.setBassEnhancerEnabled(newValue as Boolean)
PREF_VOLUME -> dolbyController.setVolumeLevelerEnabled(newValue as Boolean)
PREF_IEQ -> dolbyController.setIeqPreset(newValue.toString().toInt())
else -> return false
}
return true
@@ -205,18 +171,21 @@ class DolbySettingsFragment : PreferenceFragment(),
override fun onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean) {
dlog(TAG, "onCheckedChanged($isChecked)")
dolbyController.dsOn = isChecked
profilePref.setEnabled(isChecked)
profilePref.isEnabled = isChecked
updateProfileSpecificPrefs()
}
private fun updateSpeakerState() {
val device = audioManager.getDevicesForAttributes(ATTRIBUTES_MEDIA)[0]
isOnSpeaker = (device.type == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER)
val devices = audioManager
?.getDevicesForAttributes(ATTRIBUTES_MEDIA)
.orEmpty()
val firstType = devices.firstOrNull()?.type
isOnSpeaker = (firstType == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER)
}
private fun updateProfileSpecificPrefs() {
val unknownRes = context.getString(R.string.dolby_unknown)
val headphoneRes = context.getString(R.string.dolby_connect_headphones)
val unknownRes = getString(R.string.dolby_unknown)
val headphoneRes = getString(R.string.dolby_connect_headphones)
val dsOn = dolbyController.dsOn
val currentProfile = dolbyController.profile
@@ -226,15 +195,15 @@ class DolbySettingsFragment : PreferenceFragment(),
)
val enable = dsOn && (currentProfile != -1)
presetPref.setEnabled(enable)
spkVirtPref.setEnabled(enable)
ieqPref.setEnabled(enable)
dialoguePref.setEnabled(enable)
volumePref.setEnabled(enable)
bassPref.setEnabled(enable)
resetPref.setEnabled(enable)
hpVirtPref.setEnabled(enable && !isOnSpeaker)
stereoPref.setEnabled(enable && !isOnSpeaker)
presetPref.isEnabled = enable
spkVirtPref.isEnabled = enable
ieqPref.isEnabled = enable
dialoguePref.isEnabled = enable
volumePref.isEnabled = enable
bassPref.isEnabled = enable
resetPref.isEnabled = enable
hpVirtPref.isEnabled = enable && !isOnSpeaker
stereoPref.isEnabled = enable && !isOnSpeaker
if (!enable) return
@@ -260,9 +229,9 @@ class DolbySettingsFragment : PreferenceFragment(),
}
}
spkVirtPref.setChecked(dolbyController.getSpeakerVirtEnabled(currentProfile))
volumePref.setChecked(dolbyController.getVolumeLevelerEnabled(currentProfile))
bassPref.setChecked(dolbyController.getBassEnhancerEnabled(currentProfile))
spkVirtPref.isChecked = dolbyController.getSpeakerVirtEnabled(currentProfile)
volumePref.isChecked = dolbyController.getVolumeLevelerEnabled(currentProfile)
bassPref.isChecked = dolbyController.getBassEnhancerEnabled(currentProfile)
// below prefs are not enabled on loudspeaker
if (isOnSpeaker) {
@@ -282,7 +251,7 @@ class DolbySettingsFragment : PreferenceFragment(),
}
hpVirtPref.apply {
setChecked(dolbyController.getHeadphoneVirtEnabled(currentProfile))
isChecked = dolbyController.getHeadphoneVirtEnabled(currentProfile)
summary = null
}
}