mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 03:16:51 +01:00
Mi Band 1+2: make BT pairing optional
(Attemts to fix #512, #514, #518)
This commit is contained in:
parent
d103d09fcf
commit
4c26c2933b
@ -19,6 +19,7 @@ public final class MiBandConst {
|
||||
public static final String PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS = "mi_device_time_offset_hours";
|
||||
public static final String PREF_MI2_DATEFORMAT = "mi2_dateformat";
|
||||
public static final String PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT = "mi2_activate_display_on_lift_wrist";
|
||||
public static final String PREF_MIBAND_SETUP_BT_PAIRING = "mi_setup_bt_pairing";
|
||||
|
||||
|
||||
public static final String ORIGIN_INCOMING_CALL = "incoming_call";
|
||||
|
@ -159,20 +159,33 @@ public class MiBandPairingActivity extends GBActivity {
|
||||
}
|
||||
|
||||
private void startPairing() {
|
||||
BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macAddress);
|
||||
if (device == null) {
|
||||
GB.toast(this, "No such Bluetooth Device: " + macAddress, Toast.LENGTH_LONG, GB.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
isPairing = true;
|
||||
message.setText(getString(R.string.pairing, macAddress));
|
||||
|
||||
if (!shouldSetupBTLevelPairing()) {
|
||||
// there are connection problems on certain Galaxy S devices at least;
|
||||
// try to connect without BT pairing (bonding)
|
||||
attemptToConnect();
|
||||
return;
|
||||
}
|
||||
|
||||
IntentFilter filter = new IntentFilter(GBDevice.ACTION_DEVICE_CHANGED);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mPairingReceiver, filter);
|
||||
filter = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
|
||||
registerReceiver(mBondingReceiver, filter);
|
||||
|
||||
BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macAddress);
|
||||
if (device != null) {
|
||||
performBluetoothPair(device);
|
||||
} else {
|
||||
GB.toast(this, "No such Bluetooth Device: " + macAddress, Toast.LENGTH_LONG, GB.ERROR);
|
||||
}
|
||||
performBluetoothPair(device);
|
||||
}
|
||||
|
||||
private boolean shouldSetupBTLevelPairing() {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
return prefs.getPreferences().getBoolean(MiBandConst.PREF_MIBAND_SETUP_BT_PAIRING, true);
|
||||
}
|
||||
|
||||
private void pairingFinished(boolean pairedSuccessfully, String macAddress) {
|
||||
|
@ -25,6 +25,7 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PR
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_FITNESS_GOAL;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_SETUP_BT_PAIRING;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_USER_ALIAS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefKey;
|
||||
|
@ -380,4 +380,6 @@
|
||||
<string name="pebble_pairing_hint">A pairing dialog is expected to pop up on your Android device. If that does not happen, look in the notification drawer and accept the pairing request. After that accept the pairing request on your Pebble</string>
|
||||
|
||||
<string name="weather_notification_label">Make sure that this skin is enabled in the Weather Notification app to get weather information on your Pebble.\n\nNo configuration is needed here.\n\nYou can enable the system weather app of your Pebble from the app management.\n\nSupported watchfaces will show the weather automatically.</string>
|
||||
<string name="pref_title_setup_bt_pairing">Enable Bluetooth pairing</string>
|
||||
<string name="pref_summary_setup_bt_pairing">Deactivate this if you have trouble connecting</string>
|
||||
</resources>
|
||||
|
@ -275,6 +275,11 @@
|
||||
<PreferenceCategory
|
||||
android:key="pref_key_development"
|
||||
android:title="@string/pref_header_development">
|
||||
<CheckBoxPreference
|
||||
android:key="mi_setup_bt_pairing"
|
||||
android:title="@string/pref_title_setup_bt_pairing"
|
||||
android:summary="@string/pref_summary_setup_bt_pairing"
|
||||
android:defaultValue="true" />
|
||||
<EditTextPreference
|
||||
android:digits="0123456789ABCDEF:"
|
||||
android:key="development_miaddr"
|
||||
|
Loading…
Reference in New Issue
Block a user