1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-14 09:00:04 +02:00
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsSettingsCustomizer.java

283 lines
13 KiB
Java
Raw Normal View History

/* Copyright (C) 2022-2024 narektor, Petr Vaněk
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.galaxy_buds;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_2_NOISE_CONTROL;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_AMBIENT_VOLUME;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_PRO_ANC_LEVEL;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_PRO_BALANCE;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_PRO_NOISE_CONTROL;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_TOUCH_LEFT;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_TOUCH_LEFT_SWITCH;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_TOUCH_RIGHT;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_TOUCH_RIGHT_SWITCH;
import android.os.Parcel;
import androidx.preference.Preference;
import java.util.Collections;
import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsHandler;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class GalaxyBudsSettingsCustomizer implements DeviceSpecificSettingsCustomizer {
final GBDevice device;
public GalaxyBudsSettingsCustomizer(final GBDevice device) {
this.device = device;
}
@Override
public void onPreferenceChange(final Preference preference, final DeviceSpecificSettingsHandler handler) {
}
@Override
public void customizeSettings(final DeviceSpecificSettingsHandler handler, Prefs prefs) {
final Preference pref_galaxy_buds_pro_balance = handler.findPreference(PREF_GALAXY_BUDS_PRO_BALANCE);
if (pref_galaxy_buds_pro_balance != null) {
pref_galaxy_buds_pro_balance.setSummary(String.valueOf((prefs.getInt(PREF_GALAXY_BUDS_PRO_BALANCE, 16) - 16)));
pref_galaxy_buds_pro_balance.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
String newValue = String.valueOf((int) newVal - 16);
pref_galaxy_buds_pro_balance.setSummary(newValue);
handler.notifyPreferenceChanged(PREF_GALAXY_BUDS_PRO_BALANCE);
return true;
}
});
}
final Preference pref_galaxy_buds_pro_noise_control = handler.findPreference(PREF_GALAXY_BUDS_PRO_NOISE_CONTROL);
String pref_galaxy_buds_pro_noise_control_value = prefs.getString(PREF_GALAXY_BUDS_PRO_NOISE_CONTROL, "0");
final Preference pref_galaxy_buds_2_noise_control = handler.findPreference(PREF_GALAXY_BUDS_2_NOISE_CONTROL);
String pref_galaxy_buds_2_noise_control_value = prefs.getString(PREF_GALAXY_BUDS_2_NOISE_CONTROL, "0");
final Preference pref_galaxy_buds_pro_anc_level = handler.findPreference(PREF_GALAXY_BUDS_PRO_ANC_LEVEL);
final Preference pref_galaxy_buds_ambient_volume = handler.findPreference(PREF_GALAXY_BUDS_AMBIENT_VOLUME);
if (pref_galaxy_buds_pro_noise_control != null) {
Galaxy Buds2 Pro support (this time proper) (#3049) Mostly copied from the Buds Pro as those earbuds have a similar feature set and mostly the same protocol. Working: - Pairing - Earbud and case battery level - Finding lost device - Settings: - Noise control: - ANC/ambient/off - With one earbud - Voice detect and timeouts - Ambient sound during calls - Touch options: - Touch lock - Switch noise control, voice assistant, Spotify and volume actions - Double tap edge - Equalizer - Sound balance - Seamless earbud connection Can be improved: - ~~ANC level and ambient sound volume do nothing, and don't seem to be supported on this model as there is no toggle for either in the official app.~~ (fixed: https://codeberg.org/Freeyourgadget/Gadgetbridge/commit/26a9d274aebe6b99515709f2fac6bc66df4c18f7) - Ambient sound customization has more options than on previous models, but I can't implement it properly as I can't really hear any difference between the options (my buds might be the issue though). - ~~The touch lock toggle is once again inverted, like on the [Buds2](https://codeberg.org/Freeyourgadget/Gadgetbridge/commit/d2c4990c48297d46c90c474f50a66f9a04042b68)~~ (fixed: https://codeberg.org/Freeyourgadget/Gadgetbridge/commit/21db5390c1fb7101ea1f38c73c1ecfda08eb189b). Untested: - Settings: - In-ear detection for calls - Ambient sound customization - Game mode This PR also makes some visual changes to the settings of various Galaxy Buds models. I'd also like to be added to the wiki's allow list. I want to add the Buds2 and Buds2 Pro to the list of supported devices. --- And sorry for creating this many pull requests. This is mostly due to Codeberg breaking the reference to the branch. Co-authored-by: Narek <narek.email@gmail.com> Reviewed-on: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/3049 Reviewed-by: José Rebelo <joserebelo@noreply.codeberg.org> Reviewed-by: Andreas Shimokawa <ashimokawa@noreply.codeberg.org> Co-authored-by: narektor <narektor@noreply.codeberg.org> Co-committed-by: narektor <narektor@noreply.codeberg.org>
2023-02-21 15:50:24 +01:00
if (pref_galaxy_buds_pro_anc_level != null && pref_galaxy_buds_ambient_volume != null) {
switch (pref_galaxy_buds_pro_noise_control_value) {
case "0":
pref_galaxy_buds_pro_anc_level.setEnabled(false);
pref_galaxy_buds_ambient_volume.setEnabled(false);
break;
case "1":
pref_galaxy_buds_pro_anc_level.setEnabled(true);
pref_galaxy_buds_ambient_volume.setEnabled(false);
break;
case "2":
pref_galaxy_buds_pro_anc_level.setEnabled(false);
pref_galaxy_buds_ambient_volume.setEnabled(true);
break;
}
}
pref_galaxy_buds_pro_noise_control.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
handler.notifyPreferenceChanged(PREF_GALAXY_BUDS_PRO_NOISE_CONTROL);
switch (newVal.toString()) {
case "0":
Galaxy Buds2 Pro support (this time proper) (#3049) Mostly copied from the Buds Pro as those earbuds have a similar feature set and mostly the same protocol. Working: - Pairing - Earbud and case battery level - Finding lost device - Settings: - Noise control: - ANC/ambient/off - With one earbud - Voice detect and timeouts - Ambient sound during calls - Touch options: - Touch lock - Switch noise control, voice assistant, Spotify and volume actions - Double tap edge - Equalizer - Sound balance - Seamless earbud connection Can be improved: - ~~ANC level and ambient sound volume do nothing, and don't seem to be supported on this model as there is no toggle for either in the official app.~~ (fixed: https://codeberg.org/Freeyourgadget/Gadgetbridge/commit/26a9d274aebe6b99515709f2fac6bc66df4c18f7) - Ambient sound customization has more options than on previous models, but I can't implement it properly as I can't really hear any difference between the options (my buds might be the issue though). - ~~The touch lock toggle is once again inverted, like on the [Buds2](https://codeberg.org/Freeyourgadget/Gadgetbridge/commit/d2c4990c48297d46c90c474f50a66f9a04042b68)~~ (fixed: https://codeberg.org/Freeyourgadget/Gadgetbridge/commit/21db5390c1fb7101ea1f38c73c1ecfda08eb189b). Untested: - Settings: - In-ear detection for calls - Ambient sound customization - Game mode This PR also makes some visual changes to the settings of various Galaxy Buds models. I'd also like to be added to the wiki's allow list. I want to add the Buds2 and Buds2 Pro to the list of supported devices. --- And sorry for creating this many pull requests. This is mostly due to Codeberg breaking the reference to the branch. Co-authored-by: Narek <narek.email@gmail.com> Reviewed-on: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/3049 Reviewed-by: José Rebelo <joserebelo@noreply.codeberg.org> Reviewed-by: Andreas Shimokawa <ashimokawa@noreply.codeberg.org> Co-authored-by: narektor <narektor@noreply.codeberg.org> Co-committed-by: narektor <narektor@noreply.codeberg.org>
2023-02-21 15:50:24 +01:00
if (pref_galaxy_buds_pro_anc_level != null)
pref_galaxy_buds_pro_anc_level.setEnabled(false);
if (pref_galaxy_buds_ambient_volume != null)
pref_galaxy_buds_ambient_volume.setEnabled(false);
break;
case "1":
Galaxy Buds2 Pro support (this time proper) (#3049) Mostly copied from the Buds Pro as those earbuds have a similar feature set and mostly the same protocol. Working: - Pairing - Earbud and case battery level - Finding lost device - Settings: - Noise control: - ANC/ambient/off - With one earbud - Voice detect and timeouts - Ambient sound during calls - Touch options: - Touch lock - Switch noise control, voice assistant, Spotify and volume actions - Double tap edge - Equalizer - Sound balance - Seamless earbud connection Can be improved: - ~~ANC level and ambient sound volume do nothing, and don't seem to be supported on this model as there is no toggle for either in the official app.~~ (fixed: https://codeberg.org/Freeyourgadget/Gadgetbridge/commit/26a9d274aebe6b99515709f2fac6bc66df4c18f7) - Ambient sound customization has more options than on previous models, but I can't implement it properly as I can't really hear any difference between the options (my buds might be the issue though). - ~~The touch lock toggle is once again inverted, like on the [Buds2](https://codeberg.org/Freeyourgadget/Gadgetbridge/commit/d2c4990c48297d46c90c474f50a66f9a04042b68)~~ (fixed: https://codeberg.org/Freeyourgadget/Gadgetbridge/commit/21db5390c1fb7101ea1f38c73c1ecfda08eb189b). Untested: - Settings: - In-ear detection for calls - Ambient sound customization - Game mode This PR also makes some visual changes to the settings of various Galaxy Buds models. I'd also like to be added to the wiki's allow list. I want to add the Buds2 and Buds2 Pro to the list of supported devices. --- And sorry for creating this many pull requests. This is mostly due to Codeberg breaking the reference to the branch. Co-authored-by: Narek <narek.email@gmail.com> Reviewed-on: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/3049 Reviewed-by: José Rebelo <joserebelo@noreply.codeberg.org> Reviewed-by: Andreas Shimokawa <ashimokawa@noreply.codeberg.org> Co-authored-by: narektor <narektor@noreply.codeberg.org> Co-committed-by: narektor <narektor@noreply.codeberg.org>
2023-02-21 15:50:24 +01:00
if (pref_galaxy_buds_pro_anc_level != null)
pref_galaxy_buds_pro_anc_level.setEnabled(true);
if (pref_galaxy_buds_ambient_volume != null)
pref_galaxy_buds_ambient_volume.setEnabled(false);
break;
case "2":
Galaxy Buds2 Pro support (this time proper) (#3049) Mostly copied from the Buds Pro as those earbuds have a similar feature set and mostly the same protocol. Working: - Pairing - Earbud and case battery level - Finding lost device - Settings: - Noise control: - ANC/ambient/off - With one earbud - Voice detect and timeouts - Ambient sound during calls - Touch options: - Touch lock - Switch noise control, voice assistant, Spotify and volume actions - Double tap edge - Equalizer - Sound balance - Seamless earbud connection Can be improved: - ~~ANC level and ambient sound volume do nothing, and don't seem to be supported on this model as there is no toggle for either in the official app.~~ (fixed: https://codeberg.org/Freeyourgadget/Gadgetbridge/commit/26a9d274aebe6b99515709f2fac6bc66df4c18f7) - Ambient sound customization has more options than on previous models, but I can't implement it properly as I can't really hear any difference between the options (my buds might be the issue though). - ~~The touch lock toggle is once again inverted, like on the [Buds2](https://codeberg.org/Freeyourgadget/Gadgetbridge/commit/d2c4990c48297d46c90c474f50a66f9a04042b68)~~ (fixed: https://codeberg.org/Freeyourgadget/Gadgetbridge/commit/21db5390c1fb7101ea1f38c73c1ecfda08eb189b). Untested: - Settings: - In-ear detection for calls - Ambient sound customization - Game mode This PR also makes some visual changes to the settings of various Galaxy Buds models. I'd also like to be added to the wiki's allow list. I want to add the Buds2 and Buds2 Pro to the list of supported devices. --- And sorry for creating this many pull requests. This is mostly due to Codeberg breaking the reference to the branch. Co-authored-by: Narek <narek.email@gmail.com> Reviewed-on: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/3049 Reviewed-by: José Rebelo <joserebelo@noreply.codeberg.org> Reviewed-by: Andreas Shimokawa <ashimokawa@noreply.codeberg.org> Co-authored-by: narektor <narektor@noreply.codeberg.org> Co-committed-by: narektor <narektor@noreply.codeberg.org>
2023-02-21 15:50:24 +01:00
if (pref_galaxy_buds_pro_anc_level != null)
pref_galaxy_buds_pro_anc_level.setEnabled(false);
if (pref_galaxy_buds_ambient_volume != null)
pref_galaxy_buds_ambient_volume.setEnabled(true);
break;
}
return true;
}
});
}
if (pref_galaxy_buds_2_noise_control != null) {
switch (pref_galaxy_buds_2_noise_control_value) {
case "0":
case "1":
pref_galaxy_buds_ambient_volume.setEnabled(false);
break;
case "2":
pref_galaxy_buds_ambient_volume.setEnabled(true);
break;
}
pref_galaxy_buds_2_noise_control.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
handler.notifyPreferenceChanged(PREF_GALAXY_BUDS_2_NOISE_CONTROL);
switch (newVal.toString()) {
case "0":
case "1":
pref_galaxy_buds_ambient_volume.setEnabled(false);
break;
case "2":
pref_galaxy_buds_ambient_volume.setEnabled(true);
break;
}
return true;
}
});
}
final Preference pref_galaxy_buds_touch_right = handler.findPreference(PREF_GALAXY_BUDS_TOUCH_RIGHT);
String pref_galaxy_buds_touch_right_value = prefs.getString(PREF_GALAXY_BUDS_TOUCH_RIGHT, "1");
final Preference pref_galaxy_buds_touch_right_switch = handler.findPreference(PREF_GALAXY_BUDS_TOUCH_RIGHT_SWITCH);
if (pref_galaxy_buds_touch_right != null) {
switch (pref_galaxy_buds_touch_right_value) {
case "2":
pref_galaxy_buds_touch_right_switch.setEnabled(true);
break;
default:
pref_galaxy_buds_touch_right_switch.setEnabled(false);
}
pref_galaxy_buds_touch_right.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
handler.notifyPreferenceChanged(PREF_GALAXY_BUDS_TOUCH_RIGHT);
switch (newVal.toString()) {
case "2":
pref_galaxy_buds_touch_right_switch.setEnabled(true);
break;
default:
pref_galaxy_buds_touch_right_switch.setEnabled(false);
}
return true;
}
});
}
final Preference pref_galaxy_buds_touch_left = handler.findPreference(PREF_GALAXY_BUDS_TOUCH_LEFT);
String pref_galaxy_buds_touch_left_value = prefs.getString(PREF_GALAXY_BUDS_TOUCH_LEFT, "1");
final Preference pref_galaxy_buds_touch_left_switch = handler.findPreference(PREF_GALAXY_BUDS_TOUCH_LEFT_SWITCH);
if (pref_galaxy_buds_touch_left != null) {
switch (pref_galaxy_buds_touch_left_value) {
case "2":
pref_galaxy_buds_touch_left_switch.setEnabled(true);
break;
default:
pref_galaxy_buds_touch_left_switch.setEnabled(false);
}
pref_galaxy_buds_touch_left.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
handler.notifyPreferenceChanged(PREF_GALAXY_BUDS_TOUCH_LEFT);
switch (newVal.toString()) {
case "2":
pref_galaxy_buds_touch_left_switch.setEnabled(true);
break;
default:
pref_galaxy_buds_touch_left_switch.setEnabled(false);
}
return true;
}
});
}
/*
final Preference pref_galaxy_buds_ambient_mode = handler.findPreference(PREF_GALAXY_BUDS_AMBIENT_SOUND);
boolean is_pref_galaxy_buds_ambient_mode_enabled = prefs.getBoolean(PREF_GALAXY_BUDS_AMBIENT_SOUND, false);
final Preference pref_galaxy_buds_ambient_voice_focus_preference = handler.findPreference(PREF_GALAXY_BUDS_AMBIENT_VOICE_FOCUS_PREFERENCE);
if (pref_galaxy_buds_ambient_mode != null) {
if (is_pref_galaxy_buds_ambient_mode_enabled) {
pref_galaxy_buds_ambient_voice_focus_preference.setEnabled(true);
} else {
pref_galaxy_buds_ambient_voice_focus_preference.setEnabled(false);
}
pref_galaxy_buds_ambient_mode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
handler.notifyPreferenceChanged(PREF_GALAXY_BUDS_AMBIENT_SOUND);
if ((boolean) newVal) {
pref_galaxy_buds_ambient_voice_focus_preference.setEnabled(true);
} else {
pref_galaxy_buds_ambient_voice_focus_preference.setEnabled(false);
}
return true;
}
});
}
*/
}
@Override
public Set<String> getPreferenceKeysWithSummary() {
return Collections.emptySet();
}
public static final Creator<GalaxyBudsSettingsCustomizer> CREATOR = new Creator<GalaxyBudsSettingsCustomizer>() {
@Override
public GalaxyBudsSettingsCustomizer createFromParcel(final Parcel in) {
final GBDevice device = in.readParcelable(GalaxyBudsSettingsCustomizer.class.getClassLoader());
return new GalaxyBudsSettingsCustomizer(device);
}
@Override
public GalaxyBudsSettingsCustomizer[] newArray(final int size) {
return new GalaxyBudsSettingsCustomizer[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(final Parcel dest, final int flags) {
dest.writeParcelable(device, 0);
}
}