1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-27 11:05:49 +01:00

Sony WH-1000XM3: Disable equalizer, surround and sound position while in SBC codec

This commit is contained in:
José Rebelo 2022-01-14 00:31:58 +00:00
parent 1de2c32705
commit 83c42ebef8
11 changed files with 101 additions and 9 deletions

View File

@ -123,6 +123,7 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_SONY_AMBIENT_SOUND_LEVEL = "pref_sony_ambient_sound_level"; public static final String PREF_SONY_AMBIENT_SOUND_LEVEL = "pref_sony_ambient_sound_level";
public static final String PREF_SONY_SOUND_POSITION = "pref_sony_sound_position"; public static final String PREF_SONY_SOUND_POSITION = "pref_sony_sound_position";
public static final String PREF_SONY_SURROUND_MODE = "pref_sony_surround_mode"; public static final String PREF_SONY_SURROUND_MODE = "pref_sony_surround_mode";
public static final String PREF_SONY_EQUALIZER = "pref_sony_equalizer";
public static final String PREF_SONY_EQUALIZER_MODE = "pref_sony_equalizer_mode"; public static final String PREF_SONY_EQUALIZER_MODE = "pref_sony_equalizer_mode";
public static final String PREF_SONY_AUDIO_UPSAMPLING = "pref_sony_audio_upsampling"; public static final String PREF_SONY_AUDIO_UPSAMPLING = "pref_sony_audio_upsampling";
public static final String PREF_SONY_EQUALIZER_BAND_400 = "pref_sony_equalizer_band_400"; public static final String PREF_SONY_EQUALIZER_BAND_400 = "pref_sony_equalizer_band_400";

View File

