mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-26 16:41:43 +01:00
Xiaomi: allow forcing the connection type from connection settings
This commit is contained in:
parent
2812ad1429
commit
399248e22c
@ -427,4 +427,5 @@ public class DeviceSettingsPreferenceConst {
|
|||||||
public static final String PREF_DEVICE_ACTION_START_NON_WEAR_BROADCAST = "prefs_events_forwarding_startnonwear_broadcast";
|
public static final String PREF_DEVICE_ACTION_START_NON_WEAR_BROADCAST = "prefs_events_forwarding_startnonwear_broadcast";
|
||||||
public static final String PREF_CLAP_HANDS_TO_WAKEUP_DEVICE = "pref_key_clap_hands_to_wakeup_device";
|
public static final String PREF_CLAP_HANDS_TO_WAKEUP_DEVICE = "pref_key_clap_hands_to_wakeup_device";
|
||||||
public static final String PREF_POWER_SAVING = "pref_key_power_saving";
|
public static final String PREF_POWER_SAVING = "pref_key_power_saving";
|
||||||
|
public static final String PREF_FORCE_CONNECTION_TYPE = "pref_force_connection_type";
|
||||||
}
|
}
|
||||||
|
@ -355,6 +355,20 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] getSupportedDeviceSpecificConnectionSettings() {
|
||||||
|
final List<Integer> settings = new ArrayList<>();
|
||||||
|
|
||||||
|
if (getConnectionType().equals(ConnectionType.BOTH)) {
|
||||||
|
settings.add(R.xml.devicesettings_force_connection_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ArrayUtils.addAll(
|
||||||
|
super.getSupportedDeviceSpecificConnectionSettings(),
|
||||||
|
ArrayUtils.toPrimitive(settings.toArray(new Integer[0]))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getSupportedDeviceSpecificSettings(final GBDevice device) {
|
public int[] getSupportedDeviceSpecificSettings(final GBDevice device) {
|
||||||
final List<Integer> settings = new ArrayList<>();
|
final List<Integer> settings = new ArrayList<>();
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi;
|
||||||
|
|
||||||
|
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_FORCE_CONNECTION_TYPE;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
@ -39,6 +41,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.xiaomi.XiaomiCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.xiaomi.XiaomiCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.xiaomi.XiaomiFWHelper;
|
import nodomain.freeyourgadget.gadgetbridge.devices.xiaomi.XiaomiFWHelper;
|
||||||
@ -115,9 +118,27 @@ public class XiaomiSupport extends AbstractDeviceSupport {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DeviceCoordinator.ConnectionType getForcedConnectionTypeFromPrefs() {
|
||||||
|
final String connTypeAuto = getContext().getString(R.string.pref_force_connection_type_auto_value);
|
||||||
|
String connTypePref = getDevicePrefs().getString(PREF_FORCE_CONNECTION_TYPE, connTypeAuto);
|
||||||
|
|
||||||
|
if (getContext().getString(R.string.pref_force_connection_type_ble_value).equals(connTypePref))
|
||||||
|
return DeviceCoordinator.ConnectionType.BLE;
|
||||||
|
|
||||||
|
if (getContext().getString(R.string.pref_force_connection_type_bt_classic_value).equals(connTypePref))
|
||||||
|
return DeviceCoordinator.ConnectionType.BT_CLASSIC;
|
||||||
|
|
||||||
|
// either set to default, unknown option selected, or has not been set
|
||||||
|
return DeviceCoordinator.ConnectionType.BOTH;
|
||||||
|
}
|
||||||
|
|
||||||
private XiaomiConnectionSupport createConnectionSpecificSupport() {
|
private XiaomiConnectionSupport createConnectionSpecificSupport() {
|
||||||
DeviceCoordinator.ConnectionType connType = getCoordinator().getConnectionType();
|
DeviceCoordinator.ConnectionType connType = getCoordinator().getConnectionType();
|
||||||
|
|
||||||
|
if (connType == DeviceCoordinator.ConnectionType.BOTH) {
|
||||||
|
connType = getForcedConnectionTypeFromPrefs();
|
||||||
|
}
|
||||||
|
|
||||||
switch (connType) {
|
switch (connType) {
|
||||||
case BLE:
|
case BLE:
|
||||||
case BOTH:
|
case BOTH:
|
||||||
|
@ -3581,4 +3581,14 @@
|
|||||||
<item>ignore</item>
|
<item>ignore</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="pref_force_connection_type">
|
||||||
|
<item>@string/pref_force_connection_type_auto</item>
|
||||||
|
<item>@string/pref_force_connection_type_ble</item>
|
||||||
|
<item>@string/pref_force_connection_type_bt_classic</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="pref_force_connection_type_values">
|
||||||
|
<item>@string/pref_force_connection_type_auto_value</item>
|
||||||
|
<item>@string/pref_force_connection_type_ble_value</item>
|
||||||
|
<item>@string/pref_force_connection_type_bt_classic_value</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -2579,4 +2579,12 @@
|
|||||||
<string name="uploadwatchfaceoperation_in_progress">Uploading watchface</string>
|
<string name="uploadwatchfaceoperation_in_progress">Uploading watchface</string>
|
||||||
<string name="uploadwatchfaceoperation_complete">Watchface installation completed</string>
|
<string name="uploadwatchfaceoperation_complete">Watchface installation completed</string>
|
||||||
<string name="uploadwatchfaceoperation_failed">Watchface installation failed</string>
|
<string name="uploadwatchfaceoperation_failed">Watchface installation failed</string>
|
||||||
|
<string name="pref_force_connection_type_title">Force connection type</string>
|
||||||
|
<string name="pref_force_connection_type_description">You may try forcing the connection type in case your device does not respond to Gadgetbridge</string>
|
||||||
|
<string name="pref_force_connection_type_auto">Automatic</string>
|
||||||
|
<string name="pref_force_connection_type_ble">Bluetooth LE</string>
|
||||||
|
<string name="pref_force_connection_type_bt_classic">Bluetooth Classic</string>
|
||||||
|
<string name="pref_force_connection_type_auto_value" translatable="false">BOTH</string>
|
||||||
|
<string name="pref_force_connection_type_ble_value" translatable="false">BLE</string>
|
||||||
|
<string name="pref_force_connection_type_bt_classic_value" translatable="false">BT_CLASSIC</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<ListPreference
|
||||||
|
android:key="pref_force_connection_type"
|
||||||
|
android:icon="@drawable/ic_bluetooth"
|
||||||
|
android:title="@string/pref_force_connection_type_title"
|
||||||
|
android:summary="@string/pref_force_connection_type_description"
|
||||||
|
android:entries="@array/pref_force_connection_type"
|
||||||
|
android:entryValues="@array/pref_force_connection_type_values"
|
||||||
|
android:defaultValue="@string/pref_force_connection_type_auto_value"
|
||||||
|
/>
|
||||||
|
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user