1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 03:16:51 +01:00

Pebble: allow to configure reconnect attempts

This should help #89
This commit is contained in:
Andreas Shimokawa 2015-09-17 15:30:33 +02:00
parent 7dedff3ce1
commit 58bbcb0035
4 changed files with 15 additions and 9 deletions

View File

@ -97,6 +97,7 @@ public class SettingsActivity extends AbstractSettingsActivity {
final ListPreference audioPlayer = (ListPreference) findPreference("audio_player");
audioPlayer.setEntries(newEntries);
audioPlayer.setEntryValues(newValues);
audioPlayer.setDefaultValue(newValues[0]);
}
@Override
@ -107,6 +108,7 @@ public class SettingsActivity extends AbstractSettingsActivity {
"notification_mode_k9mail",
"pebble_emu_addr",
"pebble_emu_port",
"pebble_reconnect_attempts",
};
}

View File

@ -56,6 +56,8 @@ public class PebbleIoThread extends GBDeviceIoThread {
public static final String PEBBLEKIT_ACTION_APP_START = "com.getpebble.action.app.START";
public static final String PEBBLEKIT_ACTION_APP_STOP = "com.getpebble.action.app.STOP";
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
private final PebbleProtocol mPebbleProtocol;
private final PebbleSupport mPebbleSupport;
private boolean mIsTCP = false;
@ -67,7 +69,6 @@ public class PebbleIoThread extends GBDeviceIoThread {
private boolean mQuit = false;
private boolean mIsConnected = false;
private boolean mIsInstalling = false;
private int mConnectionAttempts = 0;
private PBWReader mPBWReader = null;
private int mAppInstallToken = -1;
@ -148,7 +149,6 @@ public class PebbleIoThread extends GBDeviceIoThread {
return false;
}
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
mPebbleProtocol.setForceProtocol(sharedPrefs.getBoolean("pebble_force_protocol", false));
gbDevice.setState(GBDevice.State.CONNECTED);
gbDevice.sendDeviceUpdateIntent(getContext());
@ -311,13 +311,13 @@ public class PebbleIoThread extends GBDeviceIoThread {
gbDevice.setState(GBDevice.State.CONNECTING);
gbDevice.sendDeviceUpdateIntent(getContext());
while (mConnectionAttempts++ < 10 && !mQuit) {
LOG.info("Trying to reconnect (attempt " + mConnectionAttempts + ")");
int reconnectAttempts = Integer.valueOf(sharedPrefs.getString("pebble_reconnect_attempts", "10"));
while (reconnectAttempts-- > 0 && !mQuit) {
LOG.info("Trying to reconnect (attempts left " + reconnectAttempts + ")");
mIsConnected = connect(gbDevice.getAddress());
if (mIsConnected)
break;
}
mConnectionAttempts = 0;
if (!mIsConnected) {
mBtSocket = null;
LOG.info("Bluetooth socket closed, will quit IO Thread");
@ -341,7 +341,6 @@ public class PebbleIoThread extends GBDeviceIoThread {
}
private void enablePebbleKitReceiver(boolean enable) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean force_untested = sharedPrefs.getBoolean("pebble_force_untested", false);
if (enable && force_untested) {
@ -403,7 +402,6 @@ public class PebbleIoThread extends GBDeviceIoThread {
private boolean evaluateGBDeviceEventPebble(GBDeviceEvent deviceEvent) {
if (deviceEvent instanceof GBDeviceEventVersionInfo) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
if (sharedPrefs.getBoolean("datetime_synconconnect", true)) {
LOG.info("syncing time");
write(mPebbleProtocol.encodeSetTime());

View File

@ -34,7 +34,7 @@
<string name="pref_header_general">General Settings</string>
<string name="pref_title_general_autoconnectonbluetooth">Connect to device when Bluetooth turned on</string>
<string name="pref_title_audo_player">Preferred audio player</string>
<string name="pref_default">default</string>
<string name="pref_default">Default</string>
<string name="pref_header_datetime">Date and Time</string>
<string name="pref_title_datetime_syctimeonconnect">Sync time</string>
<string name="pref_summary_datetime_syctimeonconnect">Sync time to device when connecting and when time or timezone changes on Android</string>
@ -63,7 +63,7 @@
<string name="pref_summary_pebble_forceprotocol">This option forces using the latest notification protocol depending on the firmware version. ENABLE ONLY IF YOU KNOW WHAT YOU ARE DOING!</string>
<string name="pref_title_pebble_forceuntested">Enable untested features</string>
<string name="pref_summary_pebble_forceuntested">Enable features that are untested. ENABLE ONLY IF YOU KNOW WHAT YOU ARE DOING!</string>
<string name="pref_title_pebble_reconnect_attempts">Reconnect attempts</string>
<string name="not_connected">not connected</string>
<string name="connecting">connecting</string>
<string name="connected">connected</string>

View File

@ -84,6 +84,12 @@
android:key="pebble_force_untested"
android:summary="@string/pref_summary_pebble_forceuntested"
android:title="@string/pref_title_pebble_forceuntested" />
<EditTextPreference
android:inputType="number"
android:key="pebble_reconnect_attempts"
android:defaultValue="12"
android:maxLength="4"
android:title="@string/pref_title_pebble_reconnect_attempts" />
<EditTextPreference
android:digits="0123456789."
android:key="pebble_emu_addr"