@ -18,11 +18,21 @@ package nodomain.freeyourgadget.gadgetbridge.activities.devicesettings;
import android.os.Parcelable; import android.os.Parcelable;
import androidx.preference.Preference;
/** /**
* A device-specific preference handler, that allows for concrete implementations to customize the preferences in * A device-specific preference handler, that allows for concrete implementations to customize the preferences in
* the {@link DeviceSpecificSettingsFragment}. * the {@link DeviceSpecificSettingsFragment}.
*/ */
public interface DeviceSpecificSettingsCustomizer extends Parcelable { public interface DeviceSpecificSettingsCustomizer extends Parcelable {
/**
* Called when a {@link Preference} changes, not caused by user input (so the preference change listener is not called).
*
* @param preference the {@link Preference} preference that changed
* @param handler the {@link DeviceSpecificSettingsHandler}
*/
void onPreferenceChange(final Preference preference, final DeviceSpecificSettingsHandler handler);
/** /**
* Customize the settings on the {@link DeviceSpecificSettingsFragment}. * Customize the settings on the {@link DeviceSpecificSettingsFragment}.
* *

View File

@ -869,7 +869,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
final Preference preference = findPreference(key); final Preference preference = findPreference(key);
if (preference == null) { if (preference == null) {
LOG.warn("Preference {} not found, ignoring", key); LOG.warn("Preference {} not found", key);
return; return;
} }
@ -883,11 +883,18 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
} else if (preference instanceof ListPreference) { } else if (preference instanceof ListPreference) {
final ListPreference listPreference = (ListPreference) preference; final ListPreference listPreference = (ListPreference) preference;
listPreference.setValue(prefs.getString(key, listPreference.getValue())); listPreference.setValue(prefs.getString(key, listPreference.getValue()));
} else if (preference instanceof EditTextPreference) {
final EditTextPreference editTextPreference = (EditTextPreference) preference;
editTextPreference.setText(prefs.getString(key, editTextPreference.getText()));
} else if (preference instanceof PreferenceScreen) { } else if (preference instanceof PreferenceScreen) {
// Ignoring // Ignoring
} else { } else {
LOG.warn("Unknown preference class {}, ignoring", preference.getClass()); LOG.warn("Unknown preference class {}, ignoring", preference.getClass());
} }
if (deviceSpecificSettingsCustomizer != null) {
deviceSpecificSettingsCustomizer.onPreferenceChange(preference, DeviceSpecificSettingsFragment.this);
}
} }
} }
} }

View File

@ -41,7 +41,7 @@ public abstract class SonyHeadphonesCoordinator extends AbstractDeviceCoordinato
@Override @Override
public DeviceSpecificSettingsCustomizer getDeviceSpecificSettingsCustomizer(final GBDevice device) { public DeviceSpecificSettingsCustomizer getDeviceSpecificSettingsCustomizer(final GBDevice device) {
return new SonyHeadphonesSettingsCustomizer(); return new SonyHeadphonesSettingsCustomizer(device);
} }
@Override @Override

View File

@ -18,20 +18,70 @@ package nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_AMBIENT_SOUND_CONTROL; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_AMBIENT_SOUND_CONTROL;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_AMBIENT_SOUND_LEVEL; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_AMBIENT_SOUND_LEVEL;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_AUDIO_CODEC;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_1000;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_16000;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_2500;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_400;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BAND_6300;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_BASS;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_EQUALIZER_MODE;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_FOCUS_VOICE; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_FOCUS_VOICE;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_SOUND_POSITION;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SONY_SURROUND_MODE;
import android.os.Parcel; import android.os.Parcel;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import androidx.preference.Preference; import androidx.preference.Preference;
import java.util.Arrays;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsHandler; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AmbientSoundControl; import nodomain.freeyourgadget.gadgetbridge.devices.sony.headphones.prefs.AmbientSoundControl;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
public class SonyHeadphonesSettingsCustomizer implements DeviceSpecificSettingsCustomizer { public class SonyHeadphonesSettingsCustomizer implements DeviceSpecificSettingsCustomizer {
final GBDevice device;
public SonyHeadphonesSettingsCustomizer(final GBDevice device) {
this.device = device;
}
@Override
public void onPreferenceChange(final Preference preference, final DeviceSpecificSettingsHandler handler) {
// Disable equalizer, sound position and surround mode if not in SBC codec, for WH-1000XM3
// TODO: Should the coordinator be responsible for this compatibility check?
if (preference.getKey().equals(PREF_SONY_AUDIO_CODEC) && device.getType().equals(DeviceType.SONY_WH_1000XM3)) {
final boolean isSbcCodec = ((EditTextPreference) preference).getText().equalsIgnoreCase("sbc");
final List<Preference> prefsToDisable = Arrays.asList(
handler.findPreference(PREF_SONY_EQUALIZER),
handler.findPreference(PREF_SONY_EQUALIZER_MODE),
handler.findPreference(PREF_SONY_EQUALIZER_BAND_400),
handler.findPreference(PREF_SONY_EQUALIZER_BAND_1000),
handler.findPreference(PREF_SONY_EQUALIZER_BAND_2500),
handler.findPreference(PREF_SONY_EQUALIZER_BAND_6300),
handler.findPreference(PREF_SONY_EQUALIZER_BAND_16000),
handler.findPreference(PREF_SONY_EQUALIZER_BASS),
handler.findPreference(PREF_SONY_SOUND_POSITION),
handler.findPreference(PREF_SONY_SURROUND_MODE)
);
for (Preference pref : prefsToDisable) {
if (pref != null) {
pref.setEnabled(isSbcCodec);
}
}
}
}
@Override @Override
public void customizeSettings(final DeviceSpecificSettingsHandler handler) { public void customizeSettings(final DeviceSpecificSettingsHandler handler) {
// Only enable the focus on voice check and voice level slider if the ambient sound control mode is ambient sound // Only enable the focus on voice check and voice level slider if the ambient sound control mode is ambient sound
@ -59,7 +109,8 @@ public class SonyHeadphonesSettingsCustomizer implements DeviceSpecificSettingsC
public static final Creator<SonyHeadphonesSettingsCustomizer> CREATOR = new Creator<SonyHeadphonesSettingsCustomizer>() { public static final Creator<SonyHeadphonesSettingsCustomizer> CREATOR = new Creator<SonyHeadphonesSettingsCustomizer>() {
@Override @Override
public SonyHeadphonesSettingsCustomizer createFromParcel(final Parcel in) { public SonyHeadphonesSettingsCustomizer createFromParcel(final Parcel in) {
return new SonyHeadphonesSettingsCustomizer(); final GBDevice device = in.readParcelable(SonyHeadphonesSettingsCustomizer.class.getClassLoader());
return new SonyHeadphonesSettingsCustomizer(device);
} }
@Override @Override
@ -75,6 +126,6 @@ public class SonyHeadphonesSettingsCustomizer implements DeviceSpecificSettingsC
@Override @Override
public void writeToParcel(final Parcel dest, final int flags) { public void writeToParcel(final Parcel dest, final int flags) {
// Nothing to do dest.writeParcelable(device, 0);
} }
} }

View File

@ -70,7 +70,8 @@ public class SonyWFSP800NCoordinator extends SonyHeadphonesCoordinator {
R.xml.devicesettings_sony_headphones_button_modes_left_right, R.xml.devicesettings_sony_headphones_button_modes_left_right,
R.xml.devicesettings_sony_headphones_pause_when_taken_off, R.xml.devicesettings_sony_headphones_pause_when_taken_off,
R.xml.devicesettings_automatic_power_off_when_taken_off, R.xml.devicesettings_automatic_power_off_when_taken_off,
R.xml.devicesettings_sony_headphones_notifications_voice_guide R.xml.devicesettings_sony_headphones_notifications_voice_guide,
R.xml.devicesettings_sony_headphones_device_info
}; };
} }
} }

View File

@ -43,9 +43,9 @@ public class SonyWH1000XM3Coordinator extends SonyHeadphonesCoordinator {
@Override @Override
public int[] getSupportedDeviceSpecificSettings(final GBDevice device) { public int[] getSupportedDeviceSpecificSettings(final GBDevice device) {
return new int[]{ return new int[]{
R.xml.devicesettings_sony_warning_wh1000xm3,
R.xml.devicesettings_sony_headphones_ambient_sound_control_wind_noise_reduction, R.xml.devicesettings_sony_headphones_ambient_sound_control_wind_noise_reduction,
R.xml.devicesettings_header_other, R.xml.devicesettings_header_other,
R.xml.devicesettings_sony_warning_wh1000xm3,
R.xml.devicesettings_sony_headphones_equalizer, R.xml.devicesettings_sony_headphones_equalizer,
R.xml.devicesettings_sony_headphones_sound_position, R.xml.devicesettings_sony_headphones_sound_position,
R.xml.devicesettings_sony_headphones_surround_mode, R.xml.devicesettings_sony_headphones_surround_mode,
@ -53,7 +53,8 @@ public class SonyWH1000XM3Coordinator extends SonyHeadphonesCoordinator {
R.xml.devicesettings_header_system, R.xml.devicesettings_header_system,
R.xml.devicesettings_sony_headphones_touch_sensor_single, R.xml.devicesettings_sony_headphones_touch_sensor_single,
R.xml.devicesettings_automatic_power_off_by_time, R.xml.devicesettings_automatic_power_off_by_time,
R.xml.devicesettings_sony_headphones_notifications_voice_guide R.xml.devicesettings_sony_headphones_notifications_voice_guide,
R.xml.devicesettings_sony_headphones_device_info
}; };
} }
} }

View File

@ -54,7 +54,8 @@ public class SonyWH1000XM4Coordinator extends SonyHeadphonesCoordinator {
R.xml.devicesettings_sony_headphones_touch_sensor_single, R.xml.devicesettings_sony_headphones_touch_sensor_single,
R.xml.devicesettings_sony_headphones_pause_when_taken_off, R.xml.devicesettings_sony_headphones_pause_when_taken_off,
R.xml.devicesettings_automatic_power_off_when_taken_off, R.xml.devicesettings_automatic_power_off_when_taken_off,
R.xml.devicesettings_sony_headphones_notifications_voice_guide R.xml.devicesettings_sony_headphones_notifications_voice_guide,
R.xml.devicesettings_sony_headphones_device_info
}; };
} }
} }

View File

@ -1383,7 +1383,9 @@
<string name="battery_case">Battery case</string> <string name="battery_case">Battery case</string>
<string name="left_earbud">Left earbud</string> <string name="left_earbud">Left earbud</string>
<string name="right_earbud">Right earbud</string> <string name="right_earbud">Right earbud</string>
<string name="audio_codec">Audio Codec</string>
<string name="pref_header_sony_ambient_sound_control">Ambient Sound Control</string> <string name="pref_header_sony_ambient_sound_control">Ambient Sound Control</string>
<string name="pref_header_sony_device_info">Device Information</string>
<string name="sony_ambient_sound">Mode</string> <string name="sony_ambient_sound">Mode</string>
<string name="sony_ambient_sound_off">Off</string> <string name="sony_ambient_sound_off">Off</string>
<string name="sony_ambient_sound_noise_cancelling">Noise Cancelling</string> <string name="sony_ambient_sound_noise_cancelling">Noise Cancelling</string>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:key="pref_key_header_sony_device_info"
android:title="@string/pref_header_sony_device_info">
<EditTextPreference
android:defaultValue="\?"
android:enabled="false"
android:icon="@drawable/ic_music_note"
android:key="pref_sony_audio_codec"
android:shouldDisableView="false"
android:title="@string/audio_codec"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
</androidx.preference.PreferenceScreen>

View File

@ -3,7 +3,7 @@
<PreferenceScreen <PreferenceScreen
android:icon="@drawable/ic_graphic_eq" android:icon="@drawable/ic_graphic_eq"
android:key="pref_key_equalizer" android:key="pref_sony_equalizer"
android:persistent="false" android:persistent="false"
android:title="@string/pref_header_equalizer"> android:title="@string/pref_header_equalizer